/* iMessage-flavoured. iOS system metrics: 17px rows, 18px bubble radius, #007AFF,
   full-width hairline separators, and a large title that stays put. */
:root {
  --blue: #007aff;
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9500;

  --bg: #ffffff;
  --bg-grouped: #ffffff;
  --bubble-in: #e9e9eb;
  --bubble-in-text: #000000;
  --bubble-out: var(--blue);
  --bubble-out-text: #ffffff;
  --bubble-auto: #f2f2f7;
  --bubble-auto-text: #8e8e93;

  --label: #000000;
  --label-2: #3c3c4399;
  --label-3: #3c3c434d;
  --separator: #3c3c435c;
  --fill: #78788033;
  --composer-bg: #ffffff;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-grouped: #000000;
    --bubble-in: #26252a;
    --bubble-in-text: #ffffff;
    --bubble-auto: #1c1c1e;
    --bubble-auto-text: #8e8e93;
    --label: #ffffff;
    --label-2: #ebebf599;
    --label-3: #ebebf54d;
    --separator: #54545899;
    --fill: #7878805c;
    --composer-bg: #000000;
  }
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* A class that sets `display` outruns the UA sheet's `[hidden] { display: none }`.
   Without this, the hidden thread sheet (position: fixed; inset: 0; display: flex)
   stays laid out and eats every tap on the screen behind it. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

button, input, textarea { font: inherit; color: inherit; }

/* ---------- passcode gate ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate__box {
  width: min(320px, 100%);
  display: grid;
  gap: 12px;
  text-align: center;
}
.gate__title { margin: 0 0 8px; font-size: 28px; font-weight: 700; letter-spacing: -0.4px; }
.gate__input {
  background: var(--fill);
  border: 0;
  border-radius: 10px;
  padding: 13px 16px;
  text-align: center;
  font-size: 17px;
}
.gate__submit {
  border: 0;
  border-radius: 10px;
  padding: 13px;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.gate__submit:active { opacity: 0.8; }
.gate__error { margin: 0; color: var(--red); font-size: 14px; min-height: 1.2em; }

/* ---------- brand ---------- */
/* Two files rather than one recoloured by CSS: the mark is a PNG, and the lockup
   is two colours (white/black wordmark + evergreen "Growth") so a filter can't
   flip one without wrecking the other. The dark-theme copy keeps the original
   white; the light-theme copy has white remapped to black, alpha untouched. */
.brand-logo { display: block; }
.brand-logo img { display: block; width: auto; }

.topbar__brand { padding-bottom: 4px; }
.topbar__brand .brand-logo img { height: 18px; }

.gate .brand-logo { justify-self: center; margin-bottom: 4px; }
.gate .brand-logo img { height: 38px; }

/* ---------- header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(var(--safe-top) + 8px) 16px 0;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.topbar__row { display: flex; align-items: center; justify-content: space-between; }
.topbar__title { margin: 0; font-size: 34px; font-weight: 700; letter-spacing: -0.8px; }

.iconbtn {
  background: none;
  border: 0;
  /* 44px is the iOS minimum tap target; the old 20px glyph in 8px of padding was
     well under it and fiddly to hit one-handed. */
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 27px;
  line-height: 1;
  padding: 0;
  color: var(--blue);
  border-radius: 10px;
  cursor: pointer;
}
.iconbtn svg { width: 25px; height: 25px; display: block; }
.iconbtn:active { opacity: 0.4; }

/* segmented filter chips */
.tabs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 0 10px;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto;
  background: var(--fill);
  border: 0;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--label);
  cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--blue); color: #fff; }
.tab__count { opacity: 0.6; margin-left: 5px; font-variant-numeric: tabular-nums; }
.tab[aria-selected="true"] .tab__count { opacity: 0.8; }

/* ---------- conversation list ---------- */
.list { padding: 0 0 calc(var(--safe-bottom) + 80px); }

/* Each row is a viewport: the action pane sits underneath, the content slides. */
.row {
  position: relative;
  overflow: hidden;
  background: var(--bg);
  touch-action: pan-y;          /* let vertical scrolling through, we take the rest */
  /* A swipe would otherwise start a text selection and drag a highlight along
     with it. Nothing in a row is worth selecting. */
  user-select: none;
  -webkit-user-select: none;
}

.row__action {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  color: #fff;
  font-size: 24px;
  /* Hidden at rest. Row heights land on fractional pixels (78.4px), so at 2x DPR
     the content's background edge falls mid-physical-pixel and a coloured sliver
     bleeds through along every row boundary. Nothing to bleed if it isn't painted. */
  visibility: hidden;
}
.row__action--right {
  justify-content: flex-start;
  padding-left: 24px;
  background: var(--blue);
}
.row__action--left {
  justify-content: flex-end;
  padding-right: 24px;
  background: var(--green);
}
.row--engaged-right .row__action--right,
.row--engaged-left .row__action--left { visibility: visible; }

.row__action-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.4px;
  opacity: 0;
  transition: opacity 0.15s;
}
.row__action--right .row__action-label { margin-left: 10px; }
.row__action--left .row__action-label { margin-right: 10px; }

/* Past the commit point the pane darkens and the label appears — the visual
   promise that letting go now will actually do it. */
.row--armed .row__action--right { background: #0060df; }
.row--armed .row__action--left { background: #248a3d; }
.row--armed .row__action-label { opacity: 1; }

/* Collapse on dismiss so the list closes the gap instead of jumping. */
.row { max-height: 400px; }
.row--leaving {
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.2s ease;
}

.row__content {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 16px 10px 16px;
  background: var(--bg);
  cursor: pointer;
  will-change: transform;
}
.row__content--animating { transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1); }

/* full-bleed hairline between rows */
.row + .row .row__content::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 0.5px;
  background: var(--separator);
}

