/* AkiliNOC - design tokens and components.
   Palette validated with the dataviz six-checks validator in both modes.
   Light categorical slots 1-5 carry a sub-3:1 contrast warning, which is
   relieved by the direct value labels every chart in this app renders. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;          /* cards / chart surface */
  --surface-2: #f9f9f7;          /* page plane */
  --surface-3: #f2f2ee;          /* inset rows, table heads */
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* Ordinal ramp for ordered scales (severity). Validated --ordinal in both
     modes: monotone lightness, adjacent dL >= 0.06, light end clears 2:1. */
  --ramp-1: #86b6ef;
  --ramp-2: #5598e7;
  --ramp-3: #256abf;
  --ramp-4: #184f95;
  --ramp-5: #0d366b;

  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-serious: #ec835a;
  --status-critical: #d03b3b;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --surface-2: #0d0d0d;
    --surface-3: #232321;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --ramp-1: #b7d3f6;
    --ramp-2: #86b6ef;
    --ramp-3: #5598e7;
    --ramp-4: #2a78d6;
    --ramp-5: #184f95;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --surface-2: #0d0d0d;
  --surface-3: #232321;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --ramp-1: #b7d3f6;
  --ramp-2: #86b6ef;
  --ramp-3: #5598e7;
  --ramp-4: #2a78d6;
  --ramp-5: #184f95;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--surface-2);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 20px; }
h2 { font-size: 15px; }
h3 { font-size: 13px; }
.muted { color: var(--text-muted); }
.secondary { color: var(--text-secondary); }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------------- layout */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 54px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 650;
  font-size: 15px;
  color: var(--text-primary);
}
.brand:hover { text-decoration: none; }
.brand span { font-size: 11px; font-weight: 500; color: var(--text-muted); }

