/* ===========================================================================
   Cadence — stylesheet  (v3)
   Warm off-white ground, clay accent. No web fonts: everything is a system
   face so the page paints on the first frame.
   ========================================================================= */

:root {
  --bg:        #F5F4EF;
  --surface:   #FFFFFF;
  --surface-2: #FAF9F5;
  --ink:       #191919;
  --ink-2:     #57544E;
  --ink-3:     #8C8880;
  --line:      #E6E2D8;
  --line-firm: #D8D3C6;

  --clay:      #C15F3C;
  --clay-soft: #D97757;
  --clay-wash: #F6E9E2;

  --slate:     #6D7A88;
  --sage:      #7F8C6B;
  --sage-wash: #ECEFE4;

  --f1: #F2DDD2;
  --f2: #E7BEA9;
  --f3: #D9997C;
  --f4: #C57150;
  --f5: #A34527;

  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 2px rgba(25,25,25,.05), 0 8px 24px rgba(25,25,25,.07);

  --ui:      system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --display: ui-serif, Georgia, "Times New Roman", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }

:focus-visible {
  outline: 2px solid var(--clay);
  outline-offset: 2px;
}

/* --- Top bar -------------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 20px;
  height: 56px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}

.mark {
  font-family: var(--display);
  font-size: 19px;
  letter-spacing: .01em;
}

.tabs { display: flex; gap: 2px; margin-left: auto; }

.tab {
  background: none;
  border: 0;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  cursor: pointer;
}
.tab:hover { background: rgba(25,25,25,.045); }
.tab.is-active { background: var(--clay-wash); color: var(--clay); }

.signout {
  color: var(--ink-3);
  text-decoration: none;
  font-size: 13px;
}
.signout:hover { color: var(--ink); }

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 24px 20px 72px;
}

.panel { display: none; }
.panel.is-active { display: block; }

/* --- Month header --------------------------------------------------------- */

.month-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.month-title {
  font-family: var(--display);
  font-size: 24px;
  font-weight: 400;
  margin: 0;
  min-width: 210px;
}

.nav-btn {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line-firm);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink-2);
  line-height: 1;
  font-size: 17px;
}
.nav-btn:hover { background: var(--surface-2); color: var(--ink); }

.month-head .btn-quiet { margin-left: auto; }

/* --- Calendar grid -------------------------------------------------------- */

.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
}
.weekdays span {
  font-size: 11px;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

/* Two-layer month transition: the month you're leaving slides out while the
   month you're entering slides in behind it, so the week columns stay
   spatially continuous. */
.grid-stage {
  position: relative;
  overflow: hidden;
}
.grid-ghost {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  pointer-events: none;
}

.grid.slide-in-right  { animation: slide-in-right  .3s cubic-bezier(.32,.72,.28,1) both; }
.grid.slide-in-left   { animation: slide-in-left   .3s cubic-bezier(.32,.72,.28,1) both; }
.grid-ghost.slide-out-left  { animation: slide-out-left  .3s cubic-bezier(.32,.72,.28,1) both; }
.grid-ghost.slide-out-right { animation: slide-out-right .3s cubic-bezier(.32,.72,.28,1) both; }

@keyframes slide-in-right  { from { transform: translateX(103%); } to { transform: translateX(0); } }
@keyframes slide-in-left   { from { transform: translateX(-103%); } to { transform: translateX(0); } }
@keyframes slide-out-left  { from { transform: translateX(0); } to { transform: translateX(-103%); } }
@keyframes slide-out-right { from { transform: translateX(0); } to { transform: translateX(103%); } }

/* display:block matters — a <button> centres its own content by default,
   which is what was floating the date number into the middle of the cell. */
.cell {
  position: relative;
  display: block;
  aspect-ratio: 1 / 0.95;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0;
  cursor: pointer;
  text-align: left;
  transition: border-color .12s ease, transform .08s ease;
  overflow: hidden;
}
.cell:hover { border-color: var(--line-firm); }
.cell:active { transform: scale(.985); }

.cell.is-blank {
  background: transparent;
  border-color: transparent;
  cursor: default;
  pointer-events: none;
}

.cell-num {
  position: absolute;
  top: 5px;
  left: 7px;
  font-size: 15px;
  line-height: 1;
  color: var(--ink-2);
}
.cell.is-today .cell-num {
  font-weight: 600;
  color: var(--clay);
}
.cell.is-today {
  border-color: var(--clay);
  box-shadow: inset 0 0 0 1px var(--clay);
}

.cell.is-fertile { background: var(--sage-wash); }
.cell.is-predicted {
  border-style: dashed;
  border-color: var(--clay-soft);
}
.cell.is-ovulation::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 4px;
  border: 1px solid var(--sage);
  pointer-events: none;
}

