:root {
  --primary: #4A6CF7;
  --primary-dark: #3451c7;
  --bg: #0f1117;
  --bg2: #1a1d2e;
  --bg3: #242842;
  --card: #1e2235;
  --text: #e4e6f0;
  --text-dim: #8a8ea8;
  --accent-green: #34d399;
  --accent-red: #f87171;
  --accent-orange: #fb923c;
  --accent-purple: #a78bfa;
  --accent-cyan: #22d3ee;
  --accent-pink: #f472b6;
  --accent-yellow: #fbbf24;
  --border: #2d3154;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  overscroll-behavior: none;
}

/* ===== FIX #12 — PERSISTENT SAVE ERROR BANNER ===== */
.save-error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 16px 20px;
  background: rgba(248, 113, 113, .95);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  z-index: 9000;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  letter-spacing: 0.3px;
  line-height: 1.4;
}

/* ===== FIX #17 — INSECURE CONTEXT WARNING ===== */
.insecure-warning {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 20px;
  background: rgba(248, 113, 113, .95);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  z-index: 99999;
}

/* ===== FIX #13 — PERSISTENCE WARNING BANNER ===== */
.persist-warning {
  padding: 8px 16px;
  background: rgba(251, 146, 60, .1);
  border-bottom: 1px solid rgba(251, 146, 60, .3);
  font-size: 12px;
  color: var(--accent-orange);
  text-align: center;
  cursor: pointer;
  transition: background .2s;
}
.persist-warning:hover {
  background: rgba(251, 146, 60, .18);
}

/* ===== LOCK SCREEN ===== */
.lock-screen {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lock-screen.hidden { display: none; }
.lock-logo { font-size: 64px; margin-bottom: 12px; cursor: pointer; user-select: none; }
.lock-title { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.lock-title span { color: var(--primary); }
.lock-tagline {
  font-size: 13px;
  color: var(--accent-cyan);
  margin-bottom: 8px;
  font-style: italic;
  min-height: 18px;
  text-align: center;
}
.lock-subtitle {
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 32px;
  text-align: center;
}
.lock-encrypted-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 20px;
  background: rgba(52, 211, 153, .1);
  color: var(--accent-green);
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 24px;
}
.lock-form { width: 100%; max-width: 340px; }
.lock-field { margin-bottom: 16px; }
.lock-field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 600;
}
.lock-field input {
  width: 100%;
  padding: 14px 18px;
  background: var(--bg3);
  border: 2px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  font-size: 16px;
  letter-spacing: 2px;
  text-align: center;
}
.lock-field input:focus { outline: none; border-color: var(--primary); }
.lock-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: all .2s;
}
.lock-btn:hover { background: var(--primary-dark); }
.lock-btn:disabled { opacity: .5; cursor: not-allowed; }
.lock-btn.secondary {
  background: var(--bg3);
  border: 1px solid var(--border);
  margin-top: 10px;
}
.lock-btn.secondary:hover { background: var(--border); }
.lock-btn.danger {
  background: rgba(248, 113, 113, .15);
  border: 1px solid rgba(248, 113, 113, .3);
  color: var(--accent-red);
  margin-top: 10px;
}
.lock-btn.danger:hover { background: rgba(248, 113, 113, .25); }
.lock-error {
  color: var(--accent-red);
  font-size: 13px;
  text-align: center;
  margin-top: 12px;
  min-height: 20px;
}
.lock-hint {
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  margin-top: 16px;
  line-height: 1.5;
}
.lock-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-dim);
  font-size: 12px;
}
.lock-divider::before,
.lock-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ===== FIX #3 — PASSKEY STRENGTH METER ===== */
.strength-meter {
  margin-bottom: 12px;
}
.strength-meter-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--bg3);
  margin-bottom: 4px;
  overflow: hidden;
}
.strength-meter-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: all .3s;
}
.strength-meter-label {
  font-size: 11px;
  font-weight: 600;
}

