/* ============================================================
   XavierDB dashboard — Material Design 3-inspired, zero deps.
   Design tokens: primary #6d4aff, surface light/dark, 8dp grid,
   motion 200-300ms, Roboto-first system stack.
   ============================================================ */

:root {
  --primary: #6d4aff;
  --primary-container: #e9e2ff;
  --on-primary: #ffffff;
  --on-primary-container: #1c0b57;
  --secondary: #00897b;
  --error: #b3261e;
  --surface: #fdf8ff;
  --surface-1: #f6f0ff;
  --surface-2: #efe9f9;
  --on-surface: #1d1b20;
  --on-surface-variant: #49454f;
  --outline: #cac4d0;
  --outline-variant: #e7e0ec;
  --shadow: rgba(0, 0, 0, .25);
  --success: #2e7d32;
  --warning: #b26a00;
  --logs-bg: #f7f8fa;
  --logs-fg: #24292f;
  --logs-warn: var(--warning);
  --logs-error: var(--error);
  --radius: 12px;
  --radius-lg: 20px;
  --elevation-1: 0 1px 2px var(--shadow), 0 1px 3px 1px rgba(0,0,0,.15);
  --elevation-2: 0 1px 2px var(--shadow), 0 2px 6px 2px rgba(0,0,0,.15);
  --elevation-3: 0 4px 8px 3px rgba(0,0,0,.2), 0 1px 3px var(--shadow);
  --ease: cubic-bezier(.2, 0, 0, 1);
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --primary: #cdbfff;
    --primary-container: #4f378b;
    --on-primary: #381e72;
    --on-primary-container: #e9ddff;
    --surface: #141218;
    --surface-1: #1e1b25;
    --surface-2: #262230;
    --on-surface: #e6e1e5;
    --on-surface-variant: #cac4d0;
    --outline: #938f99;
    --outline-variant: #49454f;
    --error: #f2b8b5;
    --success: #81c995;
    --warning: #fdd663;
    --logs-bg: #0d0d10;
    --logs-fg: #c9d1d9;
    --logs-warn: #fdd663;
    --logs-error: #ff7b72;
    --shadow: rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --primary: #cdbfff;
  --primary-container: #4f378b;
  --on-primary: #381e72;
  --on-primary-container: #e9ddff;
  --surface: #141218;
  --surface-1: #1e1b25;
  --surface-2: #262230;
  --on-surface: #e6e1e5;
  --on-surface-variant: #cac4d0;
  --outline: #938f99;
  --outline-variant: #49454f;
  --error: #f2b8b5;
  --success: #81c995;
  --warning: #fdd663;
  --logs-bg: #0d0d10;
  --logs-fg: #c9d1d9;
  --logs-warn: #fdd663;
  --logs-error: #ff7b72;
  --shadow: rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: Roboto, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--on-surface);
  background: var(--surface);
  transition: background .2s var(--ease), color .2s var(--ease);
}
.hidden { display: none !important; }

/* ---------------- login ---------------- */
.login-view {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 20% -10%, var(--surface-2), var(--surface));
}
.login-card {
  width: 340px; padding: 32px 28px; border-radius: var(--radius-lg);
  background: var(--surface-1); text-align: center;
}
.login-logo img { width: 56px; height: 56px; object-fit: contain; }
.login-title { font-size: 22px; font-weight: 500; margin-top: 8px; }
.login-subtitle { color: var(--on-surface-variant); margin: 4px 0 24px; }
.login-error { color: var(--error); min-height: 18px; margin-top: 12px; font-size: 13px; }

