/* MailMate — grayscale, high-contrast, mobile-first design system.
   Built for one-handed use outdoors: large targets, strong contrast. */

:root {
  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --line: #d9d9de;
  --line-strong: #b8b8c0;
  --ink: #18181b;
  --ink-2: #52525b;
  --ink-3: #8a8a93;
  --accent: #18181b;       /* high-contrast "primary" in grayscale */
  --accent-ink: #ffffff;
  --good: #1f7a3d;
  --warn: #8a5a00;
  --danger: #9b1c1c;
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 56px;             /* minimum touch target */
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 6px 16px rgba(0, 0, 0, 0.05);
  --maxw: 520px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

html[data-theme='dark'] {
  --bg: #0c0c0e;
  --surface: #18181b;
  --surface-2: #202024;
  --line: #2c2c31;
  --line-strong: #3a3a42;
  --ink: #fafafa;
  --ink-2: #b6b6be;
  --ink-3: #80808a;
  --accent: #fafafa;
  --accent-ink: #0c0c0e;
  --good: #4ade80;
  --warn: #fbbf24;
  --danger: #f87171;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.35);
}

/* ---- Color themes (palettes) -------------------------------------------- */
/* A palette mainly retints the accent (primary buttons, chips, bars, active
   states). Surfaces stay neutral grayscale for readability. */

html[data-palette='postal'] { --accent: #1d4ed8; --accent-ink: #ffffff; --good: #1d4ed8; }
html[data-theme='dark'][data-palette='postal'] { --accent: #3b82f6; --accent-ink: #08111f; --good: #60a5fa; }

html[data-palette='eagle'] { --accent: #b3202f; --accent-ink: #ffffff; }
html[data-theme='dark'][data-palette='eagle'] { --accent: #ef4444; --accent-ink: #1a0606; }

html[data-palette='forest'] { --accent: #1f7a3d; --accent-ink: #ffffff; }
html[data-theme='dark'][data-palette='forest'] { --accent: #34d399; --accent-ink: #04140b; }

html[data-palette='amber'] { --accent: #b45309; --accent-ink: #ffffff; }
html[data-theme='dark'][data-palette='amber'] { --accent: #f59e0b; --accent-ink: #1a1203; }

/* High-contrast: heavier lines + pure ink accent — best in bright sun. */
html[data-palette='contrast'] {
  --line: #000000; --line-strong: #000000; --ink-2: #000000; --ink-3: #3a3a3a;
  --accent: #000000; --accent-ink: #ffffff;
}
html[data-theme='dark'][data-palette='contrast'] {
  --line: #ffffff; --line-strong: #ffffff; --ink-2: #ffffff; --ink-3: #c8c8c8;
  --accent: #ffffff; --accent-ink: #000000;
}

* { box-sizing: border-box; }

/* iOS Safari ignores user-scalable=no, so rapid taps trigger double-tap zoom
   and drop taps. `manipulation` disables double-tap-zoom and the tap delay on
   controls (pinch-zoom still works), keeping fast counter taps responsive. */
button, a, .btn, .chip, .tab, .action-tile, .counter button, .iconbtn,
.seg, .swatch, label.switch, input, select, textarea {
  touch-action: manipulation;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
    Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: contain;
}

body { line-height: 1.4; }

#app {
  max-width: var(--maxw);
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  position: relative;
  background: var(--bg);
}

/* ---- App bar ------------------------------------------------------------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px calc(14px + env(safe-area-inset-top, 0px));
  padding-top: max(14px, env(safe-area-inset-top, 0px));
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}
.appbar h1 {
  font-size: 1.25rem;
  margin: 0;
  letter-spacing: -0.01em;
}
.appbar .sub { color: var(--ink-3); font-size: 0.8rem; font-weight: 500; }

.iconbtn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1.1rem;
}
.iconbtn:active { transform: scale(0.96); }

/* ---- Layout -------------------------------------------------------------- */

.screen {
  padding: 16px 16px calc(var(--nav-h) + var(--safe-b) + 24px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: rise 0.18s ease;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.section-label {
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-3);
  font-weight: 700;
  margin: 6px 2px -4px;
}

/* ---- Cards --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 12px 14px; }
.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

/* Status / hero card */
.status-card { text-align: center; padding: 22px 16px; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
}
.status-pill .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ink-3);
}
.status-pill.is-active { color: var(--good); border-color: var(--good); }
.status-pill.is-active .dot { background: var(--good); animation: pulse 1.6s infinite; }
.status-pill.is-paused { color: var(--warn); border-color: var(--warn); }
.status-pill.is-paused .dot { background: var(--warn); }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1;
}
.timer.hero { font-size: 3.4rem; margin: 14px 0 6px; }
.timer.mid { font-size: 2rem; }
.timer.small { font-size: 1.2rem; }
.timer-cap { color: var(--ink-3); font-size: 0.8rem; font-weight: 600; }

/* ---- Buttons ------------------------------------------------------------- */

.btn {
  min-height: var(--tap);
  border-radius: 14px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn.block { width: 100%; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.good { background: var(--good); color: #fff; border-color: var(--good); }
.btn.warn { background: var(--warn); color: #fff; border-color: var(--warn); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-2); }
.btn.lg { min-height: 64px; font-size: 1.1rem; }
.btn.sm { min-height: 44px; font-size: 0.9rem; padding: 0 12px; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn .big { font-size: 1.3rem; }

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.btn-grid.three { grid-template-columns: repeat(3, 1fr); }
.btn-row { display: flex; gap: 10px; }
.btn-row > .btn { flex: 1; }

/* Quick action tiles (dashboard) */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.action-tile {
  min-height: 84px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 4px;
  padding: 14px;
  cursor: pointer;
  font-weight: 700;
}
.action-tile .ico { font-size: 1.5rem; line-height: 1; }
.action-tile small { color: var(--ink-3); font-weight: 600; font-size: 0.72rem; }
.action-tile.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.action-tile.primary small { color: rgba(255,255,255,0.7); }
html[data-theme='dark'] .action-tile.primary small { color: rgba(0,0,0,0.6); }
.action-tile:active { transform: scale(0.98); }

/* ---- Stats --------------------------------------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 10px;
  text-align: center;
}
.stat .num { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .lbl { font-size: 0.7rem; color: var(--ink-3); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---- Lists --------------------------------------------------------------- */

.list { display: flex; flex-direction: column; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 4px;
  border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 700; }
.list-item .meta { color: var(--ink-3); font-size: 0.8rem; }
.list-item .right { text-align: right; white-space: nowrap; }
.list-item .right .big { font-weight: 800; font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }

.empty {
  text-align: center;
  color: var(--ink-3);
  padding: 32px 16px;
}
.empty .ico { font-size: 2rem; display: block; margin-bottom: 8px; opacity: 0.7; }

/* ---- Chips / tags -------------------------------------------------------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.tag {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-2);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 2px 6px;
  margin-right: 4px;
}

/* ---- Inputs -------------------------------------------------------------- */

input[type='text'], input[type='number'], input[type='time'],
input[type='date'], textarea, select {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--ink-2); font-weight: 600; }

/* counter */
.counter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}
.counter .count {
  font-size: 3rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 90px;
  text-align: center;
}
.counter button {
  width: 64px; height: 64px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-size: 1.8rem;
  font-weight: 700;
  cursor: pointer;
}
.counter button:active { transform: scale(0.94); }

/* ---- Toggle switch ------------------------------------------------------- */

.switch { position: relative; width: 52px; height: 32px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--line-strong);
  border-radius: 999px;
  transition: background 0.15s;
  pointer-events: none;
}
.switch .knob {
  position: absolute; top: 3px; left: 3px;
  width: 26px; height: 26px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
  pointer-events: none;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.switch input:checked + .track { background: var(--good); }
.switch input:checked + .track + .knob { transform: translateX(20px); }

/* segmented control */
.segmented {
  display: flex;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}
.seg {
  flex: 1;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-2);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.seg.on { background: var(--accent); color: var(--accent-ink); }

/* theme swatches */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 6px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  cursor: pointer;
  color: var(--ink-2);
  font-size: 0.74rem;
  font-weight: 600;
}
.swatch .dot {
  width: 34px; height: 34px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,0.15);
}
.swatch.on { border-color: var(--accent); color: var(--ink); }
.swatch.on .dot { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--accent); }

/* settings rows */
.set-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.set-row:last-child { border-bottom: 0; }
.set-row .label { font-weight: 600; }
.set-row .desc { color: var(--ink-3); font-size: 0.8rem; }

/* ---- Bars (weekly chart) ------------------------------------------------- */

.bars { display: flex; align-items: flex-end; gap: 8px; height: 140px; padding-top: 8px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar {
  width: 100%;
  background: var(--accent);
  border-radius: 6px 6px 4px 4px;
  min-height: 4px;
  transition: height 0.3s ease;
}
.bar.empty-bar { background: var(--line); }
.bar-col .day { font-size: 0.7rem; color: var(--ink-3); font-weight: 600; }
.bar-col .val { font-size: 0.66rem; color: var(--ink-2); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- Bottom navigation --------------------------------------------------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--maxw);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 30;
}
.tab {
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--ink-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  font-size: 0.66rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}
.tab .ico { font-size: 1.3rem; line-height: 1; }
.tab.on { color: var(--ink); }
.tab.on .ico { transform: translateY(-1px); }

/* ---- Toast --------------------------------------------------------------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  transform: translateX(-50%) translateY(20px);
  background: var(--ink);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: 90%;
  text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---- Modal --------------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 60;
  animation: fade 0.15s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  width: 100%;
  max-width: var(--maxw);
  border-radius: 20px 20px 0 0;
  padding: 18px 18px calc(18px + var(--safe-b));
  box-shadow: var(--shadow);
  animation: rise 0.2s ease;
}
.modal h3 { margin: 4px 0 14px; }
.modal .modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal .modal-actions .btn { flex: 1; }

hr.div { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

.helper-note {
  font-size: 0.78rem;
  color: var(--ink-3);
  text-align: center;
  padding: 4px 8px;
}

.brand-foot {
  text-align: center;
  color: var(--ink-3);
  font-size: 0.72rem;
  padding: 8px 0 4px;
}
