/* app.css — Thought Log
   Mobile-first. Designed for daily habitual use on a phone.
   All touch targets meet the 44px minimum. Font sizes ≥ 16px on inputs
   to prevent iOS Safari from auto-zooming on focus.
*/

/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  --bg:            #F3F4F0;
  --surface:       #FFFFFF;
  --surface-2:     #F7F8F4;
  --primary:       #5C7C6F;
  --primary-dk:    #4A6659;
  --primary-lt:    #E6EFEc;
  --text:          #1A2332;
  --text-2:        #4A5568;
  --text-3:        #8896A4;
  --border:        #DDE4DF;
  --danger:        #C0392B;
  --danger-lt:     #FDECEA;
  --warn-bg:       #FFFBEB;
  --warn-border:   #FDE68A;
  --warn-text:     #78350F;
  --warn-icon:     #D97706;
  --shadow-sm:     0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.04);
  --shadow:        0 2px 8px rgba(0,0,0,0.07);
  --radius:        14px;
  --radius-sm:     9px;
  --tab-h:         60px;
  --safe-top:      env(safe-area-inset-top,    0px);
  --safe-bottom:   env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  overscroll-behavior: none;          /* prevent pull-to-refresh bounce */
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* ── App shell ───────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  height: 100dvh;           /* dynamic viewport height — tracks iOS keyboard */
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: var(--bg);
}

/* ── Views ───────────────────────────────────────────────────────────────── */
.view {
  display: none;            /* hidden by default */
  flex-direction: column;
  position: absolute;
  inset: 0;
  bottom: calc(var(--tab-h) + var(--safe-bottom));
}

.view.active       { display: flex; }
.view.no-tab       { bottom: 0; }     /* views that run behind / instead of tab bar */

/* ── View header ─────────────────────────────────────────────────────────── */
.view-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + var(--safe-top)) 16px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: calc(52px + var(--safe-top));
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

.view-header h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

/* ── Scrollable view body ────────────────────────────────────────────────── */
.view-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 32px;
}

/* Hide scrollbars on mobile — they don't add value */
.view-body::-webkit-scrollbar { display: none; }
.view-body { scrollbar-width: none; }

/* ── Tab bar ─────────────────────────────────────────────────────────────── */
#tab-bar {
  display: flex;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 200;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  min-height: 44px;
  padding: 6px 4px;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s;
}

.tab-btn.active   { color: var(--primary); }
.tab-btn svg      { width: 23px; height: 23px; }

/* ── Onboarding ──────────────────────────────────────────────────────────── */
#view-onboarding {
  background: var(--primary);
  align-items: center;
  justify-content: flex-start;
  padding: calc(52px + var(--safe-top)) 24px calc(32px + var(--safe-bottom));
  text-align: center;
  gap: 0;
  overflow-y: auto;
}

.ob-logo {
  width: 76px;
  height: 76px;
  margin-bottom: 20px;
  border-radius: 18px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
}

.ob-title {
  color: #fff;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.15;
  margin-bottom: 10px;
}

.ob-sub {
  color: rgba(255,255,255,0.82);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 28px;
  max-width: 300px;
}

.install-card {
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: var(--radius);
  padding: 18px 18px 16px;
  width: 100%;
  max-width: 340px;
  text-align: left;
  margin-bottom: 24px;
}

.install-card h2 {
  color: rgba(255,255,255,0.7);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 14px;
}

.install-step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  color: rgba(255,255,255,0.90);
  font-size: 14px;
  line-height: 1.5;
}

.install-step:last-child { margin-bottom: 0; }

.step-num {
  background: rgba(255,255,255,0.22);
  color: #fff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.btn-ob-primary {
  width: 100%;
  max-width: 340px;
  background: #fff;
  color: var(--primary);
  border: none;
  border-radius: 50px;
  padding: 15px 24px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  -webkit-tap-highlight-color: transparent;
  transition: opacity 0.15s;
  margin-bottom: 12px;
}

.btn-ob-primary:active { opacity: 0.85; }

.btn-ob-skip {
  background: none;
  border: none;
  color: rgba(255,255,255,0.60);
  font-size: 14px;
  cursor: pointer;
  padding: 10px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

/* ── New Entry form ──────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
}

.field-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

.field-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
  color: var(--text-3);
  margin-left: 4px;
}

textarea,
input[type="text"] {
  width: 100%;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 16px;           /* ← prevents iOS auto-zoom on focus */
  font-family: inherit;
  color: var(--text);
  line-height: 1.55;
  resize: none;
  -webkit-appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea         { min-height: 84px; }
textarea:focus,
input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(92,124,111,0.12);
}

/* ── Distortion chips ────────────────────────────────────────────────────── */
.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  min-height: 36px;
  display: flex;
  align-items: center;
}

.chip:active        { transform: scale(0.96); }
.chip.selected {
  background: var(--primary-lt);
  border-color: var(--primary);
  color: var(--primary-dk);
  font-weight: 600;
}

/* ── Intensity slider ────────────────────────────────────────────────────── */
.intensity-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 2px;
}