/* Flow reads as a count of dots, so the cell interior stays free for a note.
   A period's first day gets a larger, deeper dot on its own line above them. */
.cell-bottom {
  position: absolute;
  left: 6px;
  right: 6px;
  bottom: 5px;
}
.start-dot {
  display: block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #8C3419;
  margin-bottom: 5px;
}
.cell-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 3px 5px;
  flex-wrap: wrap;
}
.dots { display: flex; gap: 3px; }
.dot-flow {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--f5);
  flex: none;
}
.dot-flow.is-unknown {
  background: none;
  border: 1px solid var(--f4);
}
.day-of {
  font-size: 10.5px;
  line-height: 1;
  color: var(--ink-3);
  white-space: nowrap;
}

.cell-note {
  position: absolute;
  left: 7px;
  right: 6px;
  top: 23px;
  bottom: 19px;
  font-size: 10px;
  line-height: 1.3;
  color: var(--ink-3);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.cell.has-start .cell-note { bottom: 35px; }

.cell-marks {
  position: absolute;
  top: 4px;
  right: 6px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.mark-heart {
  font-size: 19px;
  line-height: 1;
  color: var(--slate);
  font-style: normal;
}

.mark-spot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--clay-soft);
}

/* --- Cycle ribbon --------------------------------------------------------- */

.ribbon {
  margin-top: 20px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.ribbon-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.ribbon-title { font-size: 13px; color: var(--ink-2); }
.ribbon-title strong { font-family: var(--display); font-size: 17px; font-weight: 400; color: var(--ink); }
.ribbon-conf { font-size: 12px; color: var(--ink-3); }

.ribbon-track {
  position: relative;
  height: 26px;
  background: var(--surface-2);
  border-radius: 13px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.ribbon-seg { position: absolute; top: 0; bottom: 0; }
.ribbon-fertile { background: var(--sage-wash); }
.ribbon-window  { background: repeating-linear-gradient(135deg, var(--clay-wash) 0 6px, transparent 6px 12px); }
.ribbon-bleed   { background: var(--f3); }
.ribbon-now {
  position: absolute;
  top: -3px;
  bottom: -3px;
  width: 2px;
  background: var(--ink);
}
.ribbon-scale {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 6px;
}

/* --- Legend --------------------------------------------------------------- */

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  margin-top: 18px;
  font-size: 12px;
  color: var(--ink-3);
}
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  display: inline-block;
}
.swatch-flow   { width: 6px; height: 6px; border-radius: 50%; background: var(--f5); }
.swatch-spot   { border: 1.5px solid var(--clay-soft); border-radius: 50%; background: none; }
.swatch-int    { background: none; width: auto; height: auto; color: var(--slate); font-size: 13px; line-height: 1; }
.swatch-start  { background: #8C3419; border-radius: 50%; width: 11px; height: 11px; }
.swatch-fertile{ background: var(--sage-wash); border: 1px solid var(--sage); }
.swatch-pred   { background: none; border: 1.5px dashed var(--clay-soft); }

/* --- Cards, stats, tables ------------------------------------------------- */

.chart-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  margin-bottom: 18px;
}
.chart-card h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 17px;
  font-weight: 400;
}
.chart-note {
  margin: 4px 0 16px;
  font-size: 12.5px;
  color: var(--ink-3);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.stat-value {
  font-family: var(--display);
  font-size: 27px;
  line-height: 1.15;
}
.stat-value .unit { font-size: 13px; color: var(--ink-3); font-family: var(--ui); }
.stat-label {
  font-size: 11.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-top: 4px;
}
.stat-sub { font-size: 12px; color: var(--ink-3); margin-top: 6px; }

/* --- Table controls ------------------------------------------------------- */

.table-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 14px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px 5px 9px;
  border: 1px solid var(--line-firm);
  border-radius: 20px;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  background: var(--surface);
  user-select: none;
}
.chip:hover { border-color: var(--clay-soft); }
.chip input { width: 14px; height: 14px; accent-color: var(--clay); margin: 0; }
.chip.is-on { background: var(--clay-wash); border-color: var(--clay-soft); color: var(--clay); }

