/* Cast Radar Mini App — стили.
   Базовая палитра светлая (см. CLAUDE.md), но все токены переопределяются
   через JS из Telegram.WebApp.themeParams — приложение подстраивается под
   тему клиента. @media(prefers-color-scheme) — запасной вариант, если
   открыли вне Telegram (см. фолбэк-экран) или для отладки в браузере. */

:root {
  --bg: #ffffff;
  --surface: #f7f9fc;
  --surface-raised: #ffffff;
  --text: #111827;
  --secondary: #6b7280;
  --accent: #229ed9;
  --accent-pressed: #168ac1;
  --accent-contrast: #ffffff;
  --border: rgba(17, 24, 39, 0.09);
  --border-strong: rgba(17, 24, 39, 0.16);
  --danger: #dc2626;
  --success: #16a34a;
  --chip-bg: #eef4fa;
  --chip-bg-active: #229ed9;
  --chip-text-active: #ffffff;
  --shadow-sm: 0 1px 2px rgba(17, 24, 39, 0.06);
  --shadow-md: 0 6px 20px rgba(17, 24, 39, 0.08);

  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;

  --fs-display: 1.25rem;
  --fs-title: 1.0625rem;
  --fs-body: 0.9375rem;
  --fs-label: 0.8125rem;
  --fs-small: 0.75rem;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 28px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17212b;
    --surface: #1c2733;
    --surface-raised: #212d3a;
    --text: #f2f5f8;
    --secondary: #9db0c2;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.18);
    --chip-bg: #26333f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: var(--fs-body);
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button {
  font-family: inherit;
}

h1,
h2,
h3,
p {
  margin: 0;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- Загрузка / фатальные экраны ---------- */

.center-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-4);
  padding: var(--sp-6) var(--sp-5);
  text-align: center;
}

.center-screen[hidden] {
  display: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.fatal-icon {
  font-size: 34px;
  line-height: 1;
}

.fatal-title {
  font-size: var(--fs-title);
  font-weight: 600;
}

.fatal-text {
  color: var(--secondary);
  font-size: var(--fs-body);
  max-width: 320px;
}

.btn {
  appearance: none;
  border: none;
  border-radius: var(--radius-md);
  min-height: 44px;
  padding: 0 var(--sp-5);
  font-size: var(--fs-body);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.1s ease;
}

@media (prefers-reduced-motion: reduce) {
  .btn {
    transition: none;
  }
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:active {
  background: var(--accent-pressed);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
}

.btn-secondary:active {
  background: var(--border);
}

/* ---------- Шапка и сводка ---------- */

.topbar {
  padding: var(--sp-3) var(--sp-4) 0;
}

.topbar__title {
  font-size: var(--fs-display);
  font-weight: 700;
  letter-spacing: -0.01em;
}

.summary-bar {
  margin: var(--sp-2) var(--sp-4) 0;
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface);
  border-radius: var(--radius-md);
  font-size: var(--fs-label);
  font-weight: 600;
  color: var(--text);
  line-height: 1.45;
}

.summary-bar__hint {
  display: block;
  margin-top: 2px;
  font-size: var(--fs-small);
  font-weight: 400;
  color: var(--secondary);
}

/* ---------- Табы ---------- */

.tabs {
  display: flex;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

.tab {
  appearance: none;
  border: none;
  background: var(--surface);
  color: var(--secondary);
  font-size: var(--fs-label);
  font-weight: 600;
  padding: 0 var(--sp-3);
  height: 36px;
  border-radius: 999px;
  cursor: pointer;
  flex: 1;
  transition: background-color 0.15s ease, color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .tab {
    transition: none;
  }
}

.tab.active {
  background: var(--accent);
  color: var(--accent-contrast);
}

.tab__badge {
  display: inline-block;
  min-width: 16px;
  margin-left: 4px;
  font-size: 10px;
  font-weight: 700;
}

main {
  flex: 1;
  padding: 0 var(--sp-4) var(--sp-6);
}

.tab-panel[hidden] {
  display: none;
}

/* ---------- Секции формы ---------- */

.field-group {
  margin-top: var(--sp-5);
}

.field-group__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.field-label {
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--text);
}

.field-hint {
  font-size: var(--fs-small);
  color: var(--secondary);
}

.field-hint.is-active {
  color: var(--accent);
}

.field-error {
  font-size: var(--fs-small);
  color: var(--danger);
  margin-top: var(--sp-1);
  min-height: 14px;
}

input[type="text"],
input[type="number"],
input[type="search"] {
  width: 100%;
  min-height: 44px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-raised);
  color: var(--text);
  font-size: var(--fs-body);
  padding: 0 var(--sp-3);
  outline: none;
  transition: border-color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  input {
    transition: none;
  }
}

input::placeholder {
  color: var(--secondary);
}

input:focus {
  border-color: var(--accent);
}

input.has-error {
  border-color: var(--danger);
}

.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
}

/* Чипы для мультивыбора (типы ролей/проектов, выбранные города) */

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.chip {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: var(--chip-bg);
  color: var(--text);
  font-size: var(--fs-label);
  font-weight: 500;
  padding: 0 var(--sp-3);
  min-height: 40px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .chip {
    transition: none;
  }
}

.chip[aria-pressed="true"] {
  background: var(--chip-bg-active);
  color: var(--chip-text-active);
  border-color: var(--chip-bg-active);
}

