/* sleep-diary — тёмная тема для ночного использования с телефона.
   Два уровня темноты: dark (обычная ночь) и night — «спальный режим»:
   тёплый янтарный спектр и пониженная яркость, меньше бьёт по глазам
   спросонья и слабее подавляет мелатонин. */

:root,
:root[data-theme="dark"] {
  --bg:        #0e1014;
  --surface:   #171a21;
  --surface-2: #1f232c;
  --line:      #2a2f3a;
  --text:      #e6e1d8;
  --muted:     #9aa0ad;
  --accent:    #d9a05b;
  --accent-dim:#3a2e1f;
  --good:      #7fb08a;
  --warn:      #d98b5b;
  --danger:    #c2685f;
  --tap:       52px;
  --radius:    14px;
}

:root[data-theme="night"] {
  --bg:        #000000;
  --surface:   #0b0805;
  --surface-2: #14100a;
  --line:      #241b10;
  --text:      #c08a45;
  --muted:     #6d5330;
  --accent:    #e0a050;
  --accent-dim:#2a1d0c;
  --good:      #8a7a45;
  --warn:      #a8712f;
  --danger:    #96543a;
}

:root[data-theme="night"] body { filter: brightness(0.82); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

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

header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

header h1 { font-size: 15px; font-weight: 600; margin: 0; flex: 1; }
header .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }

.theme-toggle {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--accent);
  font-size: 18px;
  flex: none;
}

/* ------------------------------------------------------------------ секции */

main { padding: 12px 14px; max-width: 640px; margin: 0 auto; }
section[hidden] { display: none; }

.field { margin-bottom: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

label.q {
  display: block;
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 6px;
}

h2.group {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 20px 0 8px;
}

/* ------------------------------------------------- навигация по ночам */

.night-nav {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  gap: 8px;
  margin-bottom: 12px;
}

.night-nav button {
  min-height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 15px;
  padding: 0 8px;
}

.night-nav button:disabled { opacity: 0.35; }

/* ------------------------------------------------- ввод времени и текста */

input[type="time"], input[type="text"], textarea {
  width: 100%;
  min-height: var(--tap);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  padding: 0 12px;
  text-align: center;
  appearance: none;
}

input[type="text"], textarea {
  font-size: 16px;
  text-align: left;
  padding: 12px;
}

textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* --------------------------------------------------------- крупные кнопки */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chips button {
  flex: 1 1 auto;
  min-width: 56px;
  min-height: 46px;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }

.scale button {
  min-height: 54px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 19px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 0 2px;
}

.scale button span { font-size: 9px; font-weight: 400; color: var(--muted); line-height: 1.1; }

.chips button[aria-pressed="true"],
.scale button[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.scale button[aria-pressed="true"] span { color: var(--accent); }

/* -------------------------------------------------------- переключатели */

.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--tap);
  padding: 0 4px 0 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.toggle > span { flex: 1; font-size: 15px; }
.toggle .yn { display: flex; gap: 4px; padding: 4px; flex: none; }

.toggle .yn button {
  min-width: 56px;
  min-height: 42px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 15px;
}

.toggle .yn button[aria-pressed="true"] {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* ------------------------------------------------------------- результат */

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 8px;
  margin-bottom: 16px;
}

.metrics.one { grid-template-columns: 1fr; padding: 14px 8px; }
.metrics.one b { font-size: 28px; }
.metrics div { text-align: center; }
.metrics b { display: block; font-size: 19px; font-variant-numeric: tabular-nums; }
.metrics small { font-size: 11px; color: var(--muted); }

/* --------------------------------------------------------------- дневник */

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

.night {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 64px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
}

.night.empty { opacity: 0.5; border-style: dashed; }
.night .date { flex: 1; font-size: 15px; }
.night .date small { display: block; color: var(--muted); font-size: 12px; }
.night .val { font-size: 18px; font-variant-numeric: tabular-nums; }
.night .val small { display: block; font-size: 10px; color: var(--muted); text-align: right; }

.badge { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); }
.badge.good { color: var(--good); }
.badge.warn { color: var(--warn); }
.badge.bad  { color: var(--danger); }

/* ----------------------------------------------------------------- отчёт */

.cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 12px;
}

.cards .card { margin-bottom: 0; }
.card b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.card small { font-size: 11px; color: var(--muted); }
.card .note { font-size: 11px; margin-top: 4px; }

.chart { width: 100%; height: 170px; }
.chart text { fill: var(--muted); font-size: 9px; }

.factor {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 14px;
}

.factor .name { flex: 1; }
.factor .name small { display: block; color: var(--muted); font-size: 11px; }
.factor .delta { font-size: 15px; font-variant-numeric: tabular-nums; }

/* --------------------------------------------------------- нижняя панель */

nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 10;
  display: flex;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}

nav button {
  flex: 1;
  min-height: 60px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

nav button i { font-style: normal; font-size: 20px; }
nav button[aria-current="true"] { color: var(--accent); }

.save-bar {
  position: fixed;
  left: 14px; right: 14px;
  bottom: calc(70px + env(safe-area-inset-bottom));
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
}

.save-bar.show { opacity: 1; }
.save-bar.ok { color: var(--good); }

/* ------------------------------------------------------------------- PIN */

.gate[hidden] { display: none; }

.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 24px;
}

.gate h2 { font-weight: 500; font-size: 18px; margin: 0; }
.gate input { max-width: 220px; letter-spacing: 8px; }
.gate button {
  min-height: var(--tap);
  width: 100%;
  max-width: 220px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 17px;
}
.gate .err { color: var(--danger); font-size: 14px; min-height: 20px; }

a.export {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  background: var(--surface);
}
