/* ============================ PKIT design system ========================== */
:root {
  --radius: 10px;
  --radius-sm: 7px;
  --radius-lg: 16px;
  --sp: 4px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "Cascadia Code", "JetBrains Mono", Consolas, monospace;
  --sidebar-w: 244px;
  --shadow: 0 1px 2px rgba(0,0,0,.16), 0 8px 24px rgba(0,0,0,.18);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.14);
}

:root[data-theme="dark"] {
  --bg: #0c1017;
  --bg-2: #10161f;
  --surface: #151c27;
  --surface-2: #1b2431;
  --surface-3: #212c3b;
  --border: #232f40;
  --border-2: #2e3c50;
  --text: #e7edf5;
  --muted: #92a0b3;
  --faint: #61707f;
  --primary: #4f8cff;
  --primary-2: #3c72e0;
  --primary-soft: rgba(79,140,255,.14);
  --accent: #7c5cff;
  --success: #33c98a;
  --success-soft: rgba(51,201,138,.14);
  --warning: #f0b429;
  --warning-soft: rgba(240,180,41,.14);
  --danger: #f0596b;
  --danger-soft: rgba(240,89,107,.14);
  --info: #38bdf8;
  --info-soft: rgba(56,189,248,.14);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #eef1f7;
  --bg-2: #e7ecf4;
  --surface: #ffffff;
  --surface-2: #f6f8fc;
  --surface-3: #eef2f8;
  --border: #e0e6f0;
  --border-2: #d2dae7;
  --text: #16202e;
  --muted: #5f6b7d;
  --faint: #93a0b2;
  --primary: #2f6bed;
  --primary-2: #245ad3;
  --primary-soft: rgba(47,107,237,.10);
  --accent: #6d4dff;
  --success: #12a06a;
  --success-soft: rgba(18,160,106,.12);
  --warning: #c98a00;
  --warning-soft: rgba(201,138,0,.12);
  --danger: #dc3546;
  --danger-soft: rgba(220,53,70,.10);
  --info: #0e8fd6;
  --info-soft: rgba(14,143,214,.12);
  --shadow: 0 1px 2px rgba(20,32,46,.06), 0 10px 26px rgba(20,32,46,.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------- Layout --------------------------------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-logo { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, var(--primary), var(--accent)); display: grid; place-items: center; color: #fff; flex: none; }
.brand-name { font-weight: 700; letter-spacing: .2px; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--faint); margin-top: -2px; }

.nav { padding: 6px 10px; overflow-y: auto; flex: 1; }
.nav-group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: var(--faint); padding: 14px 10px 6px; font-weight: 600; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer; font-weight: 500; margin-bottom: 1px; position: relative;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-item.active svg { color: var(--primary); }
.nav-item svg { width: 17px; height: 17px; color: var(--faint); flex: none; }
.nav-item .nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 10.5px; font-weight: 700; padding: 1px 6px; border-radius: 10px; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 10px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; padding: 0 24px;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .crumb { color: var(--faint); font-size: 13px; }
.topbar-spacer { flex: 1; }
.content { padding: 22px 24px 60px; max-width: 1420px; width: 100%; }

/* user chip */
.userchip { display: flex; align-items: center; gap: 10px; padding: 7px 8px; border-radius: var(--radius); cursor: pointer; }
.userchip:hover { background: var(--surface); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12.5px; flex: none; text-transform: uppercase; }
.userchip .u-name { font-size: 12.5px; font-weight: 600; line-height: 1.1; }
.userchip .u-role { font-size: 11px; color: var(--muted); text-transform: capitalize; }

/* ------------------------------ Components ------------------------------ */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--border); }
.card-head h3 { margin: 0; font-size: 14.5px; font-weight: 650; }
.card-head .sub { color: var(--muted); font-size: 12.5px; }

.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, 1fr); }
.cols-3 { grid-template-columns: repeat(3, 1fr); }
.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .cols-4 { grid-template-columns: repeat(2,1fr); } .cols-3 { grid-template-columns: repeat(2,1fr); } }
@media (max-width: 760px) { .cols-2,.cols-3,.cols-4 { grid-template-columns: 1fr; } }

