/* Стиль адаптирован из дизайн-системы дашборда компании (Platforma BI,
   редизайн 2026-09, стиль «Мягкий») — тот же бренд: шрифты Onest/Inter,
   оранжевый акцент, "стеклянные" карточки со скруглением и мягкой тенью.
   Полный набор токенов/компонентов там гораздо шире (сайдбар, графики,
   таблицы, геоплатформа) — здесь оставлено только то, что нужно форме и
   истории Mini App. Шрифты — локально в /fonts (Cyrillic+Latin), без
   обращений к Google при каждом открытии. */

@font-face {
  font-family: "Onest";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/onest-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F,
    U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: "Onest";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/onest-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/inter-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F,
    U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/fonts/inter-cyrillic.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}

:root {
  color-scheme: light;
  --font: "Onest", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-num: "Inter", var(--font);

  --orange: #ff4d1a;
  --accent: var(--orange);
  --accent-2: #ff8a3d;
  --danger: #e5484d;
  --success: #16a34a;

  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --bg: #f3f4fa;
  --surface: rgba(255, 255, 255, 0.78);
  --surface-2: #f6f7fc;
  --border: rgba(13, 18, 64, 0.08);
  --border-strong: rgba(13, 18, 64, 0.16);
  --text: #0d1240;
  --text-2: #3c4468;
  --text-muted: #6b7493;
  --accent-soft: rgba(255, 77, 26, 0.12);
  --danger-soft: rgba(229, 72, 77, 0.12);
  --card-shadow: 0 1px 2px rgba(13, 18, 64, 0.04), 0 8px 24px -12px rgba(13, 18, 64, 0.12);
  --radius: 18px;
  --radius-sm: 12px;
  --blur: 18px;

  --mesh-a: rgba(255, 110, 60, 0.18);
  --mesh-b: rgba(99, 102, 241, 0.14);
  --mesh-c: rgba(20, 184, 166, 0.09);

  --badge-ok-bg: #dcfce7;
  --badge-ok-fg: #166534;
  --badge-err-bg: #fee2e2;
  --badge-err-fg: #991b1b;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #080a1a;
  --surface: rgba(20, 24, 52, 0.62);
  --surface-2: rgba(255, 255, 255, 0.035);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #eef0fb;
  --text-2: #c3c8e4;
  --text-muted: #8b93b8;
  --accent-soft: rgba(255, 110, 60, 0.16);
  --danger-soft: rgba(229, 72, 77, 0.18);
  --card-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset, 0 12px 30px -14px rgba(0, 0, 0, 0.6);
  --mesh-a: rgba(255, 90, 31, 0.14);
  --mesh-b: rgba(91, 91, 240, 0.18);
  --mesh-c: rgba(20, 184, 166, 0.07);
  --badge-ok-bg: rgba(22, 163, 74, 0.18);
  --badge-ok-fg: #86efac;
  --badge-err-bg: rgba(229, 72, 77, 0.18);
  --badge-err-fg: #fca5a5;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  position: relative;
  margin: 0;
  padding: 16px;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  transition: background-color 0.4s var(--ease);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

::selection {
  background: var(--accent);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* фоновые пятна — тот же приём, что в дашборде, приглушены под размер формы */
.mesh {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}
.mesh i {
  position: absolute;
  border-radius: 50%;
  filter: blur(60px);
  animation: drift 26s var(--ease) infinite alternate;
}
.mesh i:nth-child(1) {
  width: 60vw;
  height: 60vw;
  background: var(--mesh-a);
  top: -24vw;
  right: -20vw;
}
.mesh i:nth-child(2) {
  width: 55vw;
  height: 55vw;
  background: var(--mesh-b);
  bottom: -28vw;
  left: -10vw;
  animation-delay: -8s;
}
.mesh i:nth-child(3) {
  width: 35vw;
  height: 35vw;
  background: var(--mesh-c);
  top: 40vh;
  left: 30vw;
  animation-delay: -14s;
}
@keyframes drift {
  to {
    transform: translate3d(-4vw, 3vw, 0) scale(1.08);
  }
}

/* ═══════ Вкладки (адаптация .tabs/.tab) ═══════ */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  color: var(--text-2);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s var(--ease), color 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.tab-btn.active {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 6px 18px -6px rgba(255, 77, 26, 0.6);
}

.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* ═══════ Поля формы ═══════ */
.field-label {
  display: block;
  margin: 14px 0 4px;
  font-weight: 600;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* отступ между "Тип отчёта" и первым вопросом формы */
#report-type {
  margin-bottom: 18px;
}

/* отступ между "Обновить" и списком истории */
#refresh-history {
  margin-bottom: 16px;
}

select,
input[type="text"],
input[type="number"],
input[type="date"] {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}
input:hover,
select:hover {
  border-color: var(--text-2);
}
input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
input::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

/* select — убираем системную стрелку, рисуем свою (тот же приём, что в
   исходной дизайн-системе): цвет стрелки = --text-muted, отдельно для тёмной
   темы (data: URI не умеет var()). */
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%236b7493' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
select option {
  background: var(--surface-2);
  color: var(--text);
}
:root[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238b93b8' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}

/* input[type=number] — убираем системные стрелки-степпер (не нужны для сумм/
   показов/бюджетов, которые печатают целиком, а не крутят по 1) */
input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* input[type=date] — системный значок календаря красим под тему вместо
   чёрного по умолчанию (иначе в тёмной теме он почти не виден на тёмном фоне).
   Сам попап календаря — нативный UI ОС, его не перекрасить из CSS; color-scheme
   в :root хотя бы подбирает тёмный/светлый вариант самого попапа под тему. */
input[type="date"] {
  cursor: pointer;
}
input[type="date"]::-webkit-calendar-picker-indicator {
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  filter: opacity(0.55);
  transition: filter 0.2s, background 0.2s;
}
input[type="date"]::-webkit-calendar-picker-indicator:hover {
  filter: opacity(0.9);
  background: var(--accent-soft);
}
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(1) opacity(0.6);
}
:root[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator:hover {
  filter: invert(1) opacity(0.9);
}

/* ═══════ Кастомный datepicker (вместо <input type=date>) ═══════ */
.dp-trigger {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.dp-trigger:hover {
  border-color: var(--text-2);
}
.dp-trigger.placeholder {
  color: var(--text-muted);
}

.dp-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 10, 26, 0.45);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  animation: dpFadeIn 0.2s var(--ease);
}
@keyframes dpFadeIn {
  from {
    opacity: 0;
  }
}

.dp-modal {
  width: 100%;
  max-width: 340px;
  padding: 16px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.3);
  backdrop-filter: blur(var(--blur)) saturate(1.3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 40px 80px -20px rgba(13, 18, 64, 0.35);
  transform: translateY(8px) scale(0.98);
  animation: dpModalIn 0.25s var(--spring) forwards;
}
@keyframes dpModalIn {
  to {
    transform: none;
  }
}

.dp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-bottom: 10px;
}
.dp-label {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--text);
}
.dp-nav {
  width: 32px;
  height: 32px;
  flex: none;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.dp-nav:hover {
  background: var(--accent-soft);
  color: var(--accent);
}
.dp-nav-year {
  font-size: 12px;
}

.dp-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  margin-bottom: 4px;
}
.dp-weekdays span {
  text-align: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
  padding: 4px 0;
}

