:root {
  --blue-700: #185f9f;
  --blue-600: #2f86c8;
  --blue-500: #59a8df;
  --blue-400: #78b9e8;
  --blue-200: #cfe8f8;
  --blue-100: #eaf5fc;
  --blue-050: #f5faff;
  --navy: #173456;
  --text: #1f3349;
  --muted: #71849a;
  --line: #dce8f1;
  --surface: #ffffff;
  --page: #f6f9fc;
  --danger: #d75656;
  --shadow: 0 8px 26px rgba(38, 91, 131, .08);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { background: var(--page); }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -120px, #e2f3ff 0, transparent 340px),
    var(--page);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP",
    "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 13px 14px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--blue-400);
  box-shadow: 0 0 0 3px rgba(89, 168, 223, .14);
}
textarea { resize: vertical; }
h1, h2, p { margin-top: 0; }
h1 { font-size: 1.75rem; color: var(--navy); letter-spacing: -.02em; }
h2 { font-size: 1.08rem; color: var(--navy); }
small, .muted { color: var(--muted); }

.app-shell { min-height: 100dvh; padding-bottom: 78px; }
.app-header {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(20px, env(safe-area-inset-left));
  border-bottom: 1px solid rgba(220,232,241,.8);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { font-weight: 800; color: var(--navy); }
.header-link { color: var(--blue-600); font-weight: 700; font-size: .9rem; }

.main-content { width: 100%; }
.page {
  width: min(100% - 28px, 720px);
  margin: 0 auto;
  padding: 26px 0 36px;
}
.narrow-page { max-width: 560px; }
.researcher-page { max-width: 980px; }
.page-heading, .section-head, .calendar-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.page-heading { margin-bottom: 18px; }
.page-heading h1 { margin-bottom: 0; }
.eyebrow {
  color: var(--blue-700);
  font-weight: 700;
  font-size: .84rem;
  margin-bottom: 4px;
}
.eyebrow a { color: var(--blue-600); }

.card, .settings-card {
  background: var(--surface);
  border: 1px solid rgba(220,232,241,.9);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card { padding: 18px; margin-bottom: 14px; }
.card h2 { margin-bottom: 16px; }
.group-title { margin: 22px 4px 9px; font-size: 1rem; }

.field-row {
  display: grid;
  grid-template-columns: 1fr minmax(130px, 170px);
  gap: 14px;
  align-items: center;
  margin-bottom: 20px;
}
.field-block { margin-bottom: 20px; }
.field-label {
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 9px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.field-row .field-label { margin-bottom: 0; }
.line-icon { color: var(--blue-600); min-width: 18px; text-align: center; }
.optional { font-weight: 500; color: var(--muted); font-size: .8rem; }
.temperature-input { display: flex; align-items: center; gap: 8px; }
.temperature-input input { font-size: 1.25rem; font-weight: 700; }
.temperature-input span { font-weight: 700; color: var(--navy); }

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
}
.segmented input,
.chip-grid input,
.severity-selector input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.segmented label,
.chip-grid label,
.severity-selector label {
  border: 1px solid transparent;
  background: var(--blue-050);
  color: var(--text);
  border-radius: 13px;
  text-align: center;
  padding: 11px 8px;
  font-weight: 650;
  cursor: pointer;
}
.segmented input:checked + label,
.chip-grid input:checked + label,
.severity-selector input:checked + label {
  background: var(--blue-200);
  color: var(--blue-700);
  border-color: var(--blue-400);
  box-shadow: inset 0 0 0 1px rgba(47,134,200,.08);
}
.chip-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.chip-grid label { font-size: .9rem; }

.severity-selector {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}
.severity-selector label { border-radius: 12px; padding: 12px 4px; }
.severity-selector input:checked + label {
  color: #fff;
  background: var(--blue-500);
  border-color: var(--blue-500);
}
.severity-scale {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: .77rem;
  margin-top: 5px;
}

.btn {
  border: 0;
  border-radius: 13px;
  min-height: 46px;
  padding: 11px 17px;
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.btn-block { width: 100%; }
.btn-primary {
  color: white;
  background: linear-gradient(135deg, var(--blue-500), var(--blue-600));
  box-shadow: 0 6px 16px rgba(47,134,200,.17);
}
.btn-soft { color: var(--blue-700); background: var(--blue-100); }
.btn-ghost { color: var(--blue-700); background: transparent; border: 1px solid var(--blue-200); }
.btn-danger-ghost {
  color: var(--danger);
  background: #fff;
  border: 1px solid #efcaca;
  margin-top: 18px;
}
.round-icon-button {
  width: 42px; height: 42px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--blue-700);
  background: #fff;
  border: 1px solid var(--blue-200);
  font-size: 1.3rem;
}
.text-link { color: var(--blue-600); font-weight: 700; }

.section-head h2 { margin: 0; }
.section-head { margin-bottom: 12px; }
.list-title {
  margin: 16px 0 5px;
  font-weight: 700;
  font-size: .9rem;
  color: var(--navy);
}
.record-list { border-top: 1px solid var(--line); }
.record-row {
  display: grid;
  grid-template-columns: 52px 1fr auto 16px;
  gap: 9px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  font-size: .9rem;
}
.record-row:last-child { border-bottom: 0; }
.record-row .time { font-variant-numeric: tabular-nums; color: var(--navy); }
.record-main { font-weight: 700; }
.chevron { color: var(--muted); font-size: 1.35rem; }
.empty-state {
  color: var(--muted);
  background: var(--blue-050);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 0;
  text-align: center;
}

/* Calendar */
.calendar-title-row { margin-bottom: 15px; }
.calendar-title-row h1 { margin: 0; font-size: 1.4rem; }
.calendar-card { padding: 13px; }
.weekday-row, .month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.weekday-row span {
  text-align: center;
  font-size: .75rem;
  color: var(--muted);
  padding: 5px 0;
}
.calendar-day {
  min-height: 55px;
  border-radius: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid transparent;
}
.calendar-day:hover { background: var(--blue-050); }
.calendar-day.outside { opacity: .32; }
.calendar-day.selected {
  background: var(--blue-100);
  border-color: var(--blue-400);
}
.day-number { font-weight: 650; font-size: .9rem; }
.calendar-dots { min-height: 6px; display: flex; gap: 3px; }
.dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--blue-600);
}
.dot.daily { background: #a7cfea; }
.dot.menstruation { background: var(--blue-700); }
.dot.symptom { background: var(--blue-500); }
.calendar-legend {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 11px;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 13px;
  color: var(--muted);
  font-size: .72rem;
}
.calendar-legend span { display: flex; align-items: center; gap: 5px; }

.summary-list > div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 12px 0;
}
.summary-list > div:last-child { border-bottom: 0; }
.summary-list span { color: var(--muted); }
.summary-list strong { text-align: right; font-weight: 650; }

