/* =========================================================
   YaMetrika Reports — Admin Panel Styles (admin.css)
   Единый, человеко-читаемый файл стилей админ-панели.
   Поддержка тем: [data-theme="dark"] (по умолчанию) и [data-theme="light"]
   ========================================================= */

/* -------------------------
   1) Тема и переменные
   ------------------------- */
:root {
  --bg: #0b0b0c;
  --bg-elev: #121214;
  --bg-elev-2: #18181b;
  --border: #26262b;
  --border-strong: #33333a;
  --text: #f2f2f3;
  --muted: #9a9aa3;
  --muted-2: #6f6f78;
  --accent: #ffffff;
  --accent-ink: #0b0b0c;
  --danger: #ff5c5c;
  --danger-soft: #ff8f8f;
  --ok: #7ddc8a;
  --warn: #e0c36a;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --radius: 12px;
  --topbar-bg: rgba(11, 11, 12, 0.82);
  --input-bg: #0f0f11;
  --input-focus: #121216;
  --hover-bg: #1a1a1f;
  --ghost-hover: #1a1a1f;
  --pill-bg: #141418;
  --log-bg: #0f0f11;
}

:root[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-elev: #ffffff;
  --bg-elev-2: #fafafa;
  --border: #e5e5ea;
  --border-strong: #d1d1d6;
  --text: #111113;
  --muted: #6b6b76;
  --muted-2: #8e8e99;
  --accent: #111113;
  --accent-ink: #ffffff;
  --danger: #d92d20;
  --danger-soft: #c0362c;
  --ok: #1a7f37;
  --warn: #8a6d1d;
  --shadow: 0 18px 40px rgba(17, 17, 19, 0.08);
  --topbar-bg: rgba(245, 245, 247, 0.86);
  --input-bg: #ffffff;
  --input-focus: #ffffff;
  --hover-bg: #f0f0f3;
  --ghost-hover: #efeff2;
  --pill-bg: #f2f2f5;
  --log-bg: #fafafa;
}

/* -------------------------
   2) Базовые стили
   ------------------------- */
* {
  box-sizing: border-box;
}

html,
body,
#root {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

a {
  color: var(--text);
}

/* -------------------------
   3) Каркас и верхняя панель
   ------------------------- */
.wrap {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  color: var(--text);
  font-size: 15px;
}

.brand span {
  color: var(--muted);
  font-weight: 500;
}

.nav {
  display: flex;
  gap: 8px;
  align-items: center;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 0 18px;
}

.page-head h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: -0.02em;
}

.sub {
  color: var(--muted);
  margin: 4px 0 0;
  font-size: 14px;
}

/* -------------------------
   4) Карточки и утилиты раскладки
   ------------------------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin: 14px 0;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head h2,
.card-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}

.section-title {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin: 0 0 10px;
}

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

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.row-spread {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

/* -------------------------
   5) Формы и поля ввода
   ------------------------- */
label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

label.field span {
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font: inherit;
  color: var(--text);
  background: var(--input-bg);
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--border-strong);
  background: var(--input-focus);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

input[type="date"] {
  color-scheme: dark;
}

:root[data-theme="light"] input[type="date"] {
  color-scheme: light;
}

::placeholder {
  color: var(--muted-2);
}

/* -------------------------
   6) Кнопки
   ------------------------- */
button,
.btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 9px 14px;
  border-radius: 10px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.2;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.05s, opacity 0.15s, background 0.15s, border-color 0.15s;
}

button:hover,
.btn:hover {
  opacity: 0.92;
}

button:active,
.btn:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.secondary,
.btn.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border-strong);
}

button.ghost {
  background: transparent;
  color: var(--muted);
  border-color: transparent;
  padding: 6px 8px;
}

button.ghost:hover {
  color: var(--text);
  background: var(--ghost-hover);
}

button.danger {
  background: transparent;
  color: var(--danger-soft);
  border-color: var(--border-strong);
}

button.icon-btn,
.btn.icon-btn {
  padding: 7px;
  width: 34px;
  height: 34px;
}

button.icon-btn svg,
.btn.icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* -------------------------
   7) Текстовые утилиты
   ------------------------- */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--danger-soft); }
.ok { color: var(--ok); }

/* -------------------------
   8) Таблицы
   ------------------------- */
table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-weight: 500;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

tr:last-child td {
  border-bottom: 0;
}

/* -------------------------
   9) Метки-статусы (pills)
   ------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--border-strong);
  color: var(--muted);
  background: var(--pill-bg);
}

.pill.done { color: var(--ok); }
.pill.error { color: var(--danger-soft); }
.pill.running,
.pill.queued { color: var(--warn); }
.pill.active { color: var(--text); }
.pill.inactive { color: var(--muted); }

/* -------------------------
   10) Карточки клиентов (список)
   ------------------------- */
.client-card {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.client-card.inactive {
  opacity: 0.68;
}

.client-card-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

/* Логотип клиента: квадрат 100x100, изображение целиком (contain) с отступом */
.client-logo {
  width: 100px;
  height: 100px;
  flex: 0 0 100px;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  display: flex;
  align-items: center;
  justify-content: center;
}

.client-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 5px;
  display: block;
}

.client-logo-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 28px;
  font-weight: 600;
  text-transform: uppercase;
}

.client-card-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.client-name {
  font-weight: 600;
  font-size: 15px;
  margin: 0;
}

.client-meta {
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.client-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-top: 4px;
}

.icon-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

/* -------------------------
   11) Переключатели (toggle)
   ------------------------- */