.dp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.dp-day {
  aspect-ratio: 1;
  border: 0;
  border-radius: 9px;
  background: none;
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font-num);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.dp-day.empty {
  cursor: default;
}
.dp-day:not(.empty):hover {
  background: var(--surface-2);
}
.dp-day.today {
  color: var(--accent);
  font-weight: 700;
}
.dp-day.selected {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.dp-today-btn {
  width: 100%;
  margin-top: 12px;
  height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-2);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.dp-today-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.range-sep {
  color: var(--text-muted);
}

/* ═══════ Карточка вопроса (адаптация .card) ═══════ */
.question-block {
  margin-bottom: 12px;
  padding: 14px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.3);
  backdrop-filter: blur(var(--blur)) saturate(1.3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
}

.question-text {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--text);
}

.date-range-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 6px;
}
.date-range-row .dp-trigger {
  flex: 1;
  min-width: 0;
  width: auto;
}
.date-range-row .range-label {
  min-width: 70px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.list-row {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
  padding: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}
.list-row input {
  font-size: 13px;
  height: 36px;
  background: var(--bg);
}

.remove-row-btn {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 12.5px;
  font-weight: 500;
  text-align: left;
  padding: 2px 0;
  cursor: pointer;
}

/* ═══════ Кнопки (адаптация .btn/.btn-primary) ═══════ */
.add-row-btn,
#submit-btn,
#refresh-history {
  position: relative;
  overflow: hidden;
  width: 100%;
  margin-top: 8px;
  height: 44px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease), box-shadow 0.2s;
}
.add-row-btn:active,
#submit-btn:active,
#refresh-history:active {
  transform: scale(0.97);
}

#submit-btn,
#refresh-history {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px -6px rgba(255, 77, 26, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}
#submit-btn:hover,
#refresh-history:hover {
  background: #ff5f30;
  box-shadow: 0 10px 26px -8px rgba(255, 77, 26, 0.75), inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.add-row-btn {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid transparent;
}
.add-row-btn:hover {
  border-color: var(--accent);
}

/* ═══════ Статус / ошибки ═══════ */
.status {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  white-space: pre-wrap;
  display: none;
}
.status:not(:empty) {
  display: block;
}
.status.error {
  color: var(--danger);
  background: var(--danger-soft);
  border: 1px solid rgba(229, 72, 77, 0.25);
}
.status.ok {
  color: var(--success);
  background: var(--badge-ok-bg);
  border: 1px solid rgba(22, 163, 74, 0.25);
}

/* ═══════ История ═══════ */
.history-card {
  padding: 14px;
  margin-bottom: 8px;
  background: var(--surface);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.3);
  backdrop-filter: blur(var(--blur)) saturate(1.3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  font-size: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  margin-top: 6px;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
}
.badge.success {
  background: var(--badge-ok-bg);
  color: var(--badge-ok-fg);
}
.badge.failed {
  background: var(--badge-err-bg);
  color: var(--badge-err-fg);
}

.history-card .error-text {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: pre-wrap;
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.history-action-btn {
  flex: 1;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease), border-color 0.2s;
}
.history-action-btn:hover {
  border-color: var(--accent);
}
.history-action-btn:active {
  transform: scale(0.97);
}
.history-action-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .mesh {
    display: none;
  }
}
