/* ===========================================================
   AFC Smart ERP — design tokens
   Brand: crimson (logo), navy (uniform), gold #FFBC33 (site accent)
   =========================================================== */
:root {
  --brand: #c8102e; --brand-600: #a50d26; --brand-50: #fdecee;
  --navy: #14213d; --navy-2: #1d2d52; --gold: #ffbc33;
  --bg: #f4f5f8; --surface: #ffffff; --surface-2: #f8f9fb; --surface-3: #eef0f4;
  --border: #e3e6ec; --border-2: #d3d8e0;
  --text: #1a1d24; --text-2: #4a5160; --muted: #7a8394;
  --sidebar-bg: #14213d; --sidebar-text: #c8cfdd; --sidebar-active: rgba(255,255,255,.1);
  --ok: #1a8a4c; --ok-bg: #e5f5ec; --warn: #b26b00; --warn-bg: #fff4dc;
  --bad: #c62828; --bad-bg: #fdeaea; --info: #1f6fd1; --info-bg: #e7f0fc;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --grid: #e8ebf0;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.18);
  --radius: 12px; --radius-sm: 8px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-head: "Poppins", var(--font);
  color-scheme: light;
}
:root[data-accent="navy"]    { --brand: #1d4ed8; --brand-600: #1e40af; --brand-50: #e8eefc; }
:root[data-accent="emerald"] { --brand: #0f8a5f; --brand-600: #0b6e4b; --brand-50: #e3f4ec; }
:root[data-accent="royal"]   { --brand: #6d3fd1; --brand-600: #5a31b3; --brand-50: #efe9fb; }
:root[data-accent="gold"]    { --brand: #c17d00; --brand-600: #9c6500; --brand-50: #fff3d9; }

:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #171b23; --surface-2: #1c212b; --surface-3: #232a36;
  --border: #2a3140; --border-2: #364052;
  --text: #e9ecf2; --text-2: #b6bdcb; --muted: #8590a3;
  --sidebar-bg: #0b0e14; --sidebar-text: #aeb6c6;
  --brand-50: rgba(255,255,255,.06);
  --ok: #4cc685; --ok-bg: rgba(76,198,133,.13); --warn: #f0b23e; --warn-bg: rgba(240,178,62,.13);
  --bad: #ff6b6b; --bad-bg: rgba(255,107,107,.13); --info: #64a6ff; --info-bg: rgba(100,166,255,.13);
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --grid: #262d3a;
  --shadow: 0 1px 2px rgba(0,0,0,.3); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  color-scheme: dark;
}
:root[data-theme="dark"][data-accent="crimson"] { --brand: #e8475f; --brand-600: #d0334b; }
:root[data-theme="dark"][data-accent="navy"] { --brand: #5b8cff; --brand-600: #4677ec; }
:root[data-theme="dark"][data-accent="emerald"] { --brand: #2fb67f; --brand-600: #22a06d; }
:root[data-theme="dark"][data-accent="royal"] { --brand: #9a76ee; --brand-600: #8661e0; }
:root[data-theme="dark"][data-accent="gold"] { --brand: #f0a922; --brand-600: #da9512; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { font-family: var(--font-head); margin: 0; letter-spacing: -.01em; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.small { font-size: 12.5px; }
.center { text-align: center; }
.right { text-align: right; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.grow { flex: 1; }
.mt { margin-top: 16px; } .mt-s { margin-top: 8px; } .mb { margin-bottom: 16px; }

/* ===== Buttons & inputs ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border-2); background: var(--surface); color: var(--text); padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer; font-weight: 500; transition: .15s; white-space: nowrap; }
.btn:hover { background: var(--surface-3); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm, .sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 16px; display: inline-grid; place-items: center; position: relative; }
.icon-btn:hover { background: var(--surface-3); }
.icon-btn.sm { width: 28px; height: 28px; font-size: 12px; }
input, select, textarea { background: var(--surface); border: 1px solid var(--border-2); border-radius: var(--radius-sm); padding: 8px 10px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-50); }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.seg { display: inline-flex; background: var(--surface-3); padding: 3px; border-radius: 10px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; cursor: pointer; color: var(--text-2); font-weight: 500; font-size: 13px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ===== Login ===== */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; background: var(--surface); }
.login-art { position: relative; overflow: hidden; background: var(--navy); }
.login-art img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 20%; opacity: .45; }
.login-art-overlay { position: relative; z-index: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; padding: 48px; color: #fff; background: linear-gradient(180deg, rgba(20,33,61,.1) 0%, rgba(20,33,61,.92) 70%); }
.login-art h1 { font-size: 38px; margin: 18px 0 10px; }
.login-art p { max-width: 460px; color: #d7dcea; line-height: 1.6; }
.login-points { list-style: none; padding: 0; margin: 18px 0 0; display: grid; gap: 10px; }
.login-points li { display: flex; gap: 10px; align-items: center; color: #e8ebf3; }
.login-points span { width: 30px; height: 30px; display: grid; place-items: center; background: rgba(255,255,255,.12); border-radius: 8px; }
.crest, .crest-lg { display: grid; place-items: center; font-family: var(--font-head); font-weight: 700; color: #fff; background: linear-gradient(135deg, #c8102e, #8f0a20); border: 2px solid var(--gold); border-radius: 50%; }
.crest { width: 40px; height: 40px; font-size: 12px; flex: none; }
.crest-lg { width: 64px; height: 64px; font-size: 18px; }
.login-panel { padding: 40px 56px; display: flex; flex-direction: column; justify-content: center; max-width: 640px; overflow-y: auto; }
.login-logo { width: 100%; max-width: 520px; height: auto; margin-bottom: 18px; border-radius: 6px; }
.demo-badge { align-self: flex-start; background: #fff4dc; color: #8a5300; border: 1px solid #ffd987; padding: 4px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; margin-bottom: 14px; }
.login-panel h2 { font-size: 24px; margin-bottom: 4px; }
.role-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin: 18px 0; }
.role-card { border: 1.5px solid var(--border); border-radius: 10px; padding: 10px; cursor: pointer; background: var(--surface); text-align: left; transition: .15s; }
.role-card:hover { border-color: var(--brand); }
.role-card.active { border-color: var(--brand); background: var(--brand-50); }
.role-card .ri { font-size: 18px; }
.role-card strong { display: block; font-size: 13px; margin-top: 4px; }
.role-card span { font-size: 11px; color: var(--muted); }
.login-form { display: grid; gap: 12px; }

/* ===== Shell ===== */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 252px; flex: none; background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 16px 16px 14px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand-text strong { display: block; color: #fff; font-family: var(--font-head); font-size: 15px; }
.brand-text span { font-size: 11.5px; color: var(--gold); }
#nav { flex: 1; overflow-y: auto; padding: 8px 10px 16px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.15) transparent; }
.nav-group { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: #6f7a91; padding: 14px 10px 6px; font-weight: 600; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-text); text-decoration: none; font-size: 13.5px; cursor: pointer; }
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav-item .ni { width: 20px; text-align: center; }
.nav-item .nb { margin-left: auto; background: var(--brand); color: #fff; font-size: 10.5px; padding: 1px 7px; border-radius: 99px; }
.sidebar-foot { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.07); font-size: 12px; }
.sys-status { display: flex; gap: 8px; align-items: center; margin-bottom: 4px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.ok { background: #36c275; } .dot.warn { background: #f0b23e; } .dot.bad { background: #ff5c5c; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.search { flex: 1; max-width: 520px; display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; position: relative; }
.search input { border: 0; background: transparent; flex: 1; padding: 9px 0; box-shadow: none !important; min-width: 0; }
.search-results { position: absolute; top: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); max-height: 380px; overflow-y: auto; z-index: 50; }
.search-results .sr { padding: 9px 12px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--border); }
.search-results .sr:hover { background: var(--surface-2); }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.live-pill { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ok); background: var(--ok-bg); padding: 5px 10px; border-radius: 99px; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(26,138,76,.5); } 70% { box-shadow: 0 0 0 8px rgba(26,138,76,0); } 100% { box-shadow: 0 0 0 0 rgba(26,138,76,0); } }
.badge { position: absolute; top: -5px; right: -5px; background: var(--brand); color: #fff; font-size: 10px; min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; font-weight: 700; }
.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border: 1px solid var(--border); border-radius: 99px; cursor: pointer; }
.avatar { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 600; font-size: 12px; color: #fff; background: var(--navy); flex: none; }
.avatar.lg { width: 56px; height: 56px; font-size: 18px; }
.user-chip .uc-name { font-weight: 600; font-size: 13px; line-height: 1.1; }
.user-chip .uc-role { font-size: 11px; color: var(--muted); }
.only-mobile { display: none; }
.ticker { background: var(--navy); color: #dfe4ef; font-size: 12.5px; overflow: hidden; white-space: nowrap; height: 30px; display: flex; align-items: center; }
.ticker-track { display: inline-flex; gap: 40px; padding-left: 100%; animation: ticker 60s linear infinite; }
.ticker-track span b { color: var(--gold); font-weight: 600; }
@keyframes ticker { to { transform: translateX(-100%); } }
.view { padding: 24px; max-width: 1480px; width: 100%; margin: 0 auto; }

/* ===== Page header ===== */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }

/* ===== Cards & grid ===== */
.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.g-21 { grid-template-columns: 2fr 1fr; }
.g-12 { grid-template-columns: 1fr 2fr; }
.span-2 { grid-column: span 2; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-h h3 { font-size: 15px; font-weight: 600; }
.card-h .sub { font-size: 12px; color: var(--muted); font-weight: 400; font-family: var(--font); }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }
.kpi { padding: 16px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.kpi .k-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.kpi .k-val { font-family: var(--font-head); font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.kpi .k-foot { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.kpi .k-ico { position: absolute; right: 14px; top: 14px; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--brand-50); font-size: 17px; }
.delta-up { color: var(--ok); font-weight: 600; } .delta-down { color: var(--bad); font-weight: 600; }
.flash { animation: flash 1.2s; }
@keyframes flash { 0% { background: var(--brand-50); } 100% { background: transparent; } }

/* ===== Tables ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); position: sticky; top: 0; }
tbody tr:hover { background: var(--surface-2); }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.row-new { animation: rownew 2s; }
@keyframes rownew { 0% { background: var(--ok-bg); } 100% { background: transparent; } }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; font-size: 12.5px; color: var(--muted); }

/* ===== Pills / tags ===== */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text-2); }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--info-bg); color: var(--info); }
.pill.brand { background: var(--brand-50); color: var(--brand); }
.chip { display: inline-flex; padding: 3px 10px; border: 1px solid var(--border); border-radius: 99px; font-size: 12px; cursor: pointer; background: var(--surface); }
.chip.active { border-color: var(--brand); color: var(--brand); background: var(--brand-50); }

/* ===== Progress / bars ===== */
.bar { height: 8px; background: var(--surface-3); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .6s; }
.bar.ok > i { background: var(--ok); } .bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }

/* ===== Charts ===== */
.chart { width: 100%; position: relative; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .axis-text { fill: var(--muted); font-size: 11px; }
.chart .lbl { fill: var(--text-2); font-size: 11px; font-weight: 600; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .mark { transition: opacity .15s; }
.chart:hover .mark.dim { opacity: .35; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin-bottom: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.tip { position: fixed; z-index: 200; pointer-events: none; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-lg); padding: 8px 10px; border-radius: 8px; font-size: 12px; min-width: 120px; }
.tip b { display: block; margin-bottom: 4px; font-size: 12px; }
.tip .tr { display: flex; justify-content: space-between; gap: 12px; }
.tip .tr i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ===== Modal / drawer / toasts ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,14,22,.55); z-index: 100; display: grid; place-items: center; padding: 16px; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: 14px; width: min(640px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; }
.modal.wide { width: min(960px, 100%); }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; position: sticky; top: 0; background: var(--surface); z-index: 2; }
.modal-h h3 { font-size: 17px; }
.modal-b { padding: 20px; }
.modal-f { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@keyframes pop { from { transform: scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100%); background: var(--surface); z-index: 90; box-shadow: var(--shadow-lg); overflow-y: auto; animation: slide .2s ease-out; border-left: 1px solid var(--border); }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }
.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--brand); box-shadow: var(--shadow-lg); border-radius: 10px; padding: 10px 14px; animation: slide .2s; font-size: 13px; display: flex; gap: 10px; }
.toast.ok { border-left-color: var(--ok); } .toast.warn { border-left-color: var(--warn); } .toast.bad { border-left-color: var(--bad); }
.toast b { display: block; }
.popover { position: fixed; top: 60px; right: 16px; z-index: 80; width: min(400px, calc(100vw - 32px)); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 70vh; overflow-y: auto; }
.n-item { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; cursor: pointer; }
.n-item.unread { background: var(--brand-50); }
.n-item .n-ico { font-size: 18px; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 10px; cursor: pointer; border: 2px solid transparent; }
.swatch.active { border-color: var(--text); }

/* ===== Timeline / steps ===== */
.steps { display: grid; gap: 0; }
.step { display: grid; grid-template-columns: 28px 1fr; gap: 10px; position: relative; padding-bottom: 14px; }
.step:not(:last-child)::before { content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--border); }
.step .sd { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); font-size: 12px; font-weight: 700; z-index: 1; }
.step.done .sd { background: var(--ok); color: #fff; }
.step.run .sd { background: var(--brand); color: #fff; animation: pulse 1.2s infinite; }
.step.fail .sd { background: var(--bad); color: #fff; }
.step .st { font-weight: 600; }
.step .ss { font-size: 12px; color: var(--muted); }
.log { font-family: ui-monospace, Consolas, monospace; font-size: 12px; background: #0e1320; color: #c9d4e8; border-radius: 10px; padding: 12px; max-height: 340px; overflow-y: auto; line-height: 1.7; }
.log .t { color: #6f7f9c; } .log .ok { color: #5fd38d; } .log .warn { color: #f5c25b; } .log .bad { color: #ff7a7a; } .log .k { color: #8cb8ff; }

/* ===== Kanban ===== */
.kanban { display: grid; grid-template-columns: repeat(5, minmax(200px,1fr)); gap: 12px; overflow-x: auto; }
.kcol { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px; min-height: 200px; }
.kcol h4 { font-size: 13px; display: flex; justify-content: space-between; margin: 2px 4px 10px; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 10px; margin-bottom: 8px; box-shadow: var(--shadow); font-size: 12.5px; }
.kcard strong { display: block; font-size: 13px; }

/* ===== CCTV ===== */
.cam-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 10px; }
.cam { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16/10; cursor: pointer; border: 2px solid transparent; }
.cam.alert { border-color: var(--bad); animation: camalert 1s infinite; }
@keyframes camalert { 50% { border-color: transparent; } }
.cam.sel { border-color: var(--gold); }
.cam canvas { width: 100%; height: 100%; display: block; }
.cam-label { position: absolute; left: 8px; top: 6px; background: rgba(0,0,0,.45); padding: 1px 6px; border-radius: 4px; color: #fff; font-size: 11px; font-family: ui-monospace, Consolas, monospace; text-shadow: 0 1px 2px #000; }
.cam-rec { position: absolute; right: 8px; top: 6px; color: #fff; font-size: 11px; font-family: ui-monospace, monospace; display: flex; gap: 5px; align-items: center; }
.cam-rec i { width: 8px; height: 8px; border-radius: 50%; background: #ff3b3b; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.cam-main { aspect-ratio: 16/9; }
.timeline-bar { position: relative; height: 34px; background: var(--surface-3); border-radius: 8px; margin: 8px 0; }
.timeline-bar .tw { position: absolute; top: 0; bottom: 0; background: var(--brand-50); border: 1px dashed var(--brand); border-radius: 6px; }
.timeline-bar .tm { position: absolute; top: -4px; bottom: -4px; width: 3px; background: var(--brand); border-radius: 2px; }
.timeline-bar .tm span { position: absolute; top: -18px; left: -20px; font-size: 10.5px; white-space: nowrap; color: var(--brand); font-weight: 600; }
.timeline-bar .ev { position: absolute; top: 9px; width: 16px; height: 16px; border-radius: 50%; background: var(--warn); border: 2px solid var(--surface); }

/* ===== AI chat ===== */
.chat { display: flex; flex-direction: column; height: calc(100vh - 210px); min-height: 480px; }
.chat-body, .ai-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 86%; padding: 10px 14px; border-radius: 14px; line-height: 1.55; font-size: 13.5px; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg.bot table { margin: 8px 0; font-size: 12px; background: var(--surface); border-radius: 8px; overflow: hidden; }
.msg.bot th, .msg.bot td { padding: 6px 10px; }
.msg .src { margin-top: 8px; font-size: 11.5px; color: var(--muted); border-top: 1px dashed var(--border-2); padding-top: 6px; }
.msg .guard { margin-top: 8px; font-size: 12px; background: var(--warn-bg); color: var(--warn); padding: 6px 10px; border-radius: 8px; }
.typing span { display: inline-block; width: 6px; height: 6px; background: var(--muted); border-radius: 50%; margin-right: 3px; animation: typ 1s infinite; }
.typing span:nth-child(2) { animation-delay: .15s; } .typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typ { 50% { transform: translateY(-4px); opacity: .4; } }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 16px; border-top: 1px solid var(--border); }
.ai-input { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.ai-input input { flex: 1; }
.ai-float { position: fixed; right: 20px; bottom: 20px; width: min(400px, calc(100vw - 32px)); height: min(600px, calc(100vh - 100px)); background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lg); z-index: 95; display: flex; flex-direction: column; overflow: hidden; animation: pop .2s; }
.ai-head { padding: 12px 14px; background: linear-gradient(135deg, var(--navy), var(--navy-2)); color: #fff; display: flex; justify-content: space-between; align-items: center; }
.ai-head .icon-btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.2); }
.ai-suggest { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px; border-top: 1px solid var(--border); }

/* ===== Misc ===== */
.attn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.attn { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12.5px; user-select: none; background: var(--surface); }
.attn .st { width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; font-weight: 700; font-size: 12px; flex: none; }
.attn.P .st { background: var(--ok-bg); color: var(--ok); }
.attn.A .st { background: var(--bad-bg); color: var(--bad); }
.attn.L .st { background: var(--warn-bg); color: var(--warn); }
.attn.A { border-color: var(--bad); }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.room { border-radius: 8px; padding: 6px; font-size: 11px; text-align: center; border: 1px solid var(--border); cursor: pointer; }
.room b { display: block; font-size: 12px; }
.room.full { background: var(--brand-50); border-color: var(--brand); }
.room.part { background: var(--warn-bg); }
.room.empty { background: var(--ok-bg); }
.wf { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.wf .node { padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; border: 1px solid var(--border); background: var(--surface-2); }
.wf .node.trig { background: var(--info-bg); color: var(--info); border-color: transparent; }
.wf .node.cond { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.wf .node.act { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.wf .arrow { color: var(--muted); }
.toggle { position: relative; width: 38px; height: 22px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span { position: absolute; inset: 0; background: var(--border-2); border-radius: 99px; cursor: pointer; transition: .2s; }
.toggle span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; }
.toggle input:checked + span { background: var(--ok); }
.toggle input:checked + span::after { transform: translateX(16px); }
.perm { width: 26px; height: 26px; border-radius: 6px; display: inline-grid; place-items: center; font-size: 12px; cursor: pointer; }
.perm.y { background: var(--ok-bg); color: var(--ok); } .perm.n { background: var(--surface-3); color: var(--muted); } .perm.s { background: var(--warn-bg); color: var(--warn); }
.receipt { border: 1px dashed var(--border-2); border-radius: 10px; padding: 18px; background: var(--surface-2); }
.receipt .rh { display: flex; justify-content: space-between; border-bottom: 2px solid var(--brand); padding-bottom: 10px; margin-bottom: 12px; gap: 10px; }
.gateway { background: #fff; color: #1a1d24; border-radius: 12px; overflow: hidden; border: 1px solid #e3e6ec; }
.gateway .gh { background: #0b3d91; color: #fff; padding: 14px 16px; display: flex; justify-content: space-between; }
.pay-opt { border: 1.5px solid #e3e6ec; border-radius: 10px; padding: 12px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.pay-opt.active { border-color: #0b3d91; background: #eef3fc; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--surface-3); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.recon-col { max-height: 420px; overflow-y: auto; }
.recon-row { display: flex; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 12.5px; transition: background .3s; }
.recon-row.m { background: var(--ok-bg); }
.recon-row.x { background: var(--bad-bg); }
.recon-row.scan { background: var(--info-bg); }
.empty { padding: 36px; text-align: center; color: var(--muted); }
.hero-banner { background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 60%, var(--brand) 140%); color: #fff; border-radius: var(--radius); padding: 20px 24px; display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.hero-banner h2 { font-size: 20px; }
.hero-banner p { margin: 4px 0 0; color: #cbd3e4; }
.hero-banner .btn { background: rgba(255,255,255,.12); color: #fff; border-color: rgba(255,255,255,.25); }
.hero-banner .btn-primary { background: var(--gold); color: #1a1d24; border-color: var(--gold); }
.list-item { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: transparent; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.map { background: var(--surface-2); border-radius: 10px; }
.map svg { width: 100%; height: auto; display: block; }
.denied { text-align: center; padding: 60px 20px; }
.denied .big { font-size: 48px; }
.hash { font-family: ui-monospace, monospace; font-size: 11px; color: var(--muted); }

@media (max-width: 1200px) {
  .g-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .cam-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 980px) {
  .login { grid-template-columns: 1fr; }
  .login-art { min-height: 300px; }
  .login-art-overlay { padding: 24px 16px; }
  .login-art h1 { font-size: 28px; }
  .login-panel { padding: 24px 16px; max-width: none; }
  .sidebar { position: fixed; left: 0; z-index: 70; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .only-mobile { display: inline-grid; }
  .g-2, .g-3, .g-21, .g-12 { grid-template-columns: minmax(0,1fr); }
  .span-2 { grid-column: auto; }
  .view { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .live-pill, .user-chip .uc-text { display: none; }
}
@media (max-width: 600px) {
  .g-4 { grid-template-columns: minmax(0,1fr); }
  .cam-grid { grid-template-columns: minmax(0,1fr); }
  #aiBtn, #themeBtn { display: none; }
  .search { max-width: none; }
}
@media print {
  .sidebar, .topbar, .ticker, .toasts, .modal-f, .modal-h button { display: none !important; }
  .modal-backdrop { position: static; background: none; }
}
.donut-wrap { display: flex; align-items: center; gap: 18px; }
@media (max-width: 600px) { .donut-wrap { flex-direction: column; align-items: stretch; } .donut-wrap .chart { margin: 0 auto; } }
