/*
 * base.css — reset, design tokens (light/dark), safe areas, layout panes,
 * navigation bars and shared iOS-style controls (grouped lists, segmented
 * controls, switches). The messaging "skin" lives in imessage.css.
 *
 * Theme: tokens default to light; dark applies via prefers-color-scheme unless
 * <html data-theme="light">, or always with <html data-theme="dark">.
 */

:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-grouped: #f2f2f7;
  --bg-elevated: #ffffff;
  --bg-cell: #ffffff;
  --bg-sheet: #f2f2f7;
  --bar-bg: rgba(249, 249, 249, 0.94);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-2: rgba(118, 118, 128, 0.2);
  --sep: rgba(60, 60, 67, 0.22);
  --sep-opaque: #c6c6c8;
  --text: #000000;
  --text-2: rgba(60, 60, 67, 0.6);
  --text-3: rgba(60, 60, 67, 0.3);
  --blue: #007aff;
  --red: #ff3b30;
  --orange: #ff9500;
  --green: #34c759;
  --gray: #8e8e93;
  --highlight: rgba(0, 0, 0, 0.06);
  --selected: #007aff;
  --bubble-in: #e9e9eb;
  --bubble-in-text: #000000;
  --bubble-out: #007aff;
  --bubble-out-text: #ffffff;
  --menu-bg: rgba(250, 250, 250, 0.84);
  --scrim: rgba(0, 0, 0, 0.32);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --nav-h: 44px;
  --list-w: 340px;
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --t: 320ms;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #000000;
    --bg-grouped: #000000;
    --bg-elevated: #1c1c1e;
    --bg-cell: #1c1c1e;
    --bg-sheet: #1c1c1e;
    --bar-bg: rgba(22, 22, 24, 0.92);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(118, 118, 128, 0.32);
    --sep: rgba(84, 84, 88, 0.6);
    --sep-opaque: #38383a;
    --text: #ffffff;
    --text-2: rgba(235, 235, 245, 0.6);
    --text-3: rgba(235, 235, 245, 0.3);
    --blue: #0a84ff;
    --red: #ff453a;
    --orange: #ff9f0a;
    --green: #30d158;
    --gray: #8e8e93;
    --highlight: rgba(255, 255, 255, 0.08);
    --selected: #0a84ff;
    --bubble-in: #26252a;
    --bubble-in-text: #ffffff;
    --bubble-out: #0a84ff;
    --bubble-out-text: #ffffff;
    --menu-bg: rgba(37, 37, 39, 0.86);
    --scrim: rgba(0, 0, 0, 0.5);
    --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #000000;
  --bg-grouped: #000000;
  --bg-elevated: #1c1c1e;
  --bg-cell: #1c1c1e;
  --bg-sheet: #1c1c1e;
  --bar-bg: rgba(22, 22, 24, 0.92);
  --fill: rgba(118, 118, 128, 0.24);
  --fill-2: rgba(118, 118, 128, 0.32);
  --sep: rgba(84, 84, 88, 0.6);
  --sep-opaque: #38383a;
  --text: #ffffff;
  --text-2: rgba(235, 235, 245, 0.6);
  --text-3: rgba(235, 235, 245, 0.3);
  --blue: #0a84ff;
  --red: #ff453a;
  --orange: #ff9f0a;
  --green: #30d158;
  --gray: #8e8e93;
  --highlight: rgba(255, 255, 255, 0.08);
  --selected: #0a84ff;
  --bubble-in: #26252a;
  --bubble-in-text: #ffffff;
  --bubble-out: #0a84ff;
  --bubble-out-text: #ffffff;
  --menu-bg: rgba(37, 37, 39, 0.86);
  --scrim: rgba(0, 0, 0, 0.5);
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
}

/* ------------------------------------------------------------ reset */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.29;
  letter-spacing: -0.41px;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

