:root {
  --bg: #0f1115;
  --surface: #181b22;
  --surface-2: #20242e;
  --text: #e7eaf0;
  --muted: #8b93a3;
  --line: #2a2f3a;
  --accent: #4c8bf5;
  --green: #2ec46b;
  --red: #f0524d;
  --amber: #e0a63c;
  /* 데스크톱 주문 표 컬럼: 스토어 | 상품 | 수취인 | 연락처 | 상태 | 금액 */
  --order-cols: 84px minmax(0, 1fr) 96px 132px 64px 96px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- 상단바 ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 10;
}
.topbar h1 { font-size: 17px; margin: 0; flex: 0 0 auto; }
/* 페이지 탭 (대시보드 ↔ 통계) */
.tabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px; }
.tabs a { color: var(--muted); text-decoration: none; font-size: 13px; padding: 7px 12px;
  border-radius: 8px; min-height: 30px; display: flex; align-items: center; }
.tabs a[aria-current="page"] { background: var(--accent); color: #fff; font-weight: 600; }

.health { display: flex; gap: 6px; margin-left: auto; align-items: center; }
.light { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); box-shadow: 0 0 0 2px rgba(255,255,255,.05); }
.light.green { background: var(--green); box-shadow: 0 0 8px var(--green); }
.light.red   { background: var(--red);   box-shadow: 0 0 8px var(--red); }
.light.unknown { background: var(--muted); }

/* ---------- 레이아웃 (모바일 우선: 세로 적층) ---------- */
main {
  padding: 14px; max-width: 720px; margin: 0 auto;
  display: grid; gap: 14px;
  grid-template-areas: "summary" "stores" "supplier" "orders";
}
#summary        { grid-area: summary; }
#storeBreakdown { grid-area: stores; }
#supplierPanel  { grid-area: supplier; }
#ordersPanel    { grid-area: orders; }

/* 요약 카드: 모바일 = 매출 전폭 + (주문|미확인) 2열 적층 */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-width: 0; }
.card.sales { grid-column: 1 / -1; }
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 24px; font-weight: 700; margin-top: 6px; overflow-wrap: anywhere; }
.card .value.badge { color: var(--amber); }

