:root {
  --navy: #1f4e79; --navy-2: #173c5e; --accent: #e8452c;
  --bg: #f2f4f7; --card: #ffffff; --text: #17202a; --muted: #5f6b78; --line: #dde3ea;
  --field: #ffffff; --ok: #1e7d4f; --warn: #b26a00; --danger: #c0392b; --chip: #e8eef5;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --navy: #5b9bd5; --navy-2: #3f7fb8; --bg: #0f1419; --card: #182028; --text: #e6ebf0; --muted: #93a1b0;
    --line: #2a3542; --field: #121a21; --chip: #22303d; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
body { min-height: 100vh; overscroll-behavior-y: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy); }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }

/* ---------- top bar ---------- */
.top { position: sticky; top: 0; z-index: 20; background: var(--navy-2); color: #fff;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px; display: flex; align-items: center; gap: 8px; }
@media (prefers-color-scheme: dark) { .top { background: #111a22; border-bottom: 1px solid var(--line); } }
.top h1 { font-size: 17px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .sub { display: block; font-size: 12px; font-weight: 400; opacity: .8; }
.iconbtn { background: transparent; border: 0; color: inherit; width: 40px; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; flex: none; }
.iconbtn:active { background: rgba(255,255,255,.15); }
.iconbtn svg { width: 22px; height: 22px; }
.savestate { font-size: 12px; opacity: .85; white-space: nowrap; }

main { padding: 12px 12px calc(96px + var(--safe-b)); max-width: 760px; margin: 0 auto; }

/* ---------- cards / forms ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 12px;
  border: 1px solid var(--line); }
.card h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
@media (max-width: 380px) { .row { grid-template-columns: 1fr; } }
label.f { display: block; margin-bottom: 10px; }
label.f > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=date], input[type=number],
input[type=search], select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--field); font-size: 16px; /* 16px stops iOS zoom */ }
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--navy); outline-offset: -1px; border-color: transparent; }
.req::after { content: " *"; color: var(--accent); }
.hint { font-size: 13px; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; padding: 3px 0; }
.kv b { font-weight: 600; text-align: right; }

.seg { display: flex; background: var(--chip); border-radius: 10px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 0; border-radius: 8px; cursor: pointer; font-size: 15px; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); font-weight: 600; color: var(--navy); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 0 16px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--card); cursor: pointer; font-weight: 600; text-decoration: none; color: var(--text); }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #0f1419; } }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn svg { width: 18px; height: 18px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns .btn { flex: 1; }

/* ---------- lists ---------- */
.search { position: relative; margin-bottom: 10px; }
.qitem { display: block; text-decoration: none; color: inherit; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; box-shadow: var(--shadow); }
.qitem .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.qitem .t span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qitem .m { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; justify-content: space-between; gap: 8px; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--chip); color: var(--navy); vertical-align: middle; }
.badge.draft { color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 0 0 10px; }
.toggle input { width: 20px; height: 20px; }

.fab { position: fixed; right: 16px; bottom: calc(18px + var(--safe-b)); z-index: 15; height: 56px; padding: 0 20px;
  border-radius: 28px; border: 0; background: var(--accent); color: #fff; font-weight: 700; font-size: 16px;
  box-shadow: 0 6px 16px rgba(232,69,44,.35); display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
.fab svg { width: 22px; height: 22px; }

/* ---------- quote lines ---------- */
.line { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; background: var(--field); }
.line .hd { display: flex; gap: 8px; align-items: flex-start; }
.line .pn { font-weight: 700; font-size: 15px; word-break: break-all; }
.line .ds { font-size: 13px; color: var(--muted); margin-top: 2px; }
.line .cat { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.line .ctl { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: end; margin-top: 10px; }
.line .nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 8px; font-size: 13px; text-align: right; }
.line .nums div span { display: block; font-size: 11px; color: var(--muted); }
.line .nums .tot { font-weight: 700; font-size: 15px; }
.line .warn { color: var(--warn); font-size: 12px; margin-top: 6px; }
.line .x { margin-left: auto; color: var(--muted); }
.line .x:active { background: var(--chip); }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.stepper button { width: 42px; height: 42px; border: 0; background: transparent; font-size: 20px; cursor: pointer; }
.stepper input { width: 58px; min-height: 42px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  border-radius: 0; text-align: center; padding: 0; background: transparent; }
.disc { display: flex; align-items: center; gap: 6px; }
.disc input { text-align: right; }
.disc span { color: var(--muted); }
.mini { font-size: 11px; color: var(--muted); display: block; margin-bottom: 3px; }

/* ---------- bottom total bar ---------- */
.totalbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 18; background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + var(--safe-b)); display: flex; align-items: center; gap: 12px; }
.totalbar .amt { flex: 1; }
.totalbar .amt span { display: block; font-size: 12px; color: var(--muted); }
.totalbar .amt b { font-size: 20px; }
.totalbar-inner { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 12px; width: 100%; }