.nav { display: flex; gap: 2px; flex-wrap: wrap; }
.nav a {
  padding: 6px 11px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
}
.nav a:hover { background: var(--surface-3); text-decoration: none; }
.nav a.active { background: var(--surface-3); color: var(--text-primary); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.page { max-width: 1400px; margin: 0 auto; padding: 20px; }
.page-head {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}
.page-head p { margin: 2px 0 0; color: var(--text-muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-wide { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 980px) {
  .grid-2, .grid-3, .grid-wide { grid-template-columns: minmax(0, 1fr); }
}

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card + .card { margin-top: 16px; }
.card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 14px;
}
.card-head .sub { font-size: 12px; color: var(--text-muted); }
.card-head .actions { margin-left: auto; }

/* ------------------------------------------------------------ stat tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  box-shadow: var(--shadow);
}
.tile .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.tile .value { font-size: 26px; font-weight: 650; margin-top: 4px; line-height: 1.1; }
.tile .sub { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.tile.hero .value { font-size: 48px; letter-spacing: -0.02em; }
.tile.tone-critical .value { color: var(--status-critical); }
.tile.tone-serious .value { color: var(--status-serious); }
.tile.tone-good .value { color: var(--status-good); }

/* --------------------------------------------------------------- badges  */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  background: var(--surface-3);
  color: var(--text-secondary);
  white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.badge.tone-good .dot { background: var(--status-good); }
.badge.tone-warning .dot { background: var(--status-warning); }
.badge.tone-serious .dot { background: var(--status-serious); }
.badge.tone-critical .dot { background: var(--status-critical); }
.badge.solid.tone-critical { background: var(--status-critical); color: #fff; }
.badge.solid.tone-good { background: var(--status-good); color: #fff; }

/* --------------------------------------------------------------- tables  */

.table-wrap { overflow-x: auto; margin: 0 -16px -16px; padding: 0 16px 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--grid);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-3); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ref-link { font-family: var(--mono); font-size: 12px; font-weight: 600; }
.row-breach { box-shadow: inset 3px 0 0 var(--status-critical); }

/* ---------------------------------------------------------------- forms  */

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 14px;
  padding: 12px 14px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
input, select, textarea, button {
  font-family: inherit;
  font-size: 13px;
  color: var(--text-primary);
}
input[type="text"], input[type="email"], input[type="number"], input[type="search"],
select, textarea {
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-1);
  min-width: 110px;
}
textarea { width: 100%; min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-weight: 550;
  cursor: pointer;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn.primary { background: var(--series-1); border-color: transparent; color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--status-critical); }
.btn.sm { padding: 3px 9px; font-size: 12px; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }

.flash {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface-1);
}
.flash.ok { box-shadow: inset 3px 0 0 var(--status-good); }
.flash.error { box-shadow: inset 3px 0 0 var(--status-critical); }

/* --------------------------------------------------------------- charts  */

.chart-empty {
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
  text-align: center;
  margin: 0;
}

.hbars { display: flex; flex-direction: column; gap: 7px; }
.hbar-row {
  display: grid;
  grid-template-columns: 120px 1fr 54px;
  align-items: center;
  gap: 10px;
  cursor: default;
}
.hbar-label {
  font-size: 12px;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hbar-track {
  position: relative;
  height: 16px;
  background: var(--surface-3);
  border-radius: 3px;
  overflow: visible;
}
.hbar-fill {
  display: block;
  height: 100%;
  border-radius: 0 4px 4px 0;
  min-width: 3px;
  transition: width 0.25s ease;
}
.hbar-target {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--text-muted);
}
.hbar-value {
  font-size: 12px;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
}

.columns {
  display: flex;
  align-items: flex-end;
  gap: 0;
  height: calc(var(--col-height) + 44px);
}
.column {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  padding: 0 3px;
  cursor: default;
}
.column-value {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.column-track {
  width: 100%;
  max-width: 24px;
  height: var(--col-height);
  display: flex;
  align-items: flex-end;
  border-bottom: 1px solid var(--axis);
}
.column-fill {
  position: relative;
  width: 100%;
  border-radius: 4px 4px 0 0;
  transition: height 0.25s ease;
}
.column-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: center;
  line-height: 1.2;
}

.segmented {
  display: flex;
  height: 22px;
  border-radius: 4px;
  overflow: hidden;
  gap: 2px;              /* the 2px surface gap between segments */
  background: var(--surface-1);
}
.segmented .seg { display: block; min-width: 3px; cursor: default; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item strong {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.legend-dot { width: 9px; height: 9px; border-radius: 2px; flex: none; }
.legend-line { width: 14px; height: 2px; border-radius: 1px; flex: none; }

.linechart { width: 100%; height: auto; display: block; overflow: visible; }
.linechart .grid { stroke: var(--grid); stroke-width: 1; }
.linechart .axis { fill: var(--text-muted); font-size: 10px; font-family: var(--font); }
.linechart .line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.linechart .line-end { stroke: var(--surface-1); stroke-width: 2; }
.linechart .hit { fill: transparent; cursor: default; }
.linechart .hit:hover { fill: var(--text-muted); fill-opacity: 0.18; }

.sparkline { width: 100%; height: 28px; }
.sparkline polyline { fill: none; stroke-width: 2; stroke-linejoin: round; }

.meter { margin-top: 4px; }
.meter-track {
  position: relative;
  height: 10px;
  background: var(--surface-3);
  border-radius: 5px;
}
.meter-fill { display: block; height: 100%; border-radius: 5px; }
.meter-target {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--text-muted);
}
.meter-legend {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  margin-top: 5px;
  font-weight: 600;
}
.meter-legend .muted { font-weight: 500; }

/* -------------------------------------------------------------- tooltip  */

#tooltip {
  position: fixed;
  z-index: 100;
  pointer-events: none;
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 5px 9px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.1s;
  max-width: 260px;
}
#tooltip.show { opacity: 1; }
#tooltip strong { display: block; font-weight: 650; }

/* ------------------------------------------------------------- timeline  */

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative;
  padding: 0 0 14px 20px;
  border-left: 1px solid var(--grid);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: "";
  position: absolute;
  left: -4.5px;
  top: 5px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--axis);
  border: 2px solid var(--surface-1);
}
.timeline li.accent::before { background: var(--series-1); }
.timeline li.alert::before { background: var(--status-critical); }
.timeline .when { font-size: 11px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.timeline .what { font-size: 13px; }
.timeline .who { font-size: 11px; color: var(--text-secondary); }

.comment {
  background: var(--surface-3);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  margin-bottom: 8px;
}
.comment .meta { font-size: 11px; color: var(--text-muted); margin-bottom: 3px; }
.comment.internal { box-shadow: inset 3px 0 0 var(--status-warning); }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-muted); font-size: 12px; }
.kv dd { margin: 0; }

.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }

details.section > summary {
  cursor: pointer;
  font-weight: 600;
  padding: 6px 0;
  list-style: revert;
}

code.snippet {
  display: block;
  background: var(--surface-3);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 12px;
  overflow-x: auto;
  white-space: pre;
  color: var(--text-secondary);
}

@media (max-width: 700px) {
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; gap: 10px; }
  .page { padding: 14px; }
  .hbar-row { grid-template-columns: 88px 1fr 46px; }
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dd { margin-bottom: 6px; }
}
