/* Layout and data components. Glass tokens come from glass.css. */

:root {
  /* Chart ink and furniture on the glass panel (effective surface: Base at 50% over Background) */
  --chart-surface: #2a2a34;
  --ink: var(--glass-text);
  --ink-2: var(--glass-subtext);
  --ink-muted: var(--glass-detail);
  --grid: rgba(200, 200, 200, 0.1);
  --axis: rgba(200, 200, 200, 0.24);

  /* Categorical series, fixed order. Validated colour-blind-safe on --chart-surface. */
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s7: #9085e9;
  --s8: #e66767;
  --s-other: #7d7d8c;

  --good: #0ca30c;
  --critical: #e66767;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

/* -- Signed-out page ------------------------------------------------------- */

.gate {
  display: grid;
  place-items: center;
  padding: 16px;
}
.gate__card {
  width: min(460px, 100%);
  padding: 32px;
  text-align: center;
}
.gate__icon {
  border-radius: 14px;
  margin-bottom: 16px;
}
.gate__card h1 {
  font-size: 24px;
  margin-bottom: 12px;
}
.gate__card p {
  margin: 0 0 12px;
  color: var(--ink-2);
  text-wrap: pretty;
}
.gate__card .g-btn {
  margin-top: 12px;
  min-height: 44px;
  padding: 0 24px;
  font-size: 15px;
}

/* -- App shell ------------------------------------------------------------- */

.shell {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 16px 48px;
}

.topbar {
  position: sticky;
  top: 8px;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--glass-fill-strong);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  padding-right: 4px;
}
.brand img {
  border-radius: 8px;
}
.topbar .g-tabs {
  flex: 1;
  min-width: 0;
}
.nav-select {
  display: none;
  flex: 1;
  min-width: 0;
  font-weight: 700;
}
/* Compact layouts: the row of tabs no longer fits, so offer the views as a dropdown. */
@media (max-width: 1180px) {
  .topbar .g-tabs { display: none; }
  .nav-select { display: block; }
}
.user {
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.user__pic {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(var(--glass-base-rgb), 1);
  border: 1px solid var(--glass-stroke);
}
.user__name {
  font-weight: 600;
  font-size: 13px;
  color: var(--ink-2);
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  margin: 16px 4px 8px;
}
.filters__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
}
.filters__spacer {
  flex: 1;
}
.filters input[type="date"] {
  font-family: var(--font-ui);
  color-scheme: dark;
}
.status {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}

.view-head {
  margin: 20px 4px 12px;
}
.view-head h1 {
  font-size: 22px;
}
.view-head p {
  margin: 4px 0 0;
  color: var(--ink-muted);
  font-size: 13px;
  max-width: 80ch;
}

.subfilters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 0 4px 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}
.span-12 { grid-column: span 12; }
.span-9 { grid-column: span 9; }
.span-8 { grid-column: span 8; }
.span-6 { grid-column: span 6; }
.span-4 { grid-column: span 4; }
.span-3 { grid-column: span 3; }
.span-2 { grid-column: span 2; }
@media (max-width: 1100px) {
  .span-9, .span-8, .span-6, .span-4 { grid-column: span 12; }
  .span-3, .span-2 { grid-column: span 4; }
  .card.span-3 { grid-column: span 12; }
}
@media (max-width: 640px) {
  .span-3, .span-2 { grid-column: span 6; }
  .tile.span-4 { grid-column: span 12; }
  .brand span { display: none; }
  .user__name { display: none; }
}

/* -- Card ------------------------------------------------------------------ */

.card {
  padding: 20px 24px 20px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.card__head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.card__titles {
  flex: 1;
  min-width: 0;
}
.card__title {
  font-size: 15px;
  font-weight: 700;
}
.card__sub {
  margin-top: 2px;
  font-size: 12px;
  color: var(--ink-muted);
}
.card__body {
  flex: 1;
  min-width: 0;
  transition: opacity var(--glass-ease);
}
.card.is-loading .card__body {
  opacity: 0.45;
}
.card__msg {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  padding: 24px 0;
  color: var(--ink-muted);
  font-size: 13px;
}
.card__msg--error strong {
  color: var(--ink);
}
.card__note {
  margin-top: 12px;
  font-size: 12px;
  color: var(--ink-muted);
  text-wrap: pretty;
}

details.notes {
  margin-top: 16px;
  padding: 12px 20px;
  font-size: 13px;
  color: var(--ink-2);
}
details.notes summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
}
details.notes ul {
  margin: 8px 0 4px;
  padding-left: 18px;
}
details.notes li {
  margin: 4px 0;
  max-width: 90ch;
}

/* -- Stat tile ------------------------------------------------------------- */

.tile {
  padding: 16px 20px;
  min-width: 0;
}
.tile__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile__value {
  margin-top: 4px;
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}
.tile__value small {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-muted);
  margin-left: 2px;
}
.tile__delta {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  white-space: nowrap;
}
.tile__delta b {
  font-weight: 700;
}
.tile__delta .up-good, .tile__delta .down-good { color: var(--glass-positive); }
.tile__delta .up-bad, .tile__delta .down-bad { color: var(--glass-negative); }
.tile__spark {
  display: block;
  width: 100%;
  height: 32px;
  margin-top: 8px;
}

/* -- Charts ---------------------------------------------------------------- */

