/* ── Design tokens ─────────────────────────────── */
:root {
  --bg:          #080c0e;
  --bg-1:        #0d1419;
  --bg-2:        #111b21;
  --bg-3:        #18262e;
  --border:      #1e3040;
  --border-2:    #2a4255;

  --teal:        #1db8a0;
  --teal-dim:    #0e6e60;
  --teal-glow:   rgba(29,184,160,0.12);

  --amber:       #e8a020;
  --amber-dim:   #7a5310;

  --red:         #e05050;
  --red-dim:     #6b2020;

  --text-1:      #d8eaed;
  --text-2:      #7a9ea8;
  --text-3:      #3d5f6b;

  --font:        'SF Pro Text', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', system-ui, sans-serif;
  --font-mono:   'SF Mono', 'Fira Code', 'Consolas', monospace;

  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --radius-xl:   22px;

  --nav-h:       58px;
  --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);
}

/* ── Light mode ─────────────────────────────────── */
body.light {
  --bg:          #f0f4f5;
  --bg-1:        #ffffff;
  --bg-2:        #e8eef0;
  --bg-3:        #dde5e8;
  --border:      #cad6da;
  --border-2:    #b0c2c8;

  --teal:        #0f8f7a;
  --teal-dim:    #a8ddd5;
  --teal-glow:   rgba(15,143,122,0.10);

  --amber:       #b87010;
  --amber-dim:   #f0d8a8;

  --red:         #c03030;
  --red-dim:     #f5c0c0;

  --text-1:      #0d1e24;
  --text-2:      #3a5a66;
  --text-3:      #7a9ea8;
}

/* smooth theme transition */
body, body * {
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

/* ── Reset ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Force html + body to physically fill the device screen in iOS PWA standalone.
   Using position: fixed + inset: 0 bypasses the 100vh/100dvh quirks that leave
   a gap at the bottom on some iOS versions with viewport-fit=cover. */
html {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  background: var(--bg-1);
}

body {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font);
  background: var(--bg-1); /* must match nav + html so iOS paints safe-area strip same colour */
  color: var(--text-1);
  font-size: 16px;
  line-height: 1.5;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  /* Disable double-tap-to-zoom and prevent iOS auto-zoom on focus */
  touch-action: manipulation;
}
button { font-family: var(--font); cursor: pointer; border: none; background: none; }
input, select, textarea { font-family: var(--font); }
a { color: var(--teal); text-decoration: none; }

/* ── App shell ─────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

#view {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
}

#view::-webkit-scrollbar { display: none; }

/* ── Bottom nav ─────────────────────────────────── */
/* Last-resort approach: nav height = button zone only; padding-bottom pushes
   content up while the background bleeds through the safe-area band.
   A ::after pseudo-element extends the same colour further below to cover
   any gap that viewport-fit=cover fails to close on this iOS version. */
#nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  margin-inline: auto;
  width: 100%;
  max-width: 480px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

/* Paint the nav colour into the safe-area band below the viewport.
   Works regardless of whether viewport-fit=cover actually reaches the edge. */
#nav::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;               /* immediately below the nav box */
  height: 80px;            /* generous — covers any unreachable safe area */
  background: var(--bg-1);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  color: var(--text-3);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.nav-item svg { width: 22px; height: 22px; stroke-width: 1.5; }

.nav-item.active {
  color: var(--teal);
}

.nav-item.active svg { stroke: var(--teal); }

/* FAB — log session */
#fab {
  position: fixed;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--teal);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 101;
  box-shadow: 0 0 0 4px var(--teal-glow);
  transition: transform 0.15s, background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

#fab:active { transform: scale(0.93); background: var(--teal-dim); }
#fab svg { width: 24px; height: 24px; stroke-width: 2; }

/* ── View: page layout ─────────────────────────── */
.page { padding: 0; }

.page-header {
  padding: calc(20px + var(--safe-top)) 20px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-title {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-1);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-2);
  margin-top: 2px;
}

/* ── Cards ─────────────────────────────────────── */
.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin: 0 16px 12px;
}

.card-sm {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}

/* ── Typography ────────────────────────────────── */
.label {
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  font-weight: 500;
}

.value {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--text-1);
  font-family: var(--font-mono);
}

.value-sm {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text-1);
}

