/* Дневник давления — дизайн-система (светлая/тёмная тема, мобильный-first) */

:root {
  --bg: #f2f2f7;
  --bg-elev: #ffffff;
  --bg-soft: #f7f7fa;
  --text: #1c1c1e;
  --text-2: #6b6b70;
  --line: rgba(60, 60, 67, 0.12);
  --brand: #e0344a;
  --brand-soft: rgba(224, 52, 74, 0.12);
  --accent: #0a84ff;
  --green: #30a46c;
  --amber: #f0a01a;
  --orange: #f0682a;
  --red: #e0344a;
  --blue: #3b82f6;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
  --radius: 18px;
  --radius-sm: 12px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0f;
    --bg-elev: #16161c;
    --bg-soft: #1d1d24;
    --text: #f2f2f7;
    --text-2: #9a9aa2;
    --line: rgba(255, 255, 255, 0.1);
    --brand: #ff5c72;
    --brand-soft: rgba(255, 92, 114, 0.16);
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
  }
}

:root[data-theme="dark"] {
  --bg: #0b0b0f;
  --bg-elev: #16161c;
  --bg-soft: #1d1d24;
  --text: #f2f2f7;
  --text-2: #9a9aa2;
  --line: rgba(255, 255, 255, 0.1);
  --brand: #ff5c72;
  --brand-soft: rgba(255, 92, 114, 0.16);
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }

/* атрибут hidden должен побеждать любые display из авторских правил */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
h3 { font-size: 17px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.mono { font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------- загрузка */

.boot {
  position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg);
  z-index: 100;
}
.spinner {
  width: 30px; height: 30px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--brand);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ----------------------------------------------------------- шапка */

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(180%) blur(18px);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-heart { color: var(--brand); display: grid; place-items: center; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.brand-text b { font-size: 15px; letter-spacing: -0.01em; }
.brand-text span { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tabs { display: flex; gap: 4px; margin-left: auto; }
.tabs button {
  border: 0; background: transparent; color: var(--text-2);
  font: inherit; font-size: 14px; font-weight: 550;
  padding: 8px 14px; border-radius: 999px; cursor: pointer;
  transition: background .16s, color .16s;
}
.tabs button:hover { background: var(--bg-soft); color: var(--text); }
.tabs button.active { background: var(--brand-soft); color: var(--brand); }

.topbar-actions { display: flex; gap: 6px; margin-left: auto; }
.tabs + .topbar-actions { margin-left: 0; }
.icon-btn {
  border: 0; background: var(--bg-soft); color: var(--text-2);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer;
  display: grid; place-items: center; transition: background .16s, color .16s;
}
.icon-btn:hover { color: var(--text); background: var(--line); }

/* ----------------------------------------------------------- каркас */

main {
  max-width: 880px; margin: 0 auto;
  padding: 20px 20px calc(var(--tabbar-h) + 28px);
}

.screen { display: none; }
.screen.active { display: block; animation: fade .22s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}

/* ----------------------------------------------------------- герой */

.hero {
  display: flex; gap: 16px; align-items: stretch;
  background: linear-gradient(140deg, var(--brand) 0%, #a3142c 100%);
  color: #fff; border-radius: var(--radius);
  padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.hero-main { flex: 1; min-width: 0; }
.hero-label { font-size: 13px; opacity: .82; }
.hero-value { font-size: 38px; font-weight: 700; letter-spacing: -0.02em; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.hero-sub { font-size: 13px; opacity: .85; }
.hero-side { display: flex; flex-direction: column; gap: 8px; justify-content: center; }
.mini {
  background: rgba(255,255,255,.16); border-radius: var(--radius-sm);
  padding: 8px 12px; min-width: 130px;
}
.mini span { display: block; font-size: 11px; opacity: .85; }
.mini b { font-size: 17px; font-variant-numeric: tabular-nums; }

/* ----------------------------------------------------------- поля */

.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--text-2); margin-bottom: 6px; font-weight: 500; }

input, textarea, select {
  width: 100%; font: inherit; color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  outline: none; transition: border-color .16s, box-shadow .16s, background .16s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  background: var(--bg-elev);
}
textarea { resize: vertical; }
input[type="number"] { font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.segmented {
  display: inline-flex; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 3px;
  width: 100%;
}
.segmented button {
  flex: 1; border: 0; background: transparent; color: var(--text-2);
  font: inherit; font-size: 14px; font-weight: 550; padding: 8px 12px;
  border-radius: 999px; cursor: pointer; transition: background .16s, color .16s;
  white-space: nowrap;
}
.segmented button.active { background: var(--bg-elev); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.segmented.big button { padding: 10px; }

button.primary, button.ghost, button.danger {
  font: inherit; font-weight: 600; border-radius: var(--radius-sm);
  padding: 11px 18px; cursor: pointer; border: 1px solid transparent;
  transition: filter .16s, background .16s;
}
button.primary { background: var(--brand); color: #fff; }
button.primary:hover { filter: brightness(1.07); }
button.ghost { background: var(--bg-soft); color: var(--text); border-color: var(--line); }
button.ghost:hover { background: var(--line); }
button.danger { background: transparent; color: var(--red); border-color: var(--red); }
button.danger:hover { background: var(--red); color: #fff; }
button.wide { width: 100%; }
button.small { padding: 7px 12px; font-size: 13px; }
button:disabled { opacity: .55; cursor: default; }

.form-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-top: 4px;
}
.form-actions { display: flex; gap: 8px; }
.preview { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.form-msg { min-height: 18px; font-size: 13px; margin: 10px 0 0; color: var(--red); }
.form-msg.ok { color: var(--green); }

.inline-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; }
.inline-form .field { margin-bottom: 0; }
.inline-form button { height: 44px; }

/* ----------------------------------------------------------- списки */

.list { display: flex; flex-direction: column; gap: 8px; }

.entry {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 14px;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.entry .e-main { display: flex; align-items: baseline; gap: 8px; min-width: 190px; }
.entry .e-val { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.entry .e-val small { font-size: 13px; font-weight: 500; color: var(--text-2); }
.entry .e-meta { display: flex; flex-direction: column; gap: 2px; min-width: 96px; }
.entry .e-meta span { font-size: 12px; color: var(--text-2); }
.entry .e-note { flex: 1; font-size: 13px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.entry .e-actions { display: flex; gap: 6px; }

.badge {
  display: inline-block; font-size: 11px; font-weight: 650;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
}
.badge.crisis { background: rgba(224,52,74,.16); color: var(--red); }
.badge.high2  { background: rgba(240,104,42,.16); color: var(--orange); }
.badge.high1  { background: rgba(240,160,26,.18); color: #b8780a; }
.badge.elevated { background: rgba(240,160,26,.12); color: #b8780a; }
.badge.normal { background: rgba(48,164,108,.16); color: var(--green); }
.badge.low    { background: rgba(59,130,246,.16); color: var(--blue); }

.day-sep {
  font-size: 12px; font-weight: 650; color: var(--text-2);
  text-transform: uppercase; letter-spacing: .04em;
  margin: 12px 2px 2px;
}
.empty { padding: 22px; text-align: center; color: var(--text-2); font-size: 14px; }

/* ----------------------------------------------------------- статистика */

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.stat {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 2px;
}
.stat span { font-size: 12px; color: var(--text-2); }
.stat b { font-size: 21px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat i { font-size: 11px; color: var(--text-2); font-style: normal; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button {
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text-2);
  font: inherit; font-size: 13px; font-weight: 550; padding: 6px 12px;
  border-radius: 999px; cursor: pointer; transition: background .16s, color .16s;
}
.chips button:hover { color: var(--text); }
.chips button.active { background: var(--brand); color: #fff; border-color: transparent; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); }
.legend .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.legend .dot.sys { background: var(--brand); }
.legend .dot.dia { background: var(--accent); }
.legend .dot.pul { background: var(--green); }

.chart-wrap { overflow-x: auto; }
.chart svg { display: block; }

.slot-table { display: flex; flex-direction: column; gap: 8px; }
.slot-row {
  display: grid; grid-template-columns: 90px repeat(4, 1fr);
  gap: 8px; align-items: center;
  padding: 10px 12px; background: var(--bg-soft);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  font-size: 14px;
}
.slot-row.head { background: transparent; border: 0; padding: 0 12px; color: var(--text-2); font-size: 12px; }
.slot-row b { font-variant-numeric: tabular-nums; font-size: 16px; }
.slot-row .slot-name { font-weight: 600; }

.cats { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: grid; grid-template-columns: 190px 1fr 54px; gap: 12px; align-items: center; font-size: 14px; }
.cat-bar { height: 10px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.cat-bar i { display: block; height: 100%; border-radius: 999px; }
.cat-row .cat-num { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.cat-row.crisis .cat-bar i { background: var(--red); }
.cat-row.high2 .cat-bar i { background: var(--orange); }
.cat-row.high1 .cat-bar i { background: var(--amber); }
.cat-row.elevated .cat-bar i { background: #e8c547; }
.cat-row.normal .cat-bar i { background: var(--green); }
.cat-row.low .cat-bar i { background: var(--blue); }

/* ----------------------------------------------------------- модалка */

.modal {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.42);
  display: grid; place-items: center; padding: 18px;
  backdrop-filter: blur(3px);
}
.modal-box {
  background: var(--bg-elev); border-radius: var(--radius);
  border: 1px solid var(--line); box-shadow: var(--shadow);
  width: 100%; max-width: 460px; padding: 18px;
  max-height: 90vh; overflow-y: auto;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.modal-foot { display: flex; gap: 8px; justify-content: space-between; margin-top: 6px; }

/* ----------------------------------------------------------- тост */

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 18px);
  transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 14px; font-weight: 550;
  z-index: 70; box-shadow: var(--shadow); animation: fade .2s ease;
  max-width: 90vw; text-align: center;
}

/* ----------------------------------------------------------- экран входа */

.auth-body { display: grid; place-items: center; padding: 20px; min-height: 100vh; }
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 22px; box-shadow: var(--shadow);
  padding: 26px 22px;
}
.auth-brand { text-align: center; margin-bottom: 20px; }
.auth-brand h1 { font-size: 21px; margin: 10px 0 4px; }
.auth-brand .muted { font-size: 14px; margin: 0; }
#authMode { margin-bottom: 18px; }
.auth-card .field { margin-bottom: 13px; }

/* ----------------------------------------------------------- мобильный */

.tabbar { display: none; }

@media (max-width: 720px) {
  .tabs { display: none; }
  .topbar { padding: 10px 14px; gap: 10px; }
  .brand-text b { font-size: 14px; }
  main { padding: 14px 14px calc(var(--tabbar-h) + 22px); }

  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    display: flex; align-items: stretch;
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: color-mix(in srgb, var(--bg-elev) 88%, transparent);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 1px solid var(--line);
  }
  .tabbar button {
    flex: 1; border: 0; background: transparent; color: var(--text-2);
    font: inherit; font-size: 10.5px; font-weight: 550;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; cursor: pointer; padding: 0;
  }
  .tabbar button.active { color: var(--brand); }

  .hero { flex-direction: column; }
  .hero-value { font-size: 34px; }
  .hero-side { flex-direction: row; }
  .mini { flex: 1; min-width: 0; }

  .grid-2 { grid-template-columns: 1fr; }

  .entry { flex-wrap: wrap; gap: 10px; }
  .entry .e-main { min-width: 0; flex: 1 1 auto; }
  .entry .e-meta { flex-direction: row; gap: 8px; min-width: 0; }
  .entry .e-note { flex: 1 1 100%; }
  .entry .e-actions { margin-left: auto; }

  .slot-row { grid-template-columns: 74px repeat(3, 1fr); font-size: 13px; }
  .slot-row .hide-mobile { display: none; }
  .cat-row { grid-template-columns: 130px 1fr 40px; font-size: 13px; }
}

@media (max-width: 380px) {
  .hero-value { font-size: 30px; }
  .stat b { font-size: 19px; }
}
