/* Clash Royale Stats 3.1.0 - Habits screen (T-013 / R-011, T4-006 / R-010 + R-012).

   "When and how do I play best?" - four sub-views (When / Sessions / Elixir /
   Records, `#/habits?view=<v>`), each a stack of flat cards. A section is ONE
   `.card`: its charts and lists sit inside it, separated by spacing or a thin
   divider - there is no card inside a card any more. Card heads use the shared
   `.card-head` / `.card-title` / `.card-sub` hierarchy (components.css) with the
   honesty footnotes behind an info tip on the right.

   Reuses the shared Arena primitives (.card, .card-flat, .chip, .seg, .btn,
   .pill, .meter, the type ramp) from web/css/{tokens,components,shell}.css
   wherever they already cover a need - everything below is layout/composition
   specific to this screen, scoped under #habits-body (or a habits- prefix) so
   it can never leak into another screen.

   The heatmap/calendar sequential ramp (#184f95 -> #1c5cab -> #3987e5 ->
   #86b6ef) is a design-system literal carried in web/screens/habits.js
   (HEAT_RAMP) - a fixed visual constant, not a data-series colour. Every OTHER
   chart on this screen (Chart.js canvases) keeps reading the unchanged
   --series-1 / --series-2 etc. tokens (web/css/tokens.css). */

/* ---------- head row: view tabs + the local range chip ----------
   Phone: the tabs take a full row and the range chip sits under them, right
   aligned. From 768px up they share one row, chip on the right. No top padding
   of its own at any width: the shell pads `.content` (16px from 1024px up). */

.habits-head {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px;
  margin-bottom: 14px;
}
.habits-views-host { flex: 1 1 100%; min-width: 0; }
.habits-views-host .seg.views { margin-bottom: 0; }
.habits-range-host { margin-left: auto; }
@media (min-width: 768px) {
  .habits-views-host { flex: 0 0 auto; }
}
@media (min-width: 1024px) {
  .habits-head { margin-bottom: 18px; }
}

/* A hidden sub-view (.hidden is display:none !important; the explicit rule
   keeps the pairing obvious next to .screen-stack's display:flex). */
.habits-view.hidden { display: none; }
.habits-view.screen-stack { gap: 16px; }

/* ---------- section cards ---------- */

.habits-card { display: flex; flex-direction: column; gap: 14px; }
.habits-card > .card-head { margin-bottom: 0; }
#habits-body .card-flat { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px; }
.habits-tip-slot { display: inline-flex; flex: none; }

.habits-body { display: flex; flex-direction: column; gap: 18px; }
.habits-divided { border-top: 1px solid var(--line); padding-top: 16px; }

.habits-year-picker { max-width: 58%; overflow-x: auto; scrollbar-width: none; flex: none; }
.habits-year-picker::-webkit-scrollbar { display: none; }

