/* ===== Сон-трекер: mobile-first стили ===== */
/* Палитра: приглушённый бордово-розовый, песочный, тёплый зелёный акцент */

:root {
  /* светлая тема (день) */
  --bg: #f6efe6;
  --bg-2: #efe4d4;
  --surface: #ffffff;
  --surface-2: #fbf3ea;
  --text: #2b2228;
  --text-dim: #6b5867;
  --border: #e3d4c3;
  --accent: #6b8e6b;       /* тёплый зелёный */
  --accent-2: #8aaa78;
  --rose: #a85a6b;
  --rose-soft: #c98a93;
  --sand: #d6b98a;
  --amber: #d68a4a;
  --good: #6b8e6b;
  --warn: #d68a4a;
  --danger: #a85a6b;
  --sleep-night: #4a5670;
  --sleep-day: #b8cce0;
  --shadow: 0 2px 12px rgba(58, 40, 50, 0.08);
  --radius: 14px;
}

/* Тёмная тема: автоматически с 21:00 до 7:00 по локальному времени */
:root.dark {
  --bg: #1a1418;
  --bg-2: #221a1f;
  --surface: #261c22;
  --surface-2: #2d2128;
  --text: #efe1d8;
  --text-dim: #a99a9e;
  --border: #3a2c33;
  --accent: #7da077;
  --accent-2: #94b48a;
  --rose: #b97a89;
  --rose-soft: #c69aa1;
  --sand: #c0a578;
  --amber: #d9a06a;
  --good: #7da077;
  --warn: #d9a06a;
  --danger: #b97a89;
  --sleep-night: #5c6a86;
  --sleep-day: #6a7c95;
  --shadow: 0 2px 16px rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', 'PT Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  font-size: 17px;
  line-height: 1.45;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }

button {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
}

input, textarea, select {
  font-family: inherit;
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  width: 100%;
}
textarea { resize: vertical; min-height: 70px; }

a { color: var(--rose); }

/* === Контейнер === */
.app { max-width: 520px; margin: 0 auto; padding: 0 14px 80px; }

