/* drtripathi chat UI (TSK-2447, S1): design tokens v2 and the PhoneFrame.
   Mobile first: on a phone (480 px wide or less) the app fills the screen
   (100dvh, safe areas) and no frame is drawn. Wider, the page is quiet and an
   iPhone frame sits in the centre (TSK-2497); the app screen inside is
   393 x 852 and only the thread scrolls.
   Inside the app: square corners, no shadows, no blur, orange 5% or less.
   Logical properties only, so dir="rtl" mirrors the layout. */

@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("fonts/dm-mono-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "DM Mono";
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("fonts/dm-mono-latin-500-normal.woff2") format("woff2");
}

/* --- tokens v2 ---------------------------------------------------------------- */
/* The tokens are in static/tokens.css, generated from design_tokens.json
   by scripts/build_tokens.py (TSK-2513). It is linked before this file. */

/* --- base ------------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 400 var(--fs-body)/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere; /* long words, links and Hindi wrap at 320 px */
}
:focus-visible { outline: var(--stroke-2) solid var(--ink); outline-offset: var(--focus-gap); }

.pf-skip {
  position: absolute;
  inset-block-start: var(--s-2);
  inset-inline-start: var(--s-2);
  z-index: var(--z-skip);
  padding: var(--s-3) var(--s-4);
  min-block-size: var(--tap);
  background: var(--paper);
  color: var(--ink);
  border: var(--stroke-1) solid var(--ink);
  font: 500 var(--fs-label)/1.6 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
  text-decoration: none;
  transform: translateY(-200%);
}
.pf-skip:focus { transform: none; }

/* --- the phone: on a phone-width screen the app is the screen -------------- */
.pf-phone { position: relative; }
.pf-screen {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-columns: minmax(0, 1fr); /* a long line cannot widen the screen */
  block-size: 100vh;
  block-size: 100dvh;
  inline-size: 100%;
  background: var(--paper);
  overflow: hidden;
}
.pf-status, .pf-home, .pf-btn { display: none; }

/* header slot */
.pf-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-block-size: calc(var(--head-b) + env(safe-area-inset-top, 0px));
  padding-block-start: env(safe-area-inset-top, 0px);
  padding-inline: max(var(--s-4), env(safe-area-inset-left, 0px));
  border-block-end: var(--stroke-1) solid var(--divider);
  background: var(--paper);
}
.pf-brand { display: inline-flex; align-items: center; gap: var(--s-2); min-block-size: var(--tap); }
.pf-brand-name { font: 600 var(--fs-body)/1 var(--sans); letter-spacing: -.01em; color: var(--ink); }
.pf-brand-mark { inline-size: var(--icon); block-size: var(--icon); }

/* body slot: the only part that scrolls */
.pf-body {
  min-block-size: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-block: var(--s-6);
  padding-inline: max(var(--s-5), env(safe-area-inset-left, 0px));
}
.pf-body:focus { outline: none; }

/* bottom slot: the future composer */
.pf-bottom {
  min-block-size: calc(var(--bottom-b) + env(safe-area-inset-bottom, 0px));
  padding-block: var(--s-2) calc(var(--s-2) + env(safe-area-inset-bottom, 0px));
  padding-inline: max(var(--s-3), env(safe-area-inset-left, 0px));
  border-block-start: var(--stroke-1) solid var(--divider);
  background: var(--paper);
}

/* --- the spiral (macro templates/_spiral.html) ------------------------------ */
.pf-screen .spp {
  fill: none;
  stroke: var(--ink);
  stroke-width: var(--stroke-spiral);
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
}
.pf-screen .sp { transform-origin: 50% 50%; }
.pf-brand-mark .spp { stroke-width: var(--stroke-spiral-mark); }
.pf-turn .spp-tip { stroke: var(--orange); } /* the one orange touch */
@keyframes pf-turn { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: no-preference) {
  .pf-turn { animation: pf-turn var(--dur-idle-turn) var(--ease-linear) infinite; }
}

