:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --panel: #ffffff;
  --line: #dfe5ec;
  --text: #182230;
  --muted: #68758a;
  --primary: #0b66d0;
  --primary-dark: #08529f;
  --ok: #12855b;
  --warn: #a36a00;
  --error: #c62828;
  --sidebar: #10223a;
  --sidebar-hover: #1b3455;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
.app-shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--sidebar); color: #fff; padding: 24px 18px; display: flex; flex-direction: column; gap: 24px; }
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark { width: 44px; height: 44px; border-radius: 10px; background: #fff; color: var(--sidebar); display: grid; place-items: center; font-weight: 900; }
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; font-size: 12px; color: #aebdd2; margin-top: 4px; }
.nav { display: flex; flex-direction: column; gap: 6px; }
.nav-item { border: 0; background: transparent; color: #dce6f2; text-align: left; padding: 12px 14px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.nav-item:hover { background: var(--sidebar-hover); }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-tip { margin-top: auto; font-size: 12px; line-height: 1.6; color: #91a3bd; border-top: 1px solid rgba(255,255,255,.12); padding-top: 14px; }
.main { min-width: 0; padding: 24px 28px 50px; }
.topbar { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 25px; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.topbar-settings { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
label { display: block; font-size: 13px; color: #405065; font-weight: 600; }
select, input, textarea { width: 100%; min-height: 38px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; font: inherit; background: #fff; color: var(--text); }
.topbar-settings select { width: 165px; }
button { border: 0; border-radius: 8px; background: var(--primary); color: #fff; min-height: 38px; padding: 8px 15px; font: inherit; font-weight: 700; cursor: pointer; }
button:hover { background: var(--primary-dark); }
button.ghost { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
button.ghost:hover { background: #eef5ff; }
button.small, .small-link { min-height: 31px; padding: 5px 10px; font-size: 12px; }
.small-link { display: inline-block; color: var(--primary); text-decoration: none; border: 1px solid var(--primary); border-radius: 6px; line-height: 20px; padding: 2px 8px; background: #fff; }
.view { display: none; }
.view.active { display: block; }
.stat-grid { display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.stat b { display: block; font-size: 27px; margin-top: 6px; }
.stat span { color: var(--muted); font-size: 13px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 18px; box-shadow: 0 2px 8px rgba(20,40,70,.04); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.panel-header h2 { font-size: 17px; margin: 0; }
.panel-header.sub { margin-top: 18px; }
.panel-header h3 { font-size: 14px; margin: 0; }
.mode-bar { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-bottom: 18px; }
.mode { background: #fff; color: #3c4d63; border: 1px solid var(--line); }
.mode.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.scan-layout { display: grid; grid-template-columns: minmax(360px, 1.25fr) minmax(300px, .75fr); gap: 18px; align-items: start; }
.scan-input-wrap { display: grid; grid-template-columns: 1fr 110px; gap: 8px; margin: 10px 0 14px; }
#scanInput { min-height: 54px; font-size: 20px; font-weight: 700; letter-spacing: .5px; }
.scan-feedback { border-radius: 8px; padding: 14px; border: 1px solid var(--line); background: #f7f9fc; font-weight: 700; }
.scan-feedback.ok { background: #e9f8f1; border-color: #98d7ba; color: var(--ok); }
.scan-feedback.warn { background: #fff6df; border-color: #e3bd70; color: var(--warn); }
.scan-feedback.error { background: #fdecec; border-color: #ef9d9d; color: var(--error); }
.scan-actions { display: flex; gap: 8px; margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 8px; }
.current-bag { border: 1px dashed #a9b9cc; border-radius: 10px; padding: 14px; background: #f8fbff; }
.current-bag .barcode { font-size: 20px; font-weight: 800; color: var(--primary); }
.empty { color: var(--muted); background: #f7f9fc; border: 1px dashed var(--line); border-radius: 8px; padding: 18px; }
.scan-log { max-height: 360px; overflow: auto; display: flex; flex-direction: column; gap: 7px; }
.log-item { border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; font-size: 13px; background: #fff; }
.log-item.ok { border-left: 4px solid var(--ok); }
.log-item.warn { border-left: 4px solid var(--warn); }
.log-item.error { border-left: 4px solid var(--error); }
.search-row, .filter-row { display: grid; grid-template-columns: 1fr 110px; gap: 8px; margin-bottom: 16px; }
.filter-row { grid-template-columns: 1fr 150px 100px; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: 13px; white-space: nowrap; }
th { background: #f4f7fb; color: #4b5b70; position: sticky; top: 0; z-index: 1; }
tr:last-child td { border-bottom: 0; }
.status { display: inline-block; padding: 3px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #edf2f8; color: #4d5f77; }
.status.OPEN { background: #e8f1ff; color: var(--primary); }
.status.SEALED, .status.LOADED { background: #eaf7f0; color: var(--ok); }
.status.HANDED_OVER { background: #e8f1ff; color: var(--primary); }
.status.OPEN_CASE, .status.OPEN { color: #a35a00; background: #fff3d9; }
.status.RESOLVED { color: var(--ok); background: #e9f8f1; }
.timeline { border-left: 3px solid var(--line); margin: 14px 0 20px 8px; padding-left: 18px; display: flex; flex-direction: column; gap: 14px; }
.timeline-item { position: relative; }
.timeline-item:before { content: ""; position: absolute; left: -25px; top: 5px; width: 11px; height: 11px; border-radius: 50%; background: var(--primary); }
.timeline-item.error:before { background: var(--error); }
.timeline-item.warn:before { background: var(--warn); }
.timeline-item h4 { margin: 0 0 4px; }
.timeline-item .time { color: var(--muted); font-size: 12px; }
.diagnosis { border-radius: 9px; padding: 13px; margin: 12px 0; background: #f2f7ff; border: 1px solid #bfd8f8; }
.info-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 10px; margin: 12px 0; }
.info-item { background: #f7f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.info-item span { display: block; color: var(--muted); font-size: 12px; }
.info-item b { display: block; margin-top: 4px; word-break: break-all; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.media-card { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.media-card img, .media-card video { width: 100%; height: 140px; object-fit: cover; display: block; background: #000; }
.media-meta { padding: 8px; font-size: 12px; color: var(--muted); word-break: break-all; }
.upload-box { border-top: 1px solid var(--line); padding-top: 16px; margin-top: 18px; display: grid; gap: 8px; }
.upload-box h3 { margin: 0; font-size: 14px; }
.two-col, .setup-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-vertical { display: grid; gap: 10px; }
.muted { color: var(--muted); }
.pill { background: #eaf7f0; color: var(--ok); border-radius: 999px; padding: 4px 10px; font-size: 12px; font-weight: 700; }
.toast { position: fixed; right: 22px; bottom: 22px; display: none; background: #182230; color: #fff; border-radius: 8px; padding: 12px 16px; max-width: 360px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.show { display: block; }
@media (max-width: 1200px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } .mode-bar { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .nav { flex-direction: row; overflow: auto; }
  .nav-item { white-space: nowrap; }
  .scan-layout, .two-col, .setup-grid { grid-template-columns: 1fr; }
  .topbar { align-items: start; flex-direction: column; }
}
@media (max-width: 640px) {
  .main { padding: 16px; }
  .stat-grid, .mode-bar, .form-grid, .info-grid { grid-template-columns: 1fr; }
  .search-row, .filter-row { grid-template-columns: 1fr; }
}


/* Auth */
.hidden { display: none !important; }
.login-view { min-height:100vh; display:grid; place-items:center; background:#f4f6f8; padding:24px; }
.login-card { width:min(420px,100%); background:#fff; border-radius:16px; padding:28px; box-shadow:0 16px 40px rgba(15,23,42,.12); }
.login-card h2 { margin:22px 0 16px; }
.login-brand { margin-bottom:0; }
.login-card button { width:100%; }
.login-card .ghost { margin-top:10px; }