.toggle {
  position: relative;
  width: 42px;
  height: 24px;
  display: inline-block;
  flex: 0 0 auto;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle .track {
  position: absolute;
  inset: 0;
  background: var(--border-strong);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: 0.18s;
  cursor: pointer;
}

.toggle .track::after {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  top: 2px;
  background: var(--bg-elev);
  border-radius: 50%;
  transition: 0.18s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

.toggle input:checked + .track {
  background: var(--accent);
  border-color: var(--accent);
}

.toggle input:checked + .track::after {
  transform: translateX(18px);
  background: var(--accent-ink);
}

.toggle-wrap {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

/* -------------------------
   12) Авторизация
   ------------------------- */
.login {
  max-width: 420px;
  margin: 70px auto;
}

.login h2 {
  margin: 0 0 6px;
  font-size: 24px;
  letter-spacing: -0.02em;
}

/* -------------------------
   13) Модальные окна
   ------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  overflow: auto;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.modal-head {
  position: sticky;
  top: 0;
  background: var(--bg-elev);
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 1;
}

.modal-head h3 {
  margin: 0;
  font-size: 18px;
}

.modal-body {
  padding: 18px;
}

.modal-foot {
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  position: sticky;
  bottom: 0;
  background: var(--bg-elev);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-grid .span2 {
  grid-column: span 2;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 0;
}

.checkline input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.goals-editor {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: var(--input-bg);
}

.goal-row {
  display: grid;
  grid-template-columns: 140px 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.goal-row:last-child {
  margin-bottom: 0;
}

.hr {
  height: 1px;
  background: var(--border);
  margin: 14px 0;
}

.empty {
  color: var(--muted);
  padding: 24px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

/* -------------------------
   14) Логи и подсказки
   ------------------------- */
.log-box {
  margin-top: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--log-bg);
  padding: 10px;
  max-height: 220px;
  overflow: auto;
}

.log-line {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: var(--muted);
  padding: 2px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.log-line.error {
  color: var(--danger-soft);
}

.log-line.info {
  color: var(--text);
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin-top: 8px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text);
  text-decoration: underline;
  padding: 0;
  font: inherit;
  cursor: pointer;
}

/* -------------------------
   15) Модальное окно «Отчёты» (аккордеон по годам)
   ------------------------- */
.reports-modal {
  max-width: 860px;
}

.acc-year {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev-2);
  margin-bottom: 10px;
  overflow: hidden;
}

.acc-head {
  width: 100%;
  background: transparent;
  border: 0;
  border-bottom: 1px solid transparent;
  color: var(--text);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font: inherit;
  text-align: left;
}

.acc-year.open .acc-head {
  border-bottom-color: var(--border);
}

.acc-title {
  font-weight: 600;
}

.acc-body {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.report-row-main {
  min-width: 0;
}

.report-row-title {
  font-weight: 500;
}

.report-row-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* -------------------------
   16) Date range picker (форма отчёта)
   ------------------------- */
.report-form {
  align-items: flex-end;
}

.report-client {
  min-width: 260px;
  flex: 1 1 260px;
}

.report-period {
  flex: 1 1 320px;
  min-width: 280px;
  position: relative;
}

.report-submit {
  align-self: flex-end;
}

.date-range {
  position: relative;
}

.date-range-control {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.date-range-control:hover {
  border-color: var(--border-strong);
  background: var(--input-focus);
}

.date-range-control:focus,
.date-range-control:focus-visible {
  outline: none;
  border-color: var(--border-strong);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04);
}

:root[data-theme="light"] .date-range-control:focus,
:root[data-theme="light"] .date-range-control:focus-visible {
  box-shadow: 0 0 0 3px rgba(17, 17, 19, 0.06);
}

.date-range-icon {
  display: inline-flex;
  color: var(--muted);
}

.date-range-icon svg {
  width: 18px;
  height: 18px;
}

.date-range-label {
  flex: 1;
  min-width: 0;
}

.date-range-label.placeholder {
  color: var(--muted);
  font-weight: 400;
}

.date-range-clear {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}

.date-range-clear:hover {
  background: var(--hover-bg);
  color: var(--text);
}

.date-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 40;
  width: 320px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
}

.date-popover-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.date-month {
  font-weight: 600;
  text-transform: capitalize;
  font-size: 14px;
}

.date-weekdays,
.date-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.date-weekdays {
  margin-bottom: 4px;
}

.date-wd {
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  padding: 4px 0;
  font-weight: 500;
}

.date-cell {
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.date-cell.empty {
  cursor: default;
}

.date-cell:not(.empty):not(.edge):hover {
  background: var(--hover-bg);
}

.date-cell.in-range {
  background: var(--hover-bg);
  border-radius: 0;
}

.date-cell.edge {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}

.date-cell.start {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}

.date-cell.end {
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

.date-cell.start.end {
  border-radius: 10px;
}

.date-cell.today:not(.edge) {
  box-shadow: inset 0 0 0 1px var(--border-strong);
}

.date-popover-foot {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

/* -------------------------
   17) Адаптивность
   ------------------------- */
@media (max-width: 720px) {
  .wrap {
    padding: 16px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid .span2 {
    grid-column: span 1;
  }

  .goal-row {
    grid-template-columns: 1fr;
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
  }

  th,
  td {
    padding: 10px 6px;
  }

  .report-row {
    flex-direction: column;
    align-items: stretch;
  }

  .report-row-actions {
    justify-content: flex-start;
  }

  .client-card-top {
    flex-direction: column;
  }

  .report-client,
  .report-period {
    min-width: 100%;
    flex: 1 1 100%;
  }

  .date-popover {
    width: 100%;
    max-width: 340px;
  }
}