button, input, textarea, select {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

a { color: var(--blue); text-decoration: none; }
p { margin: 0; }
h1, h2, h3 { margin: 0; font-weight: 700; }
[hidden] { display: none !important; }

:focus { outline: none; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 6px; }

.icon {
  width: 24px;
  height: 24px;
  flex: none;
  display: inline-block;
  vertical-align: middle;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ------------------------------------------------------------ app layout */

/* The app follows the visual viewport (keyboard avoidance on iOS Safari):
   app.js sets --vv-top / --vv-height from window.visualViewport. */
.app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top, 0px);
  height: var(--vv-height, 100dvh);
  overflow: hidden;
  background: var(--bg);
}

.pane {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--bg);
}

.pane-detail { pointer-events: none; background: transparent; }
.app.detail-open .pane-detail { pointer-events: auto; }

/* Phone: the list slides 30% left (and dims) under a pushed view. */
.pane-list { transform: translateX(0); }
.app.detail-open:not(.split) .pane-list {
  transform: translateX(-30%);
  visibility: hidden;
}
.app.animating .pane-list {
  transition: transform var(--t) var(--ease), visibility 0s;
}
.app.animating.detail-open:not(.split) .pane-list {
  transition: transform var(--t) var(--ease), visibility 0s var(--t);
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  transform: translateX(100%);
  will-change: transform;
}
.view.shown { transform: translateX(0); }
.view.shown.covered { transform: translateX(-30%); visibility: hidden; }
.view.leaving { transform: translateX(100%); z-index: 2; }
.app.animating .view { transition: transform var(--t) var(--ease), visibility 0s; }
.app.animating .view.covered { transition: transform var(--t) var(--ease), visibility 0s var(--t); }
.app.animating .view.leaving { box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12); }

.detail-empty { display: none; }

/* Split view (iPad / desktop): list column + detail column. */
.app.split .pane-list {
  right: auto;
  width: var(--list-w);
  border-right: 0.5px solid var(--sep);
  transform: none;
  visibility: visible;
}
.app.split .pane-detail {
  left: var(--list-w);
  pointer-events: auto;
  background: var(--bg);
}
.app.split .view,
.app.split .view.shown {
  transform: none;
  visibility: visible;
  opacity: 1;
  transition: opacity 160ms ease-out;
  will-change: auto;
}
.app.split .view.fading-in,
.app.split .view.fading-out { opacity: 0; }
.app.split .view.fading-out { pointer-events: none; }
.app.split .detail-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-3);
  font-size: 17px;
}
.app.split .detail-empty .icon { width: 56px; height: 56px; }
.app.split .root-only { display: none; }

@media (min-width: 1100px) {
  :root { --list-w: 380px; }
}

/* ------------------------------------------------------------ nav bar */

.nav {
  position: relative;
  z-index: 5;
  flex: none;
  display: grid;
  grid-template-columns: minmax(64px, 1fr) auto minmax(64px, 1fr);
  align-items: center;
  min-height: calc(var(--nav-h) + var(--safe-top));
  padding: var(--safe-top) calc(8px + var(--safe-right)) 0 calc(8px + var(--safe-left));
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
}
.nav.has-large {
  background: var(--bg);
  border-bottom-color: transparent;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  transition: background-color 150ms, border-color 150ms;
}
.nav.has-large.scrolled {
  background: var(--bar-bg);
  border-bottom-color: var(--sep);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
}
.nav.has-large .nav-title { opacity: 0; transition: opacity 150ms; }
.nav.has-large.scrolled .nav-title { opacity: 1; }

.nav-left, .nav-right {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.nav-right { justify-content: flex-end; }
.nav-center { min-width: 0; text-align: center; }
.nav-title {
  font-weight: 600;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60vw;
}

.nav-back {
  display: inline-flex;
  align-items: center;
  height: 44px;
  margin-left: -6px;
  padding-right: 8px;
  color: var(--blue);
  font-size: 17px;
}
.nav-back .icon { width: 26px; height: 26px; margin-right: -1px; }
.nav-back-label { white-space: nowrap; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; }

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  height: 44px;
  color: var(--blue);
  font-size: 17px;
}
.nav-btn .icon { width: 27px; height: 27px; }
.nav-btn.text { padding: 0 8px; min-width: 0; }
.nav-btn.bold { font-weight: 600; }
.nav-btn:disabled { color: var(--text-3); cursor: default; }
.nav-btn:active:not(:disabled), .nav-back:active { opacity: 0.4; }

