/* PoolQuant v2 — design system
   Health-style: generous whitespace, mono numerals, no cards, hairline dividers, soft tints */

:root {
  /* paper — warm, not white */
  --paper:        #fbfaf7;     /* canvas */
  --paper-2:      #f4f2ec;     /* recessed surface (rare; only for sheets) */
  --paper-tint:   rgba(13, 74, 99, 0.04); /* selection wash */

  /* ink — never pure black */
  --ink:          #161a1f;
  --ink-2:        #4a5560;
  --ink-3:        #8893a0;
  --ink-4:        #b8c1cb;
  --rule:         rgba(22, 26, 31, 0.08);
  --rule-strong:  rgba(22, 26, 31, 0.16);

  /* brand (from icon) */
  --brand-deep:   #04202d;
  --brand:        #0d4a63;
  --brand-droplet:#7cc6e0;

  /* chemistry palette — calm, like Apple Health */
  --chem-chlorine: #1f8fb8;     /* FC, Br */
  --chem-ph:       #d18a2c;     /* pH */
  --chem-alk:      #b8682c;     /* TA */
  --chem-cya:      #6b8a4a;     /* CYA */
  --chem-salt:     #5a7a8a;     /* salt */
  --chem-temp:     #c44a2a;     /* temp */
  --chem-pressure: #6e5aa8;     /* filter pressure */
  --chem-clarity:  #2a8a8a;     /* clarity / visibility */

  /* status (used for ranges) */
  --ok:           #2f7a4f;
  --ok-bg:        rgba(47, 122, 79, 0.10);
  --warn:         #b86a18;
  --warn-bg:      rgba(184, 106, 24, 0.10);
  --bad:          #b8362c;
  --bad-bg:       rgba(184, 54, 44, 0.10);

  /* type — system stack, mono for numbers */
  --type-ui:      -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter Tight", Inter, system-ui, sans-serif;
  --type-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter Tight", Inter, system-ui, sans-serif;
  --type-num:     ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Monaco, "Cascadia Mono", monospace;
  --type-serif:   ui-serif, "New York", Georgia, "Times New Roman", serif;

  /* radii — small, restrained. only on tappables. */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  /* spacing — generous */
  --gutter: 24px;
  --col-narrow: 680px;
  --col-wide: 920px;
}

/* reset-ish */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--type-ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01" 1, "cv11" 1;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }

/* numerals */
.num { font-family: var(--type-num); font-feature-settings: "tnum" 1, "zero" 1; letter-spacing: -0.02em; }

/* the toolbar — single, top, no chrome competing with it.
   Three-column grid (left actions | center | right actions) so the
   center is centered regardless of how many icons sit on each side. */
.pq-toolbar {
  height: 56px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: saturate(140%) blur(14px);
  -webkit-backdrop-filter: saturate(140%) blur(14px);
  background: color-mix(in srgb, var(--paper) 86%, transparent);
}
.pq-toolbar-left {
  display: flex; align-items: center; gap: 4px;
  justify-self: start;
  min-width: 0;
}
.pq-toolbar-center {
  display: flex; align-items: center; justify-content: center;
  justify-self: center;
  min-width: 0;
}
.pq-toolbar-right {
  display: flex; align-items: center; gap: 4px;
  justify-self: end;
  min-width: 0;
}
.pq-toolbar .title {
  font-family: var(--type-display);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.pq-toolbar .sub {
  font-size: 13px;
  color: var(--ink-3);
}
.pq-toolbar .spacer { flex: 1; }
.pq-toolbar .iconbtn {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  color: var(--ink-2);
}
.pq-toolbar .iconbtn:hover { background: var(--paper-tint); color: var(--ink); }

/* zoom strip (the time-axis pinch control rendered as visible buttons) */
.pq-zoom {
  display: inline-flex;
  align-items: center;
  gap: 0;
  padding: 3px;
  background: rgba(22, 26, 31, 0.05);
  border-radius: 999px;
}
.pq-zoom button,
.pq-zoom a {
  padding: 5px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-3);
  border-radius: 999px;
  letter-spacing: 0;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.pq-zoom button:hover,
.pq-zoom a:hover { color: var(--ink); }
.pq-zoom button[aria-current="true"],
.pq-zoom a[aria-current="true"] {
  background: var(--ink);
  color: var(--paper);
  box-shadow: none;
}

/* hairline divider (between entries, between days) */
.hr { border: 0; border-top: 1px solid var(--rule); margin: 0; }
.dayrule {
  font-family: var(--type-num);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 24px 0 8px;
}

/* chemistry chip — used inline, not as cards */
.chem {
  display: inline-flex; align-items: baseline; gap: 6px;
}
.chem .label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.chem .val {
  font-family: var(--type-num);
  font-feature-settings: "tnum" 1;
  font-size: 18px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.02em;
}
.chem .unit {
  font-size: 12px;
  color: var(--ink-3);
  font-family: var(--type-num);
}

/* status dot */
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }

