:root {
  --bg: #f6f8f7;
  --surface: #ffffff;
  --surface-2: #f1f5f3;
  --sidebar: #ffffff;
  --text: #18231e;
  --muted: #6c7f76;
  --border: #e3ebe7;
  --accent: #17a673;
  --accent-hover: #0e8b5e;
  --accent-rgb: 23, 166, 115;
  --accent-soft: rgba(var(--accent-rgb), .10);
  --on-accent: #ffffff;
  --danger: #d95353;
  --danger-soft: #fdeeee;
  --warning: #b77918;
  --warning-soft: #fff6e7;
  --blue: #3b82f6;
  --blue-soft: #edf4ff;
  --shadow: 0 10px 34px rgba(24, 35, 30, .06);
  --radius: 16px;
  font-family: "Segoe UI", "Microsoft YaHei", system-ui, -apple-system, sans-serif;
}
html[data-accent="blue"] { --accent: #2f7cf6; --accent-hover: #1f66d8; --accent-rgb: 47, 124, 246; }
html[data-accent="violet"] { --accent: #7c5ce5; --accent-hover: #6847d4; --accent-rgb: 124, 92, 229; }
html[data-accent="orange"] { --accent: #e58a24; --accent-hover: #cf7616; --accent-rgb: 229, 138, 36; }
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101211;
    --surface: #181b1a;
    --surface-2: #202422;
    --sidebar: #141716;
    --text: #f2f5f3;
    --muted: #9aa69f;
    --border: #2a302c;
    --accent-soft: rgba(var(--accent-rgb), .16);
    --danger: #ff7b7b;
    --danger-soft: rgba(217, 83, 83, .14);
    --warning: #f0b35a;
    --warning-soft: rgba(183, 121, 24, .17);
    --blue: #8bb8ff;
    --blue-soft: rgba(59, 130, 246, .15);
    --shadow: 0 12px 36px rgba(0, 0, 0, .28);
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .1px; }
h2 { font-size: 23px; }
h3 { font-size: 15px; }
p { margin: 0; }
button, input, textarea, select { font: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Login */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; padding: 32px; box-shadow: var(--shadow);
}
.brand-logo {
  width: 54px; height: 54px; border-radius: 15px; display: block;
  object-fit: cover; background: #000;
}
.brand-logo.small { width: 38px; height: 38px; border-radius: 11px; }
.login-card h1 { font-size: 23px; margin: 20px 0 5px; }
.login-card form { margin-top: 24px; display: grid; gap: 13px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
input, textarea, select {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; padding: 11px 12px; outline: none;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface);
}
textarea { resize: vertical; }
.btn {
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 15px;
  background: var(--surface); color: var(--text); cursor: pointer; transition: .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: rgba(217, 83, 83, .28); background: var(--danger-soft); }
.btn.small { padding: 6px 10px; font-size: 12px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }
.login-foot { margin-top: 20px; color: var(--muted); font-size: 12px; text-align: center; }

/* App shell */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 238px; flex: 0 0 238px; background: var(--sidebar); border-right: 1px solid var(--border);
  padding: 22px 16px; display: flex; flex-direction: column; gap: 20px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 2px 6px 4px; }
.sidebar-brand strong { display: block; font-size: 15px; }
.sidebar-brand small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.nav { display: grid; gap: 4px; }
.nav button {
  text-align: left; border: 0; background: transparent; color: var(--muted);
  padding: 10px 12px; border-radius: 9px; cursor: pointer; font-size: 14px; position: relative;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav button.active::before {
  content: ""; position: absolute; left: 0; top: 9px; bottom: 9px; width: 3px;
  border-radius: 3px; background: var(--accent);
}
.sidebar-bottom { margin-top: auto; display: grid; gap: 16px; }
.side-label { display: block; color: var(--muted); font-size: 11px; margin-bottom: 7px; }
.accent-picker { display: flex; gap: 9px; }
.accent-dot {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
  padding: 0; box-shadow: inset 0 0 0 2px var(--sidebar);
}
.accent-dot.green { background: #17a673; }
.accent-dot.blue { background: #2f7cf6; }
.accent-dot.violet { background: #7c5ce5; }
.accent-dot.orange { background: #e58a24; }
.accent-dot.active { border-color: var(--text); }
.side-meta { display: grid; gap: 11px; font-size: 12px; }
.side-meta strong { font-size: 13px; font-weight: 600; }
.clock { color: var(--muted); font-variant-numeric: tabular-nums; }
.main { flex: 1; min-width: 0; padding: 30px 34px 50px; max-width: 1450px; }
.tab { display: none; animation: fade .16s ease; }
.tab.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-head p { margin-top: 6px; font-size: 13px; }

/* Cards and panels */
.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 13px; margin-bottom: 18px; }
.card, .panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 17px; position: relative; overflow: hidden; }
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 28px; font-weight: 700; margin-top: 8px; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 11px; margin-top: 5px; }
.card.accent .value { color: var(--accent); }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 16px; }
.panel { padding: 18px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 9px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 11px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--surface-2); }
.table-wrap { overflow-x: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12px; }
.empty { padding: 28px 10px; text-align: center; color: var(--muted); font-size: 13px; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 8px; border-radius: 999px; font-size: 11px; border: 1px solid transparent; white-space: nowrap; }
.badge.green { background: var(--accent-soft); color: var(--accent); border-color: rgba(var(--accent-rgb), .22); }
.badge.amber { background: var(--warning-soft); color: var(--warning); border-color: rgba(183, 121, 24, .22); }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: rgba(217, 83, 83, .22); }
.badge.gray { background: var(--surface-2); color: var(--muted); border-color: var(--border); }
.badge.blue { background: var(--blue-soft); color: var(--blue); border-color: rgba(59, 130, 246, .22); }

