/* Relay — operations control room
   Neutral, dense, one accent. Tabular numerals throughout. */

:root {
  --bg: #0f1215;
  --bg-raised: #151a1f;
  --bg-inset: #0b0e11;
  --border: #252b31;
  --border-strong: #333b43;
  --text: #d7dde3;
  --text-dim: #8b949d;
  --text-faint: #5c666f;
  --accent: #3d8bfd;
  --accent-soft: #1a2a3f;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f85149;
  --sev-critical: #f85149;
  --sev-high: #db6d28;
  --sev-medium: #d29922;
  --sev-low: #3fb950;
  --focus: #79b8ff;
  --radius: 4px;
  --rail-w: 56px;
  --topbar-h: 48px;
  --font: ui-sans-serif, system-ui, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 13px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Numerics always align in columns and cards */
.metric-value,
.trend-text,
.incident-table,
.clock,
.meta-chip,
.detail-kv dd,
.chart-x {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 8px;
  top: -40px;
  z-index: 100;
  padding: 8px 12px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  text-decoration: none;
  font-weight: 600;
}

.skip-link:focus {
  top: 8px;
}

/* Visible keyboard focus everywhere */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

.frame {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* Navigation rail */
.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0;
  background: var(--bg-inset);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-brand {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  margin-bottom: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  border-radius: var(--radius);
}

.rail-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  align-items: center;
}

.rail-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  width: 44px;
  padding: 8px 0;
  color: var(--text-dim);
  text-decoration: none;
  border-radius: var(--radius);
  border: 1px solid transparent;
}

.rail-item:hover {
  color: var(--text);
  background: var(--bg-raised);
}

.rail-item.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #24384f;
}

.rail-icon {
  font-size: 15px;
  line-height: 1;
}

.rail-label {
  font-size: 9px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.rail-foot {
  margin-top: auto;
  color: var(--text-faint);
  padding: 8px;
}

/* Top status bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex: 0 0 auto;
}

.topbar-mid {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
}

.app-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.app-sub {
  color: var(--text-dim);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 11px;
  color: var(--text);
  background: var(--bg);
  white-space: nowrap;
}

.status-pill[data-level="ok"] .status-dot {
  background: var(--ok);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.meta-chip {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.clock {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  letter-spacing: 0.02em;
}

.operator {
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

/* Main content */
.main {
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  outline: none;
}

/* Metrics strip */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px 12px;
  min-width: 0;
}

.metric-label {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.metric-value {
  margin: 0;
  font-family: var(--mono);
  font-size: 24px;
  font-weight: 600;
  line-height: 1.15;
  letter-spacing: -0.01em;
}

.metric-value .unit {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin-left: 2px;
}

.metric-trend {
  margin: 6px 0 0;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.trend-arrow {
  font-size: 9px;
}

.trend-text {
  font-family: var(--mono);
  font-weight: 600;
}

.trend-context {
  color: var(--text-faint);
}

.metric-trend[data-dir="up"] .trend-text,
.metric-trend[data-dir="up"] .trend-arrow {
  color: var(--text);
}

.metric-trend[data-dir="up-bad"] .trend-text,
.metric-trend[data-dir="up-bad"] .trend-arrow {
  color: var(--danger);
}

.metric-trend[data-dir="down-good"] .trend-text,
.metric-trend[data-dir="down-good"] .trend-arrow {
  color: var(--ok);
}

.metric-trend[data-dir="down-bad"] .trend-text,
.metric-trend[data-dir="down-bad"] .trend-arrow {
  color: var(--danger);
}

/* Panels */
.panel {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 14px;
  min-width: 0;
}

.panel-head {
  margin-bottom: 10px;
}

.panel-head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.panel-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.panel-sub {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--text-dim);
}

/* Throughput chart */
.chart-wrap {
  width: 100%;
}

.chart {
  display: block;
  width: 100%;
  height: 180px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chart-x {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
}

.chart-x span {
  text-align: center;
}

.chart-legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

.chart-legend > span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 10px;
  height: 3px;
  display: inline-block;
}

.swatch-accent {
  background: var(--accent);
}

.legend-note {
  color: var(--text-faint);
}

/* Filters */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 8px;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.filter-label {
  font-size: 10px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.filter-control {
  appearance: none;
  background: var(--bg-inset);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 5px 8px;
  font: inherit;
  font-size: 12px;
  min-width: 110px;
  height: 30px;
}

.filter-control:hover {
  border-color: var(--text-faint);
}

.filter-search .filter-control {
  min-width: 160px;
}

select.filter-control {
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 14px) 13px, calc(100% - 9px) 13px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}

.btn {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  height: 30px;
  padding: 0 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text);
  background: transparent;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  border-color: var(--border-strong);
  color: var(--text-dim);
  align-self: flex-end;
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  border-color: var(--text-faint);
}

.btn-secondary {
  border-color: var(--border-strong);
  background: var(--bg-inset);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-faint);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-primary.is-acked {
  background: var(--bg-inset);
  border-color: var(--ok);
  color: var(--ok);
}

.table-meta {
  min-height: 18px;
  margin-bottom: 6px;
  font-size: 11px;
  color: var(--text-dim);
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-inset);
}

.incident-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--mono);
  font-size: 12px;
}

.incident-table thead th {
  text-align: left;
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  white-space: nowrap;
  position: sticky;
  top: 0;
}

.incident-table tbody tr {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.incident-table tbody tr:last-child {
  border-bottom: 0;
}

.incident-table tbody tr:hover {
  background: var(--bg-raised);
}

.incident-table tbody tr.is-selected {
  background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}

.incident-table tbody tr:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}

