:root {
  --paper: #f1f4f0;
  --surface: #fbfcfa;
  --surface-2: #f4f7f3;
  --ink: #17201c;
  --ink-2: #3b4741;
  --muted: #6b7872;
  --line: #d8ded8;
  --line-strong: #b8c2b9;
  --jade: #1c6a59;
  --jade-soft: #dceae5;
  --jade-ink: #12463b;
  --blush: #b46572;
  --blush-soft: #f4e3e6;
  --amber: #9c6f2c;
  --amber-soft: #f3e9d6;
  --danger: #a33a3a;
  --danger-soft: #f6e2e2;
  --ok: #2c6e4f;
  --ok-soft: #dcefe3;
  --shadow: 0 1px 2px rgba(23, 32, 28, .06), 0 8px 24px rgba(23, 32, 28, .06);
  --display: "Noto Serif SC", "Songti SC", serif;
  --body: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #0f1512;
    --surface: #161d19;
    --surface-2: #1b2420;
    --ink: #e7ece8;
    --ink-2: #c0cac4;
    --muted: #8b978f;
    --line: #2a352f;
    --line-strong: #3d4a43;
    --jade: #6fc0a8;
    --jade-soft: #1e332c;
    --jade-ink: #bfe6d8;
    --blush: #d9919c;
    --blush-soft: #33232a;
    --amber: #cfa25c;
    --amber-soft: #332b1c;
    --danger: #e08b8b;
    --danger-soft: #331f1f;
    --ok: #7fc9a3;
    --ok-soft: #1b2f26;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.3);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink-2);
  font-family: var(--body);
  font-size: 14px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--jade); text-decoration: none; }
h1, h2, h3, h4 { font-family: var(--display); color: var(--ink); font-weight: 600; margin: 0; line-height: 1.35; }

.mono { font-family: var(--mono); }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
[hidden] { display: none !important; }

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr .9fr;
}
.login-left {
  background: var(--jade-ink);
  color: #eaf3ef;
  padding: 64px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}
.login-left::after {
  content: "";
  position: absolute;
  right: -120px; bottom: -160px;
  width: 480px; height: 480px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 50%;
}
.login-left::before {
  content: "";
  position: absolute;
  right: -40px; bottom: -80px;
  width: 320px; height: 320px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 50%;
}
.login-brand { font-family: var(--mono); letter-spacing: .24em; font-size: 11px; opacity: .7; }
.login-left h1 { color: #fff; font-size: clamp(30px, 4vw, 46px); line-height: 1.25; margin-top: 28px; }
.login-left p { color: rgba(234,243,239,.75); max-width: 34ch; margin-top: 20px; font-size: 15px; }
.login-meta { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; opacity: .6; }
.login-right { display: flex; align-items: center; justify-content: center; padding: 40px; }
.login-card { width: 100%; max-width: 360px; }
.login-card h2 { font-size: 24px; margin-bottom: 6px; }
.login-card .sub { color: var(--muted); margin-bottom: 28px; font-size: 13px; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .03em; }
.field input, .field select, .field textarea {
  width: 100%; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 3px; outline: none;
}
.field textarea { resize: vertical; min-height: 92px; line-height: 1.6; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--jade); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 3px; border: 1px solid transparent;
  background: var(--jade); color: #fff; cursor: pointer; font-size: 13px;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; padding: 11px; }
.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line-strong); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.danger { background: var(--danger); }
.btn.ok { background: var(--ok); }
.login-hint {
  margin-top: 24px; padding: 14px; border: 1px dashed var(--line-strong);
  border-radius: 3px; font-size: 12px; color: var(--muted); line-height: 1.8;
}
.login-hint b { color: var(--ink-2); }
.login-hint button {
  background: none; border: none; color: var(--jade); cursor: pointer; padding: 0; font-size: 12px; text-decoration: underline;
}
.login-platform { display: inline-block; margin-top: 16px; font-size: 12px; color: var(--muted); }
.login-platform:hover { color: var(--jade); }