.muted { color: var(--text-2); }
.accent { color: var(--teal); }
.warn { color: var(--amber); }
.danger { color: var(--red); }

/* ── Stat grid ─────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 16px 12px;
}

.stat-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
}

/* ── Progress bar ──────────────────────────────── */
.progress-wrap { margin: 6px 0 0; }

.progress-track {
  height: 4px;
  background: var(--bg-3);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 2px;
  transition: width 0.4s ease;
}

.progress-fill.warn { background: var(--amber); }
.progress-fill.ext { background: var(--amber-dim); }

/* ── Buttons ───────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  transition: opacity 0.15s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--teal);
  color: var(--bg);
  width: 100%;
}

.btn-primary:disabled { opacity: 0.35; }

.btn-ghost {
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text-1);
  width: 100%;
}

.btn-danger {
  background: var(--red-dim);
  border: 1px solid var(--red);
  color: var(--red);
  width: 100%;
}

/* ── Form elements ─────────────────────────────── */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 6px;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--text-1);
  font-size: 16px;
  appearance: none;
  -webkit-appearance: none;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--teal);
}

.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%237a9ea8' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* ── Dividers ──────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

/* ── Modal / sheet ─────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  padding: 12px 20px calc(32px + var(--safe-bottom));
  animation: slideUp 0.25s ease;
}

.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border-2);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
  letter-spacing: -0.01em;
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to   { transform: translateY(0); }
}

/* ── Setup / onboarding ────────────────────────── */
.setup-wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  padding: calc(48px + var(--safe-top)) calc(24px + var(--safe-right))
           calc(40px + var(--safe-bottom)) calc(24px + var(--safe-left));
}

.setup-logo {
  font-family: var(--font-mono);
  font-size: 13px;
  letter-spacing: 0.15em;
  color: var(--teal);
  text-transform: uppercase;
  margin-bottom: 48px;
}

.setup-step {
  display: none;
  flex-direction: column;
  flex: 1;
}

.setup-step.active { display: flex; }

.setup-step-num {
  font-size: 11px;
  color: var(--text-3);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.setup-step-title {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.03em;
  margin-bottom: 8px;
  line-height: 1.2;
}

.setup-step-desc {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 32px;
}

.setup-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── List rows ─────────────────────────────────── */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.list-row:last-child { border-bottom: none; }

.list-row-label { font-size: 15px; color: var(--text-1); }
.list-row-value { font-size: 14px; color: var(--text-2); }

/* ── Badge / tag ───────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-teal { background: var(--teal-glow); color: var(--teal); border: 1px solid var(--teal-dim); }
.badge-amber { background: rgba(232,160,32,0.1); color: var(--amber); border: 1px solid var(--amber-dim); }
.badge-red { background: rgba(224,80,80,0.1); color: var(--red); border: 1px solid var(--red-dim); }

/* ── Toasts ────────────────────────────────────── */
#toast-container {
  position: fixed;
  top: calc(20px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: 440px;
  pointer-events: none;
}

.toast {
  background: var(--bg-3);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-1);
  animation: toastIn 0.2s ease;
  pointer-events: all;
}

.toast.teal  { border-color: var(--teal-dim); }
.toast.amber { border-color: var(--amber-dim); }
.toast.red   { border-color: #c0392b; color: #e57373; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Utilities ─────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.px-4 { padding-left: 16px; padding-right: 16px; }
.py-2 { padding-top: 8px; padding-bottom: 8px; }
.w-full { width: 100%; }
.text-center { text-align: center; }

/* ── Empty states ──────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 32px;
  text-align: center;
  gap: 12px;
}

.empty-state svg {
  width: 48px;
  height: 48px;
  stroke: var(--text-3);
  stroke-width: 1;
}

.empty-state-title {
  font-size: 16px;
  font-weight: 500;
  color: var(--text-2);
}

.empty-state-sub {
  font-size: 13px;
  color: var(--text-3);
  line-height: 1.6;
}

/* ── Scrollbar (webkit) ────────────────────────── */
::-webkit-scrollbar { width: 0; height: 0; }

/* ── iOS tap fix ───────────────────────────────── */
* { -webkit-tap-highlight-color: transparent; }
input, select, textarea { -webkit-tap-highlight-color: transparent; }
