:root { --bg:#f3f4f7; --fg:#1b2130; --card:#fff; --line:#d6dae2; --accent:#0b6bcb; --accent-fg:#fff; --warn:#b4540a; --ok:#1a7f37; --ng:#c62828; --muted:#667085; --ret:#fde8e8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg:#13161c; --fg:#e8ebf0; --card:#1d222b; --line:#353c49; --accent:#4c9aff; --accent-fg:#0b1220; --warn:#f0a35a; --ok:#4cc26a; --ng:#ff7b7b; --muted:#98a2b3; --ret:#4a2326; }
}
* { box-sizing:border-box; }
html, body { height:100%; }
body { margin:0; background:var(--bg); color:var(--fg); font:15px/1.5 -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif; display:flex; flex-direction:column; -webkit-text-size-adjust:100%; }
button, input, select { font:inherit; color:inherit; }
button { border:1px solid var(--line); background:var(--card); border-radius:8px; padding:8px 12px; cursor:pointer; touch-action:manipulation; }
button:disabled { opacity:.45; cursor:default; }
button.primary { background:var(--accent); color:var(--accent-fg); border-color:var(--accent); font-weight:700; }
button.ghost { background:transparent; }
button.danger { color:var(--ng); border-color:var(--ng); background:transparent; }
input, select { border:1px solid var(--line); background:var(--card); border-radius:8px; padding:10px; font-size:16px; min-width:0; }
.muted { color:var(--muted); font-size:12px; }
.num { font-variant-numeric:tabular-nums; }

#bar { display:flex; align-items:center; gap:10px; padding:8px 12px; background:var(--card); border-bottom:1px solid var(--line); flex-wrap:wrap; }
#bar .who { display:flex; flex-direction:column; line-height:1.2; }
#bar .who span { font-size:12px; color:var(--muted); }
#bar .state { display:flex; align-items:center; gap:6px; flex:1; min-width:0; flex-wrap:wrap; }
#bar nav { display:flex; gap:6px; flex-wrap:wrap; }
#bar nav button { padding:6px 10px; font-size:13px; }
.pill { border-radius:999px; padding:2px 10px; font-size:12px; border:1px solid var(--line); background:transparent; }
.pill.on { color:var(--ok); border-color:var(--ok); } .pill.off { color:var(--ng); border-color:var(--ng); } .pill.wait { color:var(--warn); border-color:var(--warn); font-weight:700; }

main { flex:1; min-height:0; display:grid; grid-template-columns:minmax(0,1.25fr) minmax(320px,1fr); gap:10px; padding:10px; }
section { background:var(--card); border:1px solid var(--line); border-radius:12px; min-height:0; display:flex; flex-direction:column; overflow:hidden; }
#f-code { display:flex; gap:8px; padding:10px; border-bottom:1px solid var(--line); }
#f-code input { flex:1; }
#depts { display:flex; gap:6px; padding:8px 10px; overflow-x:auto; border-bottom:1px solid var(--line); flex:none; scrollbar-width:thin; scrollbar-color:var(--line) transparent; }
#depts button { white-space:nowrap; padding:6px 10px; font-size:13px; flex:none; }
#depts button[aria-selected="true"] { background:var(--accent); color:var(--accent-fg); border-color:var(--accent); }
#grid { flex:1; overflow-y:auto; padding:10px; display:grid; grid-template-columns:repeat(auto-fill, minmax(150px, 1fr)); gap:8px; align-content:start; }
#grid button { text-align:left; display:flex; flex-direction:column; gap:4px; min-height:74px; padding:8px; }
#grid button .n { font-size:13px; line-height:1.3; display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; word-break:break-all; }
#grid button .p { margin-top:auto; font-weight:700; }
#grid .empty { grid-column:1/-1; color:var(--muted); padding:20px; text-align:center; }