/* ---------- shell ---------- */
#app { display: grid; grid-template-columns: 208px minmax(0,1fr); min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.sidebar .logo { font-family: var(--display); font-size: 18px; color: var(--ink); padding: 0 8px 4px; }
.sidebar .logo small { display: block; font-family: var(--mono); font-size: 9px; letter-spacing: .18em; color: var(--muted); margin-top: 2px; }
.nav { margin-top: 22px; display: flex; flex-direction: column; gap: 1px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 3px; color: var(--ink-2); font-size: 13px;
}
.nav a .ic { width: 14px; text-align: center; color: var(--muted); font-size: 12px; }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--jade-soft); color: var(--jade-ink); font-weight: 500; }
.nav a.active .ic { color: var(--jade); }
.nav .sep { font-family: var(--mono); font-size: 9px; letter-spacing: .14em; color: var(--muted); padding: 16px 10px 6px; text-transform: uppercase; }
.sidebar .who {
  margin-top: auto; padding: 12px 10px; border-top: 1px solid var(--line);
  font-size: 12px; color: var(--muted);
}
.sidebar .who b { display: block; color: var(--ink); font-size: 13px; font-weight: 500; }
.sidebar .who button { margin-top: 8px; background: none; border: none; color: var(--muted); cursor: pointer; padding: 0; font-size: 11px; text-decoration: underline; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 32px; border-bottom: 1px solid var(--line);
  background: var(--paper); position: sticky; top: 0; z-index: 5;
}
.topbar .crumb { font-family: var(--mono); font-size: 11px; letter-spacing: .1em; color: var(--muted); }
.topbar .spacer { flex: 1; }
.topbar select {
  padding: 6px 10px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); font-size: 12px;
}
.topbar .store-static {
  padding: 6px 10px; border: 1px dashed var(--line-strong); border-radius: 3px;
  background: var(--surface); font-size: 12px; color: var(--muted); cursor: default;
}
.role-pill {
  font-family: var(--mono); font-size: 10px; letter-spacing: .08em;
  padding: 3px 8px; border-radius: 999px; border: 1px solid var(--line-strong); color: var(--muted);
}
.role-pill.hq { border-color: var(--jade); color: var(--jade); background: var(--jade-soft); }

.view { padding: 28px 32px 64px; max-width: 1240px; width: 100%; }
.view-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.view-head h2 { font-size: 24px; }
.view-head .desc { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------- cards / grids ---------- */
.grid { display: grid; gap: 16px; }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 18px 20px;
}
.card.tight { padding: 14px 16px; }
.card h3 { font-size: 15px; margin-bottom: 4px; }
.card .cap { font-size: 12px; color: var(--muted); }

