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

:root {
  --rose: #c27b6e;
  --rose-light: #f5e8e5;
  --rose-dark: #9e5f53;
  --sage: #7a9e8a;
  --sage-light: #e8f0eb;
  --warm-bg: #faf8f5;
  --card-bg: #ffffff;
  --text: #2d2520;
  --text-2: #6b5e58;
  --text-3: #9e918b;
  --border: #e8e0db;
  --radius: 12px;
  --radius-sm: 8px;
  --tab-h: 52px;
  --header-h: 60px;
}

body.dark {
  --warm-bg: #1a1714;
  --card-bg: #252220;
  --text: #f0ebe7;
  --text-2: #c4b8b2;
  --text-3: #7a6e69;
  --border: #38302c;
  --rose-light: #3d2420;
  --sage-light: #1e2e26;
}

html, body { height: 100%; }
body {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  background: var(--warm-bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  transition: background 0.2s, color 0.2s;
}

#app { max-width: 480px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

.app-header {
  position: sticky; top: 0; z-index: 100;
  height: var(--header-h);
  background: var(--warm-bg);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
}
.header-left { display: flex; align-items: baseline; gap: 10px; }
.app-title { font-size: 20px; font-weight: 600; color: var(--rose-dark); letter-spacing: -0.3px; }
.header-date { font-size: 13px; color: var(--text-3); }
.header-right { display: flex; gap: 4px; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; background: none; cursor: pointer;
  color: var(--text-2); display: flex; align-items: center; justify-content: center;
}
.icon-btn:active { background: var(--rose-light); }

.cycle-banner {
  background: linear-gradient(135deg, #c27b6e 0%, #a8856e 100%);
  color: white; padding: 14px 16px;
  display: flex; align-items: center; flex-wrap: wrap; gap: 0; row-gap: 8px;
}
.cycle-info { flex: 1; min-width: 70px; }
.cycle-label { display: block; font-size: 10px; opacity: 0.8; text-transform: uppercase; letter-spacing: 0.5px; }
.cycle-day { font-size: 26px; font-weight: 600; line-height: 1.1; }
.cycle-val { font-size: 14px; font-weight: 500; }
.log-period-btn {
  background: rgba(255,255,255,0.2); color: white;
  border: 1px solid rgba(255,255,255,0.4); border-radius: 20px;
  padding: 6px 14px; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.log-period-btn:active { background: rgba(255,255,255,0.35); }

.tab-bar {
  display: flex; background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky; top: var(--header-h); z-index: 90;
}
.tab {
  flex: 1; height: var(--tab-h); border: none; background: none;
  font-size: 14px; color: var(--text-3); cursor: pointer;
  position: relative; font-weight: 500;
}
.tab.active { color: var(--rose); }
.tab.active::after {
  content: ''; position: absolute; bottom: 0; left: 16px; right: 16px;
  height: 2px; background: var(--rose); border-radius: 2px 2px 0 0;
}

.tab-content { display: none; padding: 16px 16px 80px; flex-direction: column; gap: 12px; }
.tab-content.active { display: flex; }

.section-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; border: 1px solid var(--border);
}
.section-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 12px; }
.card-desc { font-size: 13px; color: var(--text-3); margin-bottom: 12px; }

.prediction-card { border-left: 3px solid var(--rose); }

.mood-row { display: flex; justify-content: space-between; }
.mood-btn {
  width: 48px; height: 48px; border-radius: 50%;
  border: 2px solid transparent; background: var(--warm-bg);
  font-size: 24px; cursor: pointer;
}
.mood-btn.active { border-color: var(--rose); transform: scale(1.12); }

.rating-row { display: flex; gap: 8px; margin-bottom: 4px; }
.rating-btn {
  flex: 1; height: 40px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-size: 15px; font-weight: 500; color: var(--text-2); cursor: pointer;
}
.rating-btn.active { background: var(--rose); border-color: var(--rose); color: white; }
.rating-label { font-size: 11px; color: var(--text-3); }

.chip-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 7px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--warm-bg);
  font-size: 13px; color: var(--text-2); cursor: pointer;
}
.chip.active { background: var(--rose); border-color: var(--rose); color: white; }

.mag-note { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--border); }
.mag-label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.mag-options { display: flex; gap: 8px; flex-wrap: wrap; }
.mag-btn {
  padding: 6px 12px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--sage-light);
  font-size: 13px; color: var(--sage); cursor: pointer;
}
.mag-btn.active { background: var(--sage); border-color: var(--sage); color: white; }

.notes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.note-label { display: block; font-size: 12px; color: var(--text-3); margin-bottom: 4px; }
.note-select {
  width: 100%; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-size: 13px; color: var(--text); appearance: none; -webkit-appearance: none;
}
.notes-text {
  width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--warm-bg); padding: 10px 12px; font-size: 14px;
  color: var(--text); resize: none; font-family: inherit;
}
.notes-text:focus, .note-select:focus { outline: 2px solid var(--rose); outline-offset: -1px; }

.save-btn {
  width: 100%; height: 48px; border-radius: var(--radius); border: none;
  background: var(--rose); color: white; font-size: 16px; font-weight: 600;
  cursor: pointer; margin-top: 4px;
}
.save-btn:active { background: var(--rose-dark); }
.save-status { text-align: center; font-size: 13px; color: var(--sage); margin-top: 6px; height: 18px; }