.chip--removable {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--chip-bg-active);
  color: var(--chip-text-active);
  border-color: var(--chip-bg-active);
}

.chip__x {
  font-size: 14px;
  line-height: 1;
}

/* Города: поиск + список */

.city-search {
  margin-bottom: var(--sp-2);
}

.city-selected {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.city-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  max-height: 220px;
  overflow-y: auto;
}

.city-row {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 44px;
  padding: 0 var(--sp-3);
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  background: var(--surface-raised);
}

.city-row:last-child {
  border-bottom: none;
}

.city-row:active {
  background: var(--surface);
}

.city-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  flex: none;
}

.city-row__label {
  font-size: var(--fs-body);
  flex: 1;
}

.city-empty {
  padding: var(--sp-4);
  color: var(--secondary);
  font-size: var(--fs-body);
  text-align: center;
}

/* Сегментированный контрол (пол) */

.segmented {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 3px;
}

.segmented__opt {
  flex: 1;
  min-height: 38px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--secondary);
  font-size: var(--fs-label);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .segmented__opt {
    transition: none;
  }
}

.segmented__opt[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Переключатель (switch) */

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: 44px;
}

.switch-row__text {
  flex: 1;
}

.switch-row__title {
  font-size: var(--fs-body);
  font-weight: 500;
}

.switch-row__desc {
  font-size: var(--fs-small);
  color: var(--secondary);
  margin-top: 2px;
}

.switch {
  position: relative;
  width: 48px;
  height: 28px;
  flex: none;
  border-radius: 999px;
  border: none;
  background: var(--border-strong);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .switch {
    transition: none;
  }
}

.switch[aria-pressed="true"] {
  background: var(--accent);
}

.switch__knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s ease;
}

@media (prefers-reduced-motion: reduce) {
  .switch__knob {
    transition: none;
  }
}

.switch[aria-pressed="true"] .switch__knob {
  transform: translateX(20px);
}

/* Раскрывающийся блок «Уточнить» */

.details {
  margin-top: var(--sp-5);
  border-top: 1px solid var(--border);
  padding-top: var(--sp-3);
}

.details__toggle {
  appearance: none;
  border: none;
  background: transparent;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) 0;
  cursor: pointer;
  color: var(--text);
  font-size: var(--fs-label);
  font-weight: 700;
}

.details__chevron {
  transition: transform 0.15s ease;
  color: var(--secondary);
}

@media (prefers-reduced-motion: reduce) {
  .details__chevron {
    transition: none;
  }
}

.details.is-open .details__chevron {
  transform: rotate(180deg);
}

.details__body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-3);
  padding-top: var(--sp-2);
}

.details__body[hidden] {
  display: none;
}

.trait-field {
  grid-column: span 1;
}

.trait-field__label {
  font-size: var(--fs-small);
  color: var(--secondary);
  margin-bottom: 4px;
  display: block;
}

/* ---------- Тулбар сохранения (запасной, если MainButton недоступен) ---------- */

.save-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--bg);
  border-top: 1px solid var(--border);
  margin: var(--sp-5) calc(var(--sp-4) * -1) 0;
}

.save-bar[hidden] {
  display: none;
}

.save-bar__status {
  font-size: var(--fs-small);
  color: var(--secondary);
}

.save-bar__status.is-saved {
  color: var(--success);
}

/* ---------- Список свежих кастингов ---------- */

.recent-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  margin-top: var(--sp-4);
}

.casting-card {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-sm);
}

.casting-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-2);
}

.casting-card__type {
  font-size: var(--fs-small);
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.casting-card__title {
  font-size: var(--fs-title);
  font-weight: 700;
  margin-top: 2px;
}

.casting-card__meta {
  font-size: var(--fs-label);
  color: var(--secondary);
  margin-top: var(--sp-1);
}

.casting-card__fee {
  font-size: var(--fs-label);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.casting-card__summary {
  margin-top: var(--sp-2);
  font-size: var(--fs-body);
  color: var(--text);
}

.role-list {
  margin-top: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.role-row {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: var(--sp-2) var(--sp-3);
}

.role-row__title {
  font-size: var(--fs-label);
  font-weight: 600;
}

.role-row__meta {
  font-size: var(--fs-small);
  color: var(--secondary);
  margin-top: 2px;
}

.req-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--sp-2);
}

.req-chip {
  font-size: var(--fs-small);
  color: var(--secondary);
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
}

.casting-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--sp-3);
  gap: var(--sp-2);
}

.casting-card__source {
  font-size: var(--fs-small);
  color: var(--secondary);
}

.link-btn {
  appearance: none;
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--accent);
  font-size: var(--fs-label);
  font-weight: 600;
  min-height: 36px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.link-btn:active {
  background: var(--surface);
}

.empty-state {
  margin-top: var(--sp-6);
  text-align: center;
  color: var(--secondary);
  font-size: var(--fs-body);
  padding: 0 var(--sp-4);
}

/* ---------- Уведомления ---------- */

.notif-card {
  margin-top: var(--sp-4);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
}

.notif-user {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-top: var(--sp-2);
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border);
}

.notif-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-contrast);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex: none;
}

.notif-user__name {
  font-weight: 600;
}

.notif-user__status {
  font-size: var(--fs-small);
  color: var(--secondary);
}

/* ---------- Тост ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: var(--fs-label);
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 50;
  max-width: 86vw;
  text-align: center;
}

.toast[hidden] {
  display: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}
