:root {
  --bg: #FAF7F5;
  --surface: #FFFFFF;
  --text: #2B2530;
  --muted: #7A7280;
  --line: #ECE6E3;
  --accent: #6D5BB0;
  --danger: #B3404A;

  --menstrual: #D9646F;
  --menstrual-bg: #F9DDE0;
  --follicular: #4E9C83;
  --follicular-bg: #DCEFE8;
  --ovulation: #D8962C;
  --ovulation-bg: #FBEBCF;
  --luteal: #8473BE;
  --luteal-bg: #E6E1F4;

  --radius: 16px;
  --tabbar-h: 58px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-top: 1rem; }
p { margin: .4rem 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

.view {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: 0 1px 2px rgba(43, 37, 48, .05);
}

/* ---- кнопки ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; margin-top: 16px; }
.link {
  background: none; border: 0; padding: 8px 0; min-height: 36px;
  color: var(--accent); font: inherit; cursor: pointer; text-align: left;
}
.link.danger { color: var(--danger); }
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px;
  background: transparent; font-size: 1.6rem; color: var(--text); cursor: pointer;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack { display: grid; gap: 8px; }
.actions { display: grid; gap: 4px; justify-items: start; padding: 4px 0 8px; }
/* нативный выбор даты/файла внутри кнопки */
.hidden-date { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

/* ---- формы ---- */
.form { display: grid; gap: 12px; }
.form label, label.form { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
input[type=text], input[type=number], input[type=date], select {
  font: inherit; font-size: 16px; color: var(--text);
  min-height: 44px; padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--bg);
  width: 100%;
}
.note { margin-top: 12px; }
.check { display: flex; gap: 10px; align-items: center; min-height: 44px; margin: 8px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }

/* ---- чипсы состояний ---- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 40px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--bg); color: var(--text); font: inherit; font-size: .95rem; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.sm { min-height: 0; padding: 2px 10px; font-size: .8rem; display: inline-block; }

/* ---- баннеры ---- */
.banner {
  display: block; text-decoration: none; color: var(--text);
  background: var(--luteal-bg); border-radius: var(--radius);
  padding: 12px 16px; margin-bottom: 12px;
}
.banner.soft { background: var(--surface); border: 1px dashed var(--line); }
.banner.urgent { background: var(--menstrual-bg); margin-top: 12px; }
.banner.urgent .claims { margin: 0; }
.banner .row { margin-top: 8px; }

/* ---- цвета фаз ---- */
.ph-menstrual { --ph: var(--menstrual); --ph-bg: var(--menstrual-bg); }
.ph-follicular { --ph: var(--follicular); --ph-bg: var(--follicular-bg); }
.ph-ovulation { --ph: var(--ovulation); --ph-bg: var(--ovulation-bg); }
.ph-luteal { --ph: var(--luteal); --ph-bg: var(--luteal-bg); }
.sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--ph); margin-right: 6px; vertical-align: 0; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ph); }

/* ---- карточка фазы ---- */
.phase-card { border-top: 5px solid var(--ph); }
.phase-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.day-line { color: var(--muted); font-size: .9rem; }
.tag { display: inline-block; font-size: .75rem; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--luteal-bg); color: var(--luteal); vertical-align: middle; }
.ring {
  --size: 56px;
  flex: none; width: var(--size); height: var(--size); border-radius: 50%;
  background: conic-gradient(var(--ph) calc(var(--p) * 360deg), var(--ph-bg) 0);
  display: grid; place-items: center;
}
.ring span { width: 42px; height: 42px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; font-weight: 600; }