/* Upload */
.user-search { margin-bottom: 14px; }
.user-search input { max-width: 420px; }
.upload-panel { background: var(--surface); }
.upload-row { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(260px, .7fr); gap: 16px; }
.dropzone {
  border: 1.5px dashed rgba(var(--accent-rgb), .35); border-radius: 13px; min-height: 145px;
  display: grid; place-items: center; align-content: center; gap: 7px; padding: 20px;
  cursor: pointer; text-align: center; color: var(--text); background: var(--accent-soft);
}
.dropzone:hover, .dropzone.drag { border-color: var(--accent); }
.dropzone input { display: none; }
.upload-side { display: grid; gap: 10px; align-content: start; }

/* Forms */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 16px; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: flex; align-items: center; gap: 9px; grid-column: 1 / -1; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); }
.segmented { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; }
.segmented button { background: transparent; border: 0; color: var(--muted); padding: 7px 13px; border-radius: 7px; cursor: pointer; font-size: 12px; }
.segmented button.active { background: var(--surface); color: var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.qr-preview { min-height: 180px; display: grid; place-items: center; border: 1px dashed var(--border); border-radius: 12px; margin: 12px 0; color: var(--muted); overflow: hidden; background: var(--surface-2); }
.qr-preview img { max-width: 100%; max-height: 280px; display: block; }

/* Modal / toast */
.modal-root { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 18px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 25, 20, .42); backdrop-filter: blur(3px); }
.modal {
  position: relative; width: min(560px, 100%); max-height: 90vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 22px; box-shadow: 0 30px 90px rgba(0,0,0,.25);
}
.modal h3 { margin-bottom: 4px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.modal .form-grid { grid-template-columns: 1fr; }
.modal .modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 200; display: grid; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 11px 16px; border-radius: 11px; box-shadow: var(--shadow); font-size: 13px; animation: toastIn .2s ease; }
.toast.error { border-color: rgba(217, 83, 83, .35); color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* Audit */
.audit-item { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.audit-item:last-child { border-bottom: 0; }
.audit-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex: 0 0 auto; }
.audit-main { min-width: 0; }
.audit-main strong { font-size: 13px; }
.audit-main p { color: var(--muted); font-size: 12px; margin-top: 3px; overflow-wrap: anywhere; }
.audit-time { color: var(--muted); font-size: 11px; margin-left: auto; white-space: nowrap; }

@media (max-width: 1100px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { display: block; }
  .sidebar { width: auto; height: auto; position: static; border-right: 0; border-bottom: 1px solid var(--border); padding: 14px 16px; }
  .nav { grid-template-columns: repeat(4, 1fr); gap: 3px; }
  .nav button { text-align: center; padding: 8px 4px; font-size: 12px; }
  .nav button.active::before { display: none; }
  .sidebar-bottom { display: none; }
  .main { padding: 20px 16px 40px; }
  .theme-block, .side-meta { display: none; }
}
@media (max-width: 640px) {
  .main { padding: 16px 12px 32px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .upload-row { grid-template-columns: 1fr; }
  .section-head { align-items: flex-start; flex-direction: column; }
  .form-grid { grid-template-columns: 1fr; }
  h2 { font-size: 20px; }
  .card .value { font-size: 24px; }
  .nav { grid-template-columns: repeat(3, 1fr); }
}