.incident-table td {
  padding: 9px 10px;
  vertical-align: middle;
  white-space: nowrap;
}

.incident-table td.title-cell {
  white-space: normal;
  min-width: 180px;
  font-family: var(--font);
  font-size: 12px;
}

.sev {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.sev-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex: 0 0 auto;
}

.sev[data-sev="critical"] { color: var(--sev-critical); }
.sev[data-sev="critical"] .sev-dot { background: var(--sev-critical); }
.sev[data-sev="high"] { color: var(--sev-high); }
.sev[data-sev="high"] .sev-dot { background: var(--sev-high); }
.sev[data-sev="medium"] { color: var(--sev-medium); }
.sev[data-sev="medium"] .sev-dot { background: var(--sev-medium); }
.sev[data-sev="low"] { color: var(--sev-low); }
.sev[data-sev="low"] .sev-dot { background: var(--sev-low); }

.status-tag {
  display: inline-block;
  padding: 2px 6px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: var(--bg);
}

.status-tag[data-status="open"] {
  color: var(--warn);
  border-color: #5c4a1a;
}

.status-tag[data-status="investigating"] {
  color: var(--danger);
  border-color: #5c2a28;
}

.status-tag[data-status="monitoring"] {
  color: var(--accent);
  border-color: #24384f;
}

.status-tag[data-status="acknowledged"] {
  color: var(--ok);
  border-color: #1f4a28;
}

.owner-unassigned {
  color: var(--warn);
  font-style: italic;
}

/* Empty state */
.empty-state {
  padding: 28px 16px;
  text-align: center;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-inset);
  margin-top: 8px;
}

.empty-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text);
}

.empty-body {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-dim);
}

/* Detail panel */
.detail-body {
  min-height: 140px;
}

.detail-placeholder {
  margin: 0;
  padding: 24px 12px;
  text-align: center;
  color: var(--text-dim);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-inset);
  font-size: 12px;
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.detail-title {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.detail-ids {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
}

.detail-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.detail-kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px 16px;
  margin: 0 0 12px;
  padding: 10px 12px;
  background: var(--bg-inset);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.detail-kv dt {
  margin: 0;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.detail-kv dd {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
}

.detail-note {
  margin: 0;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  background: var(--bg-inset);
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.5;
}

.detail-ack-banner {
  margin-top: 10px;
  padding: 8px 12px;
  border: 1px solid #1f4a28;
  border-radius: var(--radius);
  background: #12241a;
  color: var(--ok);
  font-size: 12px;
  font-weight: 600;
}

/* Toast */
.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 50;
  padding: 10px 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

/* Mobile: 390px usable, no horizontal page scroll */
@media (max-width: 760px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  .rail {
    position: sticky;
    top: 0;
    height: auto;
    flex-direction: row;
    justify-content: space-between;
    padding: 6px 10px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    z-index: 20;
  }

  .rail-brand {
    margin: 0;
    width: 28px;
    height: 28px;
    font-size: 13px;
  }

  .rail-nav {
    flex-direction: row;
    width: auto;
    gap: 2px;
  }

  .rail-item {
    width: 40px;
    padding: 6px 0;
  }

  .rail-label {
    display: none;
  }

  .rail-foot {
    display: none;
  }

  .topbar {
    height: auto;
    min-height: var(--topbar-h);
    flex-wrap: wrap;
    gap: 6px 12px;
    padding: 8px 12px;
  }

  .topbar-mid {
    order: 3;
    flex: 1 1 100%;
  }

  .meta-chip {
    display: none;
  }

  .main {
    padding: 10px 10px 20px;
    gap: 10px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric-value {
    font-size: 20px;
  }

  .panel {
    padding: 10px;
  }

  .panel-head-row {
    flex-direction: column;
  }

  .filters {
    width: 100%;
  }

  .filter {
    flex: 1 1 calc(50% - 8px);
  }

  .filter-control {
    min-width: 0;
    width: 100%;
  }

  .filter-search {
    flex: 1 1 100%;
  }

  .btn-ghost {
    flex: 1 1 100%;
    height: 32px;
  }

  .chart {
    height: 140px;
  }

  /* Stack table rows into cards below 760px */
  .table-scroll {
    overflow-x: visible;
  }

  .incident-table,
  .incident-table tbody,
  .incident-table tr,
  .incident-table td {
    display: block;
    width: 100%;
  }

  .incident-table thead {
    display: none;
  }

  .incident-table tbody tr {
    padding: 10px;
    border-bottom: 1px solid var(--border);
  }

  .incident-table td {
    padding: 2px 0;
    white-space: normal;
  }

  .incident-table td.title-cell {
    min-width: 0;
    font-weight: 600;
    font-size: 13px;
    margin: 2px 0 6px;
  }

  .incident-table td::before {
    content: attr(data-label);
    display: inline-block;
    width: 72px;
    font-family: var(--font);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-faint);
    margin-right: 6px;
  }

  .incident-table td.title-cell::before {
    display: none;
  }

  .detail-head {
    flex-direction: column;
  }

  .detail-actions {
    width: 100%;
  }

  .detail-actions .btn {
    flex: 1;
  }

  .toast {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }
}

@media (max-width: 420px) {
  .metrics {
    grid-template-columns: 1fr 1fr;
  }

  .metric {
    padding: 8px 10px;
  }

  .metric-value {
    font-size: 18px;
  }

  .metric-trend {
    flex-wrap: wrap;
  }

  .trend-context {
    flex: 1 1 100%;
  }

  .operator {
    display: none;
  }
}
