/* Commute-Compute — the Console layout from plan 04 (experiments/ui-directions/console.html).
 * Graphite chrome, amber for the answer, the map filling everything the work column does not.
 * week-ui.css draws the places table, the week and the dialog from the --cc-* properties set here.
 */

:root {
  color-scheme: dark;
  --bg: #111316;
  --panel: #181b1f;
  --cc-ink: #e9e7e2;
  --cc-paper: #1e2226;
  --cc-soft: #262b30;
  --cc-line: #343a41;
  --cc-muted: #9aa0a6;
  --cc-accent: #f2a93b;
  --cc-accent-ink: #15120c;
  --cc-warn: #ff7b6b;
  --cc-good: #7fd49b;
  --cc-font: "IBM Plex Sans", "Segoe UI", sans-serif;
  --cc-num-font: "IBM Plex Mono", ui-monospace, monospace;
  --cc-hour: 1.55rem;
  --cc-radius: 3px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--cc-ink); font: 14px/1.45 var(--cc-font); }
a { color: inherit; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.app { display: grid; grid-template-rows: auto auto 1fr; height: 100vh; }

/* ---- top strip ---- */
/* The strip wraps: its controls need about 1,200 px in one row, so on anything narrower the
 * figures take a row of their own and wrap there, rather than the page scrolling sideways
 * (TICKET-008). Each box draws its own bottom rule so a wrapped row still reads as cells. */
.top { display: flex; flex-wrap: wrap; align-items: stretch; border-bottom: 1px solid var(--cc-line); background: var(--panel); }
.top > * { border-bottom: 1px solid var(--cc-line); margin-bottom: -1px; min-width: 0; }
.ident { display: flex; flex-direction: column; justify-content: center; padding: 0.55rem 1.2rem; border-right: 1px solid var(--cc-line); }
.ident h1 { margin: 0; font-size: 0.95rem; letter-spacing: 0.02em; }
.ident span { font-size: 0.75rem; color: var(--cc-muted); }
.modebox { display: flex; align-items: center; padding: 0 1rem; border-right: 1px solid var(--cc-line); }
.modebox .cc-mode { border-color: var(--cc-line); }
.modebox .cc-mode-btn { background: transparent; min-height: 2.4rem; padding: 0.3rem 0.8rem; }
.modebox .cc-mode-btn + .cc-mode-btn { border-left-color: var(--cc-line); }
.modebox .cc-mode-btn[aria-pressed="true"] { background: var(--cc-accent); color: var(--cc-accent-ink); }
.modebox .cc-mode-hint { display: none; }
.runbox { display: flex; align-items: center; padding: 0 1rem; border-right: 1px solid var(--cc-line); }
.advbox { display: flex; align-items: center; padding: 0 1rem; border-right: 1px solid var(--cc-line); }
.filebox { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; padding: 0.4rem 1rem; border-right: 1px solid var(--cc-line); }
.cc-file { min-height: 2.2rem; padding: 0.3rem 0.6rem; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; white-space: nowrap; }
.cc-file:disabled { opacity: 0.45; cursor: not-allowed; }
.run { min-height: 2.6rem; padding: 0.45rem 1.3rem; font-size: 0.95rem; letter-spacing: 0.02em; }
.run:disabled { opacity: 0.55; cursor: progress; }
.kpis { display: flex; flex-wrap: wrap; flex: 1 1 34rem; }
.kpi { flex: 1 0 auto; padding: 0.5rem 1.2rem; border-right: 1px solid var(--cc-line); white-space: nowrap; }
.kpi.wide { flex: 2 1 12rem; min-width: 0; white-space: normal; overflow-wrap: anywhere; }
.kpi span { display: block; font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--cc-muted); }
.kpi strong { font-family: var(--cc-num-font); font-size: 1.15rem; font-weight: 600; }
.kpi.main strong { font-size: 1.6rem; color: var(--cc-accent); line-height: 1.1; }
.kpi.traffic strong { color: var(--cc-warn); }
.kpi.wide strong { font-family: var(--cc-font); font-size: 1rem; font-weight: 600; }
html[data-stale] .kpis strong { opacity: 0.45; }

