/* Wellbeing diary (TASK-015A): dashboard "Состояние" row, diary page,
 * illness period summary, timeline legend chip.
 * Uses the design tokens of style.css (loaded first). */

:root {
  --c-illness: #c92a2a;
  --c-meds: #5f3dc4;
  --c-checkin: #0b7285;
  --c-basal: #1864ab;
}
:root[data-theme="dark"] {
  --c-illness: #ff8787;
  --c-meds: #b197fc;
  --c-checkin: #66d9e8;
  --c-basal: #74c0fc;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --c-illness: #ff8787;
    --c-meds: #b197fc;
    --c-checkin: #66d9e8;
    --c-basal: #74c0fc;
  }
}
.sw-illness { --sw: var(--c-illness); }

/* ── Dashboard row ─────────────────────────────────────────────────────────── */
.state-card { margin-bottom: 20px; }
.state-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.state-actions { display: flex; gap: 6px; flex: none; }
.state-actions .btn svg { width: 16px; height: 16px; }
.state-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.state-grid.has-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.state-cell {
  background: var(--bg3); border-radius: 12px; padding: 12px 14px; min-width: 0;
  cursor: pointer; border: 1px solid transparent; transition: border-color 0.15s, background 0.15s;
}
.state-cell:hover { border-color: var(--border-strong); }
.state-cell:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.state-label { font-size: 12.5px; font-weight: 600; color: var(--text-sub); }
.state-value { font-size: 17px; font-weight: 650; margin-top: 4px; overflow-wrap: anywhere; letter-spacing: -0.01em; }
.state-sub { font-size: 12px; color: var(--text-muted); margin-top: 3px; line-height: 1.45; overflow-wrap: anywhere; }
.state-cell.is-empty .state-value { color: var(--text-muted); font-weight: 550; }

/* ── Timeline legend chip ──────────────────────────────────────────────────── */
.legend-diary {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px 5px 9px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.legend-diary:hover { background: var(--surface-hover); }
.legend-diary:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.legend-diary:not(.active) { color: var(--text-muted); border-style: dashed; }
.legend-diary:not(.active) .swatch { opacity: 0.35; }

/* ── Diary page ────────────────────────────────────────────────────────────── */
.diary-page .info-banner { margin-bottom: 16px; }
.diary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.diary-card { min-width: 0; }
.diary-card > .chart-sub { margin-top: 2px; }
.diary-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.diary-form { margin-top: 14px; }
.diary-form .form-row input, .diary-form .form-row select { max-width: none; }
.diary-subtitle { font-size: 13.5px; font-weight: 650; margin-bottom: 8px; }
.diary-fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
.diary-fieldset legend { font-size: 13px; font-weight: 550; color: var(--text-sub); margin-bottom: 8px; }
.diary-fieldset input[type="text"] { margin-top: 8px; width: 100%; }
.diary-form-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.diary-check { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; margin: -4px 0 12px; cursor: pointer; }
.diary-check input { width: auto; }
.diary-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.scale { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.scale-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 4px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); font: inherit; cursor: pointer; min-width: 0;
}
.scale-btn:hover { background: var(--surface-hover); }
.scale-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.scale-num { font-size: 16px; font-weight: 700; font-variant-numeric: tabular-nums; }
.scale-label { font-size: 11px; color: var(--text-muted); text-align: center; line-height: 1.2; }
.scale-btn[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.scale-btn[aria-pressed="true"] .scale-label { color: var(--accent); }

.chip-set { display: flex; flex-wrap: wrap; gap: 6px; }
.diary-chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.diary-details { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 10px; }
.diary-details > summary { cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--text-sub); list-style: none; }
.diary-details > summary::-webkit-details-marker { display: none; }
.diary-details > summary::before { content: "▸ "; color: var(--text-muted); }
.diary-details[open] > summary::before { content: "▾ "; }

.diary-list { list-style: none; display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.diary-list:empty { display: none; }
.diary-row { display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: 10px; background: var(--bg3); font-size: 13.5px; }
.diary-row.is-muted .diary-row-title { color: var(--text-muted); }
.diary-row-main { flex: 1; min-width: 0; }
.diary-row-title { font-weight: 600; overflow-wrap: anywhere; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.diary-row-meta { font-size: 12px; color: var(--text-muted); overflow-wrap: anywhere; margin-top: 1px; }
.diary-row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.diary-row > .btn { flex: none; }
.diary-badge { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: var(--radius-pill); background: color-mix(in srgb, var(--c-illness) 14%, transparent); color: var(--c-illness); }
.diary-ill.is-ongoing { box-shadow: inset 3px 0 0 var(--c-illness); }

.diary-date-row { margin: 12px 0 10px; }
.diary-date-row input { max-width: 220px; }
.diary-taglist { list-style: none; display: flex; flex-direction: column; gap: 4px; margin-top: 12px; font-size: 13px; }
.diary-taglist li { display: flex; gap: 10px; align-items: baseline; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.diary-tagday .link-btn { min-width: 64px; text-align: left; }

/* Illness period summary */
.diary-summary { margin-top: 10px; }
.diary-summary-title { font-size: 12.5px; color: var(--text-sub); margin-bottom: 8px; }
.diary-summary-wrap { overflow-x: auto; }
.diary-summary-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.diary-summary-table th, .diary-summary-table td { text-align: left; padding: 7px 8px; border-top: 1px solid var(--border); vertical-align: top; }
.diary-summary-table thead th { font-size: 12px; color: var(--text-muted); font-weight: 600; border-top: 0; }
.diary-summary-table tbody th { font-weight: 550; }
.diary-summary-table tbody th .link-btn { display: block; font-size: 12px; margin-top: 2px; }
.diary-summary-table .v { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }
.diary-summary-table .s { font-size: 11.5px; color: var(--text-muted); }
.diary-summary-table td.is-empty .v { color: var(--text-muted); font-weight: 500; }
.diary-summary .small { margin-top: 8px; }

@media (max-width: 960px) {
  .diary-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 760px) {
  .state-grid, .state-grid.has-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .state-head { flex-direction: column; }
  .diary-grid-3 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .scale-label { font-size: 10px; }
}
@media (max-width: 420px) {
  .state-grid, .state-grid.has-4 { grid-template-columns: minmax(0, 1fr); }
}

/* ── Long-acting insulin (TASK-015B) ───────────────────────────────────────── */
.basal-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; margin-bottom: 12px; border-radius: 12px;
  background: var(--neutral-bg); color: var(--text); font-size: 13.5px; font-weight: 550;
  border: 1px solid var(--border);
}
.basal-banner[hidden] { display: none; }
.basal-banner .icon { width: 18px; height: 18px; flex: none; stroke: var(--c-basal); fill: none; stroke-width: 2; stroke-linecap: round; }
.basal-banner-text { flex: 1; min-width: 160px; }
.diary-card .basal-banner { margin: 12px 0 0; }
.basal-reminder { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); font-size: 13px; }
.basal-reminder label { font-weight: 550; color: var(--text-sub); }
.basal-reminder input { width: auto; }
.basal-report-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.basal-report-head .diary-subtitle { margin: 0; }
.btn.btn-period[aria-pressed="true"] { background: var(--bg2); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }
.basal-report { margin-top: 10px; display: flex; flex-direction: column; gap: 14px; }
.basal-change { padding: 10px 12px; border-radius: 12px; background: var(--bg3); }
.basal-change-title { font-weight: 650; font-size: 14px; font-variant-numeric: tabular-nums; }
.basal-change .diary-summary-table { margin-top: 6px; }
.basal-change .diary-summary-table tbody th { font-size: 12.5px; }