#cart-head { display:flex; align-items:center; gap:6px; flex-wrap:wrap; padding:10px; border-bottom:1px solid var(--line); }
#cart-head b { flex:1; }
#cart { list-style:none; margin:0; padding:0; flex:1; overflow-y:auto; }
#cart li { display:grid; grid-template-columns:1fr auto; gap:2px 8px; padding:8px 10px; border-bottom:1px solid var(--line); }
#cart li.ret { background:var(--ret); }
#cart li .name { font-size:14px; word-break:break-all; cursor:pointer; }
#cart li .amt { font-weight:700; text-align:right; }
#cart li .sub { grid-column:1/-1; display:flex; align-items:center; gap:8px; font-size:13px; color:var(--muted); flex-wrap:wrap; }
#cart li .qty { display:flex; align-items:center; gap:4px; }
#cart li .qty button { width:34px; height:34px; padding:0; font-size:18px; line-height:1; }
#cart li .qty b { min-width:28px; text-align:center; color:var(--fg); }
#cart .none { padding:28px; text-align:center; color:var(--muted); display:block; }
#quick { display:flex; gap:6px; padding:8px 10px; flex-wrap:wrap; border-top:1px solid var(--line); }
#quick:empty { display:none; }
#quick button { font-size:13px; padding:6px 10px; }
#totals { padding:8px 12px; border-top:1px solid var(--line); }
#totals .r { display:flex; justify-content:space-between; font-size:14px; }
#totals .r.total { font-size:24px; font-weight:800; margin-top:4px; }
#totals .r.disc { color:var(--warn); }
#actions { display:grid; grid-template-columns:1fr 1fr 2fr; gap:8px; padding:10px; }
#actions button { padding:14px; font-size:16px; }

dialog { border:1px solid var(--line); border-radius:14px; background:var(--card); color:var(--fg); padding:0; width:min(560px, calc(100vw - 24px)); max-height:calc(100vh - 24px); }
dialog::backdrop { background:rgba(0,0,0,.45); }
#dlg-body { padding:16px; display:flex; flex-direction:column; gap:10px; }
#dlg-body h2 { margin:0; font-size:17px; }
#dlg-body .row { display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
#dlg-body .row > label { flex:none; width:96px; font-size:13px; color:var(--muted); }
#dlg-body .row > input, #dlg-body .row > select { flex:1; }
#dlg-body .foot { display:flex; gap:8px; justify-content:flex-end; margin-top:6px; flex-wrap:wrap; }
#dlg-body .seg { display:flex; gap:6px; flex-wrap:wrap; }
#dlg-body .seg button[aria-pressed="true"] { background:var(--accent); color:var(--accent-fg); border-color:var(--accent); }
#dlg-body .big { font-size:26px; font-weight:800; text-align:right; }
#dlg-body .list { max-height:38vh; overflow:auto; border:1px solid var(--line); border-radius:8px; }
#dlg-body .list .it { display:flex; justify-content:space-between; gap:8px; padding:6px 10px; border-bottom:1px solid var(--line); font-size:14px; }
#dlg-body table { width:100%; border-collapse:collapse; font-size:13px; }
#dlg-body td, #dlg-body th { padding:5px 6px; border-bottom:1px solid var(--line); text-align:left; }
#dlg-body td.num, #dlg-body th.num { text-align:right; }
.den { display:grid; grid-template-columns:repeat(2, 1fr); gap:6px 12px; }
.den label { display:flex; align-items:center; gap:6px; font-size:14px; }
.den label span { width:74px; text-align:right; }
.den input { width:100%; padding:6px 8px; }
.err { color:var(--ng); font-size:13px; min-height:1.2em; }

#paper-wrap { overflow:auto; max-height:52vh; background:var(--bg); border-radius:8px; padding:10px; }
#paper { background:#fff; color:#111; width:max-content; margin:0 auto; padding:12px 8px; box-shadow:0 1px 6px rgba(0,0,0,.25); --cw:7px; font-size:12px; }
#paper .ln { display:flex; white-space:pre; height:1.45em; line-height:1.45em; }
#paper .ln.big { height:2.6em; line-height:2.6em; font-size:22px; }
#paper .ln.bold { font-weight:700; } #paper .ln.ctr { justify-content:center; } #paper .ln.rt { justify-content:flex-end; }
#paper .ch { display:inline-block; text-align:center; }

#toast { position:fixed; left:50%; bottom:18px; transform:translateX(-50%); background:var(--fg); color:var(--bg); padding:8px 14px; border-radius:999px; font-size:14px; opacity:0; pointer-events:none; transition:opacity .2s; max-width:90vw; }
#toast.show { opacity:1; }

@media (max-width: 760px) {
  main { grid-template-columns:1fr; grid-template-rows:minmax(220px, 42vh) 1fr; overflow-y:auto; }
  #grid { grid-template-columns:repeat(auto-fill, minmax(130px, 1fr)); }
}