.btn-sm { padding: 5px 12px; font-size: 12.5px; border-radius: 20px; }
.controls-spacer { flex: 1; min-width: 4px; }

.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.data-table th {
  text-align: left;
  font-weight: 500;
  font-size: 11.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-3);
  padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table td {
  padding: 8px 12px 8px 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: 0; }
.muted { color: var(--ink-3); }

.pred-line { margin: 0 0 10px; }
.pred-date {
  font-family: var(--display);
  font-size: 25px;
  display: block;
}
.pred-meta { font-size: 13px; color: var(--ink-2); }
.conf {
  display: inline-block;
  font-size: 11.5px;
  padding: 2px 8px;
  border-radius: 20px;
  border: 1px solid var(--line-firm);
  color: var(--ink-2);
  background: var(--surface-2);
  margin-left: 6px;
  vertical-align: 2px;
}
.conf.high     { border-color: var(--sage); color: var(--sage); background: var(--sage-wash); }
.conf.moderate { border-color: var(--clay-soft); color: var(--clay); background: var(--clay-wash); }
.conf.low,
.conf.very-low { border-color: var(--line-firm); }

.caveat {
  margin: 14px 0 0;
  padding: 12px 14px;
  background: var(--surface-2);
  border-left: 2px solid var(--line-firm);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  color: var(--ink-2);
}

.empty {
  color: var(--ink-3);
  font-size: 13.5px;
  padding: 8px 0;
}

/* --- Charts (hand-drawn SVG) ---------------------------------------------- */

.chart svg { display: block; width: 100%; height: auto; }
.chart .axis-line { stroke: var(--line-firm); stroke-width: 1; }
.chart .grid-line { stroke: var(--line); stroke-width: 1; }
.chart .axis-text { fill: var(--ink-3); font-size: 10px; font-family: var(--ui); }
.chart .series-line { fill: none; stroke: var(--clay); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--surface); stroke: var(--clay); stroke-width: 2; }
.chart .bar { fill: var(--clay-soft); }
.chart .bar-alt { fill: var(--f2); }
.chart .mean-line { stroke: var(--sage); stroke-width: 1.5; stroke-dasharray: 4 4; }

/* --- Buttons -------------------------------------------------------------- */

.btn {
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 8px 15px;
  cursor: pointer;
  background: var(--surface);
}
.btn-primary { background: var(--clay); color: #fff; }
.btn-primary:hover { background: #A9512F; }
.btn-quiet { border-color: var(--line-firm); color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger-quiet { color: #A03A22; border-color: transparent; background: none; }
.btn-danger-quiet:hover { background: var(--clay-wash); }
.btn-block { width: 100%; }

.export-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-top: 10px;
}

/* --- Fields --------------------------------------------------------------- */

.field { display: block; margin-bottom: 14px; }
.field-inline { margin-bottom: 0; }
.field-label {
  display: block;
  font-size: 11.5px;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin-bottom: 5px;
}
.field input,
.field textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-firm);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  resize: vertical;
}
.field input:focus,
.field textarea:focus { border-color: var(--clay); outline: none; }

.check-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  background: var(--surface);
}
.check-row:hover { border-color: var(--line-firm); }
.check-row input { width: 17px; height: 17px; accent-color: var(--clay); }

.check-inline {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  color: var(--ink-2);
  margin-bottom: 16px;
  cursor: pointer;
}
.check-inline input { accent-color: var(--clay); }

/* --- Flow pills ----------------------------------------------------------- */

