:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --text: #e8eef7;
  --muted: #9aa9bf;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok: #16a34a;
  --warn: #d97706;
  --err: #ef4444;
  --border: #33415580;
  --radius: 14px;
  --tap: 48px;              /* минимальная площадь нажатия на телефоне */
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #eef2f7;
    --text: #0f172a;
    --muted: #55647d;
    --border: #d5dde8;
    --err: #dc2626;
  }
}

* { box-sizing: border-box; }

/* Скрытие через атрибут hidden должно побеждать любой display из классов:
   иначе .calendar { display: grid } и .btn { display: inline-flex }
   оставляли календарь и кнопку «К последним» на экране всегда. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

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

.screen[hidden] { display: none; }

h1 { font-size: 20px; margin: 0 0 2px; }
h2.section-title {
  font-size: 13px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 22px 0 8px;
}

/* ------------------------------------------------------------ раскладка */

main.layout {
  padding: 0 14px 40px;
  max-width: 1100px;
  margin: 0 auto;
  display: grid;
  gap: 0 24px;
  grid-template-columns: 1fr;
}

/* Планшет и альбомная ориентация: две колонки, лента рядом с камерой */
@media (min-width: 760px) {
  main.layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  main.layout .column:first-child { position: sticky; top: 64px; align-self: start; }
  h2.section-title { margin-top: 12px; }
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; max-width: 1100px; margin: 0 auto;
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
}
.who { min-width: 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.who strong { font-size: 15px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin: 12px 0;
  display: grid;
  gap: 12px;
}

.login-card { max-width: 420px; margin: 8vh auto; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { border-radius: 12px; }
.brand p { margin: 0; font-size: 13px; }

/* -------------------------------------------------------------- поля */

label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
label.row { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text); min-height: var(--tap); }
label.row input { width: 22px; height: 22px; accent-color: var(--accent); }

input[type=text], input[type=password], select {
  width: 100%;
  min-height: var(--tap);
  padding: 12px;
  font-size: 16px;         /* меньше 16px вызывает зум на iOS */
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
/* Пустой номер карты: снимать не мешаем, но поле заметно */
input.needs-value { border-color: var(--err); }

/* ------------------------------------------------- выбор компьютеров */

.targets { display: grid; gap: 8px; }
.targets-head {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 13px; color: var(--muted);
}
.targets-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.targets-list li { margin: 0; }
.targets-list label {
  display: flex; align-items: center; gap: 10px;
  min-height: var(--tap); padding: 8px 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 10px; cursor: pointer;
}
.targets-list label.on { border-color: var(--accent); }
.targets-list input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
.targets-list .who-pc { flex: 1; min-width: 0; display: grid; gap: 2px; }
.targets-list .name { font-size: 15px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Состояние и каталог сохранения — у каждого компьютера свои */
.targets-list .state-line { font-size: 11px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.targets-list .rename, .targets-list .forget {
  flex: none; background: none; border: none;
  color: var(--muted); font-size: 16px; line-height: 1;
  padding: 8px; margin: -8px 0; cursor: pointer;
}
.targets-list .forget { font-size: 20px; margin-right: -4px; }
.targets-list .forget:hover, .targets-list .forget:active { color: var(--err); }
.targets-list .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.targets-list .dot.online { background: var(--ok); }
/* Кнопка съёмки без выбранного адресата бесполезна: снимок некуда слать */
.btn.blocked { opacity: .5; pointer-events: none; }

details { border-top: 1px solid var(--border); padding-top: 10px; }
details summary {
  cursor: pointer; font-size: 14px; color: var(--muted);
  min-height: var(--tap); display: flex; align-items: center; gap: 8px;
  list-style: none;                 /* убираем системный треугольник */
}
details summary::-webkit-details-marker { display: none; }
/* Своя стрелка: без неё строка не читалась как раскрывающийся блок */
details summary::before {
  content: ""; flex: none; width: 9px; height: 9px;
  border-right: 2px solid currentColor; border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translate(-2px, -2px);
  transition: transform .15s;
}
details[open] summary::before { transform: rotate(-135deg) translate(-2px, -2px); }
.details-body { display: grid; gap: 12px; padding-top: 10px; }
/* Адресат в свёрнутой строке настроек */
.summary-value {
  margin-left: auto; padding-left: 10px;
  color: var(--text); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.summary-value.none { color: var(--err); font-weight: 400; }
/* Точка перед именем адресата: на связи ли он */
.summary-value.online::before, .summary-value.offline::before {
  content: ""; display: inline-block; vertical-align: middle;
  width: 7px; height: 7px; border-radius: 50%; margin-right: 6px;
}
.summary-value.online::before { background: var(--ok); }
.summary-value.offline::before { background: var(--muted); }

/* --------------------------------------------------- простая версия */

/* Экран для тех, кому нужно просто снять и отправить: крупные цели,
   никаких настроек, ничего лишнего на виду. */
#simple {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  padding: 16px;
  max-width: 560px; margin: 0 auto;
}
.simple-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.simple-top strong { font-size: 20px; }
.icon-btn {
  flex: none; width: 48px; height: 48px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--muted);
  border: 1px solid var(--border); border-radius: 12px; cursor: pointer;
}
.icon-btn:active { color: var(--err); }

.simple-main { display: grid; align-content: center; gap: 16px; }
.btn.huge {
  flex-direction: column; gap: 8px;
  min-height: 168px; font-size: 22px; border-radius: 18px;
}
.simple-gallery { min-height: 56px; font-size: 17px; }
/* Поле названия в простом виде — крупное, его заполняют перед каждым снимком */
.simple-job { min-height: 56px; font-size: 17px; text-align: center; }
.simple-job.needs-value { border-color: var(--err); }
.simple-hint { margin: -8px 0 0; text-align: center; font-size: 14px; color: var(--err); }

/* Кнопка появляется после съёмки и заметно отличается от прочих: её нужно
   нажать, иначе снимок в галерею не попадёт */
.save-photos {
  border-color: var(--accent); color: var(--accent); font-weight: 600;
}

.simple-status {
  margin: 8px 0 0; text-align: center;
  font-size: 16px; color: var(--muted);
}
.simple-status.ok { color: var(--ok); }
.simple-status.work { color: var(--text); }
.simple-status.bad { color: var(--err); }

.simple-foot { display: flex; justify-content: flex-end; }

.topbar-actions { display: flex; gap: 8px; }

/* ------------------------------------------------------------ кнопки */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap);
  padding: 12px 18px;
  font-size: 16px; font-weight: 600;
  border: 1px solid transparent; border-radius: 12px;
  cursor: pointer; user-select: none; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.primary:active { transform: scale(.99); filter: brightness(.92); }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; font-weight: 500; }
.btn.big { padding: 22px; font-size: 19px; }
.btn svg { width: 26px; height: 26px; fill: currentColor; }

.actions { display: grid; gap: 10px; margin: 14px 0; }

/* ------------------------------------------------------------ статусы */

.badge {
  display: inline-block; padding: 3px 9px;
  font-size: 12px; border-radius: 999px; white-space: nowrap;
  background: var(--surface-2); color: var(--muted);
}
.badge-online { background: color-mix(in srgb, var(--ok) 25%, transparent); color: var(--ok); }
.badge-offline { background: color-mix(in srgb, var(--err) 22%, transparent); color: var(--err); }

.banner {
  padding: 10px 12px; border-radius: 10px; font-size: 14px;
  background: color-mix(in srgb, var(--warn) 22%, transparent);
  color: var(--warn); margin-bottom: 10px;
}

.status { font-size: 14px; margin: 6px 2px 10px; }
.muted { color: var(--muted); }
.error { color: var(--err); font-size: 14px; margin: 0; }
.footnote { font-size: 13px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; font-size: 13px; }

/* -------------------------------------------------------------- лента */

.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }

