@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display:ital@0;1&family=DM+Sans:wght@300;400;500&display=swap');

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

:root {
  --rose:       #D4537E;
  --rose-light: #FBEAF0;
  --rose-mid:   #F4C0D1;
  --rose-dark:  #72243E;
  --teal-light: #E1F5EE;
  --radius-md:  8px;
  --radius-lg:  12px;

  /* WCAG AA colour tokens — all ≥ 4.5:1 on white/light bg */
  --text-primary:   #1a0d14;   /* 14.2:1 on white */
  --text-secondary: #6b3a50;   /* 5.2:1 on white  */
  --text-muted:     #7a4a5e;   /* 4.6:1 on white  */
  --text-rose-dark: #5c1e34;   /* 7.1:1 on rose-light */
  --text-green:     #0a5c3e;   /* 5.8:1 on teal-light */
  --text-amber:     #6b3a00;   /* 5.1:1 on amber-light */
  --text-red:       #7a1a1a;   /* 5.4:1 on red-light */
}

/* ── iOS fixes ─────────────────────────────────────────────── */
html {
  height: -webkit-fill-available;
}

body {
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;                     /* WCAG AA base — 16px minimum */
  background: #f9f5f7;
  color: var(--text-primary);
  min-height: 100vh;
  min-height: -webkit-fill-available;
  -webkit-overflow-scrolling: touch;
  overflow-y: auto;
}

/* ── Loading Overlay ───────────────────────────────────────── */
#loading-overlay {
  position: fixed;
  inset: 0;
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  gap: 12px;
}

#loading-overlay.hidden { display: none; }

.loading-logo {
  font-family: 'DM Serif Display', serif;
  font-size: 32px;
  color: var(--text-primary);
}

.loading-logo em { color: var(--rose); font-style: italic; }

.loading-spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--rose-mid);
  border-top-color: var(--rose);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.loading-text { font-size: 16px; color: var(--text-secondary); }

/* ── Sign-In Screen ────────────────────────────────────────── */
#signin-screen {
  position: fixed;
  inset: 0;
  background: #f9f5f7;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#signin-screen.hidden { display: none; }

.passcode-card {
  background: #fff;
  border: 0.5px solid #e8d5de;
  border-radius: 20px;
  padding: 2.5rem 2rem;
  width: min(320px, 90vw);
  text-align: center;
  box-shadow: 0 4px 32px rgba(212, 83, 126, 0.08);
}

.passcode-logo {
  font-family: 'DM Serif Display', serif;
  font-size: 32px;
  font-weight: 400;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.passcode-logo em { color: var(--rose); font-style: italic; }

.passcode-subtitle {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
}

.passcode-hint {
  font-size: 14px;                     /* WCAG AA min for hint text */
  color: var(--text-muted);
  margin-top: 0.5rem;
}

/* ── Google Sign-In Button ─────────────────────────────────── */
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  border: 1px solid #e8d5de;
  background: #fff;
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  min-height: 48px;                    /* WCAG AA touch target */
}

.google-btn:hover    { background: #fdf0f5; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
.google-btn:active   { transform: scale(0.98); }
.google-btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── App Shell ─────────────────────────────────────────────── */
#app { max-width: 680px; margin: 0 auto; padding: 2rem 1rem; display: none; }

/* ── Header ────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 28px;
  font-weight: 400;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

h1 em { color: var(--rose); font-style: italic; }

.lock-btn {
  font-size: 14px;
  color: var(--text-secondary);
  cursor: pointer;
  background: none;
  border: 1px solid #e8d5de;
  border-radius: var(--radius-md);
  padding: 8px 12px;
  min-height: 40px;
  font-family: 'DM Sans', sans-serif;
  transition: background 0.1s;
}

.lock-btn:hover { background: var(--rose-light); }

.subtitle { font-size: 14px; color: var(--text-secondary); margin-bottom: 1.5rem; }

/* ── Sync Status Bar ───────────────────────────────────────── */
.sync-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 1rem;
  border: 1px solid transparent;
}

