:root {
  --bg: #0d0f14;
  --bg-elev: #151922;
  --bg-elev-2: #1c212d;
  --bg-hover: #232a38;
  --border: #2a3142;
  --text: #e8ecf4;
  --text-dim: #98a2b8;
  --text-mute: #616c82;
  --gold: #f0b429;
  --gold-dim: #b8860b;
  --green: #2ecc71;
  --red: #ff5c5c;
  --blue: #4a9eff;
  --purple: #a77bff;
  --cyan: #22d3ee;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333c4f; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #44506a; }

/* ---------- Login ---------- */
.login-screen {
  position: fixed; inset: 0; display: grid; place-items: center;
  background:
    radial-gradient(900px 500px at 15% 10%, rgba(240, 180, 41, 0.14), transparent 60%),
    radial-gradient(700px 500px at 85% 90%, rgba(167, 123, 255, 0.14), transparent 60%),
    var(--bg);
  z-index: 100;
}
.login-card {
  width: 380px; max-width: 92vw; background: var(--bg-elev);
  border: 1px solid var(--border); border-radius: 18px;
  padding: 34px 30px 24px; box-shadow: var(--shadow);
}
.login-brand { text-align: center; margin-bottom: 26px; }
.login-logo {
  width: 60px; height: 60px; margin: 0 auto 12px; border-radius: 16px;
  display: grid; place-items: center; font-weight: 800; font-size: 22px;
  color: #1a1206; background: linear-gradient(135deg, #f0b429, #ffd76e);
  box-shadow: 0 8px 22px rgba(240, 180, 41, 0.32);
}
.login-logo.small { width: 38px; height: 38px; font-size: 14px; border-radius: 10px; margin: 0; }
.login-brand h1 { font-size: 24px; letter-spacing: 2px; }
.login-brand p { color: var(--text-dim); font-size: 13px; margin-top: 4px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
.login-error { color: var(--red); font-size: 12px; min-height: 18px; margin-bottom: 6px; }
.login-hint { margin-top: 18px; font-size: 11px; color: var(--text-mute); text-align: center; line-height: 1.7; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 226px; flex: 0 0 226px; background: var(--bg-elev);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.sidebar-brand strong { display: block; font-size: 15px; letter-spacing: 1px; }
.sidebar-brand small { color: var(--text-mute); font-size: 11px; }
.nav { flex: 1; overflow-y: auto; padding: 10px 8px; }
.nav-group-label { font-size: 10px; text-transform: uppercase; letter-spacing: 1.4px; color: var(--text-mute); padding: 12px 10px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-dim); cursor: pointer; font-size: 13.5px; user-select: none; margin-bottom: 2px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: linear-gradient(90deg, rgba(240,180,41,.18), rgba(240,180,41,.04)); color: var(--gold); box-shadow: inset 2px 0 0 var(--gold); }
.nav-item .ico { width: 18px; text-align: center; font-size: 15px; }
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }
.user-badge { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; }
.user-badge .avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-elev-2); color: var(--gold); font-weight: 700; font-size: 13px; }
.user-badge .meta { line-height: 1.25; overflow: hidden; }
.user-badge .meta strong { font-size: 13px; display: block; }
.user-badge .meta small { font-size: 11px; color: var(--text-mute); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; border-bottom: 1px solid var(--border); background: rgba(21,25,34,.8);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
}
.topbar-title h2 { font-size: 19px; }
.topbar-title p { font-size: 12px; color: var(--text-mute); margin-top: 2px; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.clock { font-size: 12px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.view { padding: 22px 24px 60px; flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--text);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
  font-family: inherit; transition: .15s; display: inline-flex; align-items: center; gap: 6px;
  white-space: nowrap;
}
.btn:hover { background: var(--bg-hover); border-color: #3a4459; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, #f0b429, #e09b12); color: #1a1206; border-color: transparent; font-weight: 600; }
.btn-primary:hover { background: linear-gradient(135deg, #ffc641, #f0a80f); }
.btn-danger { background: rgba(255,92,92,.12); color: var(--red); border-color: rgba(255,92,92,.35); }
.btn-danger:hover { background: rgba(255,92,92,.22); }
.btn-success { background: rgba(46,204,113,.12); color: var(--green); border-color: rgba(46,204,113,.35); }
.btn-success:hover { background: rgba(46,204,113,.22); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Inputs ---------- */
input, select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 8px 11px; border-radius: var(--radius-sm); font-size: 13px; font-family: inherit;
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(240,180,41,.12); }
input::placeholder, textarea::placeholder { color: var(--text-mute); }
select option { background: var(--bg-elev); }
textarea { resize: vertical; min-height: 70px; }
label.form-field { display: block; margin-bottom: 14px; }
label.form-field > span { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 6px; }
label.form-field > span .req { color: var(--red); margin-left: 2px; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.card {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card-title .sub { font-size: 12px; color: var(--text-mute); font-weight: 400; }

.stat { display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.stat .label { font-size: 12px; color: var(--text-dim); }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.stat .delta { font-size: 11px; color: var(--text-mute); }
.stat .accent { position: absolute; right: -10px; bottom: -14px; font-size: 56px; opacity: .08; }
.stat.gold .value { color: var(--gold); }
.stat.green .value { color: var(--green); }
.stat.blue .value { color: var(--blue); }
.stat.purple .value { color: var(--purple); }
.stat.red .value { color: var(--red); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-elev); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 11px 14px; font-size: 12px; color: var(--text-dim);
  background: var(--bg-elev-2); border-bottom: 1px solid var(--border); white-space: nowrap; font-weight: 600;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid rgba(42,49,66,.6); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.02); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-variant-numeric: tabular-nums; color: var(--text-dim); font-size: 12px; }
.empty { padding: 46px 20px; text-align: center; color: var(--text-mute); }
.empty .big { font-size: 34px; opacity: .3; display: block; margin-bottom: 10px; }
.row-actions { display: flex; gap: 6px; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }
.search-box { position: relative; min-width: 220px; }
.search-box input { padding-left: 30px; }
.search-box::before { content: "⌕"; position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-mute); font-size: 15px; }

/* ---------- Tags ---------- */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; font-size: 11px; background: var(--bg-elev-2); color: var(--text-dim); border: 1px solid var(--border); }
.tag.gold { color: var(--gold); border-color: rgba(240,180,41,.3); background: rgba(240,180,41,.1); }
.tag.green { color: var(--green); border-color: rgba(46,204,113,.3); background: rgba(46,204,113,.1); }
.tag.red { color: var(--red); border-color: rgba(255,92,92,.3); background: rgba(255,92,92,.1); }
.tag.blue { color: var(--blue); border-color: rgba(74,158,255,.3); background: rgba(74,158,255,.1); }
.tag.purple { color: var(--purple); border-color: rgba(167,123,255,.3); background: rgba(167,123,255,.1); }
.tag.cyan { color: var(--cyan); border-color: rgba(34,211,238,.3); background: rgba(34,211,238,.1); }

.stock-bar { width: 90px; height: 6px; background: var(--bg); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; margin-right: 8px; }
.stock-bar > i { display: block; height: 100%; border-radius: 3px; }

/* ---------- Modal ---------- */
.modal-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 200; padding: 20px; animation: fade .15s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 14px;
  width: 520px; max-width: 100%; max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow); animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0 } to { transform: none; opacity: 1 } }
