/* === Sonata PWA === */

:root {
  --bg: #0f1115;
  --bg-2: #161a22;
  --bg-3: #1f2430;
  --line: #2a3140;
  --text: #e7ecf3;
  --muted: #8a93a6;
  --accent: #7c9eff;
  --accent-2: #6ee7b7;
  --warn: #fbbf24;
  --danger: #f87171;
  --done: #34d399;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fb;
    --bg-2: #ffffff;
    --bg-3: #eef1f7;
    --line: #dde2ec;
    --text: #14181f;
    --muted: #5b6478;
    --shadow: 0 8px 24px rgba(20, 24, 31, 0.08);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "SF Pro Text", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.muted { color: var(--muted); padding: 20px; text-align: center; }

/* Визуальный feedback при сохранении фазы */
.card.saving { opacity: 0.7; transition: opacity 0.15s ease; }
.card.just-saved {
  animation: savedFlash 1.2s ease;
}
@keyframes savedFlash {
  0%   { box-shadow: 0 0 0 0 rgba(34,197,94,0.0); }
  20%  { box-shadow: 0 0 0 4px rgba(34,197,94,0.25); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0.0); }
}

/* Время в карточке */
.card-time { color: var(--muted); font-weight: 500; font-size: 13px; }

/* Бейдж "авто" для дефолтного времени */
.group-time.is-default { opacity: 0.85; cursor: pointer; padding: 2px 6px; border-radius: 8px; }
.group-time.is-default:hover { background: var(--bg-3); }
.group-time { cursor: pointer; user-select: none; }
.hint-badge {
  font-size: 9px;
  background: var(--bg-3);
  color: var(--muted);
  padding: 1px 5px;
  border-radius: 4px;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.muted.small { font-size: 12px; padding: 8px 0; }

/* Плавные переключения табов */
#day { transition: opacity 0.15s ease; }
.is-loading { opacity: 0.55; transition: opacity 0.15s ease; pointer-events: none; }
body[data-tab] #day { min-height: 300px; }

/* Кнопка taken — плавная */
.taken-btn { transition: transform 0.1s ease, opacity 0.15s ease; }
.taken-btn:active { transform: scale(0.95); }

/* Плавный UI: когда идёт фоновая загрузка */
.is-loading { opacity: 0.5; transition: opacity 0.2s ease; pointer-events: none; }

/* Выбор фазы в карточке лекарства */
.med-phase-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.med-phase-label {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}

.med-phase-select {
  flex: 1;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}

.med-phase-select:focus { border-color: var(--accent); }

/* Мульти-фаза: список слотов */
.med-phase-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.med-phase-section-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 8px;
}

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

.med-slot {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: center;
}

.med-slot-time {
  font-size: 13px;
  color: var(--text);
  font-weight: 500;
  min-width: 90px;
}

/* === Header === */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
}
.brand-emoji { font-size: 22px; }

/* === Day === */

.day {
  padding: 12px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.day-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 0 6px;
}

.day-title {
  flex: 1;
  text-align: center;
}

.day-date {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-transform: lowercase;
}

.day-progress {
  font-size: 13px;
  color: var(--muted);
  margin-top: 2px;
}

.day-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-3);
  border-radius: 6px;
  overflow: hidden;
}
.day-progress-bar > div {
  height: 100%;
  background: var(--done);
  border-radius: 6px;
  transition: width 0.3s ease;
}

/* === Group === */

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

.group-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 4px 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.group-emoji { font-size: 15px; }
.group-label { flex: 1; }
.group-count {
  background: var(--bg-3);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
}

.group-time {
  background: var(--bg-3);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0;
}

/* === Card === */

.card {
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  position: relative;
  overflow: hidden;
  animation: fade-in 0.2s ease;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--card-accent, var(--accent));
  border-radius: 4px 0 0 4px;
}

.card.taken { opacity: 0.55; }
.card.skipped { opacity: 0.4; }

.card-main {
  display: flex;
  align-items: center;
  gap: 12px;
}

.card-info {
  flex: 1;
  min-width: 0;
}

.card-name {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-dose {
  font-size: 22px;
  font-weight: 700;
  margin-top: 4px;
  letter-spacing: -0.01em;
  color: var(--text);
}

.card-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* прогресс-бар */
.card-progress {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card-progress-track {
  height: 6px;
  background: var(--bg-3);
  border-radius: 6px;
  overflow: hidden;
}
.card-progress-fill {
  height: 100%;
  background: var(--card-accent, var(--accent));
  border-radius: 6px;
  transition: width 0.3s ease;
}
.card-progress-text {
  font-size: 11px;
  color: var(--muted);
  text-align: right;
  letter-spacing: 0.02em;
}

/* кнопка «Готово» */
.taken-btn {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  transition: transform 0.1s ease, background 0.15s ease;
  flex-shrink: 0;
}

.taken-btn:active { transform: scale(0.92); }
.taken-btn.taken {
  background: var(--done);
  border-color: var(--done);
  color: #052e1f;
}
.taken-btn.skipped {
  background: var(--warn);
  border-color: var(--warn);
  color: #422b06;
}

/* === Empty === */
.empty {
  text-align: center;
  padding: 60px 24px;
  color: var(--muted);
}
.empty-emoji { font-size: 42px; }
.empty-title { margin-top: 8px; font-size: 17px; color: var(--text); font-weight: 600; }
.empty-sub { margin-top: 4px; font-size: 13px; }

/* === Tabbar === */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--bg-2) 92%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + var(--safe-bottom));
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}

.tab[aria-current="page"] { color: var(--accent); }
.tab-emoji { font-size: 18px; }

/* === Toast === */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(96px + var(--safe-bottom));
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 50;
  animation: fade-in 0.2s ease;
}

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* === Settings === */
.list-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.settings-row-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
}

.settings-time {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 15px;
  font-family: inherit;
  outline: none;
  color-scheme: dark;
}

.settings-time:focus { border-color: var(--accent); }

.btn {
  border: none;
  border-radius: 12px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  background: var(--accent);
  color: #fff;
}
.btn:active { transform: scale(0.98); }
.btn.ghost { background: var(--bg-3); color: var(--text); }