/* ── Login screen ────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  background: var(--sidebar-bg, #1e3a5f);
  padding: 24px;
}

.login-card {
  background: #fff;
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}

.login-icon { font-size: 44px; margin-bottom: 12px; }
.login-card h1 { font-size: 24px; font-weight: 700; color: #2c3e50; margin-bottom: 6px; }
.login-sub { font-size: 14px; color: #7f8c8d; margin-bottom: 24px; }

#login-form { display: flex; flex-direction: column; gap: 12px; }

#login-password {
  border: 1.5px solid #e2ecf8;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 16px;
  font-family: inherit;
  outline: none;
  text-align: center;
  letter-spacing: 3px;
  transition: border-color 0.15s;
}
#login-password:focus { border-color: #4a90d9; }

.login-error {
  font-size: 13px;
  color: #e74c3c;
  min-height: 18px;
}

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

:root {
  --primary:      #4a90d9;
  --primary-dark: #2c6fad;
  --bg:           #f0f7ff;
  --sidebar-bg:   #1e3a5f;
  --card:         #ffffff;
  --text:         #2c3e50;
  --text-muted:   #7f8c8d;
  --border:       #e2ecf8;
  --shadow:       0 2px 14px rgba(44,62,80,0.07);
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
  --safe-top:     env(safe-area-inset-top, 0px);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ── App shell ───────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh; /* dynamic viewport on mobile */
  overflow: hidden;
}

/* ── Desktop sidebar ─────────────────────────────────────────────────────── */
#sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: calc(var(--safe-top) + 28px) 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.app-name    { font-size: 17px; font-weight: 700; color: #fff; letter-spacing: -0.3px; }
.app-subtitle { font-size: 11px; color: rgba(255,255,255,0.4); margin-top: 3px; }