/* ===== BIOMETRIC ===== */
.bio-unlock-btn {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, rgba(74, 108, 247, .15), rgba(164, 139, 250, .15));
  border: 2px solid rgba(74, 108, 247, .4);
  border-radius: 16px;
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  transition: all .2s;
  margin-bottom: 8px;
}
.bio-unlock-btn:hover { border-color: var(--primary); background: rgba(74, 108, 247, .2); }
.bio-unlock-btn:active { transform: scale(0.98); }
.bio-unlock-btn .bio-icon { font-size: 32px; animation: bioPulse 2s ease-in-out infinite; }
@keyframes bioPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .7; transform: scale(1.05); }
}
.bio-prompt-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .6);
  z-index: 800;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 20px;
}
.bio-prompt-overlay.open { display: flex; }
.bio-prompt-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 24px 24px 20px 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 400px;
  text-align: center;
  animation: slideUp .3s ease;
}
@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.bio-prompt-icon { font-size: 56px; margin-bottom: 16px; }
.bio-prompt-title { font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.bio-prompt-desc { font-size: 14px; color: var(--text-dim); line-height: 1.5; margin-bottom: 24px; }
.bio-prompt-btns { display: flex; flex-direction: column; gap: 10px; }
.bio-prompt-enable {
  padding: 16px;
  background: var(--primary);
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.bio-prompt-skip {
  padding: 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 14px;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
}

/* ===== TOP NAV ===== */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.top-nav h1 { font-size: 20px; font-weight: 700; }
.top-nav h1 span { color: var(--primary); }
.top-nav-actions { display: flex; gap: 8px; }
.nav-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
  transition: all .2s;
}
.nav-btn:hover { background: var(--primary); border-color: var(--primary); }
.nav-btn.active { background: var(--primary); border-color: var(--primary); }
.nav-btn.bio-active { border-color: var(--accent-green); background: rgba(52, 211, 153, .1); }

/* ===== INSTALL BANNER ===== */
.install-banner {
  display: none;
  margin: 12px 16px;
  padding: 14px 18px;
  background: linear-gradient(135deg, rgba(74, 108, 247, .15), rgba(164, 139, 250, .1));
  border: 1px solid rgba(74, 108, 247, .3);
  border-radius: 14px;
  align-items: center;
  gap: 12px;
}
.install-banner.show { display: flex; }
.install-banner-text { flex: 1; font-size: 13px; }
.install-banner-text strong { display: block; margin-bottom: 2px; }
.install-banner-btn {
  padding: 8px 18px;
  border-radius: 10px;
  background: var(--primary);
  border: none;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.install-banner-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

/* ===== CALENDAR ===== */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px;
}
.cal-header h2 { font-size: 22px; font-weight: 600; }
.cal-nav { display: flex; gap: 8px; }
.cal-nav button {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.cal-nav button:hover { background: var(--primary); border-color: var(--primary); }
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 0 12px;
  margin-bottom: 8px;
}
.cal-weekdays span {
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 8px 0;
}
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 0 12px;
  gap: 4px;
}
.cal-day {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 14px;
  cursor: pointer;
  transition: all .2s;
  position: relative;
  font-size: 15px;
  font-weight: 500;
  border: 1px solid transparent;
}
.cal-day:hover { background: var(--bg3); }
.cal-day.other-month { color: var(--text-dim); opacity: .3; }
.cal-day.today {
  border-color: var(--primary);
  background: rgba(74, 108, 247, .15);
  color: var(--primary);
  font-weight: 700;
}
.cal-day.has-data::after {
  content: '';
  position: absolute;
  bottom: 6px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-green);
}
.cal-day.period-day {
  background: rgba(244, 114, 182, .12);
  border-color: rgba(244, 114, 182, .3);
}
.cal-day.period-day::before {
  content: '';
  position: absolute;
  top: 5px;
  right: 5px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent-pink);
}
.cal-day.selected { background: var(--primary); color: #fff; }
.cal-day.selected::after { background: #fff; }
.cal-day.selected.period-day::before { background: #fff; }

/* ===== VIEWS ===== */
.view { display: none; }
.view.active { display: block; }

/* ===== DAY DETAIL ===== */
.day-detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .3s ease;
}
.day-detail.open { transform: translateX(0); }
.day-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.back-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.day-detail-header h2 { font-size: 18px; font-weight: 600; flex: 1; }

/* ===== SECTIONS ===== */
.section {
  margin: 16px;
  padding: 20px;
  background: var(--card);
  border-radius: 16px;
  border: 1px solid var(--border);
}
.section.period-section {
  border-color: rgba(244, 114, 182, .3);
  background: linear-gradient(135deg, var(--card), rgba(244, 114, 182, .05));
}
.section-title {
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ===== PHOTOS ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 12px;
}
.photo-thumb {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; }
.photo-thumb .delete-photo {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(248, 113, 113, .9);
  border: none;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.upload-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: 2px dashed var(--border);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all .2s;
}
.upload-btn:hover { border-color: var(--primary); background: rgba(74, 108, 247, .1); }

/* ===== FILES ===== */
.file-category-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 12px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238a8ea8'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}
.file-list { margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  background: var(--bg3);
  border-radius: 10px;
  border: 1px solid var(--border);
}
.file-item .file-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.file-item .file-info { flex: 1; min-width: 0; }
.file-item .file-name {
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-item .file-cat { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.file-item .file-del {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: rgba(248, 113, 113, .15);
  border: none;
  color: var(--accent-red);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== HEALTH ===== */
.health-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.health-field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  font-weight: 600;
}
.health-field input,
.health-field textarea,
.health-field select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.health-field input:focus,
.health-field textarea:focus,
.health-field select:focus { outline: none; border-color: var(--primary); }
.health-field.full-width { grid-column: 1 / -1; }
.health-field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238a8ea8'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.health-field input[readonly] { opacity: .75; cursor: default; }
.health-entry-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  position: relative;
}
.health-entry-card .hec-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--accent-cyan);
  margin-bottom: 4px;
  padding-right: 70px;
}
.health-entry-card .hec-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.health-entry-card .hec-bmi {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}
.hec-bmi-standard { font-size: 10px; opacity: .7; font-weight: 400; }
.health-entry-card .hec-vitals { display: flex; flex-wrap: wrap; gap: 8px 14px; font-size: 13px; }
.health-entry-card .hec-vitals span { color: var(--text-dim); }
.health-entry-card .hec-vitals strong { color: var(--text); font-weight: 500; }
.health-entry-card .hec-actions { position: absolute; top: 12px; right: 12px; display: flex; gap: 6px; }
.health-entry-card .hec-actions button {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .2s;
}
.hec-edit { background: rgba(74, 108, 247, .15); color: var(--primary); }
.hec-edit:hover { background: rgba(74, 108, 247, .3); }
.hec-del { background: rgba(248, 113, 113, .15); color: var(--accent-red); }
.hec-del:hover { background: rgba(248, 113, 113, .3); }
.health-form-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg);
  border-radius: 8px;
}
.health-form-label.editing {
  color: var(--primary);
  background: rgba(74, 108, 247, .08);
  border: 1px solid rgba(74, 108, 247, .2);
}
.health-form-btns { display: flex; gap: 8px; margin-top: 14px; }
.health-add-btn {
  flex: 1;
  padding: 12px;
  background: var(--primary);
  border: none;
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.health-add-btn:hover { background: var(--primary-dark); }
.health-cancel-btn {
  padding: 12px 20px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: all .2s;
}
.health-cancel-btn:hover { background: var(--border); }
.health-entries-empty {
  text-align: center;
  padding: 16px;
  color: var(--text-dim);
  font-size: 13px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  margin-bottom: 14px;
}
.person-info-line {
  padding: 10px 14px;
  background: rgba(34, 211, 238, .06);
  border: 1px solid rgba(34, 211, 238, .2);
  border-radius: 10px;
  font-size: 13px;
  color: var(--accent-cyan);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.new-person-fields { margin-bottom: 12px; }
.missing-info-fields {
  margin-bottom: 12px;
  padding: 12px;
  background: rgba(34, 211, 238, .04);
  border: 1px dashed rgba(34, 211, 238, .2);
  border-radius: 10px;
}
.missing-info-fields .mif-title {
  font-size: 12px;
  color: var(--accent-cyan);
  font-weight: 600;
  margin-bottom: 10px;
}
.missing-info-fields .mif-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.missing-info-fields label {
  display: block;
  font-size: 12px;
  color: var(--accent-cyan);
  margin-bottom: 6px;
  font-weight: 600;
}
.missing-info-fields input,
.missing-info-fields select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid rgba(34, 211, 238, .25);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2322d3ee'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.missing-info-fields input { background-image: none; }
.missing-info-fields input:focus,
.missing-info-fields select:focus { outline: none; border-color: var(--accent-cyan); }

/* ===== PERIOD TRACKER ===== */
.period-toggle { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.toggle-switch { position: relative; width: 50px; height: 28px; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 28px;
  transition: all .3s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--text-dim);
  left: 2px;
  top: 2px;
  transition: all .3s;
}
.toggle-switch input:checked + .toggle-slider {
  background: rgba(244, 114, 182, .3);
  border-color: var(--accent-pink);
}
.toggle-switch input:checked + .toggle-slider::before {
  background: var(--accent-pink);
  transform: translateX(22px);
}
.period-toggle-label { font-size: 14px; font-weight: 500; }
.period-fields { display: none; margin-top: 4px; }
.period-fields.visible { display: block; }
.period-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.period-field label {
  display: block;
  font-size: 12px;
  color: var(--accent-pink);
  margin-bottom: 6px;
  font-weight: 600;
}
.period-field input,
.period-field select,
.period-field textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg3);
  border: 1px solid rgba(244, 114, 182, .25);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.period-field input:focus,
.period-field textarea:focus { outline: none; border-color: var(--accent-pink); }
.period-field textarea { resize: vertical; min-height: 70px; font-size: 13px; line-height: 1.5; }
.period-field select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%23f472b6'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.period-symptoms { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.symptom-chip {
  padding: 6px 14px;
  border-radius: 20px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
  transition: all .2s;
  user-select: none;
}
.symptom-chip.active {
  background: rgba(244, 114, 182, .2);
  border-color: var(--accent-pink);
  color: var(--accent-pink);
}

