/* ── cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1); min-width: 0; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 13px 16px 0; }
.card-h h3 { font-size: 14px; font-weight: 650; display: flex; align-items: center; gap: 8px; }
.card-h .sub { font-size: 12px; color: var(--text-3); font-weight: 450; }
.card-b { padding: 12px 16px 16px; }
.card-b.flush { padding: 8px 0 0; }
.card.glass { background: var(--surface-glass); backdrop-filter: blur(var(--blur)); -webkit-backdrop-filter: blur(var(--blur)); }
.card.clickable { cursor: pointer; transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur); }
.card.clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); border-color: var(--border-strong); }

/* ── KPI */
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; position: relative; overflow: hidden; }
.kpi-label { font-size: 12px; color: var(--text-2); font-weight: 560; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 23px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-sub { font-size: 11.5px; color: var(--text-3); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.kpi .delta-up { color: var(--success); font-weight: 600; }
.kpi .delta-down { color: var(--danger); font-weight: 600; }
.kpi .kpi-ico { position: absolute; right: 12px; top: 12px; width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); }
.kpi.tone-danger .kpi-ico { background: #fde8e8; color: var(--danger); }
.kpi.tone-warn .kpi-ico { background: #fef3c7; color: #b45309; }
.kpi.tone-info .kpi-ico { background: #dbeafe; color: var(--info); }
[data-theme='dark'] .kpi.tone-danger .kpi-ico { background: #3b1414; }
[data-theme='dark'] .kpi.tone-warn .kpi-ico { background: #3a2a0c; }
[data-theme='dark'] .kpi.tone-info .kpi-ico { background: #10203f; }

/* ── buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 13px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font-weight: 560; font-size: 13px; cursor: pointer; white-space: nowrap; transition: background var(--dur), border-color var(--dur), box-shadow var(--dur), transform 80ms; }
.btn:hover { background: var(--surface-2); border-color: var(--slate-400); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-600); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: #b91c1c; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12px; border-radius: 8px; }
.btn.lg { height: 42px; padding: 0 18px; font-size: 14px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 28px; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: 10px 0 0 10px; margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 10px 10px 0; }
.btn-group .btn.active { background: var(--brand-50); color: var(--brand); border-color: var(--brand-100); z-index: 1; }

/* ── inputs */
.input, .select, textarea.input { height: 34px; padding: 0 11px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); min-width: 0; transition: border-color var(--dur), box-shadow var(--dur); }
textarea.input { height: auto; padding: 8px 11px; min-height: 70px; }
.input:focus, .select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent); }
.input.invalid { border-color: var(--danger); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-2); }
.field .err { font-size: 11.5px; color: var(--danger); min-height: 0; }
.field .hint { font-size: 11.5px; color: var(--text-3); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.search-input { position: relative; }
.search-input .input { padding-left: 32px; width: 100%; }
.search-input .ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.check { display: inline-flex; align-items: center; gap: 7px; cursor: pointer; font-size: 13px; }
.check input { accent-color: var(--brand); width: 15px; height: 15px; }

/* ── badges / pills */
.badge { display: inline-flex; align-items: center; gap: 4px; height: 21px; padding: 0 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--slate-100); color: var(--slate-700); white-space: nowrap; line-height: 1; }
[data-theme='dark'] .badge { background: #1e2a26; color: var(--text-2); }
.badge.success { background: #dcfce7; color: #166534; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.info { background: #dbeafe; color: #1e40af; }
.badge.brand { background: var(--brand-50); color: var(--brand); }
.badge.critical { background: #881337; color: #fff; }
.badge.rx { background: #DC2626; color: #fff; letter-spacing: 0.02em; }
.badge.outline { background: transparent; border: 1px solid var(--border-strong); }
[data-theme='dark'] .badge.success { background: #0f2e1c; color: #86efac; }
[data-theme='dark'] .badge.danger { background: #3b1414; color: #fca5a5; }
[data-theme='dark'] .badge.warn { background: #3a2a0c; color: #fcd34d; }
[data-theme='dark'] .badge.info { background: #10203f; color: #93c5fd; }
.demo-pill { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 99px; background: #fff7e6; color: #92400e; border: 1px solid #fcd9a3; font-size: 11.5px; font-weight: 700; letter-spacing: 0.02em; white-space: nowrap; }
[data-theme='dark'] .demo-pill { background: #2c2009; border-color: #5c4313; color: #fcd34d; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; flex: none; }
.dot.live { background: var(--danger); animation: blink 1.2s steps(2, start) infinite; }
@keyframes blink { to { visibility: hidden; } }
.sev-CRITICAL { color: var(--critical); } .sev-HIGH { color: var(--danger); } .sev-MEDIUM { color: var(--warning); } .sev-LOW { color: var(--info); } .sev-INFO { color: var(--text-3); }

/* ── tables */
.table-wrap { overflow: auto; border-top: 1px solid var(--border); }
.table-toolbar { display: flex; gap: 8px; align-items: center; padding: 10px 16px; flex-wrap: wrap; }
.table-toolbar .search-input { min-width: 220px; flex: 0 1 300px; }
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.tbl th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: 11.5px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; z-index: 1; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--text); }
.tbl th .sort-ind { opacity: 0.5; margin-left: 4px; font-size: 10px; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background 120ms; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr:hover { background: var(--surface-2); }
.tbl td.num, .tbl th.num { text-align: right; }
.tbl td.wrap { white-space: normal; }
.tbl td .cell-sub { display: block; font-size: 11.5px; color: var(--text-3); }
.table-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 9px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-2); flex-wrap: wrap; }
.empty { padding: 36px 16px; text-align: center; color: var(--text-3); }
.empty .ico { opacity: 0.6; margin-bottom: 8px; }
.skeleton { background: linear-gradient(90deg, var(--slate-100), var(--slate-200), var(--slate-100)); background-size: 200% 100%; animation: shimmer 1.2s infinite linear; border-radius: 8px; min-height: 14px; }
[data-theme='dark'] .skeleton { background: linear-gradient(90deg, #17221e, #22312c, #17221e); background-size: 200% 100%; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ── tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tab { padding: 9px 13px; border: none; background: none; cursor: pointer; color: var(--text-2); font-weight: 580; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; gap: 6px; align-items: center; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* ── drawer / modal / overlay */
.overlay { position: fixed; inset: 0; background: rgba(2, 10, 6, 0.38); z-index: 80; opacity: 0; transition: opacity var(--dur) var(--ease); }
.overlay.show { opacity: 1; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--w, 560px), 100vw); background: var(--surface); z-index: 90; box-shadow: var(--shadow-3); transform: translateX(100%); transition: transform 240ms var(--ease); display: flex; flex-direction: column; border-left: 1px solid var(--border); }
.drawer.show { transform: none; }
.drawer-h, .modal-h { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.drawer-h h2, .modal-h h2 { font-size: 16px; }
.drawer-b { padding: 16px 18px; overflow-y: auto; flex: 1; }
.drawer-f, .modal-f { padding: 12px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.modal { position: fixed; left: 50%; top: 50%; width: min(var(--w, 520px), 94vw); max-height: 90vh; transform: translate(-50%, -48%) scale(0.98); opacity: 0; background: var(--surface); z-index: 95; border-radius: 18px; box-shadow: var(--shadow-3); transition: transform var(--dur) var(--ease), opacity var(--dur); display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal.show { transform: translate(-50%, -50%) scale(1); opacity: 1; }
.modal-b { padding: 16px 18px; overflow-y: auto; }

/* ── toast */
.toast-host { position: fixed; right: 18px; bottom: 18px; z-index: 120; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; min-width: 260px; max-width: 400px; background: var(--slate-900); color: #fff; border-radius: 12px; padding: 11px 14px; box-shadow: var(--shadow-3); display: flex; gap: 10px; align-items: flex-start; font-size: 13px; animation: slidein 220ms var(--ease); }
.toast.success { background: #0f3d29; } .toast.error { background: #7f1d1d; } .toast.warn { background: #78350f; }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }

/* ── popover / menu */
.popover { position: absolute; z-index: 70; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-3); min-width: 240px; padding: 6px; animation: pop 140ms var(--ease); }
@keyframes pop { from { transform: translateY(-4px); opacity: 0; } }
.menu-item { display: flex; gap: 10px; align-items: center; width: 100%; padding: 8px 10px; border-radius: 9px; background: none; border: none; text-align: left; cursor: pointer; color: var(--text); }
.menu-item:hover, .menu-item.active { background: var(--surface-2); }
.menu-item.active { color: var(--brand); font-weight: 600; }

/* ── timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 14px 26px; }
.timeline li::before { content: ''; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline .t-dot { position: absolute; left: 0; top: 3px; width: 16px; height: 16px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-50); color: var(--brand); border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border); }
.timeline .t-time { font-size: 11.5px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.timeline .t-title { font-weight: 600; font-size: 13px; }

/* ── misc */
.avatar { width: 32px; height: 32px; border-radius: 10px; flex: none; overflow: hidden; display: inline-block; vertical-align: middle; }
.avatar.lg { width: 56px; height: 56px; border-radius: 14px; }
.avatar svg { width: 100%; height: 100%; display: block; }
.progress { height: 7px; background: var(--slate-100); border-radius: 99px; overflow: hidden; }
[data-theme='dark'] .progress { background: #1e2a26; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.stat-list { display: grid; gap: 8px; }
.stat-row { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.stat-row b { font-variant-numeric: tabular-nums; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; font-weight: 550; }
.chart { width: 100%; height: 260px; }
.chart.sm { height: 180px; } .chart.lg { height: 340px; }
.divider { height: 1px; background: var(--border); margin: 12px 0; }
.callout { border-radius: 12px; padding: 10px 12px; background: var(--brand-50); color: var(--text); border: 1px solid var(--brand-100); font-size: 13px; display: flex; gap: 10px; align-items: flex-start; }
.callout.warn { background: #fffbeb; border-color: #fde68a; }
.callout.danger { background: #fef2f2; border-color: #fecaca; }
.callout.info { background: #eff6ff; border-color: #bfdbfe; }
[data-theme='dark'] .callout.warn { background: #2c2009; border-color: #5c4313; }
[data-theme='dark'] .callout.danger { background: #2b1111; border-color: #5b1c1c; }
[data-theme='dark'] .callout.info { background: #0e1a33; border-color: #1e3a6e; }
.kbd { display: inline-block; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; font-family: var(--mono); font-size: 11px; background: var(--surface-2); }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { height: 28px; padding: 0 11px; border-radius: 99px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-size: 12.5px; font-weight: 560; display: inline-flex; align-items: center; gap: 6px; }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ── top bar widgets */
.clock { display: flex; align-items: center; gap: 6px; padding: 0 4px 0 10px; height: 34px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); font-variant-numeric: tabular-nums; }
.clock .time { font-weight: 650; font-size: 13px; min-width: 132px; }
.clock .speed { font-size: 11.5px; color: var(--text-3); }
.bell-count { position: absolute; top: 2px; right: 1px; min-width: 17px; height: 17px; border-radius: 99px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
.notif-panel { width: min(400px, 94vw); max-height: 70vh; overflow-y: auto; padding: 0; }
.notif-item { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:hover { background: var(--surface-2); }
.notif-item:last-child { border-bottom: none; }

/* ── demo panel FAB */
.demo-fab { position: fixed; right: 18px; bottom: 18px; z-index: 60; }
.demo-panel { position: fixed; right: 18px; bottom: 72px; width: min(380px, 94vw); max-height: 76vh; overflow-y: auto; z-index: 61; background: var(--surface-glass); backdrop-filter: blur(var(--blur)); -webkit-backdrop-filter: blur(var(--blur)); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-3); padding: 12px; }
.seed-chip { display: inline-flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--text-2); }
.seed-chip .progress { width: 70px; }
.topbar .select { min-width: 190px; }
.clock .time, .seed-chip, .demo-pill { white-space: nowrap; }
@media (max-width: 1280px) { .topbar .search-input .input { width: 180px !important; } }

/* top bar: never push controls off-screen */
html, body { max-width: 100%; overflow-x: clip; }
.topbar { min-width: 0; }
.topbar > * { flex-shrink: 0; }
.topbar .search-input { flex: 0 1 260px; min-width: 120px; }
.topbar .search-input .input { width: 100% !important; }
.topbar .select { min-width: 0; flex: 0 1 220px; }
@media (max-width: 1280px) { .seed-chip { font-size: 0; gap: 4px; } .seed-chip .ico { width: 14px; } .clock .time { min-width: 0; } }
@media (max-width: 900px) {
  .topbar .select { flex: 1 1 auto; max-width: none !important; }
  .pill-long { display: none; }
  .demo-pill { padding: 0 8px; }
  .content { padding-bottom: 80px; }
}
@media (max-width: 380px) { .topbar .btn.icon[aria-label^='Toggle light'] { display: none; } }
.seed-chip[hidden] { display: none !important; }
@media (max-width: 1280px) and (min-width: 901px) {
  .topbar .search-input { display: none; }
  .topbar .btn.sm .hide-mobile { display: none; }
  .topbar .select { flex-basis: 170px; }
}
