/* Phase 75 (stage 3, 2.7): Today as the home screen and the phone's bottom bar
   (docs/design/NEW_LOOK.md → Stage 3, outputs/ui-review/concepts/C-today-tiles.jpg).
   Sections: the view over the chat column · the greeting with her face · the tile grid (three or
   four columns on wide screens, two on tablets, one on phones) · each tile · the bottom bar ·
   phones · the native apps' title strip. Colours, shapes and motion come from theme.css. */

/* ---------- The view: over the chat column, not a window ---------- */
#chat > dialog.today-view {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  width: auto;
  height: auto;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  color: var(--text-1);
  background: var(--page-glow), var(--surface-0);
  overflow: hidden;
}
#chat > dialog.today-view[open] { display: block; animation: td-in var(--dur-slow) var(--ease-out) both; }
@keyframes td-in { from { opacity: 0; transform: translateY(6px); } }
.td-scroll {
  container: today / inline-size;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(16px, 3.2vw, 34px) clamp(14px, 3vw, 36px) 28px;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline-strong) transparent;
}
.td-scroll > * { max-width: 1200px; margin-left: auto; margin-right: auto; }

/* ---------- The greeting: her face, the day, her mood ---------- */
.td-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 28px;
  margin-bottom: 22px;
}
.td-hello { min-width: 0; display: grid; gap: 6px; justify-items: start; }
.td-date { margin: 0; font-size: var(--fs-meta); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-2); }
#td-greeting { margin: 0; font-size: clamp(26px, 3.6vw, 40px); line-height: 1.12; font-weight: 650; letter-spacing: -0.02em; color: var(--text-1); overflow-wrap: anywhere; }
#td-greeting:focus { outline: none; }
.td-her { display: grid; gap: 4px; justify-items: start; max-width: 640px; }
.td-mood {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 6px;
  margin: 2px 0 0;
  padding: 5px 13px 5px 11px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-pill);
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  color: var(--text-1);
  font-size: 13.5px;
}
.td-mood .hp-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--success); box-shadow: 0 0 8px -1px var(--success); }
.td-her-name { font-weight: 650; }
.td-mood-text { color: var(--text-2); }
.today-her { display: block; }
#today .td-her-day { margin: 2px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; cursor: pointer; color: var(--text-2); }
#today .td-her-day.open { -webkit-line-clamp: unset; }
.td-her-day:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: 2px; border-radius: 4px; }
.td-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0 0; }
.td-face-wrap { display: grid; justify-items: center; gap: 10px; }
.td-face-btn {
  position: relative;
  width: clamp(96px, 12vw, 150px);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.td-face-btn::before { content: ""; position: absolute; inset: -18%; z-index: -1; border-radius: 50%; background: radial-gradient(closest-side, var(--accent-glow), var(--violet-glow) 55%, transparent); opacity: .7; }
.td-face-btn:hover { background: none; }
.td-face-btn:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: 6px; }
.td-face { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; box-shadow: 0 0 0 3px var(--surface-0), 0 0 0 5px color-mix(in srgb, var(--accent-solid) 70%, var(--accent-to)), 0 14px 40px -12px var(--accent-glow); }
html.sara-busy .td-face { animation: her-breathe var(--breathe) ease-in-out infinite; }
.td-ai { font-size: 11.5px; padding: 2px 10px; border-color: var(--hairline-strong); background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.td-back { position: absolute; top: 0; right: 0; }
.td-hero:has(.td-back) .td-face-wrap { margin-top: 26px; }

/* Getting started: a wide card above the tiles. */
#today .today-start {
  margin: 0 auto 16px;
  padding: 16px 18px;
  border: 1px solid var(--hairline-strong);
  border-radius: 18px;
  background: linear-gradient(160deg, color-mix(in srgb, var(--surface-2) 90%, var(--accent-to)), var(--surface-1) 75%);
  box-shadow: var(--glow-edge);
}
#today .today-start-head h3 { margin: 0; font-size: 16px; font-weight: 600; color: var(--text-1); }
#today .today-start-list { grid-template-columns: repeat(auto-fill, minmax(min(100%, 210px), 1fr)); gap: 8px; margin-top: 12px; }
#today .start-item { min-height: 44px; padding: 8px 12px; border-radius: 12px; align-items: center; }
#today .start-item .start-hint { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; }
#today .start-item.done .start-hint { display: none; }