.habits-gap { align-self: flex-start; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.habits-gap::-webkit-scrollbar { display: none; }

/* A failed request, stated inside the card that owns it, with a Retry. */
.habits-error {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 0;
}

/* A card with nothing painted yet (first visit, or the first load after a player
   switch): a few shimmering bars under its head, removed when its response lands
   or fails (G3 R1-04). */
.habits-loading { display: flex; flex-direction: column; gap: 10px; padding: 6px 0 2px; }
.habits-skel { height: 14px; border-radius: 6px; }
.habits-skel:nth-child(1) { width: 92%; }
.habits-skel:nth-child(2) { width: 78%; }
.habits-skel:nth-child(3) { width: 60%; }

/* ---------- the verdict line (When) ---------- */

.habits-insight {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: 12px; background: var(--blue-soft);
}
.habits-insight .small { font-size: 13px; line-height: 1.4; color: var(--ink); }
.habits-insight-icon { display: flex; flex: none; color: #7fb3f0; padding-top: 1px; }

/* ---------- empty states (the 2.0.0 shim owned `.empty-state` before it was
   retired in T-016; this screen carries its own definition) ---------------- */

.empty-state { text-align: center; color: var(--ink-3); padding: 28px 0; font-size: 13px; }
.empty-state.small { padding: 8px 0; }

/* ---------- when-do-you-win heatmap (R-011: "grid 30px + 24 columns", cells
   fit 390px without horizontal scroll at the standard content width;
   .heatmap-wrap keeps overflow-x:auto as a safety net on narrower viewports
   only). Phone: heatmap, legend, then the weekday margins stacked. From 768px
   the weekday margins move beside the grid. ---------------------------- */

.habits-heat { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.habits-heat-main { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.habits-dow { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
@media (min-width: 768px) {
  .habits-heat { grid-template-columns: minmax(0, 2.3fr) minmax(0, 1fr); gap: 32px; align-items: start; }
  .heat-cell { height: 15px; }
  .heat-margin-col { height: 10px; }
}

.heatmap-wrap { overflow-x: auto; padding-bottom: 2px; }
.heatmap-grid {
  display: grid;
  grid-template-columns: 30px repeat(24, minmax(0, 1fr));
  gap: 2px;
  align-items: center;
}
.heat-hour-label { font-size: 11px; color: var(--ink-3); text-align: center; }
.heat-day-label { font-size: 11px; color: var(--ink-3); font-weight: 700; }
/* The ninth grid row is the per-hour margin, not an eighth weekday: its "All"
   label and its bars sit a little apart from the Sun row and the label is
   quieter than the seven day names. */
.heat-all-label { font-weight: 600; margin-top: 6px; }
.heat-cell { height: 11px; border-radius: 2px; background: var(--s2); }
.heat-cell.masked { background: var(--s3); opacity: .5; }
.heat-margin-col { height: 8px; border-radius: 2px; background: var(--s2); margin-top: 6px; }
.heat-margin-col.masked { background: var(--s3); opacity: .5; }

.habits-legend { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.habits-legend-swatch { width: 12px; height: 8px; border-radius: 2px; flex: none; }
.habits-legend-note { margin-left: auto; }

/* Per-day-of-week margin (kept OUT of the 30px+24-column grid above so the
   literal column template is never altered by width - see R-011). Each row:
   3-letter day label + win% meter + honesty-muted pct span. */
.heat-dow-margins { display: flex; flex-direction: column; gap: 6px; }
.heat-dow-row { display: flex; align-items: center; gap: 8px; }
.heat-dow-row .heat-dow-label { width: 30px; flex: none; font-size: 12px; color: var(--ink-2); }
.heat-dow-row .meter { flex: 1; min-width: 0; }
/* The bar wears its number's colour (CRUI.pctSpan's +-2 point rule, as Cards,
   Decks and Trends do); a low-sample day keeps the tint but dimmed, like its
   greyed percentage. */
.heat-dow-row .meter.is-good .fill { background: var(--good); }
.heat-dow-row .meter.is-bad .fill { background: var(--bad); }
.heat-dow-row .meter.is-low .fill { opacity: .45; }
.heat-dow-row .pct { width: 44px; flex: none; text-align: right; font-size: 12px; }

/* ---------- stat tile rows (sessions / elixir / closeness / records) ----
   Phone: 3 columns (2 for closeness and records). Wider screens spread the tiles over
   more columns so a row of tiles stays one or two rows tall. */

.tile-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.tile-row-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile-row .wide { grid-column: 1 / -1; }
.tile-row-records { grid-template-columns: repeat(2, minmax(0, 1fr)); }
/* Elixir: its values read "4.85 / 4.79", too wide for a third of a phone. */
.tile-row-elixir { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tile-row-elixir > :last-child { grid-column: 1 / -1; }
.tile-row .card-flat .num { font-size: 18px; display: inline-flex; align-items: center; gap: 4px; }
/* Phone, Sessions: "Games / session" wraps to two lines in a third of 390px, and
   the other two tiles have one. Bottom-align the eyebrows so the three numbers
   still sit on one line (the wide tile below has its own row). */
@media (max-width: 767px) {
  .tile-row-sessions .card-flat:not(.wide) .eyebrow { margin-top: auto; }
}
.tile-row .card-flat .num .i { color: var(--elixir); }
@media (min-width: 768px) {
  .tile-row-sessions { grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 2fr); }
  .tile-row-sessions .wide { grid-column: auto; }
  .tile-row-records { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .tile-row-records .wide { grid-column: span 2; }
  .tile-row-close { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .tile-row-elixir { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .tile-row-elixir > :last-child { grid-column: auto; }
}

/* ---------- charts: two side by side from 768px, stacked on a phone ---- */

.habits-charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.habits-chart { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.habits-chart-title { margin: 0; font-size: 13px; font-weight: 700; color: var(--ink-2); line-height: 1.3; }
@media (min-width: 768px) {
  .habits-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; }
}

.chart-box { position: relative; height: 140px; }
@media (min-width: 768px) {
  .chart-box { height: 200px; }
}

/* ONE muted line standing in for a chart that has nothing to plot (Trends'
   `.trends-chart-empty`, same idea): bare axes would read as "0 %" or "no change"
   when the truth is "no data". */
.habits-chart-empty { padding: 6px 0 2px; line-height: 1.45; }

/* The expander itself is the shell's `.list-more`; an empty host takes no room. */
.habits-more-host:empty { display: none; }

/* ---------- recent sessions table ---------- */

.sessions-table-head, .sessions-row {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
}
/* 11px is the eyebrow floor (R-002), so this column header is styled AS an
   eyebrow - uppercase, 800, tracked - rather than 11px sentence case (T-016). */
.sessions-table-head {
  color: var(--ink-3); font-size: 11px; padding-bottom: 6px;
  font-weight: 800; letter-spacing: .06em; text-transform: uppercase;
}
.sessions-row { padding: 6px 0; border-top: 1px solid var(--line); }
.sessions-table-head span, .sessions-row span { white-space: nowrap; }
.sessions-row:first-child { border-top: 0; }
.col-sess-start { flex: 1 1 64px; min-width: 0; color: var(--ink-2); }
.col-sess-len { width: 50px; flex: none; color: var(--ink-2); }
.col-sess-wld { width: 86px; flex: none; color: var(--ink-2); }
.col-sess-net { width: 40px; flex: none; text-align: right; }
.col-sess-ended { width: 64px; flex: none; text-align: right; }
@media (min-width: 768px) {
  .col-sess-len { width: 72px; }
  .col-sess-wld { width: 120px; }
  .col-sess-net { width: 72px; }
  .col-sess-ended { width: 72px; }
}

/* ---------- activity calendar (R-011: 13px cells, year seg, click-to-day) -
   A played day is a real <button class="cal-cell clickable"> (G3 R1-20): the
   shell's `button` reset already strips its chrome, so it looks like the inert
   cells around it; the gold focus ring is drawn above its neighbours and the
   wrap pads the right and bottom edge so the ring is never clipped there. */

.calendar-grid-wrap { overflow-x: auto; padding: 0 3px 4px 0; }
.calendar-grid { display: grid; grid-auto-rows: 13px; gap: 2px; align-items: center; }
.cal-cell { width: 13px; height: 13px; border-radius: 3px; background: var(--s2); }
.cal-cell.step-out { background: transparent; }
.cal-cell.clickable { cursor: pointer; }
.cal-cell.clickable:focus-visible { outline-offset: 1px; position: relative; z-index: 1; }
.cal-dow-label, .cal-month-label { font-size: 11px; color: var(--ink-3); }
.cal-month-label { font-weight: 700; }

/* ---------- records milestone meter ---------- */

.records-milestones { display: flex; flex-direction: column; gap: 12px; }
.records-milestone-row { display: flex; flex-direction: column; gap: 4px; }
.records-milestone-head { display: flex; align-items: baseline; gap: 2px; }

/* ---------- range-picker sheet rows / closeness battle lists ----------- */

.range-pick-list { display: flex; flex-direction: column; }
.range-pick-row { width: 100%; text-align: left; cursor: pointer; justify-content: space-between; }
.range-pick-row.on { color: var(--gold); }

.matchup-list { display: flex; flex-direction: column; }
.matchup-row {
  display: flex; align-items: center; gap: 10px; padding: 6px 0;
  border-top: 1px solid var(--line); font-size: 12px;
}
.matchup-row:first-child { border-top: 0; }
.matchup-row .name {
  flex: 1 1 88px; min-width: 0; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.matchup-row .meta { flex: none; color: var(--ink-3); font-size: 12px; }
