:root {
  color-scheme: light;
  --ink: #1a1f24;
  --muted: #5b6570;
  --border: #d8dee3;
  --bg-card: #fff;
  --attention: #a13c1c;
  --attention-bg: #fdece3;
  --target: #1a6b3c;
  --target-bg: #e6f4ea;
  --neutral-bg: #eef0f2;
  --h1-size: 1.35rem;
  --h2-size: 1.1rem;
  --h3-size: 0.95rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f6f7f8;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

.toolbar h1 { font-size: var(--h1-size); margin: 0; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.data-as-of { color: var(--muted); font-size: 0.85rem; }

button, select {
  font: inherit;
  padding: 0.55rem 0.8rem;
  min-height: 2.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-card);
}

button { cursor: pointer; }

/* Visible keyboard-focus state on every interactive control (ticket #147). */
button:focus-visible, select:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

main { padding: 1rem; max-width: 960px; margin: 0 auto; }

h2 { font-size: var(--h2-size); margin: 1.25rem 0 0.5rem; }

#status-line:empty { display: none; }

.not-replied-note { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 0.5rem; }

/* Element qualifier bumps specificity above any later same-specificity
   `.row` rule, so this wins the cascade regardless of file order
   (ticket #153). The desktop override below (@media min-width: 720px)
   must keep the same `div.header-row` qualifier, or it silently regresses
   back to hidden at that width (ticket #154). */
div.header-row { display: none; }

.row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.35rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid transparent;
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
}

.row.status-attention { border-left-color: var(--attention); }
.row.status-target { border-left-color: var(--target); }

.cell.centre { font-weight: 600; overflow-wrap: anywhere; }
.cell.centre .phone { display: block; font-weight: 400; color: var(--muted); font-size: 0.85rem; }

.cell[data-label]::before {
  content: attr(data-label) ": ";
  font-weight: 600;
  color: var(--muted);
}
.cell.centre[data-label]::before { display: none; }

.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
}
.status-attention .badge { background: var(--attention-bg); color: var(--attention); }
.status-target .badge { background: var(--target-bg); color: var(--target); }
.status-neutral .badge { background: var(--neutral-bg); color: var(--muted); }

.empty { color: var(--muted); font-style: italic; padding: 0.5rem 0; }

/* Headline response-time number over secondary sample size (ticket #147). */
.period-value { display: block; font-weight: 700; font-size: 1.15rem; }
.period-meta { display: block; color: var(--muted); font-size: 0.8rem; }

/* Numeric columns keep digits aligned across rows (ticket #147). */
.cell, .panel-category-row, #panel-elapsed dd, #panel-unanswered dd {
  font-variant-numeric: tabular-nums;
}

/* Desktop: aligned comparison rows, no horizontal scroll needed above this width.
   Element qualifier must match the mobile hide-rule above, or that rule's
   specificity bump loses its mirror here and desktop regresses to hidden
   (ticket #154). */
@media (min-width: 720px) {
  /* minmax(0, ...) lets a long unbreakable centre name shrink and wrap
     instead of widening its column (ticket #219). */
  :root { --overview-cols: minmax(0, 1.6fr) minmax(0, 1fr) minmax(0, 1.1fr) minmax(0, 1.1fr) minmax(0, 1fr) minmax(0, 0.8fr) minmax(0, 0.7fr); }

  div.header-row {
    display: grid;
    grid-template-columns: var(--overview-cols);
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    /* Same border box as `.row` so header cells sit over row cells. */
    border: 1px solid transparent;
    border-left: 4px solid transparent;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }

  .row {
    grid-template-columns: var(--overview-cols);
    align-items: center;
    gap: 0.5rem;
  }

  .cell[data-label]::before { content: none; }
}

.details-btn {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.8rem;
  padding: 0.2rem 0.5rem;
}

.target-edit-btn {
  margin-left: 0.5rem;
  font-size: 0.8rem;
  padding: 0.15rem 0.5rem;
}

.panel-target {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  background: var(--neutral-bg);
  border-radius: 6px;
}

/* Target editor (ticket #40): small centered dialog, native default sizing. */
#target-editor {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  max-width: 320px;
}
#target-editor::backdrop { background: rgba(0, 0, 0, 0.4); }
#target-editor h2 { margin: 0 0 0.5rem; font-size: var(--h2-size); }
#target-editor-status { min-height: 1.2em; color: var(--attention); font-size: 0.85rem; }
#target-editor label { display: block; margin: 0.5rem 0 0.25rem; font-size: 0.85rem; color: var(--muted); }
#target-editor input { width: 100%; }

.target-presets { display: flex; flex-wrap: wrap; gap: 0.4rem; }
.target-preset { font-size: 0.85rem; padding: 0.3rem 0.6rem; }

.target-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Centre detail panel (ticket #39): full-screen on mobile, side panel on desktop. */
#centre-panel {
  border: none;
  margin: 0;
  padding: 0;
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  color: var(--ink);
  background: var(--bg-card);
  /* UA dialog default is overflow: auto; only #panel-body may scroll (ticket #218) */
  overflow: hidden;
}

#centre-panel[open] { display: flex; flex-direction: column; }

#centre-panel::backdrop { background: rgba(0, 0, 0, 0.4); }

#centre-panel .panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
}

#centre-panel .panel-header h2 { margin: 0; font-size: var(--h2-size); }

#panel-close {
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
}

#panel-body {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

#panel-body h3 { font-size: var(--h3-size); margin: 0 0 0.5rem; }
#panel-body section { margin-bottom: 1.25rem; }

/* max-width must equal the viewBox width (TREND_WIDTH in webapp.py) so SVG
   user units stay 1:1 with px and .trend-label really renders at 11px */
#panel-trend-svg svg { width: 100%; max-width: 320px; height: auto; }
.trend-volume { fill: var(--neutral-bg); }
.trend-line { stroke: var(--attention); stroke-width: 2; }
.trend-target { stroke: var(--muted); stroke-width: 1; }
.trend-mid { stroke: var(--muted); stroke-width: 1; opacity: 0.3; }
.trend-label {
  fill: var(--muted);
  font-size: 11px;
  /* halo keeps the in-plot midline label legible over bars */
  paint-order: stroke;
  stroke: var(--bg-card);
  stroke-width: 3px;
}

.trend-legend {
  display: flex;
  gap: 0.75rem;
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
  color: var(--muted);
}
.legend-item { display: inline-flex; align-items: center; gap: 0.3rem; }
.legend-swatch { display: inline-block; width: 12px; height: 12px; }
.legend-swatch.trend-volume { background: var(--neutral-bg); border: 1px solid var(--muted); }
.legend-swatch.trend-line { height: 2px; background: var(--attention); }
.legend-swatch.trend-target { height: 0; border-top: 1px dashed var(--muted); }

#panel-elapsed div, #panel-unanswered div {
  display: flex;
  justify-content: space-between;
  margin: 0 0 0.35rem;
}
#panel-elapsed dt, #panel-unanswered dt { color: var(--muted); }
#panel-elapsed dd, #panel-unanswered dd { margin: 0; font-weight: 600; }

.panel-category-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
/* long Category labels wrap instead of overflowing (ticket #218) */
.panel-category-row > span:first-child { overflow-wrap: anywhere; }

@media (min-width: 720px) {
  #centre-panel {
    inset: 0 0 0 auto;
    width: 480px;
    max-width: 480px;
    box-shadow: -2px 0 12px rgba(0, 0, 0, 0.15);
  }
}