/* ---------- The grid ---------- */
.td-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr));
  grid-auto-flow: row dense;
  align-items: start;
  gap: 14px;
}
@container today (min-width: 600px) { .td-wide { grid-column: span 2; } }
@container today (min-width: 1100px) { .td-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

/* ---------- A tile ---------- */
#today .td-tile {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-content: start;
  gap: 10px;
  min-width: 0;
  padding: 16px 18px 16px;
  border: 1px solid var(--hairline-strong);
  border-radius: 18px;
  background: linear-gradient(165deg, color-mix(in srgb, var(--surface-2) 94%, var(--accent-to)), var(--surface-1) 72%);
  box-shadow: var(--glow-edge);
  animation: td-tile-in var(--dur-slow) var(--ease-out) both;
}
@keyframes td-tile-in { from { opacity: 0; transform: translateY(4px); } }
#today .td-tile:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: 2px; }
.td-tile-head { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
#today .td-tile-head h3 { margin: 0; font-size: 16px; font-weight: 600; letter-spacing: var(--tracking-tight); color: var(--text-1); }
.td-count { min-width: 0; font-size: var(--fs-meta); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-tile-head > :last-child:not(h3) { margin-left: auto; }
.td-tile-head > .td-count:last-child { margin-left: 0; }
.td-body, #today .today-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
#today .today-list > p, .td-body > p { margin: 0; }
.td-link {
  justify-self: start;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent-text);
  font-size: 13.5px;
  font-weight: 600;
}
.td-link:hover { background: none; text-decoration: underline; }
.td-link:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: 2px; border-radius: 4px; }