/* --- the empty thread: the spiral, rays and one serif line ------------------ */
.pf-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-8);
  min-block-size: 100%;
  padding-block: var(--s-8);
  text-align: center;
}
.pf-empty-mark {
  position: relative;
  display: grid;
  place-items: center;
  inline-size: var(--empty-mark);
  block-size: var(--empty-mark);
}
.pf-empty-mark::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-conic-gradient(from 0deg, var(--border) 0deg .6deg, transparent .6deg 12deg);
  -webkit-mask: radial-gradient(closest-side, transparent 40%, var(--ink) 52%, transparent 100%);
  mask: radial-gradient(closest-side, transparent 40%, var(--ink) 52%, transparent 100%);
}
.pf-empty-mark .sp { position: relative; inline-size: var(--empty-spiral); block-size: var(--empty-spiral); }
.pf-serif {
  margin: 0;
  max-inline-size: 15em;
  font: 400 var(--fs-serif)/1.18 var(--serif);
  letter-spacing: -.01em;
  color: var(--ink);
  text-wrap: balance;
}

/* --- PhoneFrame (TSK-2497): wider than 480 px, a quiet page with the iPhone in
   the centre. All sizes are FrameTokens (design_tokens.json, group frame).
   The page never scrolls: on a short window the media steps of --frame-zoom
   (design_tokens.json "media") scale the whole phone so it fits with
   --frame-gap around it; only the thread (.pf-body) scrolls inside.
   The screen is the containing block of each layer (drawer, attach sheet,
   full-size picture, start screen): absolute and fixed layers stay inside it
   and its corners clip them. The status bar and the home indicator are rows
   of the screen grid, so they stay put when the thread scrolls, and they sit
   over the layers (--z-frame), as on the device. ---------------------------- */