/* ---- work column ---- */
.work { display: grid; grid-template-columns: minmax(30rem, 38rem) 1fr; min-height: 0; }
.side { overflow-y: auto; border-right: 1px solid var(--cc-line); background: var(--panel); }
.block { padding: 1rem 1.2rem; border-bottom: 1px solid var(--cc-line); }
.block h2 { margin: 0 0 0.6rem; font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.1em; color: var(--cc-muted); display: flex; justify-content: space-between; }
.block h2 span { text-transform: none; letter-spacing: 0; }
.runline { padding: 0.6rem 1.2rem; border-bottom: 1px solid var(--cc-line); min-height: 2.6rem; }
.status { margin: 0; font-size: 0.82rem; font-family: var(--cc-num-font); color: var(--cc-accent); }
.status:empty::before { content: 'Press Run to work out the week.'; color: var(--cc-muted); }
.status.error { color: var(--cc-warn); }
.progress { height: 4px; margin-top: 0.4rem; background: var(--cc-soft); }
.progress div { height: 100%; width: 0; background: var(--cc-accent); transition: width 0.2s; }
.week-status { min-height: 1.4em; margin: 0.3rem 0 0; font-size: 0.78rem; font-family: var(--cc-num-font); color: var(--cc-muted); }
.note { margin: 0.4rem 0 0; font-size: 0.75rem; color: var(--cc-muted); }
.method { padding: 1rem 1.2rem 1.4rem; margin: 0; }
.cc-places th { border-bottom-color: var(--cc-line); }
.cc-week-columns .cc-week-frame { min-width: 26rem; }
.cc-block { font-size: 0.72rem; color: #fff; }
.cc-week-columns .cc-block { padding: 0.25rem 0.3rem 0.25rem 0.35rem; }
.cc-week-columns .cc-block-time { font-size: 0.66rem; }
/* At 1.55rem an hour, a visit under two hours has room for its name only; the time is in its label. */
.cc-week-columns .cc-block-mid .cc-block-time { display: none; }
.cc-button { background: transparent; }
.cc-button:hover { background: var(--cc-soft); }
.cc-primary, .cc-primary:hover { background: var(--cc-accent); }
.cc-input { background: var(--bg); }

/* ---- address search ---- */
.home-cell, .cc-addr-cell { position: relative; display: block; }
.addr-spinner {
  display: none; position: absolute; right: 0.55rem; top: 0; bottom: 0; margin: auto;
  width: 0.75rem; height: 0.75rem; border: 2px solid var(--cc-ink); border-top-color: transparent; border-radius: 50%;
  pointer-events: none;
}
.is-loading > .addr-spinner { display: block; animation: addr-spin 0.7s linear infinite; }
.is-loading > input { padding-right: 1.6rem; }
@keyframes addr-spin { to { transform: rotate(360deg); } }
.autocomplete-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 1200;
  background: var(--cc-paper); border: 1px solid var(--cc-line); border-top: 0; max-height: 14rem; overflow-y: auto;
}
.autocomplete-item { padding: 0.45rem 0.6rem; font-size: 0.82rem; cursor: pointer; border-top: 1px solid var(--cc-line); }
.autocomplete-item:hover, .autocomplete-item.selected { background: var(--cc-soft); }

/* ---- results (Address mode) ---- */
.results h2 { color: var(--cc-ink); }
table.breakdown { width: 100%; border-collapse: collapse; margin-top: 0.6rem; font-variant-numeric: tabular-nums; font-size: 0.85rem; }
table.breakdown caption { text-align: left; font-size: 0.68rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--cc-muted); padding: 0.5rem 0 0.3rem; }
table.breakdown th, table.breakdown td { text-align: left; padding: 0.25rem 0.5rem 0.25rem 0; border-bottom: 1px solid var(--cc-line); font-weight: 400; }
table.breakdown thead th { font-size: 0.68rem; color: var(--cc-muted); text-transform: uppercase; letter-spacing: 0.06em; }
table.breakdown td { font-family: var(--cc-num-font); }
#trips-table td.where { font-family: var(--cc-font); }
.prior { color: var(--cc-accent); cursor: help; }