.flow-block {
  padding: 4px 12px 14px;
  margin-bottom: 8px;
}
.flow-pills { display: flex; gap: 6px; }
.flow-pill {
  flex: 1;
  padding: 9px 0;
  border: 1px solid var(--line-firm);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink-2);
}
.flow-pill:hover { border-color: var(--clay-soft); }
.flow-pill.is-on { color: #fff; border-color: transparent; }
.flow-pill.is-on[data-flow="1"] { background: var(--f2); color: var(--ink); }
.flow-pill.is-on[data-flow="2"] { background: var(--f3); color: var(--ink); }
.flow-pill.is-on[data-flow="3"] { background: var(--f4); }
.flow-pill.is-on[data-flow="4"] { background: var(--f5); }
.flow-pill.is-on[data-flow="5"] { background: #8C3419; }
.flow-caption { display: block; margin-top: 8px; font-size: 12.5px; color: var(--ink-3); }

.prot-block { padding: 0 12px 12px; }
.seg { display: flex; gap: 6px; }
.seg-btn {
  flex: 1;
  padding: 9px 0;
  border: 1px solid var(--line-firm);
  background: var(--surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--ink-2);
  font-size: 13.5px;
}
.seg-btn.is-on { background: var(--slate); border-color: var(--slate); color: #fff; }

/* --- Modal ---------------------------------------------------------------- */

.modal-veil {
  position: fixed;
  inset: 0;
  background: rgba(25,25,25,.32);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
  animation: veil-in .12s ease;
}
.modal-veil[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  animation: modal-in .14s ease;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px 10px;
}
.modal-head h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 18px;
  font-weight: 400;
}
.icon-btn {
  background: none;
  border: 0;
  font-size: 22px;
  line-height: 1;
  color: var(--ink-3);
  cursor: pointer;
  padding: 0 4px;
}
.icon-btn:hover { color: var(--ink); }

.modal-body { padding: 4px 18px 8px; overflow-y: auto; }
.modal-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
}
.spacer { flex: 1; }

@keyframes veil-in  { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px); } }

/* --- Toast ---------------------------------------------------------------- */

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  font-size: 13.5px;
  padding: 9px 16px;
  border-radius: 20px;
  z-index: 90;
  animation: toast-in .16s ease;
}
.toast[hidden] { display: none; }
.toast.is-error { background: #8C3419; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* --- Sign in -------------------------------------------------------------- */

.signin-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.signin { width: 100%; max-width: 300px; padding: 20px; }
.signin-mark {
  font-family: var(--display);
  font-size: 27px;
  font-weight: 400;
  margin: 0 0 22px;
  text-align: center;
}
.signin-form {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.signin-error {
  margin: -4px 0 12px;
  font-size: 13px;
  color: #8C3419;
}

.range-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 18px;
}
.range-btn {
  padding: 6px 13px;
  border: 1px solid var(--line-firm);
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12.5px;
  cursor: pointer;
}
.range-btn:hover { border-color: var(--clay-soft); }
.range-btn.is-on { background: var(--clay-wash); border-color: var(--clay-soft); color: var(--clay); }
.range-custom {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  margin-left: 2px;
}
.range-custom[hidden] { display: none; }
.range-custom input {
  padding: 5px 10px;
  font-size: 12.5px;
  border: 1px solid var(--line-firm);
  border-radius: 20px;
  background: var(--surface);
  color: var(--ink-2);
}
.range-custom input:focus { border-color: var(--clay); outline: none; }
.range-to { font-size: 12.5px; color: var(--ink-3); }
.range-caption {
  font-size: 12.5px;
  color: var(--ink-3);
  margin: -8px 0 16px;
}

/* --- Small screens -------------------------------------------------------- */

@media (max-width: 640px) {
  .topbar { gap: 10px; padding: 0 14px; }
  .mark { font-size: 17px; }
  .tab { padding: 7px 10px; font-size: 14px; }
  .signout { display: none; }
  main { padding: 18px 12px 60px; }
  .grid, .weekdays { gap: 4px; }
  .cell { aspect-ratio: 1 / 1.3; }
  .cell-num { top: 4px; left: 5px; font-size: 14px; }
  .cell-note { left: 5px; right: 4px; top: 21px; bottom: 30px; -webkit-line-clamp: 2; }
  .cell.has-start .cell-note { bottom: 46px; }
  .cell-bottom { left: 4px; right: 4px; bottom: 4px; }
  .start-dot { width: 9px; height: 9px; margin-bottom: 4px; }
  .dot-flow { width: 5px; height: 5px; }
  .dots { gap: 2px; }
  .day-of { font-size: 9.5px; }
  .mark-heart { font-size: 16px; }
  .month-title { font-size: 20px; min-width: 0; flex: 1; }
  .chart-card { padding: 16px 14px; }
  .modal { max-width: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}