.intensity-ends {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  min-width: 26px;
  text-align: center;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  height: 5px;
  border-radius: 3px;
  background: var(--border);
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.18);
  transition: transform 0.1s;
}

input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.15); }

.intensity-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--primary);
  min-width: 28px;
  text-align: center;
}

/* ── Submit button ───────────────────────────────────────────────────────── */
.btn-save {
  width: 100%;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  min-height: 54px;
  margin-top: 4px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
  letter-spacing: 0.01em;
}

.btn-save:active    { background: var(--primary-dk); transform: scale(0.99); }
.btn-save:disabled  { opacity: 0.5; cursor: default; transform: none; }

/* ── Success screen ──────────────────────────────────────────────────────── */
#view-success {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 28px calc(28px + var(--safe-bottom));
}

.success-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: var(--primary-lt);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 22px;
}

.success-ring svg { width: 42px; height: 42px; color: var(--primary); }

#view-success h2 {
  font-size: 24px;
  font-weight: 800;
  margin-bottom: 10px;
}

#view-success p {
  color: var(--text-2);
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 32px;
  max-width: 280px;
}

.btn-another {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 15px 32px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: 52px;
  width: 100%;
  max-width: 280px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
  margin-bottom: 12px;
}

.btn-another:active { background: var(--primary-dk); }

.btn-text-link {
  background: none;
  border: none;
  color: var(--text-3);
  font-size: 14px;
  cursor: pointer;
  padding: 10px;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

/* ── History ─────────────────────────────────────────────────────────────── */
.history-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
  color: var(--text-3);
  gap: 12px;
}

.history-empty p { font-size: 15px; line-height: 1.6; max-width: 240px; }

.day-group        { margin-bottom: 20px; }

.day-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
  padding: 0 2px;
}

.entry-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.1s;
  border: 1px solid transparent;
}

.entry-card:active { transform: scale(0.99); }

.entry-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 7px;
}

.entry-time { font-size: 12px; color: var(--text-3); font-weight: 500; }

.intensity-badge {
  font-size: 11px;
  color: var(--text-3);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 2px 7px;
  font-weight: 600;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 7px;
}

.tag {
  background: var(--primary-lt);
  color: var(--primary-dk);
  border-radius: 10px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
}

.entry-preview {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ── Entry detail ────────────────────────────────────────────────────────── */
#view-detail { z-index: 50; }

.detail-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}

.detail-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 6px;
}

.detail-body {
  font-size: 15px;
  color: var(--text);
  line-height: 1.65;
}

.detail-card.reframe {
  border-left: 3px solid var(--primary);
  padding-left: 14px;
}

.btn-delete {
  width: 100%;
  background: var(--danger-lt);
  color: var(--danger);
  border: 1px solid rgba(192,57,43,0.18);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 50px;
  margin-top: 4px;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}

.btn-delete:active { background: #f7d5d2; }

/* ── Back button ─────────────────────────────────────────────────────────── */
.btn-back {
  display: flex;
  align-items: center;
  gap: 2px;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 6px 4px 0;
  min-height: 44px;
  min-width: 44px;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

/* ── Export ──────────────────────────────────────────────────────────────── */
.export-stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 16px;
  margin-bottom: 12px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.stat-num {
  font-size: 44px;
  font-weight: 900;
  color: var(--primary);
  line-height: 1;
}

.stat-label {
  font-size: 14px;
  color: var(--text-3);
  margin-top: 4px;
  font-weight: 500;
}

.export-warn {
  display: flex;
  gap: 10px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 14px 14px;
  margin-bottom: 12px;
}

.export-warn svg  { width: 18px; height: 18px; color: var(--warn-icon); flex-shrink: 0; margin-top: 2px; }
.export-warn p    { font-size: 13px; color: var(--warn-text); line-height: 1.55; }

.export-options {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  margin-bottom: 16px;
}

.export-opt {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}

.export-opt:last-child { border-bottom: none; }
.export-opt:active     { background: var(--surface-2); }

.export-opt-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-sm);
  background: var(--primary-lt);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.export-opt-icon svg { width: 22px; height: 22px; color: var(--primary); }

.export-opt-text h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}

.export-opt-text p {
  font-size: 13px;
  color: var(--text-3);
}

.export-note {
  font-size: 13px;
  color: var(--text-3);
  text-align: center;
  line-height: 1.6;
  padding: 0 8px;
}

/* ── Toast notification ──────────────────────────────────────────────────── */
#toast {
  position: absolute;
  bottom: calc(var(--tab-h) + var(--safe-bottom) + 14px);
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1A2332;
  color: #fff;
  padding: 11px 20px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  max-width: calc(100% - 32px);
  opacity: 0;
  pointer-events: none;
  z-index: 500;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Loading spinner ─────────────────────────────────────────────────────── */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 48px auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Unsupported browser warning ─────────────────────────────────────────── */
#unsupported {
  display: none;
  padding: 32px 24px;
  text-align: center;
  color: var(--text-2);
  line-height: 1.6;
}
