/* Country Days Tracker — единая тема, светлая и тёмная. */

:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #e2e5ea;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #2f6feb;
  --accent-soft: #e8f0fe;
  --good: #1f9254;
  --warn: #b8770a;
  --bad: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.04);
  --country-light: 92%;
  --country-border: 72%;
  --country-text: 28%;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1d2129;
    --border: #2a2f39;
    --text: #e7e9ee;
    --muted: #9aa2b1;
    --accent: #6b9bff;
    --accent-soft: #1c2740;
    --good: #4ade80;
    --warn: #fbbf24;
    --bad: #f87171;
    --shadow: none;
    --country-light: 26%;
    --country-border: 40%;
    --country-text: 82%;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1rem; margin: 0; font-weight: 600; }
a { color: var(--accent); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.nowrap { white-space: nowrap; }
.inline { display: inline; }

/* ---------------------------------------------------------------- Шапка */

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand {
  font-weight: 600;
  text-decoration: none;
  color: var(--text);
  white-space: nowrap;
}

.tracker-switch select,
.tracker-name {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.35rem 0.6rem;
  color: var(--text);
  font-size: 0.9rem;
  max-width: 260px;
}

.topnav {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.topnav a { text-decoration: none; }
.topnav a:hover { text-decoration: underline; }

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

.container { max-width: 900px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.container-narrow { max-width: 460px; }
.container-wide { max-width: 1400px; }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 1.25rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.side-column .card:last-child { margin-bottom: 0; }

/* ------------------------------------------------------------ Год и статус */

.year-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.year-title {
  font-size: 1.6rem;
  line-height: 2rem;   /* совпадает с высотой стрелок */
  margin: 0;
  min-width: 4ch;
  text-align: center;
}

.year-nav {
  /* flex + line-height:1 центрирует глиф ‹ ›: по умолчанию он садится
     на базовую линию и визуально уезжает вниз относительно числа года. */
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
}

.year-nav:hover { background: var(--accent-soft); border-color: var(--accent); }
.year-summary { margin-left: 0.5rem; }

.badge {
  padding: 0.15rem 0.5rem;
  border-radius: 99px;
  font-size: 0.75rem;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

/* ---------------------------------------------------------- Прогресс-бар */

.progress-card { border-left: 4px solid var(--border); }
.progress-card.tone-good { border-left-color: var(--good); }
.progress-card.tone-warn { border-left-color: var(--warn); }
.progress-card.tone-bad  { border-left-color: var(--bad); }

.progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.progress-country { display: flex; align-items: center; gap: 0.75rem; }
.progress-flag { font-size: 2rem; line-height: 1; }
.progress-name { font-weight: 600; font-size: 1.1rem; }

.progress-numbers { font-variant-numeric: tabular-nums; }
.progress-current { font-size: 2rem; font-weight: 600; }
.progress-threshold { font-size: 1.1rem; color: var(--muted); }

.progress-track {
  height: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--muted);
  transition: width 0.35s ease;
}

.tone-good .progress-fill { background: var(--good); }
.tone-warn .progress-fill { background: var(--warn); }
.tone-bad  .progress-fill { background: var(--bad); }

.progress-footer {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.65rem;
  flex-wrap: wrap;
  align-items: baseline;
  font-size: 0.9rem;
}

.progress-status { font-weight: 600; }
.tone-good .progress-status { color: var(--good); }
.tone-warn .progress-status { color: var(--warn); }
.tone-bad  .progress-status { color: var(--bad); }

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

.calendar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 1rem;
}

.month-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.4rem;
  padding: 0 0.15rem;
}

.month-count {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
}

.month-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}

.weekday {
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
  padding-bottom: 2px;
}

.day {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--muted);
  font: inherit;
  padding: 0;
  overflow: hidden;
}

button.day { cursor: pointer; }
button.day:hover { border-color: var(--accent); z-index: 1; }

.day-blank { border: none; background: none; }
.day-weekend { background: var(--bg); }
.day-number { font-size: 0.65rem; line-height: 1; }
.day-flag { font-size: 0.8rem; line-height: 1; }

/* День перелёта: два флага рядом, чуть мельче, чтобы влезли в ячейку. */
.day-multi .day-flag {
  font-size: 0.6rem;
  letter-spacing: -0.04em;
  white-space: nowrap;
}

.day-filled {
  background: hsl(var(--country-hue) var(--country-sat, 55%) var(--country-light));
  border-color: hsl(var(--country-hue) var(--country-sat, 55%) var(--country-border));
  color: hsl(var(--country-hue) 40% var(--country-text));
  font-weight: 600;
}

.day-today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  z-index: 1;
}

/* Точка в углу — у дня есть отдельная правка, перекрывающая поездку. */
.day-override::after {
  content: '';
  position: absolute;
  top: 2px;
  right: 2px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent);
}

.day-dimmed { opacity: 0.3; }
.day-highlight { outline: 2px solid hsl(var(--country-hue) var(--country-sat, 55%) 45%); outline-offset: -2px; }

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 0.9rem;
  margin-top: 1rem;
  padding-top: 0.85rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
}

.legend-item { display: inline-flex; align-items: center; gap: 0.35rem; color: var(--muted); }
.legend-item.active { color: var(--text); font-weight: 600; }

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: hsl(var(--country-hue) var(--country-sat, 55%) var(--country-light));
  border: 1px solid hsl(var(--country-hue) var(--country-sat, 55%) var(--country-border));
}

/* ---------------------------------------------------------- Блоки стран */

.country-blocks { display: flex; flex-direction: column; gap: 0.4rem; }