/* Settings */
.settings-card { overflow: hidden; }
.setting-row {
  min-height: 66px;
  padding: 12px 16px;
  display: grid;
  grid-template-columns: 32px 1fr auto;
  gap: 11px;
  align-items: center;
  border-bottom: 1px solid var(--line);
}
.setting-row:last-child { border-bottom: 0; }
.setting-row > span:first-child:not(.setting-icon) { grid-column: 1 / 3; }
.setting-row div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.setting-row strong { font-size: .92rem; overflow-wrap: anywhere; }
.setting-icon { color: var(--blue-600); font-size: 1.2rem; text-align: center; }
.setting-row.disabled { opacity: .55; }

/* Auth */
.auth-wrap {
  min-height: 100dvh;
  width: min(100% - 28px, 440px);
  margin: 0 auto;
  display: grid;
  place-items: center;
  padding: 32px 0;
}
.auth-card {
  width: 100%;
  background: white;
  padding: 28px;
  border-radius: 24px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-card h1 { margin-bottom: 5px; }
.auth-mark {
  margin: 0 auto 15px;
  width: 54px; height: 54px; border-radius: 18px;
  background: var(--blue-100);
  color: var(--blue-600);
  display: grid; place-items: center;
  font-size: 2rem;
}
.stack-form { display: grid; gap: 15px; text-align: left; margin-top: 22px; }
.stack-form label > span { display: block; font-weight: 700; margin-bottom: 7px; }
.stack-form small { display: block; font-size: .76rem; margin-top: 5px; }
.auth-footer { margin-top: 20px; display: flex; gap: 8px; justify-content: center; font-size: .9rem; }
.auth-footer a { color: var(--blue-600); font-weight: 700; }

.form-errors, .errorlist {
  color: #a84040;
  background: #fff4f4;
  border-radius: 10px;
  padding: 9px 11px;
  list-style: none;
  margin: 7px 0;
  font-size: .84rem;
}

/* Modal bottom sheet */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(17,38,59,.38);
  z-index: 100;
  display: none;
  align-items: flex-end;
  justify-content: center;
}
.modal-backdrop.show { display: flex; }
.sheet-modal {
  width: min(100%, 560px);
  max-height: 92dvh;
  overflow-y: auto;
  background: white;
  border-radius: 24px 24px 0 0;
  padding: 9px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 40px rgba(23,52,86,.18);
}
.sheet-handle {
  width: 42px; height: 5px;
  background: #cad8e4;
  border-radius: 4px;
  margin: 0 auto 12px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h2 { margin: 0; font-size: 1.3rem; }
.icon-close {
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: var(--blue-050);
  color: var(--navy);
  font-size: 1.4rem;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(100%, 600px);
  height: calc(68px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  z-index: 50;
}
.bottom-nav a {
  color: #7d8c9a;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: .73rem;
  font-weight: 650;
}
.bottom-nav a.active { color: var(--blue-600); }
.nav-icon { font-size: 1.35rem; line-height: 1; }

/* Messages */
.flash-stack {
  position: fixed;
  top: 68px;
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 28px), 520px);
  z-index: 80;
}
.flash {
  background: #eff9ff;
  border: 1px solid var(--blue-200);
  color: var(--blue-700);
  padding: 11px 14px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}

/* Research */
.export-buttons { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; white-space: nowrap; }
.data-table th, .data-table td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; }
.data-table th { color: var(--muted); font-size: .78rem; }
.data-table td { font-size: .9rem; }
.table-card { padding: 0; overflow: hidden; }

@media (min-width: 700px) {
  .app-shell { padding-bottom: 0; }
  .bottom-nav {
    width: 420px;
    left: 50%;
    bottom: 14px;
    height: 62px;
    padding-bottom: 0;
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
  }
  .page { padding-bottom: 100px; }
}

@media (max-width: 420px) {
  .page { width: min(100% - 20px, 560px); padding-top: 18px; }
  h1 { font-size: 1.5rem; }
  .card { padding: 15px; border-radius: 17px; }
  .field-row { grid-template-columns: 1fr 145px; }
  .chip-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .chip-grid label { font-size: .82rem; padding: 10px 5px; }
  .record-row { grid-template-columns: 47px 1fr auto 13px; font-size: .82rem; }
}