.field-label { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; }
.field-label.mt, .save-btn.mt { margin-top: 14px; }
.mt { margin-top: 14px; }

.date-input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-size: 15px; color: var(--text); font-family: inherit;
}
.date-input:focus { outline: 2px solid var(--rose); outline-offset: -1px; }

/* Prediction */
.prediction-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pred-item { background: var(--warm-bg); border-radius: var(--radius-sm); padding: 10px 12px; }
.pred-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 4px; }
.pred-val { font-size: 16px; font-weight: 600; color: var(--rose-dark); }
.pred-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* Cycle history */
.cycle-history-list, .mag-log-list { display: flex; flex-direction: column; gap: 8px; }
.cycle-entry {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; background: var(--warm-bg);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.cycle-entry-date { font-size: 14px; font-weight: 500; }
.cycle-entry-meta { font-size: 12px; color: var(--text-3); }
.cycle-entry-flow {
  font-size: 12px; padding: 3px 10px; border-radius: 12px;
  background: var(--rose-light); color: var(--rose-dark);
}
.entry-delete { border: none; background: none; cursor: pointer; color: var(--text-3); font-size: 18px; padding: 2px 6px; }

.mag-log-entry {
  padding: 10px 12px; background: var(--warm-bg);
  border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: 13px;
}
.mag-dose { font-weight: 600; color: var(--sage); }
.mag-result { color: var(--text-2); }
.mag-result.migraine { color: #c0392b; }
.mag-result.fine { color: var(--sage); }
.mag-entry-form { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }

.checklist { display: flex; flex-direction: column; gap: 10px; }
.check-item { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text); cursor: pointer; }
.check-item input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--rose); cursor: pointer; flex-shrink: 0; }

.mini-chart { display: flex; align-items: flex-end; gap: 4px; height: 60px; }
.mini-bar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px; }
.mini-bar { width: 100%; background: var(--border); border-radius: 3px 3px 0 0; min-height: 4px; }
.mini-bar.filled { background: var(--rose); }
.mini-bar-label { font-size: 9px; color: var(--text-3); }

.trend-list { display: flex; flex-direction: column; gap: 8px; }
.trend-row { display: flex; align-items: center; gap: 10px; }
.trend-name { font-size: 13px; color: var(--text-2); min-width: 130px; }
.trend-bar-bg { flex: 1; height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; }
.trend-bar-fill { height: 100%; border-radius: 4px; background: var(--rose); }
.trend-pct { font-size: 12px; color: var(--text-3); min-width: 32px; text-align: right; }

/* Settings */
.settings-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  z-index: 300; display: flex; align-items: flex-end; justify-content: center;
}
.settings-overlay.hidden { display: none; }
.settings-panel {
  background: var(--card-bg); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 480px; max-height: 85vh;
  overflow-y: auto; padding: 0 0 40px;
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 14px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--card-bg); z-index: 1;
}
.settings-title { font-size: 17px; font-weight: 600; }
.settings-section { padding: 16px; border-bottom: 1px solid var(--border); }
.settings-group-title { font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-3); margin-bottom: 12px; }
.settings-row { display: flex; align-items: center; justify-content: space-between; min-height: 36px; }
.settings-label { font-size: 15px; color: var(--text); }
.settings-input-wrap { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--text-2); }
.settings-input {
  width: 56px; padding: 6px 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-size: 15px; color: var(--text); text-align: center;
}
.settings-action-btn {
  width: 100%; padding: 13px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--warm-bg);
  font-size: 15px; color: var(--text); cursor: pointer;
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.settings-action-btn.danger { color: #c0392b; border-color: #f5c6c6; background: #fff5f5; }
body.dark .settings-action-btn.danger { background: #2d1a1a; border-color: #5a2a2a; color: #e07070; }
.settings-hint { font-size: 12px; color: var(--text-3); line-height: 1.5; margin-top: 4px; }

/* Toggle */
.toggle-btn {
  width: 48px; height: 28px; border-radius: 14px;
  background: var(--border); border: none; cursor: pointer;
  position: relative; transition: background 0.2s;
}
.toggle-btn[aria-checked="true"] { background: var(--rose); }
.toggle-knob {
  position: absolute; top: 3px; left: 3px;
  width: 22px; height: 22px; border-radius: 50%;
  background: white; transition: transform 0.2s;
}
.toggle-btn[aria-checked="true"] .toggle-knob { transform: translateX(20px); }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: flex-end; justify-content: center; z-index: 200;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--card-bg); border-radius: 20px 20px 0 0;
  padding: 20px 20px 32px; width: 100%; max-width: 480px;
}
.modal-title { font-size: 17px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; }
.cancel-btn {
  flex: 1; height: 48px; border-radius: var(--radius);
  border: 1px solid var(--border); background: none;
  font-size: 16px; color: var(--text-2); cursor: pointer;
}
.modal-actions .save-btn { flex: 1; margin-top: 0; }

.empty-msg { font-size: 13px; color: var(--text-3); font-style: italic; }