.modal.lg { width: 780px; }
.modal.xl { width: 1000px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 15px; }
.modal-close { background: none; border: none; color: var(--text-mute); font-size: 20px; cursor: pointer; line-height: 1; padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ---------- Toast ---------- */
.toast-root { position: fixed; top: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--bg-elev-2); border: 1px solid var(--border); border-left: 3px solid var(--blue);
  padding: 11px 16px; border-radius: var(--radius-sm); box-shadow: var(--shadow); font-size: 13px;
  min-width: 220px; animation: slidein .2s ease;
}
@keyframes slidein { from { transform: translateX(20px); opacity: 0 } to { transform: none; opacity: 1 } }
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--gold); }

/* ---------- POS ---------- */
.pos { display: grid; grid-template-columns: 1fr 380px; gap: 16px; align-items: start; }
.pos-catalog { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.pos-tile {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; cursor: pointer; transition: .15s; position: relative; overflow: hidden;
}
.pos-tile:hover { border-color: var(--gold); transform: translateY(-2px); }
.pos-tile .name { font-size: 13px; font-weight: 600; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-tile .price { color: var(--gold); font-weight: 700; font-variant-numeric: tabular-nums; }
.pos-tile .stock { font-size: 11px; color: var(--text-mute); margin-top: 4px; }
.pos-tile.out { opacity: .45; cursor: not-allowed; }
.pos-tile.out:hover { border-color: var(--border); transform: none; }
.pos-cart { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); position: sticky; top: 92px; display: flex; flex-direction: column; max-height: calc(100vh - 130px); }
.pos-cart-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.pos-cart-items { flex: 1; overflow-y: auto; padding: 8px; min-height: 120px; }
.cart-item { display: flex; align-items: center; gap: 8px; padding: 8px; border-radius: var(--radius-sm); }
.cart-item:hover { background: var(--bg-hover); }
.cart-item .ci-name { flex: 1; font-size: 13px; min-width: 0; }
.cart-item .ci-name small { display: block; color: var(--text-mute); font-size: 11px; }
.qty-ctrl { display: flex; align-items: center; gap: 4px; }
.qty-ctrl button { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); cursor: pointer; font-size: 14px; line-height: 1; }
.qty-ctrl button:hover { background: var(--bg-hover); }
.qty-ctrl span { min-width: 26px; text-align: center; font-variant-numeric: tabular-nums; font-size: 13px; }
.ci-amount { width: 62px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 13px; }
.pos-cart-foot { border-top: 1px solid var(--border); padding: 14px 16px; }
.pos-total { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; font-size: 13px; color: var(--text-dim); }
.pos-total.grand { font-size: 15px; color: var(--text); }
.pos-total.grand .val { font-size: 26px; font-weight: 800; color: var(--gold); font-variant-numeric: tabular-nums; }
.pos-actions { display: flex; gap: 8px; margin-top: 12px; }
.cat-tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.cat-tab { padding: 6px 13px; border-radius: 20px; border: 1px solid var(--border); background: var(--bg-elev); cursor: pointer; font-size: 12.5px; color: var(--text-dim); }
.cat-tab.active { border-color: var(--gold); color: var(--gold); background: rgba(240,180,41,.1); }

/* ---------- Charts ---------- */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.bar-label { font-size: 10px; fill: var(--text-mute); }
.bar-value { font-size: 10px; fill: var(--text-dim); }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12px; color: var(--text-dim); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }

/* ---------- Misc ---------- */
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.kv:last-child { border-bottom: none; }
.kv span:first-child { color: var(--text-dim); }
.kv span:last-child { font-variant-numeric: tabular-nums; }
.list-scroll { max-height: 340px; overflow-y: auto; }
.text-dim { color: var(--text-dim); }
.text-mute { color: var(--text-mute); }
.text-gold { color: var(--gold); }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-1 { gap: 8px; } .gap-2 { gap: 16px; }
.justify-between { justify-content: space-between; }
.f1 { flex: 1; }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); display: inline-block; margin-right: 6px; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.pill-row { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { font-size: 12px; color: var(--text-mute); }

@media (max-width: 1100px) {
  .pos { grid-template-columns: 1fr; }
  .pos-cart { position: static; max-height: none; }
  .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: -240px; z-index: 90; transition: left .2s; }
  .sidebar.open { left: 0; }
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}