.row__dot {
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--blue);
}
.row__dot--placeholder { background: transparent; }

.row__main { flex: 1; min-width: 0; }
.row__top { display: flex; align-items: baseline; gap: 6px; }
.row__name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row__time {
  margin-left: auto;
  flex: 0 0 auto;
  font-size: 15px;
  color: var(--label-3);
  font-variant-numeric: tabular-nums;
}
/* Unanswered for more than a few hours — the whole point is that this is loud. */
.row__time--urgent { color: var(--red); font-weight: 600; }
.row__chev { flex: 0 0 auto; color: var(--label-3); font-size: 15px; margin-left: 4px; }

.row__preview {
  font-size: 15px;
  line-height: 1.3;
  color: var(--label-2);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 1px 0 0;   /* the UA's 1em bottom margin pads every row out of proportion */
}
.row--low .row__name, .row--low .row__preview { color: var(--label-3); }
.row--low .row__name { font-weight: 500; }

.row__tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--orange);
}

.empty { text-align: center; color: var(--label-3); padding: 80px 24px; }
.empty__big { font-size: 44px; display: block; margin-bottom: 12px; }

.bulk {
  display: block;
  margin: 20px auto;
  background: none;
  border: 0;
  color: var(--blue);
  font-size: 16px;
  padding: 10px;
  cursor: pointer;
}

.hint {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(var(--safe-bottom) + 12px);
  margin: 0;
  background: var(--fill);
  backdrop-filter: blur(20px);
  border-radius: 12px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--label-2);
  text-align: center;
  border: 0;
}
.hint--action { color: var(--blue); font-weight: 600; cursor: pointer; }

/* ---------- add-to-home-screen walkthrough ---------- */
.topbar__actions { display: flex; align-items: center; gap: 2px; margin-right: -8px; }

.sheet__body--walk { padding: 22px 20px calc(var(--safe-bottom) + 24px); gap: 0; }
.walk__lede { margin: 0 0 22px; font-size: 16px; line-height: 1.45; color: var(--label-2); }
.walk {
  margin: 0;
  padding-left: 1.3em;
  display: grid;
  gap: 16px;
  font-size: 16px;
  line-height: 1.45;
}
.walk li::marker { color: var(--label-3); font-weight: 600; }
/* The share glyph sits inline in the sentence, so it must ride the text baseline
   rather than sitting on it. */
.walk__glyph {
  width: 1.05em;
  height: 1.05em;
  vertical-align: -0.19em;
  margin: 0 1px;
}
.walk__cta {
  margin-top: 26px;
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 15px;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.walk__cta:active { opacity: 0.8; }
.walk__note {
  margin: 24px 0 0;
  font-size: 14px;
  line-height: 1.45;
  color: var(--label-3);
}

/* ---------- thread ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
.sheet__bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: calc(var(--safe-top) + 6px) 10px 8px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.sheet__who { display: grid; min-width: 0; text-align: center; flex: 1; }
.sheet__who strong {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet__sub { font-size: 12px; color: var(--label-3); }

.sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  -webkit-overflow-scrolling: touch;
}

.daysep {
  align-self: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--label-3);
  margin: 14px 0 6px;
}

.msg {
  position: relative;
  max-width: 75%;
  padding: 8px 14px;
  border-radius: 18px;
  font-size: 17px;
  line-height: 1.3;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin-top: 2px;
}
.msg--in { align-self: flex-start; background: var(--bubble-in); color: var(--bubble-in-text); }
.msg--out { align-self: flex-end; background: var(--bubble-out); color: var(--bubble-out-text); }

/* Last bubble in a run gets the tail, like iMessage. */
.msg--in.msg--tail { border-bottom-left-radius: 5px; }
.msg--out.msg--tail { border-bottom-right-radius: 5px; }

/* Automation is context, not conversation — flattened so it never reads as a reply. */
.msg--auto {
  align-self: flex-end;
  background: var(--bubble-auto);
  color: var(--bubble-auto-text);
  font-size: 14px;
  max-width: 82%;
}
.msg__meta {
  display: block;
  font-size: 11px;
  opacity: 0.65;
  margin-top: 4px;
}
.msg--out .msg__meta { color: #ffffffcc; }
.msg__subject { font-weight: 600; display: block; margin-bottom: 2px; }

.msg--event {
  align-self: center;
  background: none;
  color: var(--label-3);
  font-size: 13px;
  max-width: 90%;
  text-align: center;
}

/* ---------- composer ---------- */
.composer {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 8px 12px calc(var(--safe-bottom) + 8px);
  background: var(--composer-bg);
  border-top: 0.5px solid var(--separator);
}
.composer__text {
  flex: 1;
  resize: none;
  max-height: 120px;
  background: var(--bg);
  border: 1px solid var(--separator);
  border-radius: 18px;
  padding: 8px 14px;
  font-size: 17px;
  line-height: 1.3;
}
.composer__send {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  margin-bottom: 2px;
  border: 0;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.composer__send:disabled { background: var(--label-3); }
.composer__error {
  margin: 0;
  padding: 0 16px calc(var(--safe-bottom) + 8px);
  color: var(--red);
  font-size: 13px;
  background: var(--composer-bg);
}

.spinner { text-align: center; color: var(--label-3); padding: 48px; font-size: 15px; }

/* The iOS haptic trick needs a real switch in the DOM to click; keep it reachable
   to the engine but out of sight and out of the a11y tree. */
.haptic-probe {
  position: fixed;
  bottom: -60px;
  left: -60px;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
  .row__content--animating { transition: none; }
  .row__action-label { transition: none; }
}