/* ===== NOTES ===== */
.note-area {
  width: 100%;
  min-height: 100px;
  padding: 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
  line-height: 1.6;
}
.note-area:focus { outline: none; border-color: var(--primary); }

/* ===== SAVE BUTTON ===== */
.save-btn {
  width: calc(100% - 32px);
  margin: 16px;
  padding: 16px;
  background: var(--primary);
  border: none;
  border-radius: 14px;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.save-btn:hover { background: var(--primary-dark); }

/* ===== DAY SUMMARY ===== */
.day-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 16px; }
.summary-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}
.summary-card .sc-num { font-size: 20px; font-weight: 700; }
.summary-card .sc-label {
  font-size: 9px;
  color: var(--text-dim);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ===== CATEGORIES ===== */
.cat-main-list { padding: 16px; }
.cat-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all .2s;
}
.cat-card:hover { border-color: var(--primary); }
.cat-card:active { transform: scale(0.98); }
.cat-card-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  flex-shrink: 0;
}
.cat-card-info { flex: 1; }
.cat-card-name { font-size: 15px; font-weight: 600; }
.cat-card-count { font-size: 12px; color: var(--text-dim); margin-top: 3px; }
.cat-card-arrow { color: var(--text-dim); font-size: 18px; }
.cat-detail {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 200;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .3s ease;
}
.cat-detail.open { transform: translateX(0); }
.cat-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.cat-detail-header h2 { font-size: 18px; font-weight: 600; flex: 1; }
.cat-file-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: all .2s;
}
.cat-file-item:hover { border-color: var(--primary); }
.cat-file-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.cat-file-info { flex: 1; min-width: 0; }
.cat-file-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cat-file-date { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.cat-file-download {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(74, 108, 247, .15);
  border: none;
  color: var(--primary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-dim); }
.empty-state .empty-icon { font-size: 56px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.empty-state p { font-size: 14px; line-height: 1.5; }

/* ===== PERIOD TIMELINE ===== */
.period-timeline-card {
  background: var(--card);
  border: 1px solid rgba(244, 114, 182, .25);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all .2s;
}
.period-timeline-card:hover { border-color: var(--accent-pink); }
.period-timeline-card .ptc-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.period-timeline-card .ptc-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  background: rgba(244, 114, 182, .15);
  color: var(--accent-pink);
}
.period-timeline-card .ptc-date { font-size: 13px; color: var(--primary); font-weight: 600; }
.period-timeline-card .ptc-details {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
  margin-bottom: 8px;
}
.period-timeline-card .ptc-details span { color: var(--text-dim); }
.period-timeline-card .ptc-details strong { color: var(--text); }
.period-timeline-card .ptc-symptoms { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.period-timeline-card .ptc-symptoms .chip {
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  background: rgba(244, 114, 182, .1);
  color: var(--accent-pink);
}
.period-timeline-card .ptc-notes {
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-dim);
  font-style: italic;
  line-height: 1.4;
  border-left: 2px solid rgba(244, 114, 182, .3);
  padding-left: 10px;
}

/* ===== PHOTO MODAL ===== */
.photo-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .95);
  z-index: 300;
  display: none;
  align-items: center;
  justify-content: center;
}
.photo-modal.open { display: flex; }
.photo-modal img { max-width: 95%; max-height: 90vh; border-radius: 8px; }
.photo-modal .close-modal {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
  border: none;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
}