.country-block {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.7rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-left: 3px solid hsl(var(--country-hue) var(--country-sat, 55%) 55%);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.country-block:hover { border-color: var(--accent); }
.country-block.selected { background: var(--accent-soft); border-color: var(--accent); }

.country-flag { font-size: 1.4rem; line-height: 1; }
.country-body { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; }
.country-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.country-bar {
  display: block;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.country-bar > span {
  display: block;
  height: 100%;
  background: hsl(var(--country-hue) var(--country-sat, 55%) 55%);
}

.country-days { text-align: right; font-variant-numeric: tabular-nums; line-height: 1.2; }
.country-days strong { font-size: 1.05rem; display: block; }
.untracked-note { margin: 0.6rem 0 0; }

/* -------------------------------------------------------------- Поездки */

.trip-list { display: flex; flex-direction: column; gap: 0.35rem; }

.trip-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-left: 3px solid hsl(var(--country-hue) var(--country-sat, 55%) 55%);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.trip-flag { font-size: 1.2rem; }
.trip-body { display: flex; flex-direction: column; min-width: 0; }
.trip-country { font-weight: 500; }
.trip-note { font-style: italic; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trip-days { font-variant-numeric: tabular-nums; font-weight: 600; }
.trip-actions { display: flex; gap: 0.15rem; }

/* Свёрнутые строки остаются в разметке ради отчёта на печать. */
.trip-collapsed { display: none; }

.trips-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  margin-top: 0.15rem;
  padding: 0.4rem;
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--muted);
  font-size: 0.85rem;
}

.trips-toggle:hover { color: var(--accent); border-color: var(--accent); }

.trips-toggle-chevron { line-height: 1; transition: transform 0.15s ease; }
.trips-toggle[aria-expanded="true"] .trips-toggle-chevron { transform: rotate(180deg); }

/* --------------------------------------------------------------- Формы */

.stack { display: flex; flex-direction: column; gap: 0.75rem; }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 140px; }

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.85rem;
  color: var(--muted);
}

label.checkbox { flex-direction: row; align-items: center; gap: 0.4rem; }

input[type="text"], input[type="password"], input[type="number"],
input[type="date"], select {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  width: 100%;
}

/* Системная стрелка у select рисуется по-своему в каждом браузере и прижимается
   к самому краю. Рисуем свою: положение задаём мы, вид одинаков везде. */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%236b7280' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 14px;
}

@media (prefers-color-scheme: dark) {
  select {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%239aa2b1' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6.5 8 10.5 12 6.5'/%3E%3C/svg%3E");
  }
}

input:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}

button, .button-like {
  font: inherit;
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}

button:hover, .button-like:hover { border-color: var(--accent); }
button:disabled { opacity: 0.6; cursor: default; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}

button.ghost { background: transparent; }

.small-button { padding: 0.3rem 0.6rem; font-size: 0.85rem; }

.link-button {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0.2rem 0;
  cursor: pointer;
  font-size: 0.85rem;
}

.link-button.danger, .icon-button.danger { color: var(--bad); }

.icon-button {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  line-height: 1;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}

.icon-button:hover { background: var(--surface); border-color: var(--border); }

/* ------------------------------------------------------------- Диалоги */

.dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 1.25rem;
  width: min(420px, calc(100vw - 2rem));
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.25);
}

.dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog h2 { margin-bottom: 0.25rem; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}

.dialog-error, .error-block {
  color: var(--bad);
  background: color-mix(in srgb, var(--bad) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--bad) 35%, transparent);
  border-radius: var(--radius);
  padding: 0.5rem 0.65rem;
  margin: 0;
  font-size: 0.9rem;
}

/* ------------------------------------------------------- Флеши и таблицы */

.flashes { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 1rem; }

.flash {
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.9rem;
}

.flash-error {
  color: var(--bad);
  border-color: color-mix(in srgb, var(--bad) 35%, transparent);
  background: color-mix(in srgb, var(--bad) 10%, transparent);
}

.flash-success {
  color: var(--good);
  border-color: color-mix(in srgb, var(--good) 35%, transparent);
  background: color-mix(in srgb, var(--good) 10%, transparent);
}

.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th, .table td { padding: 0.5rem 0.6rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-weight: 500; font-size: 0.8rem; }
.table tr:last-child td { border-bottom: none; }
.row-inactive { opacity: 0.5; }
.actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.reset-form { display: flex; gap: 0.35rem; align-items: center; }
.reset-form input { width: 130px; padding: 0.25rem 0.4rem; font-size: 0.85rem; }

/* ---------------------------------------------------------------- Вход */

.auth-card { margin-top: 12vh; text-align: center; }
.auth-card h1 { margin-bottom: 0.25rem; }
.auth-card form { margin: 1.5rem 0 1rem; text-align: left; }

/* --------------------------------------------------------------- Печать */

@media print {
  /* В отчёт идут прогресс, календарь, страны и поездки — без органов управления. */
  .topbar, .year-nav, .calendar-legend, .dialog, .flashes,
  #settings-form, .badge, button, .button-like { display: none !important; }

  .side-column .card:has(#settings-form),
  .side-column .card:has(#export-button) { display: none !important; }

  body { background: #fff; }
  .layout { grid-template-columns: 1fr; }
  .card { box-shadow: none; break-inside: avoid; margin-bottom: 0.75rem; }
  .calendar { grid-template-columns: repeat(4, 1fr); }
  .country-block, .trip-row { break-inside: avoid; }

  /* В отчёт идут все поездки, независимо от того, свёрнут ли список на экране. */
  .trip-collapsed { display: grid !important; }
  .trips-toggle { display: none !important; }
}