/* ---------------- app shell ---------------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 0 16px; height: 64px;
  background: var(--surface-1); border-bottom: 1px solid var(--outline-variant);
  position: relative; z-index: 5;
}
.topbar-brand {
  display: flex; align-items: center; gap: 12px; text-decoration: none;
  color: var(--on-surface); font-size: 20px; font-weight: 500;
  padding: 4px 10px; margin-left: -10px; border-radius: 999px;
  transition: background .15s var(--ease);
}
.topbar-brand:hover { background: var(--surface-2); }
.topbar-title { flex: 1; display: flex; align-items: baseline; gap: 10px; }
#topbar-logo { width: 28px; height: 28px; object-fit: contain; }
.topbar-page { font-size: 14px; font-weight: 400; color: var(--on-surface-variant); }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.body { display: flex; flex: 1; overflow: hidden; }

.drawer {
  width: 232px; background: var(--surface-1); padding: 12px 8px;
  display: flex; flex-direction: column; gap: 2px; overflow-y: auto;
  transition: margin-left .25s var(--ease);
}
.nav-item {
  display: block; padding: 12px 16px; border-radius: 999px; text-decoration: none;
  color: var(--on-surface); font-weight: 500; font-size: 14px;
  transition: background .15s var(--ease);
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-container); color: var(--on-primary-container); }
.drawer-footer { margin-top: auto; padding: 12px 16px; font-size: 12px; color: var(--on-surface-variant); }

.view { flex: 1; overflow-y: auto; padding: 24px; }

@media (max-width: 840px) {
  .drawer { margin-left: -232px; position: absolute; height: calc(100vh - 64px); z-index: 4; box-shadow: var(--elevation-2); }
  .drawer.open { margin-left: 0; }
  .view { padding: 16px; }
}

/* ---------------- components ---------------- */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 500;
  padding: 10px 20px; border-radius: 999px; border: none; cursor: pointer;
  background: var(--primary); color: var(--on-primary);
  transition: filter .15s var(--ease), box-shadow .2s var(--ease), background .15s var(--ease);
}
.btn:hover { filter: brightness(1.08); box-shadow: var(--elevation-1); }
.btn:active { filter: brightness(.94); }
.btn-block { width: 100%; }
.btn-text { background: transparent; color: var(--primary); }
.btn-text:hover { background: var(--primary-container); box-shadow: none; }
.btn-outline { background: transparent; color: var(--primary); border: 1px solid var(--outline); }
.btn-outline:hover { background: var(--surface-2); box-shadow: none; }
.btn-danger { background: var(--error); color: #fff; }
.btn-small { padding: 6px 14px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.topbar-toggle {
  display: flex; align-items: center; gap: 8px;
  background: transparent; color: var(--on-surface);
  border: none; font-family: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 14px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  transition: background .15s var(--ease);
}
.topbar-toggle:hover { background: var(--surface-2); }
.topbar-toggle .ic { display: inline-flex; }
#theme-btn .ic-moon { display: none; }
#theme-btn[data-dark] .ic-moon { display: inline-flex; }
#theme-btn[data-dark] .ic-sun { display: none; }

/* settings popover (graph smoothing + poll interval — per-browser prefs) */
.settings-pop {
  position: absolute; top: 70px; right: 16px; z-index: 40;
  width: 280px; padding: 14px 16px 12px;
  background: var(--surface-1); border: 1px solid var(--outline-variant);
  border-radius: 12px; box-shadow: var(--elevation-3);
}
.settings-pop h3 { font-size: 14px; font-weight: 500; margin: 0 0 12px; }
.sp-row { margin-bottom: 12px; }
.sp-top {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; margin-bottom: 6px;
}
.sp-top label { color: var(--on-surface); }
.sp-val { color: var(--on-surface-variant); font-variant-numeric: tabular-nums; }
.sp-hint { font-size: 11px; color: var(--on-surface-variant); margin: 2px 0 0; }

.mongo-widget {
  display: flex; align-items: center;
  border: 1px solid var(--outline); border-radius: 999px;
  overflow: hidden;
}
.mongo-status {
  display: flex; align-items: center; gap: 8px;
  background: transparent; color: var(--on-surface);
  border: none; font-family: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 8px 7px 14px; cursor: pointer; white-space: nowrap;
  transition: background .15s var(--ease), filter .15s var(--ease);
}
.mongo-status:hover { background: var(--surface-2); }
.mongo-status:active { filter: brightness(.94); }
.mongo-status .dot { flex-shrink: 0; }
.mongo-refresh {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; margin: 1px 1px 1px 0; border-radius: 50%;
  border: none; background: transparent; color: var(--on-surface);
  font-size: 16px; cursor: pointer;
  transition: background .15s var(--ease);
}
.mongo-refresh:hover { background: var(--surface-2); }

.field { text-align: left; margin-bottom: 16px; }
.field label { display: block; font-size: 12px; color: var(--on-surface-variant); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 12px 14px; font-size: 14px; font-family: inherit;
  color: var(--on-surface); background: var(--surface);
  border: 1px solid var(--outline); border-radius: 8px; outline: none;
  transition: border-color .15s var(--ease);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field input:disabled { opacity: .5; }

.card {
  background: var(--surface-1); border: 1px solid var(--outline-variant); border-radius: var(--radius);
  padding: 16px; margin-bottom: 14px;
}
.card h3 { font-size: 14px; font-weight: 500; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.card .hint { font-size: 12px; color: var(--on-surface-variant); margin-top: 8px; line-height: 1.5; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 500;
  background: var(--surface-2); color: var(--on-surface-variant); cursor: pointer;
  border: 1px solid transparent;
}
.chip.active { background: var(--primary-container); color: var(--on-primary-container); }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
  text-align: left; font-size: 12px; font-weight: 500; color: var(--on-surface-variant);
  padding: 8px 10px; border-bottom: 1px solid var(--outline-variant); white-space: nowrap;
}
table.data td { padding: 10px; border-bottom: 1px solid var(--outline-variant); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: var(--surface-2); }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
}
.badge.ok { background: rgba(46,125,50,.15); color: var(--success); }
.badge.bad { background: rgba(179,38,30,.12); color: var(--error); }
.badge.warn { background: rgba(178,106,0,.15); color: var(--warning); }
.badge.info { background: var(--surface-2); color: var(--on-surface-variant); }
.badge.primary { background: var(--primary-container); color: var(--on-primary-container); }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--success); }
.dot.bad { background: var(--error); }
.dot.warn { background: var(--warning); }