/* ===== MODALS ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .7);
  z-index: 600;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-box h3 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.modal-box .modal-desc { font-size: 13px; color: var(--text-dim); margin-bottom: 20px; line-height: 1.5; }
.modal-option {
  padding: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all .2s;
}
.modal-option:hover { border-color: var(--primary); background: rgba(74, 108, 247, .05); }
.modal-option .mo-icon { font-size: 28px; margin-bottom: 8px; }
.modal-option .mo-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.modal-option .mo-desc { font-size: 12px; color: var(--text-dim); line-height: 1.4; }
.modal-option .mo-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  margin-top: 6px;
}
.mo-badge.safe { background: rgba(52, 211, 153, .15); color: var(--accent-green); }
.mo-badge.warn { background: rgba(251, 146, 60, .15); color: var(--accent-orange); }
.import-status {
  margin-top: 16px;
  padding: 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
  display: none;
}
.import-status.success {
  display: block;
  background: rgba(52, 211, 153, .1);
  border: 1px solid rgba(52, 211, 153, .3);
  color: var(--accent-green);
}
.import-status.error {
  display: block;
  background: rgba(248, 113, 113, .1);
  border: 1px solid rgba(248, 113, 113, .3);
  color: var(--accent-red);
}
.import-status.info {
  display: block;
  background: rgba(74, 108, 247, .1);
  border: 1px solid rgba(74, 108, 247, .3);
  color: var(--primary);
}
.import-passkey-form { margin-top: 16px; display: none; }
.import-passkey-form.visible { display: block; }
.import-passkey-form input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg3);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
  letter-spacing: 2px;
  text-align: center;
  margin-bottom: 12px;
}
.import-passkey-form input:focus { outline: none; border-color: var(--primary); }

/* ===== SETTINGS ===== */
.settings-field { margin-bottom: 18px; }
.settings-field label {
  display: block;
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 600;
}
.settings-field input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 15px;
}
.settings-field input:focus { outline: none; border-color: var(--primary); }
.settings-preview {
  text-align: center;
  padding: 20px;
  background: var(--bg);
  border-radius: 14px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}
