/* ─── Reset ─────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Токены: светлая тема ──────────────────────────────── */
:root {
  --bg: #F5F5F3;
  --card: #FFFFFF;
  --card-alt: #EEEDE9;
  --text: #18181A;
  --text-2: #68686E;
  --text-3: #A8A8B0;
  --border: rgba(0,0,0,0.07);
  --border-strong: rgba(0,0,0,0.13);
  --shadow: 0 1px 3px rgba(0,0,0,0.05), 0 4px 16px rgba(0,0,0,0.05);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.14);
  --accent: #D94040;
  --accent-b: #2878C8;
  --radius: 18px;
  --radius-sm: 11px;
  --tr: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

/* ─── Тёмная тема (явная) ───────────────────────────────── */
html[data-theme="dark"] {
  --bg: #111112;
  --card: #1C1C1E;
  --card-alt: #252528;
  --text: #F2F2F5;
  --text-2: #A0A0AA;
  --text-3: #606068;
  --border: rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.13);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
  color-scheme: dark;
}

/* ─── Системная тёмная ──────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #111112;
    --card: #1C1C1E;
    --card-alt: #252528;
    --text: #F2F2F5;
    --text-2: #A0A0AA;
    --text-3: #606068;
    --border: rgba(255,255,255,0.07);
    --border-strong: rgba(255,255,255,0.13);
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.25);
    --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);
    color-scheme: dark;
  }
}

html[data-theme="light"] { color-scheme: light; }
html, html[data-theme="system"] { color-scheme: light dark; }

/* ─── База ──────────────────────────────────────────────── */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  padding: 20px 16px 100px; /* низ — место для FAB */
  transition: var(--tr);
  -webkit-text-size-adjust: 100%;
}

/* ─── Лейаут ────────────────────────────────────────────── */
.app {
  max-width: 680px;
  margin: 0 auto;
  display: grid;
  gap: 12px;
}

/* ─── Карточка ──────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: var(--tr);
}

/* ─── Шапка ─────────────────────────────────────────────── */
.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 4px 2px 8px;
  gap: 12px;
}

.header-title h1 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.6px;
  color: var(--text);
  line-height: 1.1;
}

.header-sub {
  font-size: 13px;
  color: var(--text-3);
  margin-top: 3px;
}

/* ─── Переключатель темы ────────────────────────────────── */
.theme-toggle {
  display: flex;
  background: var(--card-alt);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
  transition: var(--tr);
  flex-shrink: 0;
}

.theme-btn {
  width: 30px;
  height: 28px;
  border: none;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-3);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.18s;
}

.theme-btn.active {
  background: var(--card);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0,0,0,0.14);
}

.theme-btn:hover:not(.active) { color: var(--text-2); }

/* ─── Статистика — всегда 3 колонки ────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.stat-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 14px;
  box-shadow: var(--shadow);
  transition: var(--tr);
  min-width: 0; /* предотвращаем переполнение */
}

.stat-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
  letter-spacing: -0.3px;
}

.stat-hint {
  font-size: 10px;
  color: var(--text-3);
  margin-top: 5px;
}

/* ─── График ────────────────────────────────────────────── */
.chart-legend {
  display: flex;
  gap: 14px;
  margin-bottom: 14px;
}

.leg-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
}

.leg-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 180px;
}

.chart-empty-msg {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: var(--text-3);
  pointer-events: none;
}

.chart-empty-msg.hidden { display: none; }

/* ─── Тулбар над историей ───────────────────────────────── */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 10px;
}

.list-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.list-actions {
  display: flex;
  gap: 6px;
}

.btn-tool {
  height: 30px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-tool:hover {
  background: var(--card-alt);
  color: var(--text);
}

/* ─── Подсказка свайпа ──────────────────────────────────── */
.swipe-hint {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-3);
  margin-bottom: 10px;
}

/* Только на тач-устройствах */
@media (hover: none) {
  .swipe-hint { display: flex; }
}

/* ─── Раздел label ──────────────────────────────────────── */
.section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  display: block;
  margin-bottom: 0;
}

/* ─── Свайп-обёртка ─────────────────────────────────────── */
.swipe-wrap {
  position: relative;
  overflow: hidden;
  border-bottom: 0.5px solid var(--border);
}

.swipe-wrap:last-child { border-bottom: none; }

.swipe-bg {
  position: absolute;
  top: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.1s;
  pointer-events: none;
  white-space: nowrap;
}

.swipe-left-bg {
  right: 0;
  background: var(--accent);
  color: #fff;
  justify-content: flex-end;
  min-width: 110px;
}

.swipe-right-bg {
  left: 0;
  background: var(--accent-b);
  color: #fff;
  min-width: 110px;
}

/* ─── Запись ────────────────────────────────────────────── */
.record {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  background: var(--card);
  position: relative;
  z-index: 1;
  will-change: transform;
  touch-action: pan-y;
}

.rec-date-col { min-width: 58px; }

.rec-date {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
}

.rec-time {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 1px;
}

.rec-bp {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  min-width: 78px;
  letter-spacing: -0.3px;
}

.rec-slash {
  color: var(--text-3);
  font-weight: 400;
}

.rec-pulse {
  font-size: 13px;
  color: var(--text-2);
  min-width: 50px;
}