/* ---- map ---- */
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
#map .leaflet-tile-pane { filter: grayscale(1) invert(1) brightness(0.9) contrast(0.9); }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { background: rgba(17, 19, 22, 0.8) !important; color: var(--cc-muted) !important; }
.leaflet-control-attribution a { color: var(--cc-ink) !important; }
.leaflet-bar a { background: var(--panel) !important; color: var(--cc-ink) !important; border-color: var(--cc-line) !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--cc-paper); color: var(--cc-ink); }
.field-layer { position: absolute; left: 0; top: 0; pointer-events: none; z-index: 400; transform-origin: 0 0; }
.cc-pin b { background: rgba(17, 19, 22, 0.9); color: var(--cc-ink); border-color: var(--cc-line); }
.cc-pin span { box-shadow: 0 0 0 1.5px #000, 0 2px 6px rgba(0, 0, 0, 0.6); }

/* One bar, two handles: the ramp is the track, and the two range inputs lie on it. */
.legend {
  position: absolute; z-index: 600; left: 0.8rem; bottom: 1.6rem; width: min(22rem, calc(100% - 1.6rem));
  padding: 0.55rem 0.7rem 0.5rem; background: var(--cc-paper); border: 1px solid var(--cc-line); border-radius: var(--cc-radius);
}
.legend-head { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.legend-label { font-size: 0.72rem; font-weight: 600; }
.legend-head .cc-link { font-size: 0.72rem; color: var(--cc-muted); min-height: 0; padding: 0; }
.scale { position: relative; height: 1.7rem; margin-top: 0.4rem; }
.scale .ramp {
  position: absolute; left: 0; right: 0; top: 0.45rem; height: 0.8rem;
  border-radius: var(--cc-radius);
  background: linear-gradient(to right, #006400, #90ee90, #ffff00, #ff6347, #8b0000);
}
.scale input[type="range"] {
  position: absolute; left: 0; width: 100%; height: 1.7rem; margin: 0;
  background: transparent; pointer-events: none; -webkit-appearance: none; appearance: none;
}
.scale input[type="range"]::-webkit-slider-runnable-track { height: 1.7rem; background: transparent; border: none; }
.scale input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 0.8rem; height: 1.45rem; margin-top: 0.12rem;
  background: var(--cc-ink); border: 2px solid var(--bg); border-radius: 2px; cursor: ew-resize;
}
.scale input[type="range"]::-moz-range-track { height: 1.7rem; background: transparent; border: none; }
.scale input[type="range"]::-moz-range-thumb {
  pointer-events: auto; width: 0.8rem; height: 1.45rem; background: var(--cc-ink); border: 2px solid var(--bg); border-radius: 2px; cursor: ew-resize;
}
.scale input[type="range"]:focus-visible::-webkit-slider-thumb { outline: 2px solid var(--cc-accent); outline-offset: 1px; }
.legend-ends { display: flex; justify-content: space-between; font-family: var(--cc-num-font); font-size: 0.75rem; }
#field-status { margin-top: 0.3rem; font-size: 0.68rem; }

.map-tip {
  position: absolute; z-index: 700; pointer-events: none; min-width: 13rem; max-width: 19rem;
  padding: 0.55rem 0.7rem 0.5rem; font-size: 0.8rem; line-height: 1.35;
  background: var(--cc-paper); border: 1px solid var(--cc-line); border-radius: var(--cc-radius); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.map-tip p { margin: 0; }
.map-tip-title { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--cc-muted); }
.map-tip-total { margin: 0.1rem 0 0.35rem !important; }
.map-tip-total strong { font-family: var(--cc-num-font); font-size: 1.1rem; color: var(--cc-accent); }
.map-tip-row { display: flex; align-items: baseline; gap: 0.2rem; padding: 0.12rem 0; border-top: 1px solid var(--cc-line); }
.map-tip-name { flex: 1; }
.map-tip-min { font-family: var(--cc-num-font); font-size: 0.75rem; }

.tabs { display: none; }

@media (max-width: 900px) {
  .app { height: auto; min-height: 100vh; grid-template-rows: auto auto 1fr; }
  .top { flex-direction: column; }
  .ident { border-right: 0; border-bottom: 1px solid var(--cc-line); flex-direction: row; justify-content: space-between; align-items: baseline; }
  .modebox, .runbox, .advbox, .filebox { padding: 0.5rem 0.9rem; border-right: 0; border-bottom: 1px solid var(--cc-line); }
  .modebox .cc-mode, .run, .cc-adv-btn { width: 100%; }
  .filebox { flex-wrap: wrap; }
  .filebox .cc-file { flex: 1 1 7rem; }
  /* In the column layout a flex basis is a height: size the figures by their content. */
  .kpis { flex: 0 0 auto; flex-wrap: wrap; min-width: 0; overflow: visible; }
  .kpi { padding: 0.4rem 0.9rem; flex: 1 1 9rem; min-width: 0; white-space: normal; border-bottom: 1px solid var(--cc-line); }
  .kpi.main strong { font-size: 1.3rem; }
  .tabs { display: grid; grid-template-columns: 1fr 1fr; position: sticky; top: 0; z-index: 950; background: var(--panel); border-bottom: 1px solid var(--cc-line); }
  .tabs button { font: inherit; font-weight: 600; min-height: 2.8rem; color: var(--cc-muted); background: none; border: 0; border-bottom: 2px solid transparent; }
  .tabs button[aria-selected="true"] { color: var(--cc-ink); border-bottom-color: var(--cc-accent); }
  .work { display: block; }
  .side { overflow: visible; border-right: 0; }
  .map-wrap { height: calc(100vh - 3rem); }
  body[data-view="plan"] .map-wrap { display: none; }
  body[data-view="map"] .side { display: none; }
  .cc-week-columns .cc-week-frame { min-width: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .is-loading > .addr-spinner { animation: none; }
  .progress div { transition: none; }
}