/* Weather */
.td-wx-main { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.td-wx-icon { font-size: 30px; line-height: 1; align-self: center; }
.td-wx-temp { font-size: 44px; line-height: 1; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; color: var(--text-1); }
.td-wx-words { font-size: 15px; color: var(--text-1); }
.td-wx-meta { margin: 0; font-size: var(--fs-meta); color: var(--text-2); font-variant-numeric: tabular-nums; }
.td-wx-hours { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; margin: 2px 0 0; padding: 0; list-style: none; }
.td-wx-hour { display: grid; justify-items: center; gap: 1px; padding: 6px 4px; border-radius: var(--r-control); background: color-mix(in srgb, var(--surface-3) 55%, transparent); font-size: 12px; font-variant-numeric: tabular-nums; }
.td-wx-h { color: var(--text-2); white-space: nowrap; }
.td-wx-ht { color: var(--text-1); font-weight: 600; }

/* Your day: a timeline */
.td-timeline { position: relative; display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.td-timeline::before { content: ""; position: absolute; left: calc(4.4em + 13px); top: 8px; bottom: 8px; width: 2px; border-radius: 2px; background: var(--hairline-strong); }
.td-time-row { display: grid; grid-template-columns: 4.4em 12px minmax(0, 1fr); align-items: start; column-gap: 8px; min-width: 0; }
.td-when { padding-top: 2px; font-size: var(--fs-meta); color: var(--text-2); font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-dot { position: relative; z-index: 1; margin-top: 6px; justify-self: center; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent-solid); background: var(--surface-1); }
.td-time-row.reminder .td-dot { background: var(--accent-solid); }
.td-time-row.past { opacity: .55; }
.td-time-row.past .td-dot { border-color: var(--text-3); background: var(--text-3); }
.td-what { display: grid; min-width: 0; }
.td-what-title { font-size: 14.5px; line-height: 1.35; color: var(--text-1); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow-wrap: anywhere; }
.td-what-where { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Planner: to-dos with a tick */
.td-tasks { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.td-task { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 6px; min-width: 0; min-height: 40px; padding: 2px 6px 2px 0; border-radius: var(--r-control); }
.td-task > .td-tick { grid-row: span 2; }
.td-task:hover { background: color-mix(in srgb, var(--surface-3) 45%, transparent); }
.td-tick { position: relative; flex: none; width: 36px; height: 36px; padding: 0; border: 0; border-radius: var(--r-control); background: none; }
.td-tick::before { content: ""; position: absolute; inset: 8px; border: 1.5px solid var(--text-3); border-radius: 6px; transition: background var(--dur-fast), border-color var(--dur-fast); }
.td-tick:hover { background: none; }
.td-tick:hover::before { border-color: var(--accent-solid); }
.td-tick:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: -2px; }
.td-task.done .td-tick::before { border-color: transparent; background: var(--accent-grad); }
.td-task.done .td-tick::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: var(--on-mine); font-size: 13px; font-weight: 700; }
.td-task-title { min-width: 0; font-size: 14.5px; line-height: 1.3; color: var(--text-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-task.done .td-task-title { color: var(--text-3); text-decoration: line-through; }
.td-task-side { min-width: 0; font-size: 12px; line-height: 1.3; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-task.overdue .td-task-side { color: var(--danger); }

/* She remembered: a warm card */
#today .td-warm { background: linear-gradient(165deg, color-mix(in srgb, var(--accent-solid) 20%, var(--surface-2)), color-mix(in srgb, var(--accent-solid) 7%, var(--surface-1)) 75%); border-color: color-mix(in srgb, var(--accent-solid) 30%, var(--hairline-strong)); }
.td-mems { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.td-mem { display: grid; gap: 2px; padding-left: 12px; border-left: 2px solid color-mix(in srgb, var(--accent-solid) 60%, transparent); }
.td-mem-text { margin: 0; font-size: 14.5px; line-height: 1.5; color: var(--text-1); overflow-wrap: anywhere; }
.td-mem-from { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Moments: photos like prints */
#today .today-otd { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 120px), 1fr)); gap: 10px; }
#today .td-otd-item { margin: 0; padding: 6px 6px 8px; border-radius: 12px; background: color-mix(in srgb, var(--surface-3) 70%, transparent); border: 1px solid var(--hairline); display: grid; gap: 6px; min-width: 0; }
#today .td-otd-item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; cursor: zoom-in; }
#today .td-otd-item img:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: 2px; }
#today .td-otd-item figcaption { margin: 0; font-size: 12px; line-height: 1.35; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* Background work: a terminal-like card inside */
.td-live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--success); }
.td-live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 8px -1px var(--success); animation: step-pulse calc(var(--breathe) / 3) ease-in-out infinite; }
.td-job { display: grid; gap: 4px; min-width: 0; padding: 10px 12px; border: 1px solid var(--hairline-strong); border-radius: 12px; background: var(--surface-0); }
.td-job-name { margin: 0; font: 600 13px/1.4 var(--font-mono); color: var(--text-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-job-sub { margin: 0; font-size: 12px; color: var(--text-2); }
.td-job-out { margin: 0; font: 11.5px/1.4 var(--font-mono); color: var(--text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-job-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.td-progress { width: 100%; height: 6px; border: 0; border-radius: 6px; background: var(--hairline-strong); overflow: hidden; -webkit-appearance: none; appearance: none; }
.td-progress::-webkit-progress-bar { background: var(--hairline-strong); border-radius: 6px; }
.td-progress::-webkit-progress-value { background: var(--accent-grad); border-radius: 6px; }
.td-progress::-moz-progress-bar { background: var(--accent-grad); border-radius: 6px; }

/* Home: a few devices; changes go through her */
.td-home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 120px), 1fr)); gap: 8px; }
.td-dev { display: grid; gap: 2px; align-content: start; min-width: 0; padding: 10px 12px; border: 1px solid var(--hairline-strong); border-radius: 14px; background: color-mix(in srgb, var(--surface-3) 60%, transparent); }
.td-dev.on { background: linear-gradient(150deg, color-mix(in srgb, var(--warn) 18%, var(--surface-2)), var(--surface-2)); border-color: color-mix(in srgb, var(--warn) 35%, var(--hairline-strong)); }
.td-dev-name { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-dev-state { margin: 0; font-size: 12.5px; color: var(--text-2); }
.td-dev-ask { justify-self: start; margin-top: 4px; }
.td-foot { margin: 0; }
.td-home-choose summary { cursor: pointer; font-size: 13px; color: var(--accent-text); min-height: 32px; display: flex; align-items: center; }
.td-home-picks { display: grid; gap: 2px; max-height: 220px; overflow-y: auto; margin: 4px 0; }
.td-home-picks label { display: flex; align-items: center; gap: 8px; font-size: 13.5px; min-height: 32px; }
.td-home-picks input { width: auto; accent-color: var(--accent-solid); }

/* Add to your day: one line per thing to set up */
.td-setup-item { display: grid; gap: 1px; justify-items: start; width: 100%; min-height: 44px; padding: 9px 12px; border: 1px dashed var(--hairline-strong); border-radius: 12px; background: transparent; color: var(--text-1); font-weight: 500; text-align: left; }
.td-setup-item:hover { background: color-mix(in srgb, var(--surface-3) 50%, transparent); border-color: color-mix(in srgb, var(--accent-solid) 45%, var(--hairline-strong)); }
.td-setup-item strong { font-size: 14px; font-weight: 600; }
.td-setup-item .muted { color: var(--text-2); }
.td-hide { min-height: 30px; padding: 2px 10px; }

/* Ask her anything, at the bottom */
.td-ask-row { display: flex; justify-content: center; margin: 22px auto 4px; }
.td-ask-any {
  width: min(560px, 100%);
  min-height: 50px;
  padding: 0 22px;
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r-pill);
  background: var(--glass);
  -webkit-backdrop-filter: var(--glass-filter);
  backdrop-filter: var(--glass-filter);
  box-shadow: var(--shadow-2);
  color: var(--text-2);
  font-weight: 500;
  text-align: left;
}
.td-ask-any:hover { background: var(--glass-strong); color: var(--text-1); border-color: color-mix(in srgb, var(--accent-solid) 45%, var(--hairline-strong)); }

/* The sidebar's face and name go to Today. */
button.brand { display: inline-flex; align-items: center; gap: 8px; min-width: 0; min-height: 40px; padding: 2px 8px 2px 2px; margin-left: -2px; border: 0; border-radius: var(--r-pill); background: none; color: var(--text-1); font: inherit; font-size: 20px; font-weight: 650; letter-spacing: var(--tracking-tight); }
button.brand:hover { background: color-mix(in srgb, var(--surface-3) 70%, transparent); }
button.brand:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: 2px; }
.brand-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- The phone's bottom bar ---------- */
.bottom-bar { display: none; }
@media (max-width: 720px) {
  :root { --bbar-h: calc(60px + env(safe-area-inset-bottom)); }
  #main { grid-template-rows: minmax(0, 1fr) auto; }
  .bottom-bar {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    position: relative;
    z-index: 8;
    padding: 4px max(6px, env(safe-area-inset-left)) env(safe-area-inset-bottom) max(6px, env(safe-area-inset-right));
    border-top: 1px solid var(--hairline-strong);
    background: var(--glass-strong);
    -webkit-backdrop-filter: var(--glass-filter);
    backdrop-filter: var(--glass-filter);
  }
  html.kb-up .bottom-bar { display: none; }
  /* The drawer (☰ / More) stops above the bar, so the bar still switches places while it is open. */
  html:not(.kb-up) #sidebar { bottom: var(--bbar-h); }
  html:not(.kb-up) #main.show-sidebar #sidebar-scrim { bottom: var(--bbar-h); }
  .bb-btn {
    position: relative;
    display: grid;
    justify-items: center;
    align-content: center;
    gap: 2px;
    min-width: 0;
    min-height: 52px;
    padding: 4px 2px;
    border: 0;
    border-radius: 14px;
    background: none;
    color: var(--text-2);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .01em;
  }
  .bb-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .bb-btn svg { width: 23px; height: 23px; }
  .bb-btn:hover { background: color-mix(in srgb, var(--surface-3) 60%, transparent); color: var(--text-1); }
  .bb-btn:focus-visible { outline: 2px solid var(--accent-solid); outline-offset: -2px; }
  .bb-btn[aria-current="page"] { color: var(--accent-text); }
  .bb-btn[aria-current="page"] svg { filter: drop-shadow(0 0 6px var(--accent-glow)); }
  .bb-btn[aria-current="page"]::before { content: ""; position: absolute; top: 0; left: 32%; right: 32%; height: 3px; border-radius: 0 0 3px 3px; background: var(--accent-grad); }
  .bb-btn .side-dot { position: absolute; top: 8px; right: calc(50% - 18px); }
  /* The composer sits on the bar (the bar keeps the safe area); while typing the bar steps away. */
  html:not(.kb-up) #composer { margin-bottom: 8px; }
  /* A window leaves the bar visible below it (a tap there closes the window and goes on). */
  html:not(.kb-up) body:has(> #main:not([hidden])) dialog:modal:not(.ring, .lightbox, .cmdbar, [data-required]) {
    max-height: calc(100dvh - var(--bbar-h) - 16px);
    margin-bottom: calc(var(--bbar-h) + 8px);
  }
  html:not(.kb-up) body:has(> #main:not([hidden])) .msg.show-actions > .msg-actions { bottom: calc(84px + var(--bbar-h)); }
  html:not(.kb-up) body:has(> #main:not([hidden])) .tour-offer { bottom: calc(var(--bbar-h) + 12px); }
  /* Today on a phone: the bar's Chat replaces the back button; her face beside the greeting. */
  .td-back { display: none; }
  .td-hero { grid-template-columns: minmax(0, 1fr) auto; gap: 6px 14px; margin-bottom: 16px; }
  .td-hero:has(.td-back) .td-face-wrap { margin-top: 0; }
  .td-face-btn { width: 76px; }
  .td-face-wrap { gap: 6px; align-self: start; }
  .td-ai { font-size: 10.5px; padding: 1px 8px; }
  #today .td-tile { padding: 14px 15px; border-radius: 16px; }
  .td-scroll { padding: 16px 12px 22px; }
  .td-ask-row { margin-top: 16px; }
  /* Getting started: two short columns (the hint is in each item's place once opened). */
  #today .today-start-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #today .start-item .start-hint { display: none; }
  #today .start-item { padding: 8px 10px; }
}
@media (max-width: 380px) {
  .td-hero { grid-template-columns: minmax(0, 1fr); }
  .td-face-wrap { grid-row: 1; justify-self: start; grid-auto-flow: column; align-items: center; }
  .td-face-btn { width: 56px; }
  .td-mood { font-size: 12.5px; }
}
@media (pointer: coarse) {
  .td-link, .td-home-choose summary, .td-home-picks label { min-height: 44px; }
  .td-tick { width: 44px; height: 44px; }
  .td-tick::before { inset: 11px; }
  .td-task { min-height: 44px; }
}

/* ---------- The native apps' title strip ---------- */
html.shell .td-scroll { padding-top: calc(var(--titlebar) + clamp(12px, 2.4vw, 26px)); }