.claims { margin: .25rem 0; padding-left: 1.1rem; }
.claims li { margin: .35rem 0; }
.meta { white-space: nowrap; }
.conf { font-size: .7rem; padding: 1px 6px; border-radius: 6px; background: var(--bg); color: var(--muted); }
.conf-высокая { background: var(--follicular-bg); color: #2F6B58; }
.conf-средняя { background: var(--ovulation-bg); color: #8A5A10; }
.src { font-size: .72rem; color: var(--muted); }

.events { list-style: none; margin: 0; padding: 0; }
.events li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.events li:last-child { border-bottom: 0; }
.ev-name { flex: 1; }
.ev-when { color: var(--muted); font-size: .9rem; }

/* ---- календарь ---- */
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-head h2 { margin: 0; font-size: 1.1rem; }
.cal-head h2::first-letter { text-transform: uppercase; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.wd { margin: 8px 0 4px; text-align: center; font-size: .75rem; color: var(--muted); }
.cell {
  position: relative; aspect-ratio: 1; min-height: 40px;
  border: 0; border-radius: 10px; padding: 0;
  background: var(--ph-bg, transparent); color: var(--text);
  font: inherit; cursor: pointer;
  display: grid; place-items: center;
}
.cell.empty { background: none; cursor: default; }
.cell.pred { background: repeating-linear-gradient(135deg, var(--ph-bg, transparent) 0 5px, var(--surface) 5px 7px); }
.cell.pms { box-shadow: inset 0 -3px 0 var(--luteal); }
.cell.today { outline: 2px solid var(--text); outline-offset: -2px; font-weight: 700; }
.cell .num { font-size: .95rem; }
.cell .marks { position: absolute; bottom: 4px; left: 0; right: 0; display: flex; justify-content: center; gap: 3px; }
.m-start, .m-entry { display: inline-block; width: 6px; height: 6px; border-radius: 50%; }
.m-start { background: var(--menstrual); box-shadow: 0 0 0 1.5px var(--surface); }
.m-entry { background: var(--accent); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 12px; font-size: .8rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 0; }
.legend .m-start, .legend .m-entry { margin-right: 6px; }
.pred-sw { background: repeating-linear-gradient(135deg, var(--line) 0 3px, var(--surface) 3px 5px); border: 1px solid var(--line); }
.forecast { margin: 0; padding-left: 1.1rem; }

/* ---- дневник ---- */
.ins-phase { margin-top: 14px; }
.ins-title { font-weight: 600; margin-bottom: 6px; }
.bar { display: grid; grid-template-columns: minmax(90px, 36%) 1fr 40px; align-items: center; gap: 8px; font-size: .9rem; margin: 4px 0; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--ph); border-radius: 4px; }
.bar-val { text-align: right; color: var(--muted); font-size: .8rem; }
.typical { list-style: none; margin: 0; padding: 0; }
.typical li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); }

.entries { list-style: none; margin: 0; padding: 0; }
.entry {
  width: 100%; text-align: left; font: inherit; color: inherit;
  background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 10px 0; cursor: pointer;
}
.entries li:last-child .entry { border-bottom: 0; }
.entry-head { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.entry-moods { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.entry-note { margin-top: 4px; color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }

/* ---- настройки ---- */
.starts, .mood-edit, .sources { list-style: none; margin: 0 0 8px; padding: 0; }
.starts li { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); }
.mood-edit li { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.mood-edit input { flex: 1; }
#mood-add { margin-top: 8px; flex-wrap: nowrap; }
#mood-add input { flex: 1; min-width: 0; }
.checks { list-style: none; margin: 8px 0 12px; padding: 0; }
.checks li { padding: 4px 0; }
.checks .ok { color: #2F6B58; }
.checks .bad { color: var(--danger); }
.sources li { margin: 6px 0; font-size: .9rem; overflow-wrap: anywhere; }

/* ---- нижний лист ---- */
.sheet {
  border: 0; padding: 0; margin: auto auto 0;
  width: 100%; max-width: 560px; max-height: 88vh;
  border-radius: 20px 20px 0 0; background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgba(43, 37, 48, .35); }
#sheet-body { padding: 20px 16px calc(env(safe-area-inset-bottom) + 16px); overflow-y: auto; max-height: 88vh; }
#sheet-body h2::first-letter { text-transform: uppercase; }
#sheet-body .chips { margin-top: 8px; }

/* ---- таббар ---- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255, 255, 255, .92);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  display: grid; place-items: center; align-content: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: .7rem;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { color: var(--accent); }