/* range badge — quiet, soft tint, not a button */
.range {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px;
  letter-spacing: 0.02em;
}
.range.ok   { background: var(--ok-bg);   color: var(--ok); }
.range.warn { background: var(--warn-bg); color: var(--warn); }
.range.bad  { background: var(--bad-bg);  color: var(--bad); }

/* composer — anchored to the bottom of the timeline column */
.pq-composer {
  position: sticky; bottom: 0;
  background: linear-gradient(to top, var(--paper) 60%, color-mix(in srgb, var(--paper) 0%, transparent));
  padding: 24px 0 16px;
  display: flex; align-items: flex-end; gap: 10px;
}
.pq-composer .input {
  flex: 1;
  min-height: 44px;
  padding: 11px 16px;
  border-radius: 22px;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 15px;
  display: flex; align-items: center;
}
.pq-composer .input .placeholder { color: var(--ink-3); }
.pq-composer .send {
  width: 44px; height: 44px;
  border-radius: 22px;
  background: var(--brand-deep); color: white;
  display: inline-flex; align-items: center; justify-content: center;
}
.pq-composer .icon {
  width: 36px; height: 36px;
  border-radius: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2);
}
.pq-composer .icon:hover { background: var(--paper-tint); color: var(--ink); }

/* glass surfaces */
.glass {
  background: color-mix(in srgb, var(--paper) 70%, transparent);
  backdrop-filter: saturate(140%) blur(18px);
  -webkit-backdrop-filter: saturate(140%) blur(18px);
}

/* ── PoolQuant v2 — shell + entry-row + integration glue ─────────────── */

.nb-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--paper);
}

/* toolbar safe-area + iOS PWA Dynamic Island clearance */
.pq-toolbar {
  height: calc(56px + env(safe-area-inset-top));
  padding-top: env(safe-area-inset-top);
}
.pq-toolbar .nb-back {
  color: var(--ink-2);
}
.pq-toolbar .nb-title-block .title {
  font-family: var(--type-display);
  font-size: 17px; font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 240px;
}
@media (max-width: 700px) {
  .pq-toolbar { gap: 8px; padding-left: 12px; padding-right: 12px; }
  .pq-toolbar .nb-title-block .title { max-width: 140px; font-size: 15px; }
  .pq-zoom button, .pq-zoom a { padding: 5px 9px; font-size: 12px; }
}

/* Single-column reading column (Now / Day / Weeks all use this) */
.nb-col {
  width: 100%;
  max-width: var(--col-narrow);
  margin: 0 auto;
  padding: 0 28px;
  flex: 1;
  display: flex;
  flex-direction: column;
}
.nb-col.wide { max-width: var(--col-wide); }
@media (max-width: 700px) {
  .nb-col { padding: 0 18px; }
}

/* hairline divider */
.hr { border: 0; border-top: 1px solid var(--rule); margin: 0; }