.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--on-surface-variant); font-size: 12px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }

.stat { background: var(--surface-1); border: 1px solid var(--outline-variant); border-radius: var(--radius); padding: 10px 14px; }
.stat .stat-label { font-size: 11px; color: var(--on-surface-variant); text-transform: uppercase; letter-spacing: .6px; }
.stat .stat-value { font-size: 19px; font-weight: 500; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .stat-sub { font-size: 11px; color: var(--on-surface-variant); margin-top: 2px; }
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }

/* overview: blocked-apps alert strip */
.ov-alert {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  background: rgba(179,38,30,.08); border: 1px solid rgba(179,38,30,.35);
  border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px;
  color: var(--error); font-size: 13px;
}

/* overview: extra breathing room between the system charts and app traffic */
#ov-traffic { margin-top: 22px; }

/* overview: all-apps RPS chart (shared scale) + window selector */
#ov-rps { margin-top: 22px; }
#ov-rps canvas { width: 100%; height: 190px; display: block; }
.rps-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.rps-legend .rl { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--on-surface-variant); font-family: var(--mono); font-variant-numeric: tabular-nums; }
.rps-legend .rl i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
/* legend + "Show details" button share a row — button sits top right, below the summary text */
.rps-head { display: flex; align-items: flex-start; gap: 10px; position: relative; margin-bottom: 8px; }
.rps-head .rps-legend { flex: 1; }
#ov-rps-details { flex: none; }
.rps-controls { display: flex; justify-content: center; position: relative; margin-top: 10px; }
.win-pop {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 40;
  width: 280px; padding: 10px 12px;
  background: var(--surface-1); border: 1px solid var(--outline-variant); border-radius: 10px;
  box-shadow: var(--elevation-2);
}
/* "Show details" popover — per-app switches for the name_id breakdown */
.det-pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 40;
  width: 250px; padding: 10px 12px;
  background: var(--surface-1); border: 1px solid var(--outline-variant); border-radius: 10px;
  box-shadow: var(--elevation-2);
}

/* Global ⇄ Focus mode switch — always at the exact midpoint of the RPS card
   header: the h3 is a 1fr / auto / 1fr grid, so the two equal side columns
   keep the switch centered regardless of title/summary text widths */
