/* Дневник тренировок — оформление.
   Принципы: крупные элементы под палец, тёмная тема (в зале часто свет слепит),
   минимум отвлекающего, никаких внешних шрифтов (в России CDN отваливаются). */
:root {
  --bg: #0f1115;
  --card: #171a21;
  --card2: #1e222b;
  --line: #2a2f3a;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --accent: #4c8dff;
  --ok: #3ecf8e;
  --warn: #f0b429;
  --err: #ff6b6b;
  --radius: 14px;
}

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

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 17px; line-height: 1.4;
  padding-bottom: env(safe-area-inset-bottom);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.error { color: var(--err); min-height: 22px; }

/* Предупреждение о сохранности данных (копия устарела) */
.alert {
  background: #3a1616; border: 1px solid var(--err); color: #ffc0c0;
  border-radius: var(--radius); padding: 10px 12px; margin: 0 0 12px; font-size: 15px;
}
.backup { padding: 8px 0; }
.backup.good { color: var(--ok); }
.backup.bad { color: var(--err); font-weight: 600; }

/* Уведомление о восстановленном черновике: кнопки внутри предупреждения. */
#draft-notice b { color: #fff; }
#draft-notice .draft-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
#draft-notice .draft-row button { padding: 8px 10px; font-size: 14px; }

.screen { max-width: 640px; margin: 0 auto; padding: 12px; }

