/* ==========================================================================
   flow-watch - themed to the Digitelos design system.

   Tokens are lifted from the Digitelos site (github.com/noncodersimon/digitelos,
   css/main.css) so the two stay in step: brand spectrum from the Fibonacci
   spiral logo kit, cobalt -> azure -> vermilion -> amber, with ink and
   parchment neutrals.

   House rule there is "cobalt and azure dominate, vermilion sparingly, amber
   for highlights only". That is followed here with one deliberate reading:
   chrome uses cobalt and azure ONLY, which keeps the vermilion family free to
   mean "down" in the data. A dashboard cannot afford a red button competing
   with a red price move.
   ========================================================================== */

:root {
  /* Brand colours, fixed */
  --cobalt:    #2B57DB;
  --azure:     #17A2E8;
  --vermilion: #EF3F18;
  --amber:     #F98E12;
  --ink:       #0B0B10;
  --parchment: #ECEAE1;

  /* Semantic - light theme */
  color-scheme: light;
  --bg:           #FBFAF6;
  --surface:      #FFFFFF;
  --text:         var(--ink);
  --text-muted:   #55555F;
  --border:       #E3E0D5;
  --accent:       var(--cobalt);
  --accent-hover: #1E43B8;
  --on-accent:    #FFFFFF;
  --focus-ring:   var(--cobalt);
  --input-border: #8A8678;   /* 3.6:1 against a white fill */
  --tint:         #F2F5FD;   /* cobalt at ~8% on white */
  --tint-azure:   #EAF6FD;
  --tint-amber:   #FDF1DF;
  --tint-down:    #FBEBE7;

  /* Data semantics. --down is the accessible darkened vermilion the Digitelos
     kit uses for CTAs (5.4:1 on white); --up is pitched at the same weight so
     neither side of the market shouts louder than the other. */
  --up:      #1F7A4D;
  --down:    #C9300C;
  --neutral: var(--text-muted);

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --radius: 12px;
  --radius-sm: 8px;
  --max-width: 1000px;
}

* { box-sizing: border-box; }

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

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- header ---------- */

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

header h1 { margin: 0; font-size: 1.15rem; font-weight: 700; }
header h1 a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--text);
  text-decoration: none;
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}
.brand-mark { width: 1.65rem; height: 1.65rem; flex: none; }

main { max-width: var(--max-width); margin: 0 auto; padding: 1rem; }

.loading, .empty { color: var(--text-muted); text-align: center; padding: 2rem 1rem; }

/* ---------- badges (strip + picker) ---------- */