#ov-rps > h3 { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px; }
.rps-mode { position: relative; display: inline-flex; align-items: center; gap: 3px; flex: none; }
#ov-rps-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ov-rps-summary { justify-self: end; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rm-track {
  position: relative; display: inline-flex; padding: 2px;
  border-radius: 999px; background: var(--surface-2); border: 1px solid var(--outline-variant);
}
.rm-thumb {
  position: absolute; top: 2px; bottom: 2px; left: 2px; width: 62px;
  border-radius: 999px; background: var(--surface); box-shadow: var(--elevation-1);
  transition: transform .18s var(--ease);
}
.rps-mode[data-mode="focus"] .rm-thumb { transform: translateX(62px); }
.rm-opt {
  position: relative; z-index: 1; width: 62px; padding: 2px 0;
  border: 0; border-radius: 999px; background: none;
  font: inherit; font-size: 12px; line-height: 1.5; color: var(--on-surface-variant); cursor: pointer;
}
.rm-opt.on { color: var(--primary); font-weight: 600; }
.rm-arrow {
  border: 1px solid var(--outline-variant); border-radius: 999px; background: var(--surface-2);
  padding: 3px 8px; font-size: 10px; line-height: 1; color: var(--on-surface-variant); cursor: pointer;
}
.rm-arrow:hover { background: var(--surface); color: var(--primary); }