/* KPI tile */
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .kpi-icon { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi .kpi-icon svg { width: 18px; height: 18px; }
.kpi .kpi-value { font-size: 27px; font-weight: 720; letter-spacing: -.5px; line-height: 1.1; }
.kpi .kpi-foot { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 600; line-height: 1.7; white-space: nowrap; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-muted   { background: var(--surface-3);    color: var(--muted); }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 6px; font-size: 11.5px; background: var(--surface-3); color: var(--muted); font-weight: 500; }

/* status dot */
.sdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.sdot.online { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.sdot.offline { background: var(--faint); }
.sdot.pending { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }

/* buttons */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border-2); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 13px; cursor: pointer; transition: filter .12s, background .12s, border-color .12s; white-space: nowrap; }
.btn:hover { border-color: var(--faint); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--primary); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; }
.btn-block { width: 100%; justify-content: center; }

/* inputs */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 11.5px; color: var(--faint); }
.input, .select, .textarea {
  width: 100%; padding: 9px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-2);
  background: var(--bg-2); color: var(--text); font-size: 13.5px; font-family: inherit; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.textarea { resize: vertical; min-height: 76px; }
select.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2392a0b3' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 620px){ .form-row { grid-template-columns: 1fr; } }

/* toolbar / search */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search { position: relative; flex: 1; min-width: 200px; max-width: 340px; }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--faint); }
.search input { padding-left: 34px; }

/* table */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl thead th { text-align: left; padding: 11px 14px; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.tbl tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr.clickable { cursor: pointer; }
.tbl tbody tr.clickable:hover { background: var(--surface-2); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; }
.cell-strong { font-weight: 600; }
.cell-sub { color: var(--muted); font-size: 12px; }

/* modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(4,8,14,.55); backdrop-filter: blur(2px); display: grid; z-index: 100; padding: 24px; overflow-y: auto; }
.modal-backdrop.center { place-items: center; }
.modal-backdrop.side { justify-items: end; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); width: 100%; max-width: 520px; box-shadow: var(--shadow); animation: pop .16s ease; max-height: calc(100vh - 48px); display: flex; flex-direction: column; }
.modal.lg { max-width: 720px; }
.modal.side-panel { border-radius: var(--radius-lg) 0 0 var(--radius-lg); max-width: 560px; height: calc(100vh - 48px); align-self: start; }
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0; } }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 16px; font-weight: 650; }
.modal-head .x { margin-left: auto; cursor: pointer; color: var(--muted); border-radius: 6px; padding: 4px; display: grid; place-items: center; }
.modal-head .x:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 20px; border-top: 1px solid var(--border); }

/* toast */
#toast-root { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--primary); border-radius: var(--radius-sm); padding: 11px 15px; box-shadow: var(--shadow); font-size: 13px; min-width: 240px; max-width: 380px; animation: slidein .2s ease; display: flex; gap: 10px; align-items: center; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } }

/* misc */
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; }
.gap-6 { gap: 6px; } .gap-8 { gap: 8px; } .gap-16 { gap: 16px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.right { margin-left: auto; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.text-sm { font-size: 12.5px; }
.text-lg { font-size: 16px; }
.strong { font-weight: 650; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.page-title { font-size: 20px; font-weight: 700; margin: 0 0 2px; letter-spacing: -.3px; }
.page-sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.pill-tabs { display: inline-flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.pill-tabs button { border: none; background: transparent; color: var(--muted); padding: 6px 13px; border-radius: 6px; font-weight: 600; font-size: 12.5px; cursor: pointer; }
.pill-tabs button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* empty / loading */
.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty svg { width: 34px; height: 34px; color: var(--faint); margin-bottom: 10px; }
.spinner { width: 22px; height: 22px; border: 2.5px solid var(--border-2); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
.loading-wrap { display: grid; place-items: center; padding: 60px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* progress bar */
.progress { height: 7px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 6px; }
.progress.success > span { background: var(--success); }
.progress.warning > span { background: var(--warning); }

/* definition list / detail rows */
.dl { display: grid; grid-template-columns: 140px 1fr; gap: 9px 14px; font-size: 13px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; }

/* key/value stat inline */
.statline { display: flex; gap: 22px; flex-wrap: wrap; }
.statline .s-val { font-size: 19px; font-weight: 700; }
.statline .s-lbl { font-size: 12px; color: var(--muted); }

/* charts */
.chart svg { display: block; width: 100%; overflow: visible; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.legend .lg { display: flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 80% -10%, var(--primary-soft), transparent),
  radial-gradient(900px 500px at 0% 110%, rgba(124,92,255,.12), transparent); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 30px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.login-brand .brand-logo { width: 38px; height: 38px; }
.login-demo { margin-top: 16px; font-size: 12px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; }
.login-demo code { color: var(--text); }
.err-text { color: var(--danger); font-size: 12.5px; }

.hidden { display: none !important; }