.badge {
  display: inline-block;
  min-width: 3.2em;
  text-align: center;
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
  font-weight: 600;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
.badge.hot  { background: var(--tint-down);  color: var(--down); }
.badge.warm { background: var(--tint-amber); color: #92540A; }  /* amber is a highlight, not a text colour */
.badge.cool { background: var(--tint-azure); color: #0A6E9E; }
.badge.na   { background: #F1EFE8; color: #8A8678; font-weight: 400; }

/* ---------- detail view ---------- */

.back {
  display: inline-block;
  margin-bottom: 0.7rem;
  color: var(--accent);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
}
.back:hover { text-decoration: underline; }
.detail h2 { margin: 0 0 0.2rem; color: var(--text); font-size: 1.3rem; font-family: var(--font-display); }
.detail .meta-line {
  color: var(--text-muted);
  font-size: 0.8rem;
  margin-bottom: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ranges { margin-bottom: 0.7rem; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.ranges button {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}
.ranges button:hover { border-color: var(--accent); color: var(--accent); }
.ranges button.active {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}

/* Overlay toggles. Deliberately lighter than the range pills next to them -
   a range is a mode, an overlay is a thing you add, and they should not read
   as the same control. */
.overlays {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0 0 0.7rem;
}
.overlays button {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.22rem 0.65rem;
  font-family: var(--font-display);
  font-size: 0.76rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}
.overlays button:hover { border-color: var(--accent); color: var(--accent); }
.overlays button.active {
  background: var(--tint);
  border-style: solid;
  border-color: var(--accent);
  color: var(--accent);
}

#chart {
  width: 100%;
  height: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* "Unusual today" - the screener's ranking folded under the chart. A single
   horizontally scrolling row: enough to answer "where is the activity",
   never a second destination. */
.strip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.7rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 0.2rem;
}
/* The label is a button and has to look like one at rest - hover styling
   alone is invisible on a phone. Pill treatment matches the overlay toggles;
   open state fills like an active range pill. */
.strip-toggle {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--accent);
  white-space: nowrap;
  flex: none;
  background: var(--tint);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.28rem 0.75rem;
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease;
}
.strip-toggle:hover { background: var(--accent); color: var(--on-accent); }
.strip-chevron { display: inline-block; transition: transform 160ms ease; }
.strip-toggle.open .strip-chevron { transform: rotate(180deg); }
.strip-toggle.open { background: var(--accent); color: var(--on-accent); }

.strip-expanded {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem 0.8rem;
  margin-top: 0.5rem;
}
.strip-section h3 {
  font-family: var(--font-display);
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0.5rem 0 0.4rem;
}
.strip-note {
  text-transform: none;
  letter-spacing: 0;
  font-family: var(--font-body);
  font-weight: 400;
  color: var(--text-muted);
}
.strip-grid { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.strip-item {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.7rem;
  text-decoration: none;
  color: var(--text);
  font-size: 0.85rem;
  white-space: nowrap;
}
.strip-item:hover { border-color: var(--accent); }
.strip-item.current { border-color: var(--accent); background: var(--tint); }
.strip-name { max-width: 11em; overflow: hidden; text-overflow: ellipsis; }

/* marker key + tapped-event card, under the chart */
.marker-key {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.9rem;
  font-size: 0.76rem;
  color: var(--text-muted);
  margin: 0.5rem 0 0;
}
.key-item { white-space: nowrap; }
.key-hint { font-style: italic; }

.event-card {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 0.6rem 0.8rem;
  margin-top: 0.6rem;
}
.event-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font-display);
  margin-bottom: 0.3rem;
}
.event-card-close {
  background: transparent;
  border: none;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 0.2rem;
}
.event-card-close:hover { color: var(--accent); }
.event-row {
  display: flex;
  gap: 0.55rem;
  padding: 0.4rem 0;
  border-top: 1px solid var(--border);
  font-size: 0.88rem;
}
.event-glyph { flex: none; font-size: 1rem; }
.event-who { color: var(--text-muted); font-size: 0.82rem; }
.event-detail { color: var(--text-muted); font-size: 0.82rem; margin-top: 0.15rem; }
.event-src {
  display: inline-block;
  margin-top: 0.2rem;
  font-size: 0.8rem;
  font-weight: 500;
}

.panel-note { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.7rem; }

footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0.9rem 1rem 1.6rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  color: var(--text-muted);
  font-size: 0.78rem;
}
footer a { color: var(--text-muted); text-decoration: none; }
footer a:hover { color: var(--accent); text-decoration: underline; }
.credit { display: inline-flex; align-items: center; gap: 0.35rem; }
.credit img { width: 0.95rem; height: 0.95rem; }

/* ---------- instrument picker: region > sector > instrument ---------- */

.picker {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 0 0 0.7rem;
}
.picker > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.65rem 0.85rem;
  cursor: pointer;
  list-style: none;
}
.picker > summary::-webkit-details-marker { display: none; }
.picker-current {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--text);
}
.picker-hint {
  font-family: var(--font-display);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  white-space: nowrap;
}
.picker[open] .picker-hint {
  background: var(--accent);
  color: var(--on-accent);
  border-color: var(--accent);
}
.picker-body {
  border-top: 1px solid var(--border);
  padding: 0.3rem 0.85rem 0.7rem;
  max-height: 60vh;
  overflow-y: auto;
}

.pick-region > summary {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text);
  padding: 0.55rem 0;
  cursor: pointer;
}
.pick-count { color: var(--text-muted); font-weight: 400; font-size: 0.78rem; }
/* Sector is its own disclosure, so the tree collapses at two levels. Only the
   region and sector holding the current instrument start open - with 26
   instruments an all-open tree is a wall of text on a phone. */
.pick-sector { margin: 0 0 0.1rem 0.55rem; }
.pick-sector > summary {
  font-family: var(--font-display);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 0.4rem 0;
  cursor: pointer;
}
.pick-sector > summary:hover { color: var(--accent); }

.pick-search { position: relative; margin: 0.5rem 0 0.4rem; }
.pick-search-icon {
  position: absolute;
  left: 0.7rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}
.pick-search input {
  width: 100%;
  padding: 0.5rem 0.7rem 0.5rem 2.1rem;
  border: 1px solid var(--input-border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.92rem;
}
.pick-search input::placeholder { color: var(--text-muted); }
.pick-search input:focus { border-color: var(--accent); }
.pick-empty {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 0;
  padding: 0.5rem 0.2rem;
}
.pick-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.55rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  font-size: 0.92rem;
}
.pick-item:hover { background: var(--tint); }
.pick-item.current { background: var(--accent); color: var(--on-accent); }
.pick-item.current .pick-type { color: rgba(255, 255, 255, 0.78); }
.pick-type {
  font-family: var(--font-display);
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

@media (max-width: 640px) {
  main { padding: 0.75rem 0.6rem; }
  .overlays button { font-size: 0.72rem; padding: 0.2rem 0.55rem; }
  #chart { height: 340px; }
  .picker-current { font-size: 1.15rem; }
}
