:root {
  --ink: #17221d;
  --muted: #68736d;
  --line: #dfe5e1;
  --surface: #ffffff;
  --canvas: #f4f6f4;
  --green: #27745a;
  --green-soft: #dcece5;
  --blue: #315f78;
  --rose: #9d4d56;
  --amber: #956819;
  --danger: #a43737;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--canvas); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }

.center-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.center-view > p { color: var(--muted); }
.spinner { width: 28px; height: 28px; border: 3px solid #d7dfda; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.access-panel { width: min(100%, 460px); text-align: center; }
.access-panel h1 { margin: 10px 0 12px; font-size: 30px; }
.access-panel p:not(.eyebrow) { color: var(--muted); line-height: 1.7; }
.access-panel .primary-button { margin-top: 16px; }
.lock-mark, .brand-mark { display: inline-grid; place-items: center; color: #fff; background: var(--ink); font-weight: 800; }
.lock-mark { width: 54px; height: 54px; border-radius: 8px; font-size: 21px; }
.brand-mark { width: 34px; height: 34px; border-radius: 6px; }
.text-link { display: block; margin-top: 18px; color: var(--muted); text-decoration: none; }
.text-link:hover { color: var(--ink); }

.topbar { position: sticky; top: 0; z-index: 20; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.96); }
.topbar-inner { width: min(1180px, calc(100% - 40px)); min-height: 68px; margin: auto; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--ink); font-weight: 750; text-decoration: none; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.account-copy { display: grid; text-align: right; line-height: 1.25; }
.account-copy strong { font-size: 14px; }
.account-copy span { color: var(--muted); font-size: 11px; }
.icon-button, .quiet-button, .primary-button, .secondary-button, .danger-button { border: 0; border-radius: 6px; cursor: pointer; text-decoration: none; }
.icon-button { width: 40px; height: 40px; display: inline-grid; place-items: center; border: 1px solid var(--line); color: var(--ink); background: var(--surface); font-size: 21px; }
.quiet-button { min-height: 40px; padding: 0 15px; border: 1px solid var(--line); color: var(--ink); background: var(--surface); }
.primary-button, .secondary-button, .danger-button { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; padding: 0 20px; color: #fff; font-weight: 700; }
.primary-button { background: var(--green); }
.secondary-button { background: var(--blue); }
.danger-button { background: var(--danger); }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid rgba(49,95,120,.24); outline-offset: 2px; }

.page-shell { width: min(1180px, calc(100% - 40px)); margin: auto; padding: 52px 0 72px; }
.page-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 32px; margin-bottom: 26px; }
.page-intro h1 { margin: 5px 0 10px; font-size: clamp(30px, 4vw, 46px); line-height: 1.12; }
.page-intro p:not(.eyebrow) { max-width: 700px; margin: 0; color: var(--muted); line-height: 1.7; }
.eyebrow { margin: 0; color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: 0; }
.quick-actions { display: flex; flex-shrink: 0; gap: 10px; }
.privacy-strip { display: flex; align-items: center; gap: 10px; min-height: 46px; padding: 10px 14px; border: 1px solid #cfe0d8; color: #315d4c; background: #eef6f2; font-size: 13px; }
.privacy-strip span:last-child { color: #557065; }
.privacy-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-bottom: 0; background: var(--surface); margin-top: 28px; }
.metrics article { min-width: 0; padding: 22px; border-right: 1px solid var(--line); }
.metrics article:last-child { border-right: 0; }
.metrics span, .metrics small { display: block; color: var(--muted); font-size: 12px; }
.metrics strong { display: inline-block; margin: 8px 7px 4px 0; font-size: 30px; line-height: 1; }
.metrics small { display: inline; }

.trend-section, .history-section, .advice-section { border-top: 1px solid var(--line); background: var(--surface); }
.trend-section { padding: 26px 24px 28px; border: 1px solid var(--line); }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 20px; }
.section-heading h2 { margin: 4px 0 0; font-size: 21px; }
.legend { display: flex; gap: 14px; color: var(--muted); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend i { width: 12px; height: 12px; border-radius: 2px; }
.level-0 { background: #e8ece9; }
.level-1 { background: #8dc1ab; }
.level-2 { background: #27745a; }
.trend-grid { display: grid; grid-template-columns: repeat(28, minmax(10px, 1fr)); gap: 5px; }
.trend-day { position: relative; aspect-ratio: 1; min-height: 15px; border-radius: 2px; background: #e8ece9; }
.trend-day[data-count="1"] { background: #8dc1ab; }
.trend-day[data-count="2"] { background: #27745a; }
.trend-day:hover::after { content: attr(data-label); position: absolute; z-index: 4; left: 50%; bottom: calc(100% + 8px); transform: translateX(-50%); width: max-content; padding: 5px 7px; border-radius: 4px; color: #fff; background: var(--ink); font-size: 11px; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .85fr); gap: 24px; margin-top: 32px; align-items: start; }
.history-section, .advice-section { padding: 24px; border: 1px solid var(--line); }
.danger-link { border: 0; color: var(--danger); background: transparent; cursor: pointer; }
.history-list { display: grid; gap: 10px; }
.history-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; min-height: 78px; padding: 14px; border: 1px solid var(--line); border-radius: 6px; background: #fbfcfb; }
.history-kind { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 6px; color: #fff; background: var(--green); font-weight: 800; }
.history-kind.sex { background: var(--blue); }
.history-main { min-width: 0; }
.history-main strong { display: block; margin-bottom: 5px; }
.history-main p { margin: 0; overflow: hidden; color: var(--muted); font-size: 13px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 8px; }
.history-meta span { padding: 3px 6px; border-radius: 4px; color: #52605a; background: #edf1ee; font-size: 11px; }
.history-meta .warning { color: #8d3c3c; background: #f8e7e7; }
.row-actions { display: flex; gap: 4px; }
.row-actions button { width: 36px; height: 36px; border: 0; border-radius: 5px; color: var(--muted); background: transparent; cursor: pointer; }
.row-actions button:hover { color: var(--ink); background: #edf1ee; }
.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--ink); }
.empty-state p { max-width: 440px; margin: 8px auto 0; line-height: 1.6; }

.advice-list { display: grid; gap: 10px; }
.advice-item { padding: 14px 15px; border-left: 3px solid var(--green); background: #f6f8f6; }
.advice-item.urgent { border-color: var(--danger); background: #fff4f3; }
.advice-item.attention { border-color: var(--amber); background: #fff9ed; }
.advice-item.info { border-color: var(--blue); }
.advice-item h3 { margin: 0 0 7px; font-size: 15px; }
.advice-item p, .medical-note { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.65; }
.medical-note { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 11px; }

.record-dialog, .confirm-dialog { width: min(calc(100% - 28px), 660px); max-height: min(90vh, 820px); padding: 0; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: var(--surface); box-shadow: 0 24px 80px rgba(23,34,29,.24); }
.record-dialog::backdrop, .confirm-dialog::backdrop { background: rgba(17,24,21,.52); }
.record-dialog form { padding: 24px; overflow: auto; }
.dialog-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 22px; }
.dialog-header h2 { margin: 4px 0 0; }
.kind-control { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 0 0 18px; padding: 0; border: 0; }
.kind-control legend { grid-column: 1 / -1; margin-bottom: 7px; color: var(--muted); font-size: 13px; }
.kind-control label { cursor: pointer; }
.kind-control input { position: absolute; opacity: 0; }
.kind-control span { min-height: 44px; display: grid; place-items: center; padding: 8px; border: 1px solid var(--line); border-radius: 6px; color: var(--muted); }
.kind-control input:checked + span { border-color: var(--green); color: var(--green); background: var(--green-soft); font-weight: 700; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; }
.field { display: grid; gap: 7px; color: var(--muted); font-size: 13px; }
.field.full { grid-column: 1 / -1; }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 9px 11px; border: 1px solid #ccd5d0; border-radius: 5px; color: var(--ink); background: #fff; }
.field textarea { resize: vertical; line-height: 1.55; }
.field small { text-align: right; }
.check-field { grid-column: 1 / -1; display: flex; align-items: flex-start; gap: 9px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.check-field input { width: 18px; height: 18px; flex: 0 0 auto; accent-color: var(--green); }
.sex-fields { margin-top: 18px; padding: 16px; border-left: 3px solid var(--blue); background: #f3f7f9; }
.protection-control { margin-bottom: 14px; }
.consent { color: var(--ink); }
.note-field { margin-top: 18px; }
.form-error { min-height: 20px; margin: 10px 0 0; color: var(--danger); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }
.confirm-dialog { width: min(calc(100% - 28px), 420px); }
.confirm-dialog > div { padding: 24px; }
.confirm-dialog h2 { margin: 0 0 10px; font-size: 21px; }
.confirm-dialog p { color: var(--muted); line-height: 1.6; }

.privacy-cover { position: fixed; inset: 0; z-index: 100; display: grid; place-content: center; justify-items: center; padding: 24px; text-align: center; color: var(--ink); background: #eef2ef; }
.privacy-cover h2 { margin: 18px 0 6px; }
.privacy-cover p { margin: 0 0 20px; color: var(--muted); }

@media (max-width: 820px) {
  .account-copy { display: none; }
  .page-intro { display: block; }
  .quick-actions { margin-top: 22px; }
  .quick-actions button { flex: 1; }
  .content-grid { grid-template-columns: 1fr; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .metrics article:nth-child(2) { border-right: 0; }
  .metrics article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .trend-grid { grid-template-columns: repeat(14, 1fr); }
}

@media (max-width: 560px) {
  .topbar-inner, .page-shell { width: min(100% - 24px, 1180px); }
  .topbar-inner { min-height: 62px; }
  .brand > span:last-child { display: none; }
  .page-shell { padding: 32px 0 48px; }
  .page-intro h1 { font-size: 32px; }
  .quick-actions { display: grid; }
  .privacy-strip { align-items: flex-start; flex-wrap: wrap; }
  .privacy-strip span:last-child { width: 100%; padding-left: 18px; }
  .metrics article { padding: 17px; }
  .trend-section, .history-section, .advice-section { padding: 18px; }
  .legend { display: none; }
  .history-row { grid-template-columns: auto minmax(0, 1fr); }
  .row-actions { grid-column: 2; justify-content: flex-end; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .record-dialog form { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
