:root {
  --bg: #f4f6fa; --surface: #ffffff; --surface-2: #f8f9fc; --border: #e3e7ef; --border-strong: #cdd3df;
  --text: #1b2333; --text-2: #4a5568; --muted: #7a8599;
  --primary: #3651d4; --primary-600: #2a42b8; --primary-soft: #e9edfc;
  --brand: #cc0000;
  --good: #1e8a4c; --good-soft: #e3f4ea; --warn: #b26b00; --warn-soft: #fdf1dc;
  --bad: #c62828; --bad-soft: #fde8e8; --info-soft: #e8f1fd;
  --chart: #4a63de; --chart-hover: #2a42b8; --grid: #edf0f5;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 10px; --sidebar: 240px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f131b; --surface: #171c26; --surface-2: #1d2330; --border: #2a3242; --border-strong: #3a4458;
    --text: #e7ebf3; --text-2: #b6bfcf; --muted: #8590a5;
    --primary: #7d92ff; --primary-600: #9aabff; --primary-soft: #232c4d;
    --good: #4cc27f; --good-soft: #17301f; --warn: #f0b04a; --warn-soft: #33270f;
    --bad: #ff7b7b; --bad-soft: #3a1b1b; --info-soft: #182a40;
    --chart: #7d92ff; --chart-hover: #a8b6ff; --grid: #232a38;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f131b; --surface: #171c26; --surface-2: #1d2330; --border: #2a3242; --border-strong: #3a4458;
  --text: #e7ebf3; --text-2: #b6bfcf; --muted: #8590a5;
  --primary: #7d92ff; --primary-600: #9aabff; --primary-soft: #232c4d;
  --good: #4cc27f; --good-soft: #17301f; --warn: #f0b04a; --warn-soft: #33270f;
  --bad: #ff7b7b; --bad-soft: #3a1b1b; --info-soft: #182a40;
  --chart: #7d92ff; --chart-hover: #a8b6ff; --grid: #232a38;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.45; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 20px; margin: 0; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 650; color: var(--text-2); }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { text-align: right; } .nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* layout */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar); background: var(--surface); border-right: 1px solid var(--border); position: fixed; inset: 0 auto 0 0; overflow-y: auto; z-index: 30; transition: transform .2s; }
.brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 15px; }
.brand-name { font-weight: 700; font-size: 14px; line-height: 1.1; } .brand-sub { font-size: 11px; color: var(--muted); }
.nav-group { padding: 10px 10px 4px; }
.nav-group-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 4px 10px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px; color: var(--text-2); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a .ico { width: 18px; text-align: center; opacity: .85; }
.main { flex: 1; margin-left: var(--sidebar); min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 20px; position: sticky; top: 0; z-index: 20; }
.topbar .spacer { flex: 1; }
.menu-btn { display: none; }
.content { padding: 20px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .spacer { flex: 1; }
.user-chip { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.user-chip:hover { background: var(--surface-2); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 12px; }
.backdrop { display: none; }
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 25; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 0 12px; }
  .hide-sm { display: none !important; }
}

/* cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card + .card { margin-top: 16px; }
.grid > .card + .card, .grid > div > .card:first-child { margin-top: 0; }
.grid { display: grid; gap: 16px; }
.grid.k4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid.k2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid.k2-1 { grid-template-columns: 2fr 1fr; }
@media (max-width: 1100px) { .grid.k4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid.k3 { grid-template-columns: repeat(2, minmax(0,1fr)); } .grid.k2-1 { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .grid.k4, .grid.k3, .grid.k2 { grid-template-columns: 1fr; } }
.stat .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.section-title { display: flex; align-items: center; gap: 8px; margin: 22px 0 10px; font-size: 13px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: .04em; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 500; }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-600); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.lg { height: 44px; font-size: 15px; padding: 0 20px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.link { border: 0; background: none; color: var(--primary); padding: 0 4px; height: auto; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
input[type=checkbox] { width: auto; }
textarea { min-height: 70px; resize: vertical; }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
label.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 14px; }
.form-grid .span2 { grid-column: span 2; } .form-grid .span-all { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid .span2 { grid-column: auto; } }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; }
.toolbar .grow { flex: 1; min-width: 160px; }

/* tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tfoot td { font-weight: 650; background: var(--surface-2); }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--primary-soft); color: var(--primary); border-color: transparent; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 9px 14px; font: inherit; font-weight: 550; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* modal & toast */
.modal-bg { position: fixed; inset: 0; background: rgba(10,15,25,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; z-index: 100; overflow-y: auto; }
.modal { background: var(--surface); border-radius: 12px; width: 100%; max-width: 760px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.sm { max-width: 460px; } .modal.lg { max-width: 1000px; }
.modal-head { display: flex; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; flex: 1; }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }
.x { background: none; border: 0; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--text); color: var(--surface); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; font-weight: 500; }
.toast.err { background: var(--bad); color: #fff; } .toast.ok { background: var(--good); color: #fff; }

/* chart */
.chart { position: relative; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 180px; border-bottom: 1px solid var(--border-strong); padding-top: 8px; background-image: linear-gradient(var(--grid) 1px, transparent 1px); background-size: 100% 25%; }
.bar { flex: 1; background: var(--chart); border-radius: 4px 4px 0 0; min-height: 0; position: relative; cursor: default; }
.bar:hover, .bar:focus { background: var(--chart-hover); outline: none; }
.bar-hit { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 4px; }
.tip { position: absolute; pointer-events: none; background: var(--text); color: var(--surface); font-size: 12px; padding: 6px 9px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -100%); z-index: 5; box-shadow: var(--shadow); }
.hbar { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; gap: 8px; align-items: center; margin: 6px 0; font-size: 12.5px; }
.hbar .track { height: 10px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--chart); border-radius: 0 4px 4px 0; }