/* ---------- sheet (picker / dialogs) ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; height: 92vh; height: 92dvh; border-radius: 16px 16px 0 0;
  display: flex; flex-direction: column; overflow: hidden; animation: up .18s ease-out; }
.sheet.small { height: auto; max-height: 90dvh; }
@keyframes up { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .sh { padding: 12px; background: var(--card); border-bottom: 1px solid var(--line); }
.sheet .sh .ttl { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.sheet .sh .ttl h3 { margin: 0; flex: 1; font-size: 17px; }
.sheet .sb { flex: 1; overflow-y: auto; padding: 8px 12px calc(16px + var(--safe-b)); -webkit-overflow-scrolling: touch; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips + .chips { margin-top: 8px; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 7px 13px; font-size: 14px; cursor: pointer; white-space: nowrap; }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.on { color: #0f1419; } }
.pick { display: flex; gap: 10px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-bottom: 6px; cursor: pointer; width: 100%; text-align: left; }
.pick:active { background: var(--chip); }
.pick .i { flex: 1; min-width: 0; }
.pick .pn { font-weight: 700; font-size: 15px; }
.pick .ds { font-size: 13px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pick .pr { font-weight: 600; font-size: 14px; white-space: nowrap; text-align: right; }
.pick .pr small { display: block; font-weight: 400; color: var(--muted); font-size: 11px; }
.pick.added { border-color: var(--ok); }
.pick .plus { width: 34px; height: 34px; border-radius: 50%; background: var(--chip); display: inline-flex; align-items: center; justify-content: center; flex: none; color: var(--navy); font-size: 22px; font-weight: 600; }
.pick.added .plus { background: var(--ok); color: #fff; }
.count { font-size: 13px; color: var(--muted); padding: 4px 2px 8px; }

.vers { list-style: none; padding: 0; margin: 0; }
.vers li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); font-size: 14px; }
.vers li:first-child { border-top: 0; }
.vers li .i { flex: 1; min-width: 0; }
.vers li .i small { display: block; color: var(--muted); font-size: 12px; }
.vers .iconbtn { color: var(--navy); }

/* ---------- login ---------- */
.login { max-width: 380px; margin: 0 auto; padding: calc(env(safe-area-inset-top, 0px) + 12vh) 20px 40px; }
.login img { display: block; height: 48px; margin: 0 auto 8px; }
.login h1 { text-align: center; font-size: 20px; margin: 0 0 24px; color: var(--navy); }
.err { color: var(--danger); font-size: 14px; margin: 6px 0 10px; min-height: 1em; }

/* ---------- tabs (admin) ---------- */
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl td { padding: 8px 4px; border-top: 1px solid var(--line); vertical-align: top; }

#toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-b)); transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #1b2631; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 60; transition: .2s; pointer-events: none; max-width: 90vw; }
#toast.on { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--danger); }

.menu { position: absolute; right: 8px; top: calc(100% - 4px); background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.2); min-width: 200px; overflow: hidden; z-index: 30; }
.menu button { display: block; width: 100%; text-align: left; padding: 13px 16px; border: 0; background: transparent; cursor: pointer; font-size: 15px; }
.menu button + button { border-top: 1px solid var(--line); }
.menu .danger { color: var(--danger); }
@media (min-width: 700px) { main { padding-top: 18px; } .line .ctl { grid-template-columns: auto 160px; justify-content: space-between; } }

/* product lines (ICT / CCTV) */
.badge.line { display: inline-block; background: transparent; border: 1px solid var(--line); color: var(--muted);
  font-weight: 700; font-size: 10px; line-height: 1.3; padding: 0 5px; border-radius: 4px; vertical-align: 2px; min-height: 0; }
.sechead { display: flex; justify-content: space-between; align-items: baseline; margin: 14px 2px 6px;
  font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--navy); border-bottom: 2px solid var(--navy); padding-bottom: 4px; }
.sechead:first-child { margin-top: 2px; }
.sechead b { font-size: 14px; color: var(--text); letter-spacing: 0; }
.hint.need { color: var(--danger); font-weight: 600; }

/* two-step verification + access log */
.steps { padding-left: 20px; margin: 0 0 12px; font-size: 15px; }
.steps li { margin-bottom: 10px; }
.qr { background: #fff; width: 190px; height: 190px; margin: 10px auto; padding: 6px; border-radius: 8px; }
.qr svg { width: 100%; height: 100%; display: block; }
.qr svg .dark, .qr svg [class*="dark"] { fill: #000; }
code.key { display: block; text-align: center; font-size: 15px; letter-spacing: 1px; padding: 8px; background: var(--chip);
  border-radius: 8px; margin-top: 6px; word-break: break-all; user-select: all; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.codes code { background: var(--chip); padding: 8px; border-radius: 8px; text-align: center; font-size: 15px; letter-spacing: 1px; }
.logrow { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 6px; font-size: 14px; }
.logrow.bad { border-left-color: var(--danger); }
.logrow .t { display: flex; justify-content: space-between; gap: 8px; }
.logrow .t span, .logrow .m { color: var(--muted); font-size: 12px; }
.logrow .m { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.logrow .ua { text-align: right; }
