/* Responsive browser layout. Desktop and Electron layouts remain unchanged. */
.sp-mobile-topbar,
.sp-mobile-overlay,
.sp-mobile-close {
  display: none;
}

/* 견적 품목 보기 버튼: PC와 모바일 공통 */
.sp-quote-items-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-bottom: 10px;
  color: #86868b;
  font-size: 12px;
}

.sp-quote-items-toggle {
  min-height: 34px;
  padding: 0 14px;
  border: none;
  border-radius: 8px;
  background: #f0f0f2;
  color: #6e6e73;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.sp-quote-items-toggle.is-active {
  background: #ffffff;
  color: #1d1d1f;
  box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04);
}

@media (max-width: 760px) {
  html,
  body,
  #root {
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    overflow: hidden;
  }

  .sp-app {
    display: block !important;
    width: 100% !important;
    overflow: hidden !important;
  }

  .sp-main {
    width: 100% !important;
    height: 100dvh !important;
    padding: calc(72px + env(safe-area-inset-top)) 12px calc(24px + env(safe-area-inset-bottom)) !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }

  .sp-sidebar {
    position: fixed !important;
    z-index: 9300;
    inset: 0 auto 0 0 !important;
    width: min(84vw, 320px) !important;
    height: 100dvh !important;
    padding: calc(20px + env(safe-area-inset-top)) 12px calc(18px + env(safe-area-inset-bottom)) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-x: hidden;
    overflow-y: auto;
    border-right: 1px solid rgba(128, 128, 128, 0.22) !important;
    box-shadow: 14px 0 42px rgba(0, 0, 0, 0.18);
    transform: translateX(-105%);
    transition: transform 220ms ease;
  }

  .sp-mobile-nav-open .sp-sidebar {
    transform: translateX(0);
  }

  .sp-mobile-topbar {
    position: fixed;
    z-index: 9100;
    inset: 0 0 auto 0;
    height: calc(60px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 14px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 5px 18px rgba(0, 0, 0, 0.07);
  }

  .sp-mobile-brand {
    display: flex;
    align-items: center;
    gap: 9px;
  }

  .sp-mobile-brand img {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    object-fit: cover;
    box-shadow: 0 3px 10px rgba(11, 31, 58, 0.16);
  }

  .sp-mobile-brand strong,
  .sp-mobile-brand small {
    display: block;
  }

  .sp-mobile-brand strong {
    font-size: 16px;
    line-height: 1.1;
  }

  .sp-mobile-brand small {
    margin-top: 3px;
    font-size: 10px;
  }

  .sp-mobile-menu-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    padding: 0;
    border-radius: 12px;
    cursor: pointer;
  }

  .sp-mobile-overlay {
    position: fixed;
    z-index: 9200;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(15, 18, 24, 0.46);
    opacity: 0;
    pointer-events: none;
    transition: opacity 220ms ease;
  }

  .sp-mobile-nav-open .sp-mobile-overlay {
    display: block;
    opacity: 1;
    pointer-events: auto;
  }

  .sp-mobile-close {
    position: absolute;
    z-index: 2;
    top: calc(12px + env(safe-area-inset-top));
    right: 10px;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #86868b;
    font-size: 25px;
    cursor: pointer;
  }

  .sp-sidebar .sp-nav {
    min-height: 300px;
  }

  .sp-sidebar > .web-logout {
    display: block;
    width: 100%;
    flex: 0 0 auto;
    margin-bottom: 8px;
  }

  .sp-card {
    min-width: 0 !important;
    padding: 14px !important;
    border-radius: 12px !important;
  }

  .sp-page-header {
    padding: 14px !important;
    margin-bottom: 12px !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .sp-page-header > div:last-child {
    width: 100%;
  }

  .sp-settings-layout {
    min-width: 0 !important;
    flex-direction: column !important;
    gap: 12px !important;
  }

  .sp-settings-nav {
    width: 100% !important;
    flex-direction: row !important;
    gap: 4px !important;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: none;
  }

  .sp-settings-nav::-webkit-scrollbar {
    display: none;
  }

  .sp-settings-nav > button {
    flex: 0 0 auto;
    min-height: 42px;
    white-space: nowrap;
  }

  .sp-settings-content {
    width: 100% !important;
  }

  .sp-community-grid,
  .sp-main [style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .sp-main [style*="width: 380px"],
  .sp-main [style*="width: 860px"],
  .sp-main [style*="min-width: 420px"] {
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
  }

  .sp-main input,
  .sp-main select,
  .sp-main textarea {
    max-width: 100% !important;
    min-width: 0 !important;
    min-height: 42px;
    font-size: 16px !important;
  }

  .sp-main button {
    max-width: 100%;
    min-height: 40px;
    touch-action: manipulation;
  }

  .sp-main table {
    min-width: 720px;
  }

  /* 견적 품목표는 모바일에서 가로로 잘리지 않도록 품목별 카드로 전환 */
  .sp-main table.sp-quote-items-table {
    min-width: 0;
    display: block;
  }

  .sp-main table.sp-quote-items-table thead {
    display: none;
  }

  .sp-main table.sp-quote-items-table tbody,
  .sp-main table.sp-quote-items-table tr,
  .sp-main table.sp-quote-items-table td {
    display: block;
    width: 100%;
    box-sizing: border-box;
  }

  .sp-main table.sp-quote-items-table tr {
    margin-bottom: 12px;
    padding: 10px;
    border: 1px solid rgba(128, 128, 128, 0.22);
    border-radius: 12px;
    background: rgba(128, 128, 128, 0.045);
  }

  .sp-main table.sp-quote-items-table td {
    display: grid;
    grid-template-columns: 82px minmax(0, 1fr);
    align-items: center;
    gap: 4px;
    padding: 5px 0 !important;
    text-align: left !important;
    border: 0;
  }

  .sp-main table.sp-quote-items-table td::before {
    color: #86868b;
    font-size: 12px;
    font-weight: 600;
  }

  .sp-main table.sp-quote-items-table td:nth-child(1)::before { content: "품목명"; }
  .sp-main table.sp-quote-items-table td:nth-child(2)::before { content: "규격 / 사양"; }
  .sp-main table.sp-quote-items-table td:nth-child(3)::before { content: "수량"; }
  .sp-main table.sp-quote-items-table td:nth-child(4)::before { content: "단위"; }
  .sp-main table.sp-quote-items-table td:nth-child(5)::before { content: "원가(단가)"; }
  .sp-main table.sp-quote-items-table td:nth-child(6)::before { content: "개별마진%"; }
  .sp-main table.sp-quote-items-table td:nth-child(7)::before { content: "판매단가"; }
  .sp-main table.sp-quote-items-table td:nth-child(8)::before { content: "금액"; }
  .sp-main table.sp-quote-items-table td:nth-child(9) {
    display: flex;
    justify-content: flex-end;
    padding-top: 8px !important;
  }

  .sp-main table.sp-quote-items-table td:nth-child(9)::before {
    display: none;
  }

  .sp-quote-items-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-bottom: 10px;
    color: #86868b;
    font-size: 12px;
  }

  .sp-quote-items-toggle {
    min-height: 34px !important;
    padding: 0 14px;
    border: none;
    border-radius: 8px;
    background: #f0f0f2;
    color: #6e6e73;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  }

  .sp-quote-items-toggle.is-active {
    background: #ffffff;
    color: #1d1d1f;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04);
  }

  .sp-quote-full-preview-button { width: auto; }
  .sp-quote-preview {
    position: static !important;
    z-index: auto;
    inset: auto;
    max-height: none !important;
    overflow: hidden !important;
    margin: 12px 0 0 !important;
    background: #fff;
  }
  .sp-quote-preview > div:first-child { position: static; top: auto; z-index: auto; background: #fff; }

  /* 한 줄 보기: 원래 표를 유지하고 가로 스크롤 */
  .sp-main table.sp-quote-items-table.sp-quote-items-table--single {
    display: table;
    min-width: 720px;
  }

  .sp-main table.sp-quote-items-table.sp-quote-items-table--single thead {
    display: table-header-group;
  }

  .sp-main table.sp-quote-items-table.sp-quote-items-table--single tbody {
    display: table-row-group;
  }

  .sp-main table.sp-quote-items-table.sp-quote-items-table--single tr {
    display: table-row;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
  }

  .sp-main table.sp-quote-items-table.sp-quote-items-table--single td {
    display: table-cell;
    width: auto;
    padding: 8px !important;
    text-align: left !important;
    border: 0;
  }

  .sp-main table.sp-quote-items-table.sp-quote-items-table--single td::before {
    display: none;
  }

  .sp-main h1,
  .sp-main h2,
  .sp-main h3 {
    overflow-wrap: anywhere;
  }

  .web-login {
    min-height: 100dvh;
    padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  }

  .web-login-card {
    width: 100% !important;
    max-width: 410px;
    padding: 24px !important;
    border-radius: 16px !important;
  }

  .web-login-card input {
    min-height: 48px;
    font-size: 16px !important;
  }

  .web-login-submit {
    min-height: 48px;
  }
}

@media (max-width: 360px) {
  .sp-main {
    padding-inline: 8px !important;
  }

  .sp-card,
  .sp-page-header {
    padding: 12px !important;
  }

  .web-login-card {
    padding: 20px !important;
  }
}