/* page eyebrow — pool name + zoom context, sits above any page content */
.nb-now-eyebrow {
  font-size: 13px;
  color: var(--ink-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 32px 0 16px;
  font-family: var(--type-num);
}

/* ── entry rows (Now zoom) ────────────────────────────────────────────── */

.nb-stream {
  display: flex; flex-direction: column;
  flex: 1;
  padding-bottom: 48px;
}

.nb-entry {
  display: grid;
  grid-template-columns: 76px 1fr;
  column-gap: 20px;
  padding: 14px 0;
  border-top: 1px solid var(--rule);
}
.nb-entry.first-of-day { border-top: 0; }
.nb-entry.weather { padding: 10px 0; align-items: baseline; }

.nb-ts {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-family: var(--type-num);
  white-space: nowrap;
}
.nb-who {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nb-body { font-size: 15px; color: var(--ink); line-height: 1.55; }
.nb-body p { margin: 0 0 0.4em; }
.nb-body p:last-child { margin-bottom: 0; }
.nb-body-em {
  font-family: var(--type-display);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.005em;
  line-height: 1.45;
  color: var(--ink);
}

/* reading row (single-metric) */
.nb-reading-row {
  display: flex; align-items: baseline;
  gap: 12px;
  flex-wrap: wrap;
}
.nb-reading-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
}
.nb-reading-big {
  font-family: var(--type-num);
  font-size: 28px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
}
.nb-reading-mid {
  font-family: var(--type-num);
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.02em;
  line-height: 1;
  color: var(--ink);
}
.nb-reading-unit {
  font-size: 13px;
  color: var(--ink-3);
  font-family: var(--type-num);
}

/* multi-metric grid inside an entry */
.nb-reading-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 28px;
}
.nb-reading-grid .cell {
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
}
.nb-reading-grid .cell .row {
  display: flex; align-items: baseline; gap: 8px;
}
@media (max-width: 480px) {
  .nb-reading-grid { grid-template-columns: 1fr; gap: 10px; }
}

/* note */
.nb-note { font-size: 15px; color: var(--ink); line-height: 1.55; }

/* weather */
.nb-weather-text {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink-2); font-size: 13px;
}

/* photo / image */
.nb-image {
  display: block;
  max-width: 200px; max-height: 134px;
  border-radius: 6px;
  cursor: zoom-in;
}
.nb-photo-caveat {
  margin-top: 10px;
  padding: 10px 14px;
  border-left: 2px solid var(--warn);
  background: var(--warn-bg);
  border-radius: 0 6px 6px 0;
  font-size: 13px; color: var(--ink-2);
}

/* question (italicised display type) */
.nb-question {
  font-family: var(--type-display);
  font-size: 17px;
  font-style: italic;
  color: var(--ink);
  line-height: 1.45;
}

/* assistant answer */
.nb-answer-section { margin-top: 14px; }
.nb-answer-section .h {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 500;
  margin-bottom: 6px;
}
.nb-answer-section ul {
  margin: 0; padding: 0; list-style: none;
  display: flex; flex-direction: column; gap: 4px;
}
.nb-answer-section li {
  display: flex; gap: 10px; align-items: baseline;
  color: var(--ink-2); font-size: 14px;
}

/* action — indented with brand-droplet rule */
.nb-action {
  font-size: 15px; color: var(--ink); line-height: 1.55;
  padding-left: 12px;
  border-left: 2px solid var(--brand-droplet);
}

/* user-input echo (the user's typed message before any processing) */
.nb-user-text {
  font-size: 15px; color: var(--ink); line-height: 1.55;
}


/* "Earlier entries" hint at the top of the river */
.nb-earlier {
  text-align: center;
  font-size: 12px;
  color: var(--ink-3);
  padding: 16px 0 4px;
  font-family: var(--type-num);
  letter-spacing: 0.04em;
}