/* Focus-mode app picker popover (single-select, drops under the ▾ arrow) */
.focus-pop {
  position: absolute; top: calc(100% + 6px); left: 50%; transform: translateX(-50%); z-index: 40;
  width: 250px; padding: 10px 12px;
  background: var(--surface-1); border: 1px solid var(--outline-variant); border-radius: 10px;
  box-shadow: var(--elevation-2);
}
.fp-row {
  display: flex; align-items: center; gap: 9px; padding: 4px 7px;
  border-radius: 6px; font-size: 12.5px; cursor: pointer;
}
.fp-row:hover { background: var(--surface-2); }
.fp-row.sel { background: var(--primary-container); }
.fp-row .fp-check { margin-left: auto; color: var(--primary); font-weight: 700; }
/* threshold slider section at the bottom of the details popover */
.dp-thr-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--outline-variant);
}
.dp-thr-row .wp-title { font-size: 11px; color: var(--on-surface-variant); text-transform: uppercase; letter-spacing: .5px; }
.dp-thr-row .wp-val { font-family: var(--mono); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.det-pop input[type="range"] { width: 100%; }
.dp-title { font-size: 11px; color: var(--on-surface-variant); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
.dp-list { display: flex; flex-direction: column; gap: 2px; max-height: 240px; overflow-y: auto; }
.dp-row { display: flex; align-items: center; gap: 9px; padding: 3px 0; font-size: 12.5px; cursor: pointer; }
.dp-row .dp-sw { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.dp-row .dp-name { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-row input[type="checkbox"] {
  appearance: none; -webkit-appearance: none; flex: none;
  width: 30px; height: 17px; border-radius: 9px; margin: 0;
  background: var(--surface-2); border: 1px solid var(--outline);
  position: relative; cursor: pointer; transition: background .15s var(--ease);
}
.dp-row input[type="checkbox"]::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--on-surface-variant);
  transition: left .15s var(--ease), background .15s var(--ease);
}
.dp-row input[type="checkbox"]:checked { background: var(--primary); border-color: var(--primary); }
.dp-row input[type="checkbox"]:checked::after { left: 15px; background: var(--on-primary); }

/* mini single-line charts */
.chart-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; }
.chart-card {
  background: var(--surface-1); border: 1px solid var(--outline-variant); border-radius: var(--radius);
  padding: 10px 12px;
}
.chart-card .chart-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chart-card .chart-label { font-size: 11px; color: var(--on-surface-variant); text-transform: uppercase; letter-spacing: .6px; }
.chart-card .chart-value { font-size: 19px; font-weight: 500; font-variant-numeric: tabular-nums; }
.chart-card .chart-sub { font-size: 11px; color: var(--on-surface-variant); margin-top: 1px; }
.chart-card canvas { width: 100%; height: 48px; display: block; margin-top: 6px; }

.progress { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; border-radius: 3px; background: var(--primary); transition: width .3s var(--ease); }

.sparkline { display: block; }
.tree ul { list-style: none; padding-left: 18px; }
.tree .tree-node { margin: 1px 0; }
.tree .tree-row {
  display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-radius: 8px; cursor: pointer;
  position: relative;
}
.tree .tree-row:hover { background: var(--surface-2); }
.tree .tree-row.selected { background: var(--primary-container); }
.tree .caret { width: 14px; text-align: center; display: inline-block; font-size: 11px; color: var(--on-surface-variant); transform: rotate(90deg); transition: transform .15s var(--ease); }
.tree .caret.closed { transform: rotate(0deg); }
.tree .tree-meta { margin-left: auto; display: flex; gap: 8px; align-items: center; font-size: 11px; color: var(--on-surface-variant); font-variant-numeric: tabular-nums; }
/* fixed-width meta slots — app rows and name rows align vertically like a table */
.tree .tree-meta .weight-label, .tree .tree-meta .tm-weight { width: 50px; flex: none; text-align: center; }
.tree .tree-meta .tm-spark { width: 70px; flex: none; }
.tree .tree-meta .tm-rps { width: 11ch; flex: none; white-space: nowrap; }
.tree .tree-meta .tm-limit { width: 10ch; flex: none; white-space: nowrap; }
.tree .tree-meta .tm-p50 { width: 11ch; flex: none; white-space: nowrap; }
.tree .tree-meta .tm-seen { width: 9ch; flex: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree .tree-meta .blockbtn { min-width: 70px; }

/* inline permission panels */
.panel {
  margin: 4px 0 10px 22px; padding: 12px 14px;
  border: 1px solid var(--outline-variant); border-radius: 10px;
  background: var(--surface);
}
.panel .panel-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .8px;
  color: var(--on-surface-variant); margin-bottom: 8px;
}
.panel hr { border: none; border-top: 1px solid var(--outline-variant); margin: 10px 0; }
.panel .sub-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--on-surface-variant); margin: 10px 0 6px; }
.perm-search { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.perm-search input {
  flex: 1; min-width: 120px; padding: 7px 10px; font-size: 12.5px; font-family: var(--mono);
  color: var(--on-surface); background: var(--surface-1);
  border: 1px solid var(--outline); border-radius: 8px; outline: none;
}
.perm-search input:focus { border-color: var(--primary); }
.perm-row { display: flex; align-items: center; gap: 10px; padding: 4px 6px; border-radius: 8px; font-size: 13px; }
.perm-row:hover { background: var(--surface-2); }
.perm-name { font-family: var(--mono); font-size: 12.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.perm-hint { font-size: 11px; color: var(--on-surface-variant); white-space: nowrap; }
.perm-lock { font-size: 11px; color: var(--on-surface-variant); }
.dim { opacity: .55; }

/* action badges — three tiers: solid = explicit · dashed/tinted = inherited · hollow = no rule · gray fill = inherit database */
.perm-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-bottom: 6px; }
.perm-legend .llabel { font-size: 11px; color: var(--on-surface-variant); }
.perm-tools { display: inline-flex; gap: 4px; align-items: center; flex: none; }
.acts { display: inline-flex; gap: 3px; align-items: center; flex: none; }
.act {
  font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .2px;
  padding: 2px 6px; border-radius: 5px; border: 1px solid transparent; cursor: pointer;
  line-height: 1.5; user-select: none; transition: filter .12s var(--ease);
}
.act:hover:not([disabled]) { filter: brightness(1.15); }
.act[disabled] { cursor: not-allowed; }
.act.allow { background: #2e7d32; color: #fff; border-color: #2e7d32; }
.act.deny { background: #b3261e; color: #fff; border-color: #b3261e; }
.act.inherit-allow { background: rgba(46,125,50,.10); color: var(--success); border-color: rgba(46,125,50,.5); border-style: dashed; }
.act.inherit-deny { background: rgba(179,38,30,.08); color: var(--error); border-color: rgba(179,38,30,.5); border-style: dashed; }
.act.inherit { background: var(--surface-2); color: var(--on-surface-variant); border-color: transparent; }
.act.none { background: transparent; color: var(--on-surface-variant); border-color: var(--outline); border-style: dashed; }

/* collection overrides */
.perm-colls { margin: 2px 0 6px 10px; border-left: 2px solid var(--outline-variant); padding-left: 8px; }
.perm-colls .perm-row { padding: 2px 6px; }
.perm-colls .perm-name { font-size: 11.5px; }
.perm-add { display: flex; gap: 6px; align-items: center; margin: 4px 0 0 4px; }
.perm-add input {
  flex: 1; min-width: 90px; max-width: 190px; padding: 5px 8px; font-size: 11.5px; font-family: var(--mono);
  border: 1px solid var(--outline); border-radius: 6px; background: var(--surface-1); color: var(--on-surface); outline: none;
}
.perm-add input:focus { border-color: var(--primary); }
.mini-btn {
  width: 22px; height: 22px; border: none; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--on-surface-variant); font-size: 12px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s var(--ease), color .12s var(--ease);
}
.mini-btn:hover { background: var(--surface-2); color: var(--on-surface); }
.mini-btn.add { width: auto; padding: 0 10px; font-size: 11px; font-weight: 600; color: var(--primary); }
.mini-btn.add:hover { background: var(--primary-container); color: var(--on-primary-container); }

/* switch */
.switch { position: relative; width: 34px; height: 20px; flex: none; }
.switch input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; z-index: 2; }
.switch .track {
  position: absolute; inset: 0; border-radius: 999px; background: var(--outline);
  transition: background .15s var(--ease);
}
.switch .thumb {
  position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%;
  background: #fff; box-shadow: var(--elevation-1); transition: transform .15s var(--ease), left .15s var(--ease), width .15s var(--ease), top .15s var(--ease), height .15s var(--ease), border-radius .15s var(--ease);
}
.switch input:checked ~ .thumb { transform: translateX(14px); }
.switch input:checked ~ .track { background: var(--primary); }
.switch input:indeterminate ~ .track { background: var(--outline); }
.switch input:indeterminate ~ .thumb { transform: none; left: 11px; top: 8px; width: 12px; height: 4px; border-radius: 2px; }
.switch input:disabled { cursor: not-allowed; }
.switch input:disabled ~ .track { opacity: .4; }
.switch input:disabled ~ .thumb { opacity: .5; box-shadow: none; }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar .spacer { flex: 1; }
.table-sm td { padding: 6px 8px; }
.table-sm th { padding: 5px 8px; }
.tnum { font-variant-numeric: tabular-nums; }
.perms-summary { font-size: 11px; color: var(--on-surface-variant); }
.blockbtn { font-size: 12px; padding: 4px 12px; }

/* config sliders */
.sf { margin-bottom: 14px; }
.sf-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.sf-top label { font-size: 12px; color: var(--on-surface-variant); }
.sf-value { font-family: var(--mono); font-size: 12.5px; font-variant-numeric: tabular-nums; color: var(--on-surface); }
input[type="range"] { width: 100%; accent-color: var(--primary); cursor: pointer; }

/* app weight chip + popover */
.weight-label {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; cursor: pointer;
  background: var(--surface-2); color: var(--on-surface-variant);
  transition: background .12s var(--ease), color .12s var(--ease);
}
.weight-label:hover { background: var(--primary-container); color: var(--on-primary-container); }
.weight-label.w-alt { background: var(--primary-container); color: var(--on-primary-container); }
.weight-pop {
  position: absolute; top: calc(100% + 6px); right: 8px; z-index: 40;
  width: 200px; padding: 10px 12px;
  background: var(--surface-1); border: 1px solid var(--outline-variant); border-radius: 10px;
  box-shadow: var(--elevation-2);
}
.weight-pop .wp-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.weight-pop .wp-title { font-size: 11px; color: var(--on-surface-variant); text-transform: uppercase; letter-spacing: .5px; }
.weight-pop .wp-val { font-family: var(--mono); font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.weight-pop .wp-hint { font-size: 10.5px; color: var(--on-surface-variant); margin-top: 6px; line-height: 1.4; }

/* rules editor */
.rule-row { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 8px; background: var(--surface); margin-bottom: 6px; flex-wrap: wrap; }
.rule-row input { width: 130px; padding: 7px 10px; border: 1px solid var(--outline); border-radius: 6px; background: var(--surface); color: var(--on-surface); font-family: var(--mono); font-size: 12px; }
.rule-row .actions-box { display: flex; gap: 4px; }
.rule-row .src-tag { font-size: 10px; color: var(--on-surface-variant); text-transform: uppercase; letter-spacing: .5px; }

/* config form */
.config-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.history-list { max-height: 240px; overflow-y: auto; font-size: 12px; }
.history-list div { padding: 6px 8px; border-bottom: 1px solid var(--outline-variant); display: flex; gap: 8px; }
.history-list .h-desc { flex: 1; }

/* logs */
.logs-card {
  display: flex; flex-direction: column;
  height: calc(100vh - 64px - 48px - 14px); /* topbar + view padding + card margin */
}
.logs-box {
  background: var(--logs-bg); color: var(--logs-fg); font-family: var(--mono); font-size: 12px;
  border-radius: 8px; padding: 12px; flex: 1; min-height: 240px;
  overflow-y: auto; white-space: pre-wrap;
}
@media (max-width: 840px) {
  .logs-card { height: calc(100vh - 64px - 32px - 14px); }
}
.logs-box .lwarn { color: var(--logs-warn); }
.logs-box .lerror { color: var(--logs-error); }
.logs-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px;
}
.logs-head h3 { margin: 0; }
.logs-head svg { vertical-align: -2px; }
.logs-filterbar {
  position: relative; display: flex; align-items: center; gap: 8px; margin-bottom: 8px;
}
.logs-fbadges { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.f-group {
  display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap;
  font-size: 11px; color: var(--on-surface-variant);
}
.f-chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--primary-container); color: var(--on-primary-container);
  border-radius: 999px; padding: 2px 4px 2px 10px; font-size: 11px;
}
.f-chip .f-x {
  background: none; border: none; cursor: pointer; color: inherit; opacity: .75;
  font-size: 11px; line-height: 1; padding: 2px 4px; border-radius: 50%;
}
.f-chip .f-x:hover { opacity: 1; background: var(--surface-2); color: var(--error); }
.fl-sugg {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: flex-start;
  max-height: 180px; overflow-y: auto; margin-top: 2px;
}
.sugg {
  border: 1px solid var(--outline); border-radius: 999px; cursor: pointer;
  background: var(--surface); color: var(--on-surface); font-size: 11px;
  padding: 3px 10px; font-family: var(--mono);
  transition: background .12s var(--ease), border-color .12s var(--ease);
}
.sugg:hover { border-color: var(--primary); }
.sugg.on { background: var(--primary-container); border-color: var(--primary-container); color: var(--on-primary-container); }
.logs-pop {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 40;
  min-width: 260px; padding: 10px 12px;
  background: var(--surface-1); border: 1px solid var(--outline-variant); border-radius: 10px;
  box-shadow: var(--elevation-3);
}
.logs-pop.open { display: block; }
.logs-pop .lp-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.logs-pop .lp-row label { width: 46px; flex: none; font-size: 11px; color: var(--on-surface-variant); }
.logs-pop select, .logs-pop input[type=text] {
  flex: 1; min-width: 0; padding: 5px 8px; font-size: 12px; font-family: var(--mono);
  border: 1px solid var(--outline); border-radius: 6px; background: var(--surface); color: var(--on-surface);
  outline: none;
}
.logs-pop select:focus, .logs-pop input[type=text]:focus { border-color: var(--primary); }
.logs-pop .lp-row select { min-width: 130px; }

/* snackbar + dialog */
.snackbar {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px);
  background: var(--on-surface); color: var(--surface); padding: 12px 20px; border-radius: 8px;
  font-size: 14px; z-index: 100; transition: transform .25s var(--ease); max-width: 90vw;
  box-shadow: var(--elevation-3);
}
.snackbar.show { transform: translateX(-50%) translateY(0); }
.dialog-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.dialog { background: var(--surface-1); border-radius: var(--radius-lg); padding: 24px; width: 460px; max-width: 100%; max-height: 85vh; overflow-y: auto; }
.dialog h3 { margin-bottom: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* misc */
.section-title { font-size: 16px; font-weight: 500; margin: 20px 0 10px; }
.formula-box {
  background: var(--surface); border: 1px dashed var(--outline); border-radius: 8px;
  padding: 12px; font-family: var(--mono); font-size: 12px; line-height: 1.7; margin-top: 10px;
}
.empty-note { color: var(--on-surface-variant); font-size: 13px; padding: 20px; text-align: center; }
canvas { max-width: 100%; }