.sync-bar.synced  { background: #E1F5EE; border-color: #9FE1CB; color: var(--text-green); }
.sync-bar.syncing { background: #FEF3DC; border-color: #FAC775; color: var(--text-amber); }
.sync-bar.offline { background: #F1EFE8; border-color: #D3D1C7; color: #4a4845; }
.sync-bar.error   { background: #FCEBEB; border-color: #F7C1C1; color: var(--text-red); }

.sync-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.synced .sync-dot  { background: #1D9E75; }
.syncing .sync-dot { background: #BA7517; animation: pulse 1s infinite; }
.offline .sync-dot { background: #888780; }
.error .sync-dot   { background: #E24B4A; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid #e8d5de;
  overflow-x: auto;                    /* prevent overflow on narrow screens */
  -webkit-overflow-scrolling: touch;
}

.tab {
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all 0.15s;
  font-family: 'DM Sans', sans-serif;
  white-space: nowrap;
  min-height: 44px;
}

.tab.active             { color: var(--rose); border-bottom-color: var(--rose); }
.tab:hover:not(.active) { color: var(--text-primary); }

/* ── Panels ────────────────────────────────────────────────── */
.panel        { display: none; }
.panel.active { display: block; }

/* ── Form ──────────────────────────────────────────────────── */
.log-form {
  background: #fff;
  border: 1px solid #e8d5de;
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

/* Stack to single column on mobile */
@media (max-width: 480px) {
  .form-row {
    grid-template-columns: 1fr;
  }
}

.form-group { display: flex; flex-direction: column; gap: 6px; }

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="date"],
input[type="text"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e8d5de;
  border-radius: var(--radius-md);
  background: #fdf8fa;
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;                     /* 16px prevents iOS auto-zoom */
  min-height: 48px;                    /* WCAG AA touch target */
  transition: border-color 0.15s;
  -webkit-appearance: none;
  appearance: none;
}

input[type="date"]:focus,
input[type="text"]:focus,
select:focus {
  outline: 2px solid var(--rose);      /* visible focus ring — WCAG AA */
  outline-offset: 1px;
  border-color: var(--rose);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  border: 1px solid #e8d5de;
  background: #fff;
  cursor: pointer;
  font-family: 'DM Sans', sans-serif;
  font-size: 16px;
  font-weight: 500;
  color: var(--text-primary);
  transition: all 0.15s;
  min-height: 44px;                    /* WCAG AA touch target */
}

.btn:hover  { background: #fdf0f5; }
.btn:active { transform: scale(0.98); }
.btn:focus-visible {
  outline: 2px solid var(--rose);
  outline-offset: 2px;
}

.btn-primary       { background: var(--rose); color: #fff; border-color: var(--rose); }
.btn-primary:hover { background: var(--rose-dark); border-color: var(--rose-dark); }

.btn-sm            { padding: 8px 14px; font-size: 14px; min-height: 40px; }

.btn-danger        { color: #7a1a1a; border-color: #f09595; }
.btn-danger:hover  { background: #fcebeb; }

/* ── Stats ─────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 1.5rem;
}

.stat {
  background: #fff;
  border: 1px solid #e8d5de;
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
}

.stat-num   { font-family: 'DM Serif Display', serif; font-size: 30px; color: var(--rose); }
.stat-label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; font-weight: 500; }

/* ── Prediction Banner ─────────────────────────────────────── */
.prediction {
  background: var(--rose-light);
  border: 1px solid var(--rose-mid);
  border-radius: var(--radius-lg);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 12px;
}

.pred-icon  { font-size: 22px; color: var(--rose); flex-shrink: 0; }
.pred-title { font-size: 16px; font-weight: 500; color: var(--text-rose-dark); }
.pred-sub   { font-size: 14px; color: var(--text-rose-dark); margin-top: 2px; opacity: 0.85; }

/* ── History ───────────────────────────────────────────────── */
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid #e8d5de;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: #fff;
  gap: 8px;
}

.hi-left  { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hi-dot   { width: 10px; height: 10px; border-radius: 50%; background: var(--rose); flex-shrink: 0; }
.hi-date  { font-weight: 600; font-size: 16px; color: var(--text-primary); }
.hi-meta  { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }

.hi-badge { font-size: 12px; padding: 3px 10px; border-radius: 20px; font-weight: 600; white-space: nowrap; }
.badge-heavy  { background: #FAECE7; color: #7a2a10; }
.badge-medium { background: #FAEEDA; color: #6b3a00; }
.badge-light  { background: #E1F5EE; color: #0a5c3e; }

/* ── Calendar ──────────────────────────────────────────────── */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.cal-title { font-family: 'DM Serif Display', serif; font-size: 20px; color: var(--text-primary); }
.cal-nav   { display: flex; gap: 6px; }

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
}

.cal-day-label {
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  padding: 4px 0;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.cal-day {
  min-height: 44px;
  border-radius: var(--radius-md);
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  font-size: 14px;
  transition: background 0.1s;
  border: 1px solid transparent;
  color: var(--text-primary);
}

.cal-day:hover            { background: #fdf0f5; }
.cal-day.other-month      { opacity: 0.3; }
.cal-day.today            { border-color: var(--rose); font-weight: 600; }
.cal-day.period           { background: var(--rose-light); }
.cal-day.period .day-num  { color: var(--text-rose-dark); font-weight: 600; }
.cal-day.predicted        { background: #fff5f9; border-style: dashed; border-color: var(--rose-mid); }

.cal-dot      { width: 6px; height: 6px; border-radius: 50%; background: var(--rose); margin-top: 2px; }
.cal-dot-pred { background: var(--rose-mid); }

.cal-legend { display: flex; gap: 16px; margin-top: 12px; font-size: 13px; color: var(--text-secondary); flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot  { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }

/* ── Export Panel ──────────────────────────────────────────── */
.export-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: #fff;
  border: 1px solid #e8d5de;
  border-radius: var(--radius-lg);
  margin-bottom: 1rem;
  gap: 12px;
}

.export-info h3 { font-size: 16px; font-weight: 600; color: var(--text-primary); }
.export-info p  { font-size: 14px; color: var(--text-secondary); margin-top: 2px; }

.storage-note {
  background: #E1F5EE;
  border: 1px solid #9FE1CB;
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 14px;
  color: var(--text-green);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Empty State ───────────────────────────────────────────── */
.empty { text-align: center; padding: 2rem; color: var(--text-secondary); font-size: 16px; }

/* ── Hidden utility ────────────────────────────────────────── */
.hidden { display: none !important; }