@media (width > 30rem) {
  body.pf-page {
    display: grid;
    place-items: center;
    min-block-size: 100vh;
    min-block-size: 100dvh;
    padding: var(--frame-gap);
    background: var(--desk);
  }
  .pf-skip { position: fixed; }

  .pf-phone {
    zoom: var(--frame-zoom);
    padding: var(--bezel);
    border-radius: var(--device-corner);
    corner-shape: var(--frame-corner-shape);
    background: var(--ink);
    box-shadow: var(--shadow-device);
  }
  /* A continuous scale where the browser can compute it: no 0.05 steps
     (TSK-2535). Else the --frame-zoom steps above stay. */
  @supports (zoom: tan(atan2(1px, 1px))) {
    .pf-phone { zoom: var(--frame-fit); }
  }
  .pf-screen {
    position: relative;
    grid-template-rows: var(--status-b) auto 1fr auto var(--home-b);
    inline-size: var(--screen-i);
    block-size: var(--screen-b);
    border-radius: var(--screen-corner);
    corner-shape: var(--frame-corner-shape);
    isolation: isolate;
    contain: layout paint; /* a position: fixed layer is placed in the screen too */
  }
  .pf-head { min-block-size: var(--head-b); padding-block-start: 0; }
  .pf-bottom { min-block-size: var(--bottom-b); padding-block-end: var(--s-2); }

  /* status bar: time | dynamic island | signal, wifi, battery */
  .pf-status, .pf-home {
    position: relative;
    z-index: var(--z-frame);
    pointer-events: none;
    color: var(--ink);
  }
  .pf-status {
    display: grid;
    grid-template-columns: 1fr var(--island-i) 1fr;
    align-items: center;
  }
  .pf-time {
    justify-self: center;
    font: 600 var(--fs-lead)/1 var(--font-system);
    letter-spacing: -.02em;
    font-variant-numeric: tabular-nums;
  }
  .pf-island {
    justify-self: center;
    inline-size: var(--island-i);
    block-size: var(--island-b);
    border-radius: var(--island-corner);
    background: var(--ink);
  }
  .pf-icons {
    justify-self: center;
    display: inline-flex;
    align-items: center;
    gap: var(--status-gap);
    direction: ltr;
  }
  .pf-ico { display: block; fill: currentColor; }
  .pf-signal { inline-size: var(--signal-i); block-size: var(--signal-b); }
  .pf-wifi { inline-size: var(--wifi-i); block-size: var(--wifi-b); }
  .pf-battery { inline-size: var(--battery-i); block-size: var(--battery-b); }
  .pf-bat-shell { fill: none; stroke: currentColor; stroke-opacity: .4; }

  /* home indicator */
  .pf-home {
    display: grid;
    justify-items: center;
    align-items: end;
    padding-block-end: var(--home-bar-end);
  }
  .pf-home span {
    inline-size: var(--home-bar-i);
    block-size: var(--home-bar-b);
    border-radius: var(--home-bar-corner);
    background: var(--ink);
  }

  /* side buttons on the band (decoration): action, volume up and down | side.
     The layer covers the phone box and is left-to-right in each language,
     so the buttons stay where the device has them (TSK-2534). */
  .pf-btns { position: absolute; inset: 0; direction: ltr; pointer-events: none; }
  .pf-btn {
    display: block;
    position: absolute;
    inline-size: var(--side-btn-i);
    background: var(--metal);
    box-shadow: inset 0 0 0 var(--stroke-1) var(--metal-edge);
  }
  .pf-btn-action, .pf-btn-up, .pf-btn-down {
    inset-inline-start: calc(var(--side-btn-i) * -1);
    border-start-start-radius: var(--side-btn-corner);
    border-end-start-radius: var(--side-btn-corner);
  }
  .pf-btn-action { inset-block-start: var(--side-btn-action-at); block-size: var(--side-btn-action-b); }
  .pf-btn-up     { inset-block-start: var(--side-btn-up-at); block-size: var(--side-btn-vol-b); }
  .pf-btn-down   { inset-block-start: var(--side-btn-down-at); block-size: var(--side-btn-vol-b); }
  .pf-btn-power  {
    inset-inline-end: calc(var(--side-btn-i) * -1);
    inset-block-start: var(--side-btn-power-at);
    block-size: var(--side-btn-power-b);
    border-start-end-radius: var(--side-btn-corner);
    border-end-end-radius: var(--side-btn-corner);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* S6 shell (TSK-2452): header, thread, composer. Logical properties only. */
.cs-sr {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* header: menu | brand | new chat */
.pf-head { justify-content: space-between; padding-inline: max(var(--s-1), env(safe-area-inset-left, 0px)); }
.cs-head-side { display: flex; flex: 1 1 0; justify-content: flex-start; }
.cs-head-end { justify-content: flex-end; }
.cs-new { margin: 0; }
.cs-icon {
  display: inline-grid;
  place-items: center;
  inline-size: var(--tap);
  block-size: var(--tap);
  padding: 0;
  border: 0;
  border-radius: var(--r);
  background: transparent;
  color: var(--ink);
  font: 500 var(--fs-label)/1 var(--mono);
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.cs-icon:hover { background: var(--divider); }
.cs-ico {
  inline-size: var(--icon);
  block-size: var(--icon);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

/* thread: the newest message at the end */
.pf-body { display: flex; flex-direction: column; }
.cs-thread {
  display: flex;
  flex-direction: column;
  gap: var(--s-5);
  margin-block-start: auto; /* few messages sit at the end, next to the composer */
}
.cs-thread:empty { display: none; }
.cs-empty { flex: 1 0 auto; gap: var(--s-6); }
.cs-end { display: block; block-size: 1px; flex: none; }

/* messages: the layout of the thread (S7 owns the inside of each message) */
.cs-thread > .msg { margin: 0; overflow-wrap: anywhere; }
.cs-thread > .msg-assistant { align-self: stretch; } /* no bubble: text on paper */
/* The person's message: one ink border only. A saved message carries its own
   bubble (.mx-bubble) or file card (.mx-file); the live one (.cs-mine, chat.js)
   is plain text and gets the same bubble here. */
.cs-thread > .msg-person {
  align-self: flex-end;
  max-inline-size: 85%;
}
.cs-thread > .msg-person > .mx-bubble,
.cs-thread > .msg-person > .mx-file { max-inline-size: none; }
.cs-thread > .msg-person.cs-mine {
  padding: var(--s-3) var(--s-4);
  border: var(--stroke-1) solid var(--ink);
  border-radius: var(--r);
  background: var(--paper);
  white-space: pre-wrap;
}
.cs-streaming { white-space: pre-wrap; }
/* The message entry is in motion.css (U5: an-in), TSK-2546. */

/* typing: the spiral turns while the answer is on the way */
.cs-typing { display: flex; align-items: center; min-block-size: var(--tap); }
.cs-typing .sp { inline-size: 28px; block-size: 28px; }
@media (prefers-reduced-motion: no-preference) {
  .cs-typing .pf-turn { animation-duration: var(--dur-spiral); }
}

/* a short state line: no answer, try again */
.cs-notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  padding-block: var(--s-2);
  border-block-start: var(--stroke-1) solid var(--divider);
  font-size: var(--fs-small);
  color: var(--pencil-60);
}
.cs-retry {
  min-block-size: var(--tap);
  padding-inline: var(--s-3);
  border: var(--stroke-1) solid var(--ink);
  border-radius: var(--r);
  background: transparent;
  color: var(--ink);
  font: 500 var(--fs-label)/1.2 var(--mono);
  letter-spacing: .06em;
  text-transform: uppercase;
  cursor: pointer;
}

/* the suggestion chips: one tap sends the text */
.cs-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--s-2);
  max-inline-size: 22rem;
  margin: 0;
}
.cs-chip {
  min-block-size: var(--tap);
  padding: var(--s-2) var(--s-3);
  border: var(--stroke-1) solid var(--ink);
  border-radius: var(--r);
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--fs-small)/1.3 var(--mono);
  text-align: start;
  cursor: pointer;
}
.cs-chip:hover { background: var(--divider); }
/* the returning home: the chips stand apart from the "Your health today" lines */
.cs-home { align-self: center; margin-block-start: var(--s-8); }

/* composer: + | text | send. The field grows to 4 lines. */
.pf-bottom { display: flex; align-items: center; }
.cs-composer {
  display: flex;
  flex: 1 1 auto;
  align-items: flex-end;
  gap: var(--s-2);
  margin: 0;
}
.cs-field {
  flex: 1 1 auto;
  min-inline-size: 0;
  min-block-size: var(--tap);
  max-block-size: calc(6em + 2 * var(--s-field) + 2 * var(--stroke-1)); /* 4 lines of 1.5 */
  padding: var(--s-field) var(--s-3);
  border: var(--stroke-1) solid var(--border);
  border-radius: var(--r);
  background: var(--white);
  color: var(--text);
  font: 400 var(--fs-body)/1.5 var(--sans); /* 16 px: no zoom on iOS */
  resize: none;
  overflow-y: auto;
  field-sizing: content;
}
.cs-field::placeholder { color: var(--pencil-60); }
.cs-field:focus { outline: none; border-color: var(--ink); box-shadow: inset 0 0 0 var(--stroke-1) var(--ink); }
.cs-attach { border: var(--stroke-1) solid var(--border); }
.cs-send { background: var(--ink); color: var(--paper); }
.cs-send:hover { background: var(--ink); }
.cs-send:disabled { background: var(--border); color: var(--paper); cursor: default; }

/* A page with no composer (the gallery) shows no empty bar at the bottom: the
   slot keeps only the safe area (TSK-2527). Last in the file, so it wins over
   the frame sizes above. */
.pf-bottom:not(:has(*)) {
  min-block-size: env(safe-area-inset-bottom, 0px);
  padding: 0;
  border-block-start: 0;
}