/* POS */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .pos { grid-template-columns: 1fr; } }
.scan-box { display: flex; gap: 8px; }
.scan-box input { font-size: 16px; height: 44px; }
.suggest { position: absolute; left: 0; right: 0; top: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); z-index: 10; max-height: 320px; overflow-y: auto; }
.suggest div { padding: 8px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.suggest div:hover, .suggest div.sel { background: var(--primary-soft); }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px; font-variant-numeric: tabular-nums; }
.totals .grand { font-size: 22px; font-weight: 750; padding-top: 8px; border-top: 1px dashed var(--border-strong); }
.gift-row td { background: var(--warn-soft); }
.qty { width: 64px; text-align: center; }

/* calendar */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { font-size: 11px; color: var(--muted); text-align: center; font-weight: 600; }
.cal .day { border: 1px solid var(--border); border-radius: 8px; padding: 6px; min-height: 58px; font-size: 11.5px; background: var(--surface); }
.cal .day .d { font-weight: 700; font-size: 13px; }
.st-PRESENT { background: var(--good-soft) !important; } .st-HALF_DAY { background: var(--warn-soft) !important; }
.st-ABSENT, .st-UNPAID_LEAVE { background: var(--bad-soft) !important; } .st-LEAVE { background: var(--info-soft) !important; }
.st-HOLIDAY, .st-WEEK_OFF { background: var(--surface-2) !important; }
.register td { padding: 4px 3px; text-align: center; font-size: 11px; }
.register td.name { text-align: left; white-space: nowrap; padding: 4px 10px; font-size: 12.5px; }
.checkin-card { text-align: center; padding: 24px; }
.checkin-card .clock { font-size: 34px; font-weight: 750; letter-spacing: -.02em; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--bg), var(--primary-soft)); }
.login { width: 100%; max-width: 380px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 6px 16px; }
.perm-group { margin-top: 10px; font-weight: 650; font-size: 12px; text-transform: uppercase; color: var(--muted); grid-column: 1 / -1; }
.alert { padding: 10px 14px; border-radius: 8px; background: var(--info-soft); color: var(--text); margin-bottom: 12px; font-size: 13px; }
.alert.bad { background: var(--bad-soft); color: var(--bad); } .alert.warn { background: var(--warn-soft); color: var(--text); } .alert.good { background: var(--good-soft); }
.checkin-bar { background: var(--warn-soft); color: var(--text); padding: 8px 16px; font-size: 13px; display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--border); }
.alert.warn { background: var(--warn-soft); }

/* reminder board */
.board { border: 1px solid var(--bad); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.board.calm { border-color: var(--border); }
.board-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.board-head h2 { margin: 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 99px; font-weight: 650; font-size: 12.5px; background: var(--surface-2); }
.chip.red { background: var(--bad-soft); color: var(--bad); } .chip.amber { background: var(--warn-soft); color: var(--warn); }
.board-col h3 { display: flex; justify-content: space-between; align-items: center; }
.alert-row { display: flex; justify-content: space-between; gap: 8px; padding: 7px 10px; border-radius: 8px; margin-bottom: 6px; font-size: 13px; border-left: 4px solid transparent; background: var(--surface-2); }
.alert-row.red { background: var(--bad-soft); border-left-color: var(--bad); }
.alert-row.amber { background: var(--warn-soft); border-left-color: var(--warn); }
.alert-row .amt { font-weight: 700; white-space: nowrap; }
tr.row-red td { background: var(--bad-soft); } tr.row-amber td { background: var(--warn-soft); }
.stock-red { color: var(--bad); font-weight: 700; }

.sub-banner { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; background: var(--warn-soft); border: 1px solid var(--warn); }
.sub-banner.bad { background: var(--bad-soft); border-color: var(--bad); }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.photo-grid figure { margin: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.photo-grid img { width: 100%; height: 140px; object-fit: contain; display: block; cursor: zoom-in; background: #fff; padding: 4px; box-sizing: border-box; }
/* Image placeholder: always shows the whole picture (letterboxed), never cropped. */
.img-box { position: relative; display: inline-block; background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; vertical-align: top; }
.img-box img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; padding: 4px; box-sizing: border-box; display: block; }
.img-box.zoom img { cursor: zoom-in; }
.photo-grid figcaption { font-size: 11px; padding: 4px 6px; display: flex; justify-content: space-between; gap: 4px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters select, .filters input { width: auto; }
.dmg-chip { margin-top: 4px; font-size: 12px; background: var(--warn-soft); color: var(--warn); border-radius: 6px; padding: 3px 8px; display: inline-flex; gap: 6px; align-items: center; }