.store-breakdown { display: flex; gap: 8px; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.store-breakdown span { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; }

/* ---------- 패널 ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 15px; margin: 0; }
.toggle { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

/* 받는 번호 입력 줄 — 모바일에서도 44px 터치 타깃 */
.phone-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.phone-label { color: var(--muted); font-size: 13px; flex: 0 0 auto; }
.phone-input {
  flex: 1; min-width: 0; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; color: var(--text); font-size: 15px; padding: 10px 12px; min-height: 44px;
}
.phone-input::placeholder { color: var(--muted); opacity: .6; }
.btn-compact { flex: 0 0 auto; padding: 10px 14px; }

/* 미발송 주문내역 */
.pending-head { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 8px; }
.check-all { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; cursor: pointer; min-height: 40px; }
.check-all input { width: 20px; height: 20px; accent-color: var(--accent); }
.muted-count { color: var(--muted); font-size: 13px; }
.pending-list { display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pending-item { display: flex; gap: 10px; align-items: flex-start; background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.pending-item:has(.pending-check:checked) { border-color: var(--accent); }
.pending-check { width: 20px; height: 20px; margin-top: 2px; accent-color: var(--accent); flex: 0 0 auto; }
.pi-body { min-width: 0; flex: 1; }
.pi-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.pi-name { font-weight: 600; font-size: 14px; overflow-wrap: anywhere; }
.pi-store { font-size: 11px; color: var(--muted); flex: 0 0 auto; }
.pi-recv { font-size: 13px; color: var(--text); margin-top: 3px; }
.pi-addr { font-size: 12px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }

.preview {
  white-space: pre-wrap; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; font-size: 13px; line-height: 1.55; color: var(--text);
  max-height: 300px; overflow: auto; -webkit-overflow-scrolling: touch;
}
.panel-actions { display: flex; gap: 8px; margin-top: 12px; }

/* 버튼: 터치 타깃 44px 이상, 모바일에선 전폭 */
.btn {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 12px 16px; border-radius: 12px; font-size: 15px; cursor: pointer;
  min-height: 44px; flex: 1;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }

/* ---------- 주문 목록 ---------- */
.orders-table { min-width: 0; }
.orders { display: flex; flex-direction: column; gap: 8px; }
/* 데스크톱 표 헤더 — 모바일에선 숨김 */
.orders-head { display: none; }

/* 주문 행: 모바일 = 3줄 적층 카드 */
.order {
  display: grid; gap: 2px 10px; align-items: center;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "store  amt"
    "prod   prod"
    "meta   meta";
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 12px 14px; min-width: 0;
}
.order.unseen { border-left: 3px solid var(--amber); }
.o-store  { grid-area: store; font-size: 11px; color: var(--muted); }
.o-amt    { grid-area: amt; font-weight: 700; font-size: 15px; text-align: right; white-space: nowrap; }
.o-prod   { grid-area: prod; font-weight: 600; font-size: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.o-meta   { grid-area: meta; color: var(--muted); font-size: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
.o-status { display: none; } /* 모바일: 상태는 o-store 안에 텍스트로 표기 */
.o-receiver, .o-phone { white-space: nowrap; }

.pill { font-size: 10px; padding: 2px 7px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.pill.mushroom { color: var(--green); border-color: var(--green); }
.pill.demo { color: var(--amber); border-color: var(--amber); font-weight: 600; letter-spacing: .02em; }
.pill.status-new { color: var(--accent); border-color: var(--accent); }

.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line); padding: 12px 18px; border-radius: 10px; z-index: 50; }

.empty { color: var(--muted); padding: 8px 2px; }

/* ============================================================
   태블릿 (≥700px): 요약 3열, 버튼은 내용 폭
   ============================================================ */
@media (min-width: 700px) {
  .cards { grid-template-columns: repeat(3, 1fr); }
  .card.sales { grid-column: auto; }
  .btn { flex: 0 0 auto; }
  .panel-actions { justify-content: flex-end; }
}

/* ============================================================
   데스크톱 (≥1024px): 2컬럼(거래처 | 주문표), 주문목록은 표로
   ============================================================ */
@media (min-width: 1024px) {
  main {
    max-width: 1280px; padding: 20px 24px; gap: 16px;
    grid-template-columns: 400px minmax(0, 1fr);
    grid-template-areas:
      "summary  summary"
      "stores   stores"
      "supplier orders";
    align-items: start;
  }
  .topbar { padding: 14px 24px; }
  .topbar h1 { font-size: 18px; }
  #supplierPanel { position: sticky; top: 76px; }
  .preview { max-height: 380px; }
  .card .value { font-size: 26px; }

  /* 주문 목록 → 표 (wrapper가 테두리, rows 컨테이너는 display:contents 로 투명화) */
  .orders-table { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
  .orders { display: contents; }
  .orders-head, .order {
    display: grid; grid-template-columns: var(--order-cols);
    gap: 0 12px; align-items: center;
    padding: 10px 14px;
  }
  .orders-head {
    background: var(--surface); color: var(--muted); font-size: 11px;
    text-transform: uppercase; letter-spacing: .06em;
    border-bottom: 1px solid var(--line);
  }
  .orders-head span:last-child { text-align: right; }
  .order {
    grid-template-areas: none; border: 0; border-radius: 0; background: transparent;
    border-bottom: 1px solid var(--line);
  }
  .order:last-child { border-bottom: 0; }
  .order:hover { background: var(--surface); }
  .order.unseen { border-left: 3px solid var(--amber); padding-left: 11px; }
  .o-store, .o-amt, .o-prod, .o-meta { grid-area: auto; }
  .o-store { font-size: 12px; }
  .o-store .o-status-inline { display: none; } /* 데스크톱은 상태 컬럼이 따로 */
  .o-meta { display: contents; } /* 수취인/연락처를 각자 컬럼으로 승격 */
  .o-receiver { color: var(--text); font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
  .o-phone { color: var(--muted); font-size: 13px; }
  .o-status { display: block; }
  .o-amt { font-size: 14px; }
}

/* 초광폭 (≥1440px): 주문 컬럼 여유 */
@media (min-width: 1440px) {
  :root { --order-cols: 100px minmax(0, 1fr) 120px 150px 80px 110px; }
}

/* ============================================================
   통계 페이지
   ============================================================ */
.stats-main { display: grid; gap: 14px; grid-template-areas: none; grid-template-columns: 1fr; }

/* 세그먼트 토글 (일별/월별) */
.seg { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 3px; }
.seg-btn { border: 0; background: transparent; color: var(--muted); font-size: 14px;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; min-height: 38px; }
.seg-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

/* 차트 */
.legend { display: flex; gap: 14px; margin: 2px 0 8px; color: var(--muted); font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.chart-wrap { position: relative; }
#trendChart { width: 100%; height: 220px; display: block; }
#trendChart .grid { stroke: var(--line); stroke-width: 1; }
#trendChart .axis-label { fill: var(--muted); font-size: 11px; }
#trendChart .chart-empty { fill: var(--muted); font-size: 14px; }
#trendChart .hit { cursor: pointer; }
.chart-tip { position: absolute; top: 6px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 10px; font-size: 12px; line-height: 1.5; pointer-events: none;
  min-width: 140px; box-shadow: 0 4px 16px rgba(0,0,0,.4); z-index: 5; }
.tip-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }

/* 통계 표 */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-top: 10px; }
.stat-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 460px; }
.stat-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  text-align: right; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.stat-table th:first-child { text-align: left; }
.stat-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.stat-table td:first-child { text-align: left; }
.stat-table tr:last-child td { border-bottom: 0; }
.stat-table .strong { font-weight: 600; }
.stat-table .empty { text-align: center; color: var(--muted); }
.prod-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.bar-col { width: 30%; min-width: 80px; }
.hbar { height: 10px; border-radius: 0 4px 4px 0; background: var(--accent); }

/* 모바일: 표 가로스크롤 최소화 — 스토어별 열은 숨기고 핵심 열만 */
@media (max-width: 699px) {
  .stat-table { min-width: 0; }
  #trendTable th:nth-child(3), #trendTable td:nth-child(3),
  #trendTable th:nth-child(4), #trendTable td:nth-child(4) { display: none; }
  #productTable th:nth-child(3), #productTable td:nth-child(3) { display: none; }
  .prod-name { max-width: 130px; }
}

/* 데스크톱: 추이 넓게 + 품목 패널 나란히 */
@media (min-width: 1024px) {
  .stats-main { max-width: 1280px; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
  #trendChart { height: 260px; }
}