/* delete affordance — appears on row hover */
.nb-entry .nb-delete {
  margin-top: 4px;
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-3);
  border-radius: var(--r-sm);
  opacity: 0;
  transition: opacity .15s, background .15s, color .15s;
}
.nb-entry:hover .nb-delete { opacity: 0.5; }
.nb-entry .nb-delete:hover { opacity: 1; color: var(--bad); background: var(--bad-bg); }

/* ── composer (Now zoom) ──────────────────────────────────────────────── */

.nb-composer-wrap {
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--paper) 70%, color-mix(in srgb, var(--paper) 0%, transparent));
  /* Safari fills the home-indicator zone with its bottom URL bar, and
     env(safe-area-inset-bottom) returns 0 in that case — so the default
     here is a small constant. Standalone PWA branches below to add the
     safe-area padding back, since there's no URL bar to fill the band. */
  padding: 24px 0 16px;
  z-index: 10;
}
@media (max-width: 600px) {
  .nb-composer-wrap {
    padding: 12px 0 4px;
  }
}
/* PWA standalone — add safe-area padding so the home indicator has clearance */
@media (display-mode: standalone) {
  .nb-composer-wrap {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}
@media (display-mode: standalone) and (max-width: 600px) {
  .nb-composer-wrap {
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
  }
}
.nb-composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
@media (max-width: 600px) {
  .nb-composer { gap: 6px; }
}

/* Quick-fill chips — horizontally scrollable strip above the textarea.
   Hidden as soon as the user starts typing so they don't crowd the view.
   Right-edge fade hints at more content; vertical wheel events are
   translated to horizontal scroll by JS so a regular mouse can use it. */
.nb-chips-wrap {
  position: relative;
  margin: 0 -8px;
}
.nb-chips-wrap::after {
  content: "";
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 32px;
  pointer-events: none;
  background: linear-gradient(to right,
    color-mix(in srgb, var(--paper) 0%, transparent),
    var(--paper));
  opacity: 0;
  transition: opacity 0.18s ease;
}
.nb-chips-wrap.has-overflow-right::after { opacity: 1; }
.nb-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  padding: 4px 8px;
}
.nb-chips::-webkit-scrollbar { display: none; }
.nb-chip {
  flex-shrink: 0;
  padding: 8px 16px;
  background: var(--paper-2);
  border: 0;
  border-radius: 999px;
  color: var(--ink);
  font: inherit;
  font-family: var(--type-num);
  font-size: 14px;
  letter-spacing: 0;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--pq-dur-fast) var(--pq-ease), transform var(--pq-dur-fast) var(--pq-ease);
}
.nb-chip:hover  { background: color-mix(in srgb, var(--paper-2) 75%, var(--ink) 6%); }
.nb-chip:active { transform: scale(0.97); }
/* Chip strip stays visible at all times. Toggling its visibility based on
   typing state changed composer-wrap height mid-keyboard, which made iOS
   re-run its auto-scroll-to-focused-element math and the textarea jumped
   around. Keeping the strip always present trades vertical space for
   stable layout — net better UX. */

/* Textarea — full width on its own row. Pixel line-height + matching padding
   so a single line sits perfectly centered (no asymmetric whitespace top/bot). */
.nb-composer textarea {
  width: 100%;
  min-width: 0;
  height: 44px;
  min-height: 44px;
  max-height: 180px;
  padding: 11px 16px;
  border-radius: 22px;
  background: var(--paper-2);
  color: var(--ink);
  font-size: 15px;
  font-family: var(--type-ui);
  border: 0;
  outline: 0;
  resize: none;
  line-height: 22px;          /* 11 + 22 + 11 = 44, matches box height exactly */
  overflow-wrap: anywhere;
  word-break: break-word;
}
@media (max-width: 600px) {
  .nb-composer textarea {
    font-size: 13px;
    padding: 13px 14px;
    line-height: 18px;        /* 13 + 18 + 13 = 44 */
  }
}
.nb-composer textarea::placeholder { color: var(--ink-3); }