/* === Шапка === */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0 10px;
  position: sticky; top: 0; background: var(--bg); z-index: 20;
}
.profile-pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 44px;
  font-weight: 500;
}
.profile-pill .dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--rose-soft);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; color: white; font-weight: 600;
}
.sex-m .profile-pill .dot { background: #7a96b3; }
.sex-f .profile-pill .dot { background: var(--rose); }

.tabbar {
  display: flex; gap: 6px; padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  margin: 10px 0 18px;
}
.tabbar button {
  flex: 1; padding: 10px 6px; min-height: 44px;
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 14px; font-weight: 500;
}
.tabbar button.active { background: var(--accent); color: white; }

/* === Онбординг === */
.onboard {
  min-height: 100vh;
  display: flex; flex-direction: column; justify-content: center;
  padding: 24px 18px;
  background: linear-gradient(180deg, var(--bg) 0%, var(--bg-2) 100%);
}
.onboard h1 { font-size: 26px; margin-bottom: 6px; }
.onboard p.lead { color: var(--text-dim); margin: 0 0 24px; }
.onboard .field { margin-bottom: 16px; }
.onboard label { display: block; margin-bottom: 6px; font-size: 14px; color: var(--text-dim); }
.onboard .sex-toggle {
  display: flex; gap: 8px;
}
.onboard .sex-toggle button {
  flex: 1; padding: 14px; min-height: 56px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; font-weight: 500;
}
.onboard .sex-toggle button.active.m { background: #d6e2ef; border-color: #7a96b3; color: #2c3e50; }
.onboard .sex-toggle button.active.f { background: #efd6db; border-color: var(--rose); color: #6b2733; }
:root.dark .onboard .sex-toggle button.active.m { background: #2c3e50; color: #d6e2ef; }
:root.dark .onboard .sex-toggle button.active.f { background: #4a2730; color: #efd6db; }

.btn-primary {
  display: block; width: 100%;
  padding: 16px; min-height: 56px;
  background: var(--accent); color: white;
  border-radius: 14px; font-weight: 600;
  font-size: 17px;
  margin-top: 12px;
}
.btn-primary:disabled { opacity: 0.4; }
.btn-secondary {
  display: block; width: 100%;
  padding: 14px; min-height: 48px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 8px;
}
.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 14px; min-height: 44px;
  border-radius: 10px; color: var(--text-dim);
  font-size: 14px;
}
.btn-ghost:active { background: var(--surface-2); }

/* === Большая центральная кнопка трекера === */
.tracker-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.tracker-card .label-row { display:flex; align-items:baseline; justify-content:space-between; margin-bottom: 14px; }
.tracker-card .status { font-size: 14px; color: var(--text-dim); }
.big-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 100%;
  padding: 28px 14px;
  min-height: 140px;
  border-radius: 18px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-2) 100%);
  color: white;
  font-weight: 600;
  font-size: 22px;
  margin-bottom: 14px;
  box-shadow: 0 6px 20px rgba(107, 142, 107, 0.3);
}
.big-btn.night {
  background: linear-gradient(180deg, #6b7da0 0%, #4a5670 100%);
  box-shadow: 0 6px 20px rgba(74, 86, 112, 0.3);
}
.big-btn .timer { font-size: 14px; opacity: 0.92; margin-top: 6px; font-weight: 500; }

/* Шкала окна сна */
.window {
  position: relative;
  height: 56px;
  background: var(--surface-2);
  border-radius: 10px;
  margin: 12px 0 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.window .scale {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0;
  display: flex;
}
.window .scale .early { background: rgba(214, 138, 74, 0.18); flex: 1; }
.window .scale .good { background: rgba(107, 142, 107, 0.32); flex: 1.6; }
.window .scale .late { background: rgba(168, 90, 107, 0.22); flex: 1; }
.window .now-marker {
  position: absolute; top: 0; bottom: 0;
  width: 3px; background: var(--text);
  transition: left 0.3s;
  border-radius: 2px;
}
.window .now-marker::after {
  content: ''; position: absolute; left: 50%; top: -5px;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 7px solid var(--text);
}
.window-labels { display: flex; justify-content: space-between; font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.window-hint { font-size: 15px; color: var(--text); margin-top: 10px; }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 14px; min-height: 44px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 14px;
  color: var(--text);
}
.chip:active { background: var(--surface); }
.chip.active { background: var(--accent); color: white; border-color: var(--accent); }
.chip.amber.active { background: var(--amber); border-color: var(--amber); }

.section-title { font-size: 13px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; margin: 18px 0 10px; font-weight: 600; }

/* === Карточка записи дня === */
.day-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
.day-card .head { display: flex; justify-content: space-between; align-items: baseline; }
.day-card .head .when { font-size: 14px; color: var(--text-dim); }
.day-card .head .dur { font-weight: 600; font-size: 17px; }
.day-card .meta { display:flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.day-card .note { font-size: 14px; color: var(--text-dim); margin-top: 6px; }
.day-card .actions { display:flex; gap: 6px; margin-top: 10px; }
.day-card .actions button { padding: 8px 12px; min-height: 36px; border-radius: 8px; background: var(--surface-2); font-size: 13px; color: var(--text-dim); }

.metric-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
.metric-card .name { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.metric-card .val { font-size: 22px; font-weight: 700; margin-top: 4px; }
.metric-card .norm { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.metric-card.in-norm .val { color: var(--good); }
.metric-card.below .val { color: var(--warn); }
.metric-card.above .val { color: var(--rose); }

.alert-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--amber);
  border-radius: 12px;
  margin-bottom: 10px;
}
.alert-card.ok { border-left-color: var(--good); }
.alert-card.soon { border-left-color: var(--accent); }
.alert-card.warn { border-left-color: var(--amber); }
.alert-card.danger { border-left-color: var(--rose); }
.alert-card .icon { font-size: 22px; }
.alert-card .body { flex: 1; }
.alert-card .title { font-weight: 600; margin-bottom: 4px; }
.alert-card .text { font-size: 14px; color: var(--text); }
.alert-card .why { font-size: 13px; color: var(--text-dim); margin-top: 6px; display: none; }
.alert-card .action { font-size: 13px; color: var(--text); margin-top: 8px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.alert-card .toggle { font-size: 12px; color: var(--text-dim); margin-top: 6px; }
.alert-card.expanded .why { display: block; }

.disclaimer { font-size: 12px; color: var(--text-dim); padding: 12px; background: var(--surface-2); border-radius: 10px; margin-top: 14px; }

/* === Дашборд === */
.dashboard { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin-bottom: 16px; box-shadow: var(--shadow); overflow-x: auto; }
.dashboard h3 { font-size: 14px; margin-bottom: 8px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.dashboard svg { display: block; width: 100%; height: auto; }

/* === Формы и кнопки в модалках === */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 100; display: flex; align-items: flex-end; justify-content: center; padding: 14px; }
.modal {
  background: var(--surface);
  border-radius: 18px 18px 14px 14px;
  padding: 18px;
  width: 100%; max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h2 { margin-bottom: 12px; }
.modal .field { margin-bottom: 12px; }
.modal label { display:block; font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.modal .actions { display: flex; gap: 8px; margin-top: 14px; }
.modal .actions button { flex: 1; min-height: 48px; padding: 12px; border-radius: 12px; font-weight: 600; }
.modal .actions .save { background: var(--accent); color: white; }
.modal .actions .cancel { background: var(--surface-2); color: var(--text); }
.modal .actions .delete { background: var(--rose); color: white; }

.profile-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; }
.profile-list .item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; min-height: 52px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px;
}
.profile-list .item.active { border-color: var(--accent); }

.search { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; min-height: 44px; margin-bottom: 12px; }

.bullet-list { font-size: 14px; color: var(--text-dim); padding-left: 18px; margin: 6px 0 0; }
.bullet-list li { margin-bottom: 4px; }

.muted { color: var(--text-dim); font-size: 13px; }
.center { text-align: center; }
.spacer { height: 12px; }

/* Узкий телефон */
@media (max-width: 360px) {
  body { font-size: 16px; }
  .big-btn { min-height: 120px; font-size: 20px; }
  .metric-card .val { font-size: 18px; }
}