.item {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 12px 8px 8px;
}
.item img {
  width: 56px; height: 56px; object-fit: cover;
  border-radius: 8px; background: var(--surface-2);
}
.item .title { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .state { font-size: 12px; font-weight: 600; text-align: right; white-space: nowrap; }
.state-wait { color: var(--muted); }
.state-send { color: var(--accent); }
.state-err  { color: var(--err); }
.state-server { color: var(--warn); }
.state-done { color: var(--ok); }

/* Убрать снимок, который сервер не принимает */
.item .state .drop {
  display: block; margin-top: 4px; margin-left: auto;
  background: none; border: none; padding: 4px 0 0;
  color: var(--muted); font: inherit; font-size: 12px;
  text-decoration: underline; cursor: pointer;
}

/* ------------------------------------------------------------ календарь */

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-head .section-title { margin: 0; }

.calendar { display: grid; gap: 10px; }
.calendar-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.calendar-week, .calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px;
}
.calendar-week span { text-align: center; font-size: 11px; color: var(--muted); }
.calendar-grid button {
  aspect-ratio: 1; min-height: 38px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid transparent; border-radius: 8px;
  font-size: 14px; cursor: pointer;
}
/* День без снимков нажать нельзя — смотреть там нечего */
.calendar-grid button[disabled] { opacity: .35; cursor: default; background: transparent; }
.calendar-grid button .count { font-size: 10px; color: var(--muted); line-height: 1; }
.calendar-grid button.has { border-color: var(--accent); font-weight: 600; }
.calendar-grid button.today { outline: 1px dashed var(--muted); }
.calendar-grid button.picked { background: var(--accent); color: #fff; }
.calendar-grid button.picked .count { color: #fff; }
.calendar-grid .blank { min-height: 38px; }

/* Крестик в углу карточки: убрать неудачный снимок с сервера */
#recent .item { position: relative; padding-right: 34px; }
#recent .item .state { padding-right: 4px; }
.drop-photo {
  position: absolute; top: 2px; right: 2px;
  width: 30px; height: 30px; padding: 0;
  display: flex; align-items: center; justify-content: center;
  background: none; border: none; border-radius: 8px;
  color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer;
}
.drop-photo:hover, .drop-photo:active { color: var(--err); background: var(--surface-2); }

/* Разделитель дней: лента идёт по времени съёмки, и границы дней должны
   быть видны сразу */
.day-sep {
  list-style: none;
  padding: 6px 2px 0;
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted);
}
.day-sep:first-child { padding-top: 0; }

.item .file {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Раскрытая строка: в комментарии бывает важная заметка, и обрезать её
   насовсем нельзя. Нажатие снимает обрезку со всех текстов сразу. */
#recent .item { cursor: pointer; }
#recent .item.open .title,
#recent .item.open .sub,
#recent .item.open .file {
  white-space: normal; overflow: visible; text-overflow: clip;
  overflow-wrap: anywhere;
}
#recent .item.open .title { font-size: 15px; }
#recent .item.open .file { user-select: all; }   /* путь удобно выделить целиком */
#recent .item.open { background: var(--surface-2); align-items: start; }

.progress { height: 3px; border-radius: 2px; background: var(--surface-2); overflow: hidden; grid-column: 1 / -1; }
.progress > i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

/* ------------------------------------------------------------ подсказка */

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 18px; font-size: 14px; max-width: 90vw;
  box-shadow: 0 12px 30px #0006; z-index: 20;
}
.toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