.settings-preview .sp-icon { font-size: 48px; margin-bottom: 8px; }
.settings-preview .sp-title { font-size: 20px; font-weight: 700; }
.settings-preview .sp-title span { color: var(--primary); }
.settings-preview .sp-tag { font-size: 12px; color: var(--accent-cyan); margin-top: 4px; font-style: italic; }
.settings-section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  margin: 24px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.settings-bio-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 16px;
}
.settings-bio-row .toggle-switch input:checked + .toggle-slider {
  background: rgba(52, 211, 153, .3);
  border-color: var(--accent-green);
}
.settings-bio-row .toggle-switch input:checked + .toggle-slider::before {
  background: var(--accent-green);
  transform: translateX(22px);
}

/* ===== CHARTS ===== */
.chart-controls {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
}
.chart-controls label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
}
.chart-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 14px;
  margin-bottom: 16px;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238a8ea8'%3E%3Cpath d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 16px center;
}
.metric-chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.metric-chip {
  padding: 8px 14px;
  border-radius: 20px;
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.metric-chip.active { font-weight: 600; }
.metric-chip .mc-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background .2s;
}
.chart-btn {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  border: none;
  border-radius: 12px;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
}
.chart-btn:hover { background: var(--primary-dark); }
.chart-btn:disabled { opacity: .4; cursor: not-allowed; }
.chart-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  overflow: hidden;
}
.chart-container canvas { width: 100%; border-radius: 8px; }
.chart-info {
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
}
.chart-legend { display: flex; justify-content: center; gap: 24px; margin-top: 12px; }
.chart-legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; }
.chart-legend-dot { width: 12px; height: 12px; border-radius: 50%; }
.chart-legend-label { font-size: 12px; color: var(--text); }
.chart-axis-hint {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 6px;
  padding: 0 4px;
}

/* ===== BOTTOM NAV ===== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 8px 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  z-index: 100;
}
.bottom-nav button {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 10px;
  padding: 8px 0;
  cursor: pointer;
  transition: all .2s;
}
.bottom-nav button .bnav-icon { font-size: 22px; }
.bottom-nav button.active { color: var(--primary); }
.main-content { padding-bottom: 80px; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent-green);
  color: #000;
  padding: 12px 24px;
  border-radius: 25px;
  font-size: 14px;
  font-weight: 600;
  z-index: 700;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  white-space: nowrap;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 360px) {
  .day-summary { grid-template-columns: repeat(2, 1fr); }
  .health-grid { grid-template-columns: 1fr; }
  .period-dates { grid-template-columns: 1fr; }
  .missing-info-fields .mif-grid { grid-template-columns: 1fr; }
}