nav { flex: 1; padding: 10px 0; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.58);
  cursor: pointer;
  transition: background 0.13s, color 0.13s;
  border-left: 3px solid transparent;
  font-size: 14px;
}
.nav-item:hover  { color: rgba(255,255,255,0.9); background: rgba(255,255,255,0.06); }
.nav-item.active { color: #fff; background: rgba(255,255,255,0.1); border-left-color: #74bbff; }
.nav-icon { font-size: 15px; width: 20px; text-align: center; }

/* ── Mobile top bar (hidden on desktop) ─────────────────────────────────── */
#topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: calc(var(--safe-top) + 52px);
  padding-top: var(--safe-top);
  background: var(--sidebar-bg);
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.topbar-title { color: #fff; font-size: 17px; font-weight: 700; }

/* ── Main content ────────────────────────────────────────────────────────── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

#content {
  flex: 1;
  overflow-y: auto;
  padding: 36px 44px 48px;
  -webkit-overflow-scrolling: touch;
}

/* ── Mobile bottom nav (hidden on desktop) ───────────────────────────────── */
#bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(56px + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--sidebar-bg);
  z-index: 100;
}

.bnav-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  padding: 8px 4px;
  transition: color 0.13s;
  -webkit-tap-highlight-color: transparent;
}
.bnav-item.active  { color: #74bbff; }
.bnav-icon  { font-size: 20px; line-height: 1; }
.bnav-label { font-size: 10px; font-weight: 500; }

/* ── View header ─────────────────────────────────────────────────────────── */
.view-header { margin-bottom: 28px; }
.view-header h1 { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; color: var(--text); }
.view-header .date-sub { font-size: 14px; color: var(--text-muted); margin-top: 4px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card h2 { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 16px; }

/* ── Mood selector ───────────────────────────────────────────────────────── */
.mood-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.mood-option {
  flex: 1 1 calc(9.09% - 6px); /* 11 per row on desktop */
  min-width: 52px;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px 8px;
  border-radius: 12px;
  cursor: pointer;
  border: 2px solid transparent;
  background: #f4f8ff;
  transition: transform 0.13s, box-shadow 0.13s, border-color 0.13s, background 0.13s;
  -webkit-tap-highlight-color: transparent;
}
.mood-option:hover  { background: #eaf2ff; transform: translateY(-2px); }
.mood-option.selected { transform: translateY(-4px); box-shadow: 0 6px 18px rgba(0,0,0,0.12); }

.mood-num      { font-size: 18px; font-weight: 700; color: var(--text); line-height: 1; }
.mood-sublabel { font-size: 8px; color: var(--text-muted); text-align: center; line-height: 1.3; min-height: 20px; }

/* ── Mood description card ───────────────────────────────────────────────── */
.mood-desc-card {
  display: flex; flex-direction: column; gap: 6px;
  border-left: 4px solid var(--border);
  background: #f4f8ff;
  border-radius: 0 12px 12px 0;
  padding: 14px 18px;
  margin-bottom: 16px;
  transition: border-left-color 0.2s, background 0.2s;
  min-height: 60px;
  justify-content: center;
}
.mood-desc-category  { font-size: 13px; font-weight: 700; }
.mood-desc-text      { font-size: 14px; color: var(--text); line-height: 1.55; }
.mood-desc-placeholder { font-size: 14px; color: var(--text-muted); font-style: italic; }

/* ── Notes ───────────────────────────────────────────────────────────────── */
.notes-textarea {
  width: 100%; height: 120px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 14px; font-family: inherit; color: var(--text);
  resize: vertical; outline: none;
  transition: border-color 0.15s;
  background: #fafcff;
}
.notes-textarea:focus { border-color: var(--primary); }

/* ── Logged entry ────────────────────────────────────────────────────────── */
.logged-card {
  background: var(--card); border-radius: 16px; padding: 36px;
  box-shadow: var(--shadow); text-align: center;
}
.logged-mood-display { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 6px; }
.logged-emoji  { font-size: 40px; }
.logged-number { font-size: 52px; font-weight: 800; line-height: 1; }
.logged-denom  { font-size: 22px; color: var(--text-muted); align-self: flex-end; padding-bottom: 5px; }
.logged-desc   { color: var(--text-muted); margin-bottom: 18px; }
.logged-notes  { background: #f4f8ff; border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; text-align: left; color: var(--text); line-height: 1.65; }
.no-notes      { color: var(--text-muted); font-style: italic; margin-bottom: 18px; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary); color: #fff; border: none;
  border-radius: 10px; padding: 12px 28px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.13s, transform 0.13s, box-shadow 0.13s;
  font-family: inherit; min-height: 44px;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(74,144,217,0.4); }
.btn-primary:disabled { opacity: 0.38; cursor: not-allowed; }

.btn-secondary {
  background: transparent; color: var(--primary);
  border: 1.5px solid var(--primary); border-radius: 10px;
  padding: 8px 18px; font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background 0.13s;
  font-family: inherit; min-height: 36px;
}
.btn-secondary:hover:not(:disabled) { background: rgba(74,144,217,0.07); }
.btn-secondary:disabled { opacity: 0.5; cursor: default; }

/* ── Graph ───────────────────────────────────────────────────────────────── */
.period-controls { display: flex; gap: 8px; margin-bottom: 16px; }
.toggle-btn {
  padding: 7px 20px; border-radius: 8px;
  border: 1.5px solid var(--border); background: var(--card);
  color: var(--text-muted); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: all 0.13s; font-family: inherit; min-height: 36px;
}
.toggle-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.chart-wrap {
  background: var(--card); border-radius: 16px; padding: 20px 22px;
  box-shadow: var(--shadow); height: 390px;
}
.chart-legend { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-bottom: 12px; }
.legend-dot {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-muted);
}
.legend-dot::before { content: ''; width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legend-dot.mania::before    { background: rgba(224,85,80,0.85); }
.legend-dot.hypo::before     { background: rgba(232,146,58,0.85); }
.legend-dot.balanced::before { background: rgba(61,168,102,0.85); }
.legend-dot.mild-dep::before { background: rgba(155,89,182,0.85); }
.legend-dot.severe::before   { background: rgba(74,127,165,0.85); }
.legend-dot.empty::before    { background: rgba(180,180,180,0.45); }
#main-chart { height: calc(100% - 44px) !important; }

/* ── Monthly report ──────────────────────────────────────────────────────── */
.month-nav { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; }
.month-nav-label { font-size: 16px; font-weight: 600; min-width: 160px; text-align: center; }
.icon-btn {
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 8px; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 20px; color: var(--text);
  transition: background 0.13s; font-family: inherit; flex-shrink: 0;
}
.icon-btn:hover    { background: var(--bg); }
.icon-btn:disabled { opacity: 0.3; cursor: default; pointer-events: none; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card  { background: var(--card); border-radius: 14px; padding: 18px 14px; box-shadow: var(--shadow); text-align: center; }
.stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; }
.stat-value { font-size: 30px; font-weight: 800; color: var(--text); line-height: 1; }
.stat-sub   { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.monthly-chart-wrap { background: var(--card); border-radius: 16px; padding: 16px 20px; box-shadow: var(--shadow); height: 230px; margin-bottom: 18px; }
#monthly-chart { height: 100% !important; }

.notable-section, .missed-section { margin-bottom: 18px; }
.section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 10px; }
.notable-entry { background: var(--card); border-radius: 12px; padding: 14px 18px; box-shadow: var(--shadow); margin-bottom: 8px; }
.notable-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.notable-badge  { color: #fff; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.notable-score  { font-size: 13px; font-weight: 700; color: var(--text-muted); }
.notable-entry p { color: var(--text); font-size: 13px; line-height: 1.55; }
.missed-badges   { display: flex; flex-wrap: wrap; gap: 8px; }
.missed-badge    { background: #fff0ee; color: #c0392b; border: 1px solid #fad4cf; padding: 4px 10px; border-radius: 6px; font-size: 12px; }

/* ── History ─────────────────────────────────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 10px; }
.history-item { background: var(--card); border-radius: 14px; padding: 16px 20px; box-shadow: var(--shadow); display: flex; justify-content: space-between; align-items: center; gap: 16px; transition: transform 0.1s; }
.history-item:hover { transform: translateX(3px); }
.history-date      { font-weight: 600; color: var(--text); margin-bottom: 3px; }
.history-note      { font-size: 13px; color: var(--text-muted); max-width: 480px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-score     { font-size: 26px; font-weight: 800; text-align: right; line-height: 1; }
.history-score-sub { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ── Settings ─────────────────────────────────────────────────────────────── */
.settings-card { background: var(--card); border-radius: 16px; padding: 20px 24px; box-shadow: var(--shadow); margin-bottom: 16px; }
.settings-section-title { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); margin-bottom: 12px; }
.setting-row { display: flex; justify-content: space-between; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--border); gap: 20px; }
.setting-row:last-child { border-bottom: none; padding-bottom: 0; }
.setting-info label { display: block; font-size: 14px; font-weight: 500; color: var(--text); margin-bottom: 2px; }
.setting-info p     { font-size: 12px; color: var(--text-muted); line-height: 1.45; }
.setting-info code  { font-family: 'SF Mono', Monaco, monospace; font-size: 11px; background: #f0f4f8; padding: 1px 4px; border-radius: 3px; }
.time-input { border: 1.5px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 14px; font-family: inherit; color: var(--text); outline: none; flex-shrink: 0; min-height: 36px; }
.time-input:focus { border-color: var(--primary); }

/* Toggle */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { display: none; }
.slider { position: absolute; cursor: pointer; inset: 0; background: #ccc; border-radius: 24px; transition: background 0.2s; }
.slider::before { content: ''; position: absolute; width: 18px; height: 18px; background: #fff; border-radius: 50%; left: 3px; top: 3px; transition: transform 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state p { font-size: 15px; }

/* ── Reminder banner (in-app fallback) ───────────────────────────────────── */
.reminder-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 999;
  background: #1e3a5f; color: #fff; padding: 14px 20px;
  display: flex; justify-content: space-between; align-items: center;
  font-size: 14px;
}
.reminder-banner button { background: none; border: none; color: rgba(255,255,255,0.7); font-size: 18px; cursor: pointer; padding: 0 4px; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(24px + var(--safe-bottom)); left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: rgba(20,42,72,0.92); color: #fff;
  padding: 11px 22px; border-radius: 24px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none;
  transition: opacity 0.22s, transform 0.22s;
  backdrop-filter: blur(12px); box-shadow: 0 4px 20px rgba(0,0,0,0.18); z-index: 9999;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.14); border-radius: 3px; }

/* ═══════════════════════════════════════════════════════════════════════════
   MOBILE — max-width 768px
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  /* Hide desktop sidebar, show mobile chrome */
  #sidebar    { display: none; }
  #topbar     { display: flex; }
  #bottom-nav { display: flex; }

  /* Offset content for top bar and bottom nav */
  #main { padding-top: calc(var(--safe-top) + 52px); }
  #content { padding: 20px 16px calc(72px + var(--safe-bottom)); }

  /* Smaller view headers */
  .view-header { margin-bottom: 18px; }
  .view-header h1 { font-size: 20px; }

  /* Mood selector: 6 per row (two rows of 6+5) */
  .mood-option {
    flex: 1 1 calc(16.66% - 6px);
    min-width: 44px;
    padding: 8px 2px 6px;
  }
  .mood-num { font-size: 16px; }
  .mood-sublabel { font-size: 7px; min-height: 16px; }

  /* Stats grid: 2×2 on mobile */
  .stats-grid { grid-template-columns: repeat(2, 1fr); }

  /* Chart height */
  .chart-wrap { height: 300px; }
  #main-chart { height: calc(100% - 56px) !important; }
  .monthly-chart-wrap { height: 190px; }

  /* Legend wraps nicely */
  .chart-legend { gap: 8px 12px; }

  /* Logged card more compact */
  .logged-card { padding: 24px 20px; }
  .logged-number { font-size: 44px; }

  /* History notes don't overflow too much */
  .history-note { max-width: 200px; }

  /* Month nav */
  .month-nav-label { min-width: 120px; font-size: 14px; }
}

/* ── Very small phones ───────────────────────────────────────────────────── */
@media (max-width: 375px) {
  .mood-sublabel { display: none; }
  .mood-option   { min-width: 36px; }
}