.kpi .label { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.kpi .value { font-family: var(--display); font-size: 27px; color: var(--ink); margin-top: 8px; font-variant-numeric: tabular-nums; }
.kpi .value small { font-size: 13px; color: var(--muted); font-family: var(--body); }
.kpi .delta { font-size: 12px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.up { color: var(--ok); }
.down { color: var(--danger); }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 500; padding: 9px 12px; border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }
.table .clickable { cursor: pointer; }
.table-wrap { overflow-x: auto; }

.badge {
  display: inline-block; font-size: 11px; padding: 2px 8px; border-radius: 999px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge.jade { background: var(--jade-soft); color: var(--jade-ink); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blush { background: var(--blush-soft); color: var(--blush); }
.badge.grey { background: var(--surface-2); color: var(--muted); border-color: var(--line); }
.badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.green { background: var(--ok-soft); color: var(--ok); }

/* ---------- chart ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 150px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .bar .fill { width: 100%; background: var(--jade-soft); border-top: 2px solid var(--jade); border-radius: 1px; min-height: 2px; transition: height .3s; }
.bars .bar .lab { font-family: var(--mono); font-size: 9px; color: var(--muted); white-space: nowrap; }
.bars .bar:hover .fill { background: var(--jade); opacity: .55; }

/* ---------- AI queue ---------- */
.queue-item { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 18px; align-items: start; padding: 16px 0; border-bottom: 1px solid var(--line); }
.queue-item:last-child { border-bottom: none; }
.queue-item .who b { font-family: var(--display); color: var(--ink); font-size: 15px; }
.queue-item .reason { font-size: 13px; color: var(--ink-2); margin-top: 4px; }
.queue-item .msg { font-size: 12.5px; color: var(--muted); margin-top: 8px; padding-left: 10px; border-left: 2px solid var(--line-strong); }
.queue-item .meta { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.queue-item .acts { display: flex; gap: 6px; }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: minmax(0,1.4fr) minmax(300px,1fr); gap: 16px; align-items: start; }
.svc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.svc-row:last-child { border-bottom: none; }
.svc-row .nm { font-size: 13px; color: var(--ink); }
.svc-row .pr { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.disc-input { width: 64px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px; background: var(--surface); font-size: 12px; text-align: right; }
.total-line { display: flex; justify-content: space-between; padding: 6px 0; font-size: 13px; }
.total-line.big { font-size: 17px; font-family: var(--display); color: var(--ink); border-top: 1px solid var(--line-strong); margin-top: 8px; padding-top: 12px; }

/* ---------- drawer / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15,21,18,.34); z-index: 40; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: min(560px, 100vw);
  background: var(--paper); border-left: 1px solid var(--line); z-index: 41;
  overflow-y: auto; padding: 26px 28px 60px; box-shadow: -12px 0 40px rgba(0,0,0,.12);
}
.drawer h2 { font-size: 22px; }
.drawer .close { position: absolute; top: 18px; right: 20px; background: none; border: none; font-size: 20px; color: var(--muted); cursor: pointer; }
.drawer .grid { gap: 10px; }
.drawer .kpi { padding: 12px 14px; }
.drawer .kpi .value { font-size: 19px; margin-top: 6px; overflow-wrap: anywhere; }
.drawer .kpi .delta { font-size: 11px; }
.modal {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  width: min(460px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--line);
  border-radius: 4px; z-index: 41; padding: 24px; box-shadow: var(--shadow);
  max-height: calc(100vh - 40px); overflow-y: auto;
}
.modal h3 { margin-bottom: 14px; }

/* ---------- toast ---------- */
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--ink); color: var(--paper); padding: 9px 16px; border-radius: 3px; font-size: 13px;
  box-shadow: var(--shadow); animation: pop .2s ease-out;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }

@media (max-width: 1000px) {
  .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .g3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .pos { grid-template-columns: minmax(0,1fr); }
}
@media (max-width: 820px) {
  .login-screen { grid-template-columns: minmax(0,1fr); }
  .login-left { display: none; }
  #app { grid-template-columns: minmax(0,1fr); }
  .sidebar {
    position: fixed; bottom: 0; left: 0; right: 0; top: auto; height: auto;
    flex-direction: row; overflow-x: auto; border-right: none; border-top: 1px solid var(--line);
    padding: 8px; z-index: 30; gap: 2px;
  }
  .sidebar .logo, .sidebar .who, .nav .sep { display: none; }
  .nav { flex-direction: row; margin-top: 0; }
  .nav a { white-space: nowrap; padding: 6px 10px; }
  .view { padding: 18px 16px 96px; }
  .topbar { padding: 10px 16px; }
  .g4, .g3, .g2 { grid-template-columns: minmax(0,1fr); }
  .queue-item { grid-template-columns: minmax(0,1fr); gap: 10px; }
  .queue-item .acts { justify-content: flex-start; }
}

/* ---------- AI wallet ---------- */
.wallet-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.wallet-head h3 { margin: 0; }
.wallet-head .acts { display: flex; gap: 6px; margin-left: auto; }
.wallet-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); gap: 14px; margin-top: 16px; }
.wallet-cell { padding: 12px 14px; border: 1px solid var(--line); border-radius: 4px; background: var(--surface-2); }
.wallet-cell .k { font-family: var(--mono); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.wallet-cell .v { font-family: var(--display); font-size: 20px; color: var(--ink); margin-top: 6px; font-variant-numeric: tabular-nums; }
.wallet-cell .v.danger { color: var(--danger); }
.wallet-cell .n { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.wallet-budget { margin-top: 16px; }
.wallet-budget .line { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; color: var(--muted); }
.wallet-track { height: 6px; margin-top: 7px; border-radius: 999px; background: var(--line); overflow: hidden; }
.wallet-track > i { display: block; height: 100%; background: var(--jade); }
.wallet-track.bad > i { background: var(--danger); }
.wallet-alert {
  margin-top: 14px; padding: 9px 12px; border: 1px solid var(--amber); border-left-width: 3px;
  border-radius: 3px; background: var(--amber-soft); color: var(--amber); font-size: 12.5px; line-height: 1.6;
}
.wallet-agents { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 6px; }
.wallet-agents .svc-row { padding: 8px 0; }
@media (max-width: 820px) {
  .wallet-strip { grid-template-columns: 1fr 1fr; }
  .wallet-head .acts { margin-left: 0; }
}