.rec-note {
  font-size: 12px;
  color: var(--text-3);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Бейджи ────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.b-low      { background: #E0EDFF; color: #0A47A0; }
.b-norm     { background: #E2F5DA; color: #2A5C0B; }
.b-elevated { background: #FFF3D6; color: #7A4700; }
.b-high-1   { background: #FFE4CC; color: #8A3800; }
.b-high-2   { background: #FFD6D6; color: #991A1A; }
.b-high-3   { background: #FFB3B3; color: #7A0000; }
.b-unknown  { background: var(--card-alt); color: var(--text-3); }

html[data-theme="dark"] .b-low,
html[data-theme="dark"] .b-norm,
html[data-theme="dark"] .b-elevated,
html[data-theme="dark"] .b-high-1,
html[data-theme="dark"] .b-high-2,
html[data-theme="dark"] .b-high-3 { filter: brightness(0.72) saturate(1.4); }

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]):not([data-theme="dark"]) .b-low,
  html:not([data-theme="light"]):not([data-theme="dark"]) .b-norm,
  html:not([data-theme="light"]):not([data-theme="dark"]) .b-elevated,
  html:not([data-theme="light"]):not([data-theme="dark"]) .b-high-1,
  html:not([data-theme="light"]):not([data-theme="dark"]) .b-high-2,
  html:not([data-theme="light"]):not([data-theme="dark"]) .b-high-3 { filter: brightness(0.72) saturate(1.4); }
}

/* ─── Кнопка удаления (только не-тач) ──────────────────── */
.btn-del {
  width: 28px;
  height: 28px;
  border: none;
  background: none;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.14s;
}

.btn-del:hover {
  color: var(--accent);
  background: rgba(217,64,64,0.1);
}

/* На тач-устройствах кнопку удаления скрываем — используем свайп */
@media (hover: none) {
  .btn-del { display: none; }
}

/* ─── Пустое состояние ──────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 40px 0 24px;
  color: var(--text-3);
  font-size: 13px;
}

.empty-icon {
  font-size: 30px;
  margin-bottom: 10px;
  opacity: 0.35;
}

/* ─── FAB ───────────────────────────────────────────────── */
.fab {
  position: fixed;
  bottom: 28px;
  right: 20px;
  z-index: 50;
  height: 52px;
  padding: 0 22px 0 16px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 20px rgba(217,64,64,0.38);
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.fab:hover {
  transform: scale(1.03);
  box-shadow: 0 6px 28px rgba(217,64,64,0.45);
}

.fab:active { transform: scale(0.97); }

.fab.hidden {
  transform: scale(0.8) translateY(20px);
  opacity: 0;
  pointer-events: none;
}

/* ─── Модальное окно ────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 80;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  background: var(--card);
  width: 100%;
  max-width: 540px;
  border-radius: 22px 22px 0 0;
  padding: 12px 20px 36px;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.34, 1.2, 0.64, 1);
  max-height: 92dvh;
  overflow-y: auto;
}

.modal-overlay.open .modal-sheet {
  transform: translateY(0);
}

/* Десктоп — центрированный попап */
@media (min-width: 620px) {
  .modal-overlay { align-items: center; }

  .modal-sheet {
    border-radius: 22px;
    padding: 24px 24px 28px;
    max-width: 480px;
    transform: scale(0.94) translateY(20px);
  }

  .modal-overlay.open .modal-sheet {
    transform: scale(1) translateY(0);
  }

  .modal-handle { display: none; }
}

/* Ручка */
.modal-handle {
  width: 36px;
  height: 4px;
  background: var(--border-strong);
  border-radius: 2px;
  margin: 0 auto 16px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: none;
  background: var(--card-alt);
  border-radius: 999px;
  cursor: pointer;
  color: var(--text-2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  flex-shrink: 0;
}

.modal-close:hover { color: var(--text); }

/* ─── Форма в модале ────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-full { grid-column: 1 / -1; }

.field-label {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  letter-spacing: 0.02em;
}

.field-input {
  width: 100%;
  height: 46px;
  padding: 0 12px;
  background: var(--card-alt);
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

.field-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--card);
}

.field-input::placeholder { color: var(--text-3); }

/* ─── Дата/время — единое поле ──────────────────────────── */
.date-wrap {
  position: relative;
}

.date-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
  z-index: 1;
}

.field-input.has-icon { padding-left: 34px; cursor: pointer; }

input[type="datetime-local"]::-webkit-calendar-picker-indicator {
  opacity: 0;
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: pointer;
}

/* ─── Кнопка «Добавить» в модале ───────────────────────── */
.btn-add {
  width: 100%;
  height: 48px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.01em;
  transition: opacity 0.15s, transform 0.1s;
}

.btn-add:hover  { opacity: 0.82; }
.btn-add:active { transform: scale(0.99); }

/* ─── Toast ──────────────────────────────────────────────  */
.toast {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0;
  transition: opacity 0.28s ease, transform 0.28s ease;
  pointer-events: none;
  white-space: nowrap;
  z-index: 200;
  max-width: calc(100vw - 40px);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ─── Оверлей D&D ───────────────────────────────────────── */
.drag-overlay {
  position: fixed;
  inset: 12px;
  background: rgba(217,64,64,0.06);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: 20px;
}

.drag-overlay.visible { display: flex; }

.drag-overlay-inner {
  text-align: center;
  color: var(--accent);
  pointer-events: none;
}

.drag-overlay-inner svg { margin-bottom: 12px; }

.drag-overlay-title {
  font-size: 17px;
  font-weight: 600;
}

/* ─── Адаптив ───────────────────────────────────────────── */
@media (max-width: 560px) {
  body { padding: 14px 12px 100px; }

  .app { gap: 10px; }

  .header-title h1 { font-size: 22px; }

  .card { padding: 16px; border-radius: 14px; }
  .stat-card { border-radius: 14px; padding: 14px 10px; }
  .stat-value { font-size: 17px; }
  .stat-label { font-size: 9px; }

  .rec-note { display: none; }

  .fab { bottom: 20px; right: 16px; height: 48px; font-size: 14px; }
}