.chart {
  position: relative;
  width: 100%;
}
.chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}
.chart text {
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 600;
  fill: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .crosshair { stroke: rgba(255, 255, 255, 0.5); stroke-width: 1; }
.chart .series-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { stroke: var(--chart-surface); stroke-width: 2; }
.chart .anno-line { stroke: rgba(255, 255, 255, 0.45); stroke-width: 1; }
.chart .anno-label { fill: var(--ink-2); font-family: var(--font-ui); font-size: 11px; }
.chart .end-label { fill: var(--ink-2); font-family: var(--font-ui); font-size: 11px; font-weight: 600; }
.chart .hit { fill: transparent; }
.chart .col.is-dim { opacity: 0.55; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
}
.legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
}
.swatch--line {
  width: 14px;
  height: 0;
  border-top: 2px solid;
  border-radius: 0;
  background: none !important;
}

.tip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  min-width: 120px;
  max-width: 320px;
  padding: 8px 12px;
  border: 1px solid var(--glass-stroke);
  border-radius: var(--glass-radius-md);
  background: rgba(32, 32, 39, 0.94);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  font-size: 12px;
}
.tip__title {
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--ink-2);
}
.tip__row {
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.6;
}
.tip__row b {
  font-family: var(--font-num);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.tip__row span.name {
  color: var(--ink-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* -- Bar rows (ranked bars, funnels, grouped comparisons) ----------------- */

.bars {
  display: grid;
  grid-template-columns: minmax(90px, max-content) minmax(0, 1fr) max-content;
  align-items: center;
  gap: 6px 12px;
  font-size: 13px;
}
.bars--funnel {
  grid-template-columns: minmax(90px, max-content) minmax(0, 1fr) max-content max-content;
}
.bars__label {
  color: var(--ink-2);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}
.bars__label small {
  color: var(--ink-muted);
  font-weight: 600;
  margin-right: 6px;
  font-family: var(--font-num);
}
.bars__track {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: 3px 0;
  border-left: 1px solid var(--axis);
}
.bars__bar {
  height: 14px;
  min-width: 1px;
  border-radius: 0 4px 4px 0;
  transition: filter var(--glass-ease);
}
.bars__track:hover .bars__bar,
.bars__bar:hover {
  filter: brightness(1.2);
}
.bars--thin .bars__bar {
  height: 8px;
}
.bars__value {
  font-family: var(--font-num);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  white-space: nowrap;
}
.bars__value div {
  line-height: 1.25;
}
.bars__extra {
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.bars__head {
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-muted);
  text-align: right;
}
.bars__head:first-child {
  text-align: left;
}

/* Tall segmented bars: one whole per row, split into parts */
.seg {
  display: grid;
  grid-template-columns: minmax(80px, max-content) minmax(0, 1fr) max-content;
  align-items: center;
  gap: 8px 12px;
  font-size: 13px;
}
.seg__bar {
  display: flex;
  gap: 2px;
  height: 28px;
  min-width: 0;
}
.seg__part {
  min-width: 0;
  border-radius: 4px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  font-family: var(--font-num);
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  white-space: nowrap;
  transition: filter var(--glass-ease);
}
.seg__part:hover {
  filter: brightness(1.2);
}

/* -- Tables ---------------------------------------------------------------- */

.table-wrap {
  overflow: auto;
  max-height: 420px;
  margin: 0 -8px;
}
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th,
table.data td {
  padding: 6px 8px;
  text-align: left;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
table.data th {
  position: sticky;
  top: 0;
  background: #2c2c37;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  z-index: 1;
}
table.data th.num {
  text-align: right;
}
table.data td.num {
  text-align: right;
  font-family: var(--font-num);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
table.data td.num {
  font-size: 14px;
}
table.data tr.is-clickable {
  cursor: pointer;
}
table.data tr.is-clickable:hover td {
  background: rgba(255, 255, 255, 0.04);
}
table.data tr[aria-selected="true"] td {
  background: rgba(var(--glass-accent-rgb), 0.35);
}
table.data td .muted,
.muted {
  color: var(--ink-muted);
}
.cellnum {
  font-family: var(--font-num);
  font-size: 14px;
  font-weight: 600;
}
.cellbar {
  display: inline-block;
  height: 8px;
  border-radius: 0 4px 4px 0;
  vertical-align: middle;
  margin-right: 6px;
}

/* -- Lists and forms used by the browser views ----------------------------- */

.picker {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 520px;
  overflow: auto;
  margin: 0 -8px;
}
.picker button {
  all: unset;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 10px;
  border-radius: var(--glass-radius-sm);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.picker button:hover {
  background: rgba(255, 255, 255, 0.05);
}
.picker button[aria-selected="true"] {
  background: rgba(var(--glass-accent-rgb), 0.9);
  color: #fff;
}
.picker button:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.85);
  outline-offset: -2px;
}
.picker__group {
  margin: 8px 10px 2px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin-bottom: 12px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-muted);
  min-width: 0;
}
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
pre.raw {
  max-height: 360px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: var(--glass-radius-md);
  background: rgba(0, 0, 0, 0.25);
  font: 500 12px/1.5 var(--font-num);
  color: var(--ink-2);
}

/* -- Dialog ---------------------------------------------------------------- */

dialog.g-dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 24px;
  color: var(--ink);
  background: rgba(40, 40, 50, 0.96);
  border: 1px solid var(--glass-stroke);
  border-radius: var(--glass-radius);
}
dialog.g-dialog::backdrop {
  background: rgba(10, 10, 14, 0.6);
  backdrop-filter: blur(4px);
}
dialog.g-dialog h2 {
  font-size: 18px;
  margin-bottom: 8px;
}
dialog.g-dialog p {
  margin: 0 0 12px;
  font-size: 13px;
  color: var(--ink-2);
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}
.anno-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}
.anno-row .g-input:nth-child(2) {
  flex: 1;
  min-width: 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