/* Composer row — camera, textarea, send all on a single horizontal line.
   Replaces the prior stacked "actions row". */
.nb-composer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.nb-composer-row textarea { flex: 1; }
.nb-composer-row .icon-btn {
  width: 44px; height: 44px;
  border-radius: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--ink-2);
  flex-shrink: 0;
  background: none; border: 0; cursor: pointer;
  transition: background var(--pq-dur-fast) var(--pq-ease), color var(--pq-dur-fast) var(--pq-ease);
}
.nb-composer-row .icon-btn:hover { background: var(--paper-tint); color: var(--ink); }
.nb-composer-row .send {
  width: 44px; height: 44px;
  border-radius: 22px;
  background: var(--brand-deep);
  color: white;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0;
  flex-shrink: 0;
  cursor: pointer;
}
.nb-composer-row .send:hover { background: var(--brand); }
.nb-composer-row .send:disabled { background: var(--ink-4); cursor: default; }

/* streaming cursor */
.nb-streaming::after {
  content: "▍";
  margin-left: 2px;
  color: var(--brand);
  animation: nb-blink 1.1s steps(2, start) infinite;
}
@keyframes nb-blink { to { opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  .nb-streaming::after { animation: none; opacity: 0.5; }
}

/* mono helper */
.num { font-feature-settings: "tnum" 1, "zero" 1; }

/* ── page-switch loading feedback ─────────────────────────────────────── */
/* Clicking a zoom-strip link kicks off a full-page navigation. Two layers:
   (1) static colour change applied instantly so iOS Safari, which freezes
       paint during nav, still shows visible feedback in its frozen frame;
   (2) pulse animation on the active pill for browsers that keep rendering
       (desktop Safari/Chrome/Firefox). */
.pq-toolbar.is-loading .pq-zoom a:not([aria-current="true"]),
.pq-toolbar.is-loading .pq-zoom button:not([aria-current="true"]) {
  color: var(--ink-4);
}
.pq-toolbar.is-loading .pq-zoom a[aria-current="true"],
.pq-toolbar.is-loading .pq-zoom button[aria-current="true"] {
  animation: nb-pulse 1.1s ease-in-out infinite;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--ink) 18%, transparent);
}
.pq-toolbar.is-loading .nb-title-block .title {
  animation: nb-pulse 1.1s ease-in-out infinite;
  color: var(--ink-3);
}
@keyframes nb-pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}
@media (prefers-reduced-motion: reduce) {
  .pq-toolbar.is-loading .pq-zoom a[aria-current="true"],
  .pq-toolbar.is-loading .pq-zoom button[aria-current="true"],
  .pq-toolbar.is-loading .nb-title-block .title { animation: none; opacity: 0.65; }
}

/* ── line-clamp for long messages ─────────────────────────────────────── */
/* Applied imperatively by JS after measuring overflow — we only clamp
   bodies that genuinely exceed the line budget so short messages don't get
   a useless "Show more" button. */
.nb-clamp-on {
  display: -webkit-box;
  -webkit-line-clamp: 7;
  -webkit-box-orient: vertical;
  line-clamp: 7;
  overflow: hidden;
  position: relative;
}
.nb-clamp-on::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 2em;
  background: linear-gradient(to bottom,
    color-mix(in srgb, var(--paper) 0%, transparent),
    var(--paper));
  pointer-events: none;
}
.nb-clamp-on.is-expanded {
  display: block;
  -webkit-line-clamp: unset;
  line-clamp: unset;
  overflow: visible;
}
.nb-clamp-on.is-expanded::after { display: none; }
.nb-show-more {
  font: inherit;
  font-size: 13px;
  color: var(--ink-3);
  background: none;
  border: 0;
  padding: 4px 0;
  margin-top: 2px;
  cursor: pointer;
  letter-spacing: 0.02em;
}
.nb-show-more:hover { color: var(--ink); }