/* --- вход --- */
.login-box { margin-top: 18vh; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-box h1 { font-size: 26px; margin: 0 0 4px; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local] {
  width: 100%; padding: 14px; font-size: 17px; color: var(--text);
  background: var(--card2); border: 1px solid var(--line); border-radius: var(--radius);
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  font: inherit; color: var(--text); background: var(--card2);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; cursor: pointer;
}
button:active { transform: translateY(1px); }
.big { padding: 16px; font-size: 18px; font-weight: 600; }
.primary { background: var(--accent); border-color: var(--accent); color: #06101f; }
.primary.save { background: var(--ok); border-color: var(--ok); color: #04220f; }
.ghost { background: transparent; }
.wide { width: 100%; }

/* --- верхняя панель --- */
.topbar { display: flex; align-items: center; gap: 8px; padding: 4px 0 10px; }
.brand { font-weight: 700; font-size: 18px; }
.status { margin-left: auto; font-size: 14px; color: var(--muted); }
.status.online { color: var(--ok); }
.status.offline { color: var(--warn); }
.status.pending { color: var(--warn); }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.tab { flex: 1; padding: 12px 8px; font-weight: 600; background: var(--card); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #06101f; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.row { display: flex; gap: 8px; margin: 10px 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { padding: 8px 10px; font-size: 15px; background: var(--card); }

/* --- выбор упражнения ---
   Отдельный список вместо поля со свободным вводом: так название выбирается
   из уже имеющихся, а почти-дубликаты («спин» и «Спин») не заводятся. */
select#ex-select, select#analysis-select {
  width: 100%; padding: 14px; font: inherit; font-size: 17px; font-weight: 600;
  color: var(--text); background-color: var(--card2);
  border: 1px solid var(--line); border-radius: var(--radius);
  appearance: none;                     /* своя стрелка — вид одинаков везде */
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
select#ex-select:focus, select#analysis-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.new-ex {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin: 8px 0;
}
.new-ex .field { margin-top: 0; }

/* --- ввод подхода --- */
.set-inputs { display: flex; gap: 8px; margin: 12px 0; }
/* min-width: 0 обязательно: без него поля ввода не сжимаются и выдавливают
   кнопки «−/+» за край экрана. */
.stepper { flex: 1; min-width: 0; }
/* Весу больше места, чем повторам: «100 кг» — три цифры, а «−2.5/+2.5» шире,
   чем «−1/+1». Раньше оба поля делили строку поровну, и в поле веса не
   помещалось три знака. */
#strength-inputs .stepper:nth-child(1) { flex: 1.35; }
#strength-inputs .stepper:nth-child(2) { flex: 1; }
.stepper-label { font-size: 14px; color: var(--muted); display: block; margin-bottom: 6px; }
.stepper-row { display: flex; align-items: center; gap: 6px; }
.stepper-row input {
  min-width: 0; width: 100%; text-align: center; font-size: 19px; font-weight: 700; padding: 10px 2px;
}
.step { min-width: 44px; padding: 12px 4px; font-size: 14px; }

.setlist { list-style: none; padding: 0; margin: 12px 0; }
.setlist li {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin-bottom: 8px;
}
.setlist .num { color: var(--muted); min-width: 26px; }
.setlist .val { font-weight: 600; flex: 1; }
.setlist .x { background: transparent; border: none; color: var(--err); font-size: 20px; padding: 4px 10px; }

/* --- самочувствие --- */
.feel { display: flex; gap: 8px; }
.feel button { flex: 1; font-size: 26px; padding: 10px 0; background: var(--card); }
.feel button.sel { background: var(--accent); border-color: var(--accent); }

/* --- история --- */
.history { list-style: none; padding: 0; margin: 0; }
.history li {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.history .h-head { display: flex; align-items: baseline; gap: 10px; }
.history .h-date { font-weight: 700; }
.history .h-meta { color: var(--muted); font-size: 14px; margin-left: auto; }
.history .h-sets { color: var(--muted); font-size: 15px; margin-top: 6px; }
.history .h-del { background: transparent; border: none; color: var(--err); padding: 4px 8px; }

/* --- анализ --- */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.totals div { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.totals b { display: block; font-size: 22px; margin-top: 4px; }
h2 { font-size: 17px; margin: 20px 0 8px; color: var(--muted); font-weight: 600; }
.chart { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; }
table { width: 100%; border-collapse: collapse; font-size: 15px; margin-top: 10px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; }


/* ---------------------------------------------------------- таймер отдыха */
/* Компактно: в зале экран нужен для ввода веса и подходов, а не для таймера. */
.rest {
  margin: 8px 0 10px; padding: 8px 10px;
  border: 1px solid #262b36; border-radius: 12px; background: #171a21;
}
.rest-top { display: flex; align-items: center; gap: 6px; }
.rest-label { color: #9aa0a6; font-size: 12px; }
.rest-time {
  margin-left: auto; font-size: 22px; font-weight: 700; letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums; color: #e8eaed;
}
.rest.running .rest-time { color: #3ecf8e; }
.rest-start .rest-time { font-size: 20px; }
.rest .chips { margin-top: 6px; }
.rest .rest-top button { min-width: 42px; min-height: 32px; padding: 6px 8px; font-size: 14px; }
/* Пресеты — своя строка, но без лишнего «воздуха» снизу от общего правила .chips */
#rest-presets { margin: 4px 0 0; }
#rest-presets .chip { padding: 6px 9px; font-size: 14px; }

/* выбранный пресет отдыха и выбранное самочувствие — явно заметны */
.chip.active { border-color: #4c8dff; color: #fff; background: #1d2634; }

/* две кнопки в один ряд (на узком экране — друг под другом) */
.row.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
@media (max-width: 360px) { .row.two { grid-template-columns: 1fr; } }


/* --- тип упражнения: силовое или кардио --- */
.kind-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0;
}
.kind-toggle button {
  padding: 12px 8px; border: 1px solid #262b36; background: #171a21;
  color: #e8eaed; border-radius: 12px; font-size: 15px;
}
.kind-toggle button.active {
  border-color: #4c8dff; background: #1c2434; color: #fff; font-weight: 600;
}

/* ---------------------------------------------------- четыре вкладки */
/* «Календарь» — четвёртая вкладка, на узком экране подписи надо ужать. */
.tabs .tab { font-size: 15px; padding: 12px 4px; }

/* ---------------------------------------------------- детали тренировки */
.history li[data-w] { cursor: pointer; }
.history .h-open { color: var(--muted); font-size: 20px; line-height: 1; padding: 0 6px; }
.detail-head { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.detail-head .h-del {
  margin-left: auto; background: transparent; border: none; color: var(--err); font-size: 15px;
}
.detail-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px; margin-bottom: 6px;
}
.detail-card .d-date { font-weight: 700; font-size: 17px; }
.detail-card .d-note { margin-top: 8px; }
table tr.warmup { color: var(--muted); }

/* Строка упражнения внутри таблицы подходов: название, значок вида и итог. */
table.detail-sets { margin-top: 14px; }
table.detail-sets tr.ex-row td { background: var(--card2); }
.ex-line { display: flex; align-items: baseline; gap: 6px; }
.ex-line .ex-icon { font-size: 15px; }
.ex-line .ex-name { font-weight: 700; }
.ex-line .ex-total { margin-left: auto; color: var(--muted); font-size: 14px; }

/* ---------------------------------------------------- календарь */
.cal-head { display: flex; align-items: center; gap: 8px; margin: 4px 0 10px; }
.cal-title { flex: 1; text-align: center; font-weight: 700; font-size: 18px; }
.cal-head button { min-width: 48px; font-size: 20px; }
.cal-head button:disabled { opacity: 0.3; }
.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
  text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 6px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-cell {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  min-height: 54px; padding: 4px 2px; text-align: center;
}
.cal-cell.empty { background: transparent; border-color: transparent; }
.cal-cell.has { cursor: pointer; }
.cal-cell.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.cal-cell .cal-num { font-size: 14px; color: var(--muted); }
.cal-cell.has .cal-num { color: var(--text); font-weight: 700; }
.cal-cell .cal-marks { font-size: 15px; line-height: 1.2; }
.cal-legend { margin: 10px 0 4px; }

/* ---------------------------------------------------- терапия */
.th-upcoming { margin: 2px 0 8px; }
.th-upcoming b { color: var(--text); }
.th-upcoming .due { color: var(--warn); font-weight: 600; }

.th-day {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin: 12px 0 8px;
}
.th-day h2 { margin: 0 0 8px; font-size: 17px; }

.th-intakes { margin: 6px 0 10px; }
.th-intake {
  display: grid; grid-template-columns: 1fr 74px 66px 30px;
  grid-template-areas: "med dose vol del" "site site site site";
  gap: 6px; align-items: center;
  background: var(--card2); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px; margin-bottom: 8px;
}
.th-intake select[data-role=med] { grid-area: med; }
.th-intake input[data-role=dose] { grid-area: dose; }
.th-intake input[data-role=volume] { grid-area: vol; }
.th-intake button[data-role=del] { grid-area: del; }
.th-intake select[data-role=site] { grid-area: site; }
.th-intake input, .th-intake select { min-height: 38px; padding: 6px 8px; font-size: 15px; }
.th-intake .x {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  min-height: 38px; padding: 0;
}
.th-intake .vol-note { grid-area: vol; font-size: 13px; color: var(--muted); text-align: center; }
.th-add-row select { flex: 1; }

.th-meds .th-med {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px; margin-bottom: 8px;
}
.th-meds .th-med input { min-height: 38px; padding: 6px 8px; font-size: 15px; }
/* Подписи полей карточки препарата — видимым текстом, а не placeholder'ом:
   placeholder исчезает, как только в поле есть значение, и остаются три числа
   подряд без смысла. */
.th-meds .th-med .med-field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.th-meds .th-med .med-field > span { font-size: 11px; line-height: 1.2; color: var(--muted); }
.th-meds .th-med .med-field.wide { grid-column: 1 / -1; }
/* На узком экране две колонки не помещаются: «Концентрация, мг/мл» ломается
   на три строки, а имя препарата обрезается. Пусть будет одна колонка. */
@media (max-width: 420px) {
  .th-meds .th-med { grid-template-columns: 1fr; }
}
.th-meds .th-med .med-name { grid-column: 1 / -1; font-weight: 700; }
.th-meds .th-med .med-foot {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--muted);
}
.th-meds .th-med .med-foot button { margin-left: auto; padding: 6px 10px; font-size: 14px; }
.cal-cell.sel { outline: 2px solid var(--ok); outline-offset: -2px; }

/* Селекты вне двух «именных» (выбор упражнения / анализа) не были оформлены
   вовсе — в тёмной теме они оставались белыми. Правило общее, а конкретные
   #ex-select и #analysis-select переопределяют его выше. */
select {
  font: inherit; color: var(--text); background: var(--card2);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; width: 100%;
}
select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.th-intake select, .th-intake input { border-radius: 8px; }
.th-meds .th-med input { border-radius: 8px; }