.large-title {
  font-family: var(--font-display);
  font-size: 34px;
  line-height: 41px;
  font-weight: 700;
  letter-spacing: 0.37px;
  padding: 2px calc(16px + var(--safe-right)) 6px calc(16px + var(--safe-left));
}

/* ------------------------------------------------------------ scroll areas */

.scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.scroll.grouped { background: var(--bg-grouped); }
.view.grouped-bg, .view.grouped-bg .nav.has-large:not(.scrolled) { background: var(--bg-grouped); }

.bottom-pad { height: calc(24px + var(--safe-bottom)); }

/* ------------------------------------------------------------ grouped lists */

.group-header {
  padding: 22px calc(32px + var(--safe-right)) 7px calc(32px + var(--safe-left));
  font-size: 13px;
  line-height: 18px;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: -0.08px;
}
.group-footer {
  padding: 7px calc(32px + var(--safe-right)) 0 calc(32px + var(--safe-left));
  font-size: 13px;
  line-height: 18px;
  color: var(--text-2);
  letter-spacing: -0.08px;
}
.group {
  margin: 0 calc(16px + var(--safe-right)) 0 calc(16px + var(--safe-left));
  background: var(--bg-cell);
  border-radius: 10px;
  overflow: hidden;
}
.cell {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 11px 16px;
  text-align: left;
  color: var(--text);
  background: var(--bg-cell);
}
.cell + .cell::before {
  content: "";
  position: absolute;
  top: 0;
  left: 16px;
  right: 0;
  border-top: 0.5px solid var(--sep);
}
button.cell:active, a.cell:active { background: var(--highlight); }
.cell .cell-label { flex: 1; min-width: 0; }
.cell .cell-value { color: var(--text-2); text-align: right; }
.cell .chev { width: 16px; height: 16px; color: var(--text-3); }
.cell.action { color: var(--blue); }
.cell.destructive { color: var(--red); }
.cell.center { justify-content: center; }
.cell input[type="text"], .cell input[type="date"] {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  font-size: 17px;
  padding: 0;
}
.cell input[type="date"] { text-align: right; color: var(--blue); min-height: 24px; }

/* Segmented control */
.segmented {
  display: flex;
  position: relative;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill);
  gap: 0;
}
.segmented button {
  flex: 1;
  position: relative;
  min-height: 30px;
  padding: 4px 8px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.08px;
  white-space: nowrap;
}
.segmented button + button::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  border-left: 1px solid var(--sep);
}
.segmented button[aria-pressed="true"] {
  background: var(--bg-elevated);
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 3px 1px rgba(0, 0, 0, 0.04);
}
:root[data-theme="dark"] .segmented button[aria-pressed="true"] { background: #636366; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .segmented button[aria-pressed="true"] { background: #636366; }
}
.segmented button[aria-pressed="true"]::before,
.segmented button[aria-pressed="true"] + button::before { border-color: transparent; }

/* Switch */
.switch {
  position: relative;
  flex: none;
  width: 51px;
  height: 31px;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
  border-radius: 16px;
  background: var(--fill-2);
  cursor: pointer;
  transition: background-color 200ms;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
  transition: transform 200ms var(--ease);
}
.switch:checked { background: var(--green); }
.switch:checked::after { transform: translateX(20px); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 18px;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  background: var(--blue);
  color: #fff;
}
.btn.secondary { background: var(--fill); color: var(--blue); }
.btn:active { opacity: 0.7; }

/* Empty states */
.empty {
  padding: 64px 32px;
  text-align: center;
  color: var(--text-2);
  font-size: 15px;
}
.empty h2 { font-size: 22px; color: var(--text); margin-bottom: 6px; font-weight: 700; }

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

/* The list pane's root column. */
.list-view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}
