:root {
  --bg: #F0EEEA; --card: #FAFAF8; --card2: #F5F3EF;
  --border: #DDD9D1; --border2: #C8C3B8;
  --text: #2C2A25; --muted: #8A857B; --muted2: #B0AA9F;
  --accent: #3D5A6E; --accent2: #2E4654; --accent-light: #EBF0F3;
  --dep: #B8524E; --hap: #5C8A57; --mot: #3D7BA8; --foc: #2E8B8B;
  --anx: #C4960F; --str: #8B6BAE; --hyp: #CF7A2E; --mix: #7B3F8D;
  --pos: #4CAF50; --neg: #E53935; --warn: #F9A825;
  --heading: 'Fraunces', Georgia, serif;
  --body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --radius: 8px; --radius-lg: 12px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--body); background: var(--bg); color: var(--text); line-height: 1.5; min-height: 100vh; }
h1, h2, h3 { font-family: var(--heading); font-weight: 600; line-height: 1.25; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ═══ NAV ═══ */
.nav { display: flex; align-items: center; gap: 12px; padding: 0 20px; height: 56px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.nav-brand { font-family: var(--heading); font-size: 18px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.brand-icon { font-size: 22px; }
.nav-brand:hover { text-decoration: none; }
.nav-left { flex-shrink: 0; }
.nav-tabs { display: flex; gap: 2px; overflow-x: auto; flex: 1; padding: 0 8px; scrollbar-width: none; }
.nav-tabs::-webkit-scrollbar { display: none; }
.nav-tab { padding: 16px 14px; font-size: 13px; font-weight: 500; color: var(--muted); border: none; background: none; cursor: pointer; white-space: nowrap; border-bottom: 2.5px solid transparent; transition: all 0.15s; font-family: var(--body); }
.nav-tab:hover { color: var(--text); }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 700; }
.nav-right { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.nav-privacy { font-size: 11.5px; color: var(--accent); font-weight: 600; padding: 6px 12px; background: var(--accent-light); border-radius: 20px; white-space: nowrap; }
.nav-privacy:hover { background: var(--accent); color: #FFF; text-decoration: none; }

/* ═══ BUTTONS ═══ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 20px; border-radius: var(--radius); font-size: 14px; font-weight: 600; font-family: var(--body); cursor: pointer; border: none; transition: all 0.15s; }
.btn-sm { padding: 6px 14px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }
.btn-primary { background: var(--accent); color: #FFF; }
.btn-primary:hover { background: var(--accent2); }
.btn-outline { background: transparent; border: 1.5px solid var(--accent); color: var(--accent); }
.btn-outline:hover { background: var(--accent-light); }
.btn-danger { background: var(--neg); color: #FFF; }
.btn-danger:hover { background: #C62828; }
.btn-ghost { background: none; border: none; color: var(--muted); padding: 6px 10px; }
.btn-ghost:hover { color: var(--text); background: var(--card2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ═══ INPUTS ═══ */
.input { padding: 8px 12px; border: 1.5px solid var(--border); border-radius: var(--radius); font-size: 14px; font-family: var(--body); background: #FFF; color: var(--text); outline: none; transition: border-color 0.15s; }
.input:focus { border-color: var(--accent); }
.input-sm { padding: 6px 10px; font-size: 13px; width: 80px; }
select.input { cursor: pointer; }
textarea.input { resize: vertical; min-height: 60px; }

/* ═══ WELCOME PAGE ═══ */
.welcome-wrap { display: flex; justify-content: center; align-items: center; min-height: calc(100vh - 56px); padding: 32px 20px; }
.welcome-card { text-align: center; max-width: 560px; animation: fadeUp 0.5s ease-out; }
.welcome-icon { font-size: 56px; margin-bottom: 16px; animation: float 3s ease-in-out infinite; }
.welcome-card h1 { font-size: 42px; color: var(--text); margin-bottom: 8px; }
.welcome-sub { font-size: 16px; color: var(--muted); margin-bottom: 32px; line-height: 1.6; }
.welcome-privacy { background: #E8F5E9; border: 1px solid #C8E6C9; border-radius: var(--radius-lg); padding: 20px; text-align: left; font-size: 13.5px; line-height: 1.6; margin-bottom: 32px; }
.welcome-privacy a { display: block; margin-top: 8px; font-weight: 600; }
.shield { font-size: 18px; margin-right: 6px; }
.welcome-actions { display: flex; flex-direction: column; gap: 12px; }

/* ═══ SETUP WIZARD ═══ */
.setup-wrap { max-width: 680px; margin: 0 auto; padding: 32px 20px; }
.setup-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 32px; animation: fadeUp 0.3s ease-out; }
.setup-progress { height: 4px; background: var(--border); border-radius: 2px; margin-bottom: 28px; }
.setup-bar { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.4s ease; }
.setup-step h2 { font-size: 24px; margin-bottom: 8px; }
.illness-grid { display: grid; gap: 10px; margin: 20px 0; }
.illness-option { display: block; cursor: pointer; }
.illness-option input { display: none; }
.illness-card { padding: 16px; border: 2px solid var(--border); border-radius: var(--radius); transition: all 0.15s; }
.illness-card strong { display: block; font-size: 15px; margin-bottom: 4px; }
.illness-card span { font-size: 12.5px; color: var(--muted); }
.illness-option input:checked + .illness-card { border-color: var(--accent); background: var(--accent-light); }
.var-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.var-checkbox { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; cursor: pointer; }
.var-checkbox:has(input:checked) { background: var(--accent-light); border-color: var(--accent); }
.var-checkbox input { accent-color: var(--accent); }
.add-custom-row { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.add-custom-row .input { flex: 1; }
.threshold-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; font-size: 14px; }
.threshold-row label { font-weight: 600; min-width: 160px; }
.file-warning { background: #FFF8E1; border: 1px solid #FFE082; border-radius: var(--radius); padding: 14px; font-size: 13px; line-height: 1.5; }

/* ═══ MAIN APP LAYOUT ═══ */
.tab-content { max-width: 1080px; margin: 0 auto; padding: 24px 20px; animation: fadeUp 0.25s ease-out; }
.section { margin-bottom: 32px; }
.section-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; flex-wrap: wrap; gap: 8px; }
.section-title { font-size: 20px; font-weight: 600; color: var(--accent); border-bottom: 2px solid var(--accent); padding-bottom: 4px; display: inline-block; }
.section-sub { font-size: 13px; color: var(--muted); margin-top: 4px; line-height: 1.5; }

/* ═══ CARDS & STATS ═══ */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.stat-grid { display: flex; flex-wrap: wrap; gap: 12px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; flex: 1 1 150px; min-width: 140px; }
.stat-label { font-size: 11px; color: var(--muted); letter-spacing: 0.5px; text-transform: uppercase; margin-bottom: 4px; }
.stat-value { font-size: 28px; font-weight: 700; font-family: var(--heading); }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ═══ STATUS CHECK ═══ */
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-bottom: 8px; }
.status-box { border: 1px solid var(--border); border-left-width: 6px; border-radius: var(--radius); padding: 14px 16px; background: var(--card); display: flex; flex-direction: column; }
.status-box .cond { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); font-weight: 700; }
.status-box .state { font-family: var(--heading); font-size: 22px; font-weight: 700; margin: 2px 0 2px; line-height: 1.2; }
.status-box .meta { font-size: 12px; color: var(--muted); }
.status-box .episode { margin-top: 10px; font-size: 12px; font-weight: 600; padding: 6px 9px; border-radius: 6px; background: #FCEDEC; color: var(--neg); line-height: 1.4; }
.status-box.mixed { border-left-color: var(--mix) !important; }
.status-box.mixed .episode { background: #F3ECF6; color: var(--mix); }
.status-box.cycle { border-left-color: var(--dep) !important; }
.status-trend { font-size: 12px; font-weight: 700; margin-top: 2px; }
.status-trend.worsening { color: var(--neg); }
.status-trend.improving { color: var(--pos); }
.status-trend.stable { color: var(--muted); }

/* ═══ TABLES ═══ */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { background: var(--accent); color: #FFF; padding: 8px 10px; text-align: center; font-weight: 600; font-size: 11.5px; white-space: nowrap; }
td { padding: 7px 10px; border-bottom: 1px solid var(--border); text-align: center; }
tr:nth-child(even) { background: var(--card2); }
tr:hover { background: #EDE9E0; }
.row-highlight { background: #FFD6D6 !important; }
.row-highlight td { border-bottom-color: #F4A8A8 !important; }

/* ═══ CHARTS ═══ */
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.chart-card canvas { width: 100% !important; }

/* ═══ ENTRY FORM ═══ */
.entry-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.entry-group { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.entry-group h4 { font-family: var(--heading); font-size: 15px; margin-bottom: 12px; color: var(--accent); border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.entry-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 13px; }
.entry-row label { flex: 1; color: var(--text); }
.entry-row input, .entry-row select { width: 80px; text-align: center; }
.entry-slider { display: flex; align-items: center; gap: 8px; }
.entry-slider input[type="range"] { flex: 1; accent-color: var(--accent); }
.entry-slider .val { font-weight: 700; width: 24px; text-align: center; font-size: 14px; }
.binary-toggle { display: flex; border: 1.5px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.binary-toggle button { padding: 4px 14px; font-size: 12px; font-weight: 600; border: none; background: #FFF; cursor: pointer; font-family: var(--body); }
.binary-toggle button.active-yes { background: var(--pos); color: #FFF; }
.binary-toggle button.active-no { background: var(--neg); color: #FFF; }
.qopt { font-size: 11px; cursor: pointer; flex: 1; text-align: center; padding: 6px 2px; border-radius: 4px; border: 1px solid var(--border); background: #FFF; font-family: var(--body); color: var(--text); transition: all 0.12s; }
.qopt:hover { border-color: var(--accent); }
.qopt-active { border-color: var(--accent) !important; background: var(--accent-light) !important; font-weight: 600; }
.entry-date { font-size: 14px; font-weight: 600; }
.entry-actions { display: flex; gap: 8px; margin-top: 20px; justify-content: flex-end; flex-wrap: wrap; }
.entry-nav { display: flex; gap: 8px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.history-row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 6px; cursor: pointer; font-size: 13px; }
.history-row:hover { background: var(--accent-light); }
.history-row .date { font-weight: 600; min-width: 80px; }
.wiz-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.wiz-item:last-child { border-bottom: none; }
.wiz-label { font-size: 15px; font-weight: 500; color: var(--text); margin-bottom: 10px; text-align: center; }
.info-tip { display: inline-block; cursor: pointer; color: var(--accent); font-size: 14px; margin-left: 4px; vertical-align: middle; }

/* ═══ CORRELATION HEATMAP ═══ */
.heatmap-grid { display: inline-grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.heatmap-cell { display: flex; align-items: center; justify-content: center; padding: 4px 2px; font-size: 10px; font-weight: 500; min-height: 32px; min-width: 48px; }
.heatmap-header { background: var(--accent); color: #FFF; font-weight: 600; font-size: 9px; padding: 6px 4px; }
.heatmap-row-label { background: var(--accent); color: #FFF; font-weight: 600; font-size: 10px; padding: 6px 8px; text-align: right; }
.corr-view-tabs { display: flex; gap: 4px; margin-bottom: 16px; }
.corr-view-tab { padding: 8px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 500; border: 1px solid var(--border); background: var(--card); cursor: pointer; font-family: var(--body); }
.corr-view-tab.active { background: var(--accent); color: #FFF; border-color: var(--accent); }

/* ═══ ULTRADIAN SEGMENT BAR ═══ */
.segment-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 8px 0 6px; }
.segment-bar-label { font-size: 12px; font-weight: 600; color: var(--muted); margin-right: 4px; }
.seg-btn { padding: 7px 14px; border-radius: 20px; font-size: 13px; font-weight: 500; border: 1px solid var(--border); background: var(--card); cursor: pointer; font-family: var(--body); }
.seg-btn:hover { border-color: var(--accent); }
.seg-btn.logged { border-color: var(--accent); color: var(--accent); }
.seg-btn.active { background: var(--accent); color: #FFF; border-color: var(--accent); }

/* ═══ MEDICATION CARDS ═══ */
.med-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.med-card h4 { font-family: var(--heading); margin-bottom: 8px; }
.med-compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-top: 8px; }
.med-stat { text-align: center; padding: 8px; border-radius: var(--radius); background: var(--card2); }
.med-stat .label { font-size: 10px; color: var(--muted); text-transform: uppercase; }
.med-stat .value { font-size: 18px; font-weight: 700; font-family: var(--heading); }

/* ═══ FINDINGS ═══ */
.finding { display: flex; gap: 8px; align-items: flex-start; padding: 6px 0; font-size: 13.5px; line-height: 1.5; }
.finding-icon { flex-shrink: 0; }

/* ═══ DROPDOWN / MENU ═══ */
.dropdown { position: absolute; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.12); padding: 6px 0; min-width: 200px; z-index: 200; }
.dropdown-item { display: block; padding: 8px 16px; font-size: 13px; color: var(--text); cursor: pointer; border: none; background: none; width: 100%; text-align: left; font-family: var(--body); }
.dropdown-item:hover { background: var(--accent-light); }
.dropdown-sep { border-top: 1px solid var(--border); margin: 4px 0; }

/* ═══ MODAL ═══ */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 300; }
.modal { position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%); background: var(--card); border-radius: var(--radius-lg); padding: 28px; max-width: 560px; width: 90%; max-height: 80vh; overflow-y: auto; z-index: 301; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.modal h2 { font-size: 20px; margin-bottom: 12px; }

/* ═══ TOAST ═══ */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--text); color: #FFF; padding: 12px 24px; border-radius: var(--radius); font-size: 14px; font-weight: 500; z-index: 400; animation: fadeUp 0.3s; }

/* ═══ STATIC PAGES ═══ */
.static-page { max-width: 720px; margin: 0 auto; padding: 32px 20px 64px; }
.static-page h1 { font-size: 32px; margin-bottom: 8px; }
.static-page .lead { font-size: 16px; color: var(--muted); margin-bottom: 32px; }
.static-page section { margin-bottom: 32px; }
.static-page h2 { font-size: 20px; margin-bottom: 8px; color: var(--accent); }
.static-page h3 { font-size: 16px; margin: 16px 0 8px; }
.static-page p, .static-page li { font-size: 14px; line-height: 1.7; }
.static-page ul, .static-page ol { padding-left: 24px; margin: 8px 0; }
.static-page li { margin-bottom: 4px; }
.static-page code { background: var(--card2); padding: 2px 6px; border-radius: 4px; font-size: 13px; }
.back-link { display: inline-block; margin-bottom: 20px; font-size: 14px; font-weight: 600; }
.privacy-box { padding: 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 14px; line-height: 1.6; }
.privacy-box.green { background: #E8F5E9; border: 1px solid #A5D6A7; }
.privacy-box.yellow { background: #FFF8E1; border: 1px solid #FFE082; }
.privacy-table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 13px; }
.privacy-table th, .privacy-table td { padding: 8px 12px; border: 1px solid var(--border); text-align: left; }
.privacy-table th { background: var(--accent); color: #FFF; }

/* ═══ SETTINGS ═══ */
.settings-section { margin-bottom: 24px; }
.settings-section h3 { margin-bottom: 12px; }

/* ═══ HELPERS ═══ */
.text-muted { color: var(--muted); font-size: 13px; }
.text-dep { color: var(--dep); } .text-hap { color: var(--hap); } .text-hyp { color: var(--hyp); }
.text-pos { color: var(--pos); } .text-neg { color: var(--neg); }
.flex { display: flex; } .flex-wrap { flex-wrap: wrap; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; }

/* ═══ ANIMATIONS ═══ */
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }

/* ═══ DONATE ═══ */
.nav-donate { font-size: 11.5px; color: #B8524E; font-weight: 700; padding: 6px 12px; border: 1.5px solid #B8524E; border-radius: 20px; white-space: nowrap; transition: all 0.15s; }
.nav-donate:hover { background: #B8524E; color: #FFF; text-decoration: none; }
.btn-donate { background: #B8524E; color: #FFF; }
.btn-donate:hover { background: #9E413D; }
.welcome-donate { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; gap: 10px; }
.welcome-donate span { font-size: 12.5px; color: var(--muted); }

/* Floating tooltip for truncated chart axis labels */
.axis-tip { position: fixed; z-index: 9999; pointer-events: none; display: none; background: var(--text); color: #FFF; font-family: var(--body); font-size: 12px; font-weight: 500; padding: 6px 10px; border-radius: 6px; max-width: 280px; box-shadow: 0 4px 14px rgba(0,0,0,0.25); }

/* ═══ RESPONSIVE ═══ */
@media (max-width: 640px) {
  .nav { padding: 0 12px; gap: 8px; }
  .nav-privacy { display: none; }
  .nav-donate { padding: 5px 10px; }
  .welcome-card h1 { font-size: 32px; }
  .entry-grid { grid-template-columns: 1fr; }
  .stat { flex: 1 1 120px; min-width: 120px; }
  .stat-value { font-size: 22px; }
}
