:root {
  --bg: #f5f6f8; --card: #fff; --text: #1f2937; --muted: #6b7280; --line: #e5e7eb;
  --primary: #2563eb; --primary-weak: #eff6ff; --danger: #dc2626; --danger-weak: #fef2f2;
  --ok: #059669; --ok-weak: #ecfdf5; --warn: #d97706; --warn-weak: #fffbeb; --side: #1f2937;
  --radius: 10px;
  /* 입력칸·버튼·표머리·뱃지 등 (다크모드에서 함께 바뀌도록 색을 전부 변수로) */
  --field: #fff; --hover: #f9fafb; --soft: #fafafa; --chip: #f3f4f6; --chip-text: #374151;
  --border-strong: #d1d5db; --focus: #bfdbfe; --danger-line: #fecaca; --receipt-bg: #fffdf5; --receipt-line: #e5d9a8;
  --shadow: rgba(0,0,0,.1);
  color-scheme: light;
}
/* 다크모드: 눈부심을 줄이려고 완전 검정 대신 짙은 회색 바탕, 글자도 순백 대신 밝은 회색 */
:root[data-theme="dark"] {
  --bg: #0f1115; --card: #171a21; --text: #e5e7eb; --muted: #9ca3af; --line: #2a2f3a;
  --primary: #3b82f6; --primary-weak: rgba(59,130,246,.16); --danger: #f87171; --danger-weak: rgba(248,113,113,.15);
  --ok: #34d399; --ok-weak: rgba(52,211,153,.14); --warn: #fbbf24; --warn-weak: rgba(251,191,36,.14); --side: #0b0d11;
  --field: #1f232b; --hover: #222733; --soft: #1c2028; --chip: #262b35; --chip-text: #d1d5db;
  --border-strong: #3a4150; --focus: #1e3a8a; --danger-line: #7f1d1d; --receipt-bg: #1d1b15; --receipt-line: #4a4330;
  --shadow: rgba(0,0,0,.5);
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }

/* 레이아웃 */
.layout { display: flex; min-height: 100vh; }
.side { width: 200px; background: var(--side); color: #d1d5db; flex-shrink: 0; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { color: #fff; font-weight: 700; font-size: 17px; padding: 18px 18px 12px; display: flex; align-items: center; gap: 8px; }
.side nav a { display: flex; align-items: center; gap: 8px; color: #d1d5db; padding: 9px 18px; }
.side nav a:hover { background: #374151; }
.side nav a.on { background: #374151; color: #fff; font-weight: 600; border-left: 3px solid #60a5fa; padding-left: 15px; }
.side .sec { font-size: 11px; color: #9ca3af; padding: 14px 18px 4px; }
.side .me { padding: 14px 18px; border-top: 1px solid #374151; font-size: 13px; }
.main { flex: 1; min-width: 0; padding: 22px 26px 80px; }
.topbar { display: none; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: #9ca3af; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #10b981; display: inline-block; }

/* 카드·그리드 */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split > * { min-width: 0; }
.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: block; color: inherit; }
.stat .k { color: var(--muted); font-size: 12px; }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 2px; }
.stat .s { font-size: 12px; color: var(--muted); }
.stat.alert .v { color: var(--danger); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.big { font-size: 18px; font-weight: 700; }
.hr { border-top: 1px solid var(--line); margin: 12px 0; }

/* 폼 */
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 8px; width: 100%; background: var(--field); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
input.sm { width: 80px; padding: 5px 8px; }
input[type=checkbox] { width: auto; }
button, .btn { font: inherit; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--field); color: var(--text); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; }
button:hover, .btn:hover { background: var(--hover); }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: #1d4ed8; }
button.danger { color: var(--danger); border-color: var(--danger-line); }
button.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
button.link { border: 0; background: none; color: var(--primary); padding: 2px 4px; }
button.sm, .btn.sm { padding: 4px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* 표 */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--soft); white-space: nowrap; }
tr.click { cursor: pointer; }
td:first-child { min-width: 140px; }
#shf td:first-child { min-width: 0; width: 28px; }
tr.click:hover td { background: var(--hover); }
tfoot td { font-weight: 700; }

/* 배지 */
.b { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--chip); color: var(--chip-text); white-space: nowrap; }
.b.red { background: var(--danger-weak); color: var(--danger); }
.b.green { background: var(--ok-weak); color: var(--ok); }
.b.blue { background: var(--primary-weak); color: var(--primary); }
.b.amber { background: var(--warn-weak); color: var(--warn); }
.b.gray { background: var(--chip); color: var(--muted); }

/* 탭 */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.on { color: var(--primary); border-color: var(--primary); font-weight: 600; }

/* 자동완성 */
.ac { position: relative; }
.ac-list { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px var(--shadow); max-height: 340px; overflow-y: auto; }
.ac-list div.it { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.ac-list div.it:hover, .ac-list div.it.on { background: var(--primary-weak); }

/* 옵션 선택 버튼 */
.opts { display: flex; flex-wrap: wrap; gap: 6px; }
.opt { border: 1px solid var(--border-strong); border-radius: 8px; padding: 6px 10px; background: var(--field); color: var(--text); cursor: pointer; font-size: 13px; text-align: left; }
.opt small { display: block; color: var(--muted); font-size: 11px; }
.opt.on { border-color: var(--primary); background: var(--primary-weak); }
.opt.zero small { color: var(--warn); }

/* 정산서 미리보기(카톡 복사·인쇄용) */
.receipt { white-space: pre-wrap; font-family: inherit; background: var(--receipt-bg); border: 1px dashed var(--receipt-line); border-radius: 8px; padding: 14px; font-size: 13px; line-height: 1.7; }

/* 토스트·모달·오프라인 */
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
#toast div { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 90vw; }
#toast div.err { background: var(--danger); }
#modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; overflow-y: auto; }
#modal[hidden] { display: none; }
#modal .box { background: var(--card); border-radius: 12px; padding: 20px; width: 100%; max-width: 640px; }
#offline { position: fixed; inset: 0; z-index: 200; background: rgba(17,24,39,.85); display: flex; align-items: center; justify-content: center; padding: 16px; }
#offline[hidden] { display: none; }
.offline-box { background: var(--card); border-radius: 14px; padding: 28px; max-width: 420px; text-align: center; }
.offline-icon { font-size: 40px; }

/* 로그인 */
.login { max-width: 360px; margin: 12vh auto; }
/* 사장님 회사 로고(검정 바탕 흰 글씨, 원본 160px이라 그보다 키우지 않음) */
.login .logo { display: block; width: 128px; height: 128px; margin: 0 auto 20px; border-radius: 18px; }
.login .brand { text-align: center; font-size: 24px; font-weight: 800; margin-bottom: 16px; }

.empty { padding: 30px; text-align: center; color: var(--muted); }

/* 태블릿·휴대폰 */
/* 태블릿 가로(1024px)까지는 한 단으로 쌓아야 표가 찌그러지지 않음 */
@media (max-width: 1200px) {
  .split { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1000px) {
  .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .layout { display: block; }
  .side { position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; width: 240px; }
  .side.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 10px; background: var(--side); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 30; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 20px; padding: 0 4px; }
  .main { padding: 16px 16px 80px; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .hide-m { display: none; }
  th, td { padding: 7px 6px; }
}

/* 인쇄: 정산서만 */
@media print {
  .side, .topbar, .no-print, #toast { display: none !important; }
  .main { padding: 0; }
  .card { border: 0; }
  .receipt { border: 0; background: #fff; font-size: 14px; }
}

/* 대시보드 */
.delta { font-weight: 600; }
.delta.up { color: var(--ok); }
.delta.down { color: var(--danger); }
.trend { display: flex; gap: 6px; align-items: flex-end; height: 120px; padding-top: 4px; }
.trend .tcol { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; height: 100%; cursor: default; }
.trend .tbar-wrap { flex: 1; display: flex; align-items: flex-end; border-bottom: 1px solid var(--line); }
.trend .tbar { width: 100%; max-width: 28px; margin: 0 auto; background: var(--primary); opacity: .45; border-radius: 4px 4px 0 0; }
.trend .tcol.cur .tbar { opacity: 1; }
.trend .tcol:hover .tbar { opacity: .85; }
.trend .tlab { font-size: 11px; color: var(--muted, #6b7280); text-align: center; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 우측 상단 다크/라이트 모드 전환 (로그인 화면 포함 어디서나) */
.theme-toggle { position: fixed; top: 12px; right: 16px; z-index: 40; width: 38px; height: 38px; padding: 0; justify-content: center;
  border-radius: 50%; font-size: 17px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 2px 8px var(--shadow); }
/* 각 화면 첫 줄(제목 + 오른쪽 버튼)이 전환 버튼과 겹치지 않게 자리 비움 */
.main > :first-child { margin-right: 48px; }
@media (max-width: 900px) { .theme-toggle { top: 5px; right: 10px; width: 34px; height: 34px; font-size: 15px; } .topbar { padding-right: 56px !important; } .main > :first-child { margin-right: 0; } }
@media print {
  .theme-toggle { display: none; }
  /* 정산서 인쇄·PDF는 다크모드여도 항상 흰 종이에 검은 글씨 */
  :root[data-theme="dark"] { --bg: #fff; --card: #fff; --text: #111; --muted: #555; --line: #ddd; --soft: #fafafa; color-scheme: light; }
}
/* 상품·재고 목록: 제목 클릭 정렬 */
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--primary); }

/* 메뉴 도움말 [?] (2026-10-28) */
.help-q { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; min-width: 18px; padding: 0; margin-left: 6px;
  border-radius: 50%; border: 1px solid currentColor; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700; line-height: 1; cursor: pointer; vertical-align: middle; opacity: .75; }
.help-q:hover, .help-q:focus-visible { opacity: 1; }
.side nav a .help-q { margin-left: auto; color: #9ca3af; }
.help-tip { position: absolute; z-index: 1000; max-width: min(320px, calc(100vw - 16px)); background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.5; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.help-tip b { display: block; margin-bottom: 4px; }
@media print { .help-q, .help-tip { display: none !important; } }
