/*
  Общие стили сервиса. Дизайн-система взята со стиля rbs-program:
  Inter + Playfair Display, белый фон, чёрный текст, сине-фиолетовый градиент.

  Здесь же сайдбар (рендерится sidebar.js) и переиспользуемые элементы —
  карточки, формы, таблицы, бейджи. Специфика конкретной страницы живёт
  в её собственном <style>.
*/

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&family=Playfair+Display:ital,wght@0,400;0,500;1,400;1,500&display=swap');

:root {
  --white: #ffffff;
  --paper: #f3f5fb;
  --smoke: #e8edfb;
  --line: #d1d9eb;
  --linen: #f0f4fd;
  --ink: #0d0d0d;
  --ash: #374151;
  --pebble: #6b7280;
  --iron: #9ca3af;

  --blue: #2563eb;
  --blue-deep: #1d4ed8;
  --grad: linear-gradient(135deg, #0ea5e9 0%, #2563eb 50%, #8b5cf6 100%);

  --green: #059669;
  --green-bg: #ecfdf5;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --red: #dc2626;
  --red-bg: #fef2f2;

  --sans: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
  --serif: 'Playfair Display', ui-serif, Georgia, serif;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100vh;
  background: var(--white);
  font-family: var(--sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

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

/* ---------- Layout: сайдбар + контент ---------- */

.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--white);
  border-right: 1px solid var(--smoke);
  padding: 26px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .logo {
  width: 144px;
  margin: 4px auto 12px;
}

.sidebar .logo img {
  display: block;
  width: 100%;
  height: auto;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--pebble);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all .25s var(--ease);
}

.sidebar a .icon {
  width: 19px;
  height: 19px;
  display: grid;
  place-items: center;
  flex: 0 0 19px;
  color: currentColor;
}
.sidebar a .icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.sidebar a:hover { background: var(--linen); color: var(--ink); }

.sidebar a.active {
  background: var(--linen);
  color: var(--blue-deep);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--blue);
}

.sidebar-account {
  margin-top: auto;
  padding: 14px 10px 2px;
  border-top: 1px solid var(--smoke);
}

.sidebar-account-label {
  margin-bottom: 6px;
  color: var(--iron);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.sidebar-account select { padding: 8px 9px; font-size: 12px; }
.sidebar-user { display: flex; align-items: center; justify-content: space-between; gap: 6px; margin-top: 7px; }
.sidebar-user span { min-width: 0; overflow: hidden; color: var(--pebble); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user button { padding: 5px 7px; font-size: 10px; }

.main-content { flex: 1; min-width: 0; padding: 36px 52px; max-width: none; }

/* ---------- Верхняя панель проекта ---------- */

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 45;
  min-height: 68px;
  margin: -36px -52px 32px;
  padding: 10px 32px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 20px;
  background: rgba(255, 255, 255, .94);
  border-bottom: 1px solid var(--smoke);
  backdrop-filter: blur(14px);
}

.topbar-controls { display: flex; align-items: center; justify-content: flex-end; gap: 24px; min-width: 0; }
.topbar-context { display: flex; align-items: center; gap: 24px; min-width: 0; }
.topbar-project, .topbar-balance { display: grid; gap: 2px; }
.topbar-project > span, .topbar-balance > span {
  color: var(--iron);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.topbar-project .lf-select { width: 176px; }
.topbar-project .lf-control-trigger {
  min-height: 23px;
  padding: 1px 22px 1px 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  font-size: 13px;
  font-weight: 700;
}
.topbar-project .lf-control-trigger:hover:not(:disabled) { background: transparent; box-shadow: none; }
.topbar-project .lf-select-menu { width: 224px; min-width: 224px; }
.topbar-balance strong { font-size: 13px; white-space: nowrap; }
.topbar-balance strong.low { color: var(--red); }

.topbar-profile-wrap { position: relative; }
.topbar-profile {
  width: auto;
  padding: 5px 7px;
  display: flex;
  align-items: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--ink);
  background: transparent;
  text-align: left;
}
.topbar-profile:hover:not(:disabled), .topbar-profile[aria-expanded="true"] {
  transform: none;
  opacity: 1;
  border-color: var(--smoke);
  background: var(--paper);
}
.topbar-avatar {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--grad);
  color: white;
  font-size: 11px;
  font-weight: 800;
}
.topbar-person { display: grid; gap: 1px; min-width: 0; }
.topbar-person strong { max-width: 180px; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.topbar-person small { max-width: 180px; overflow: hidden; color: var(--pebble); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.topbar-chevron { color: var(--iron); font-size: 13px; }
.topbar-chevron svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.topbar-profile-menu {
  display: none;
  position: absolute;
  top: calc(100% + 7px);
  right: 0;
  width: 210px;
  padding: 7px;
  border: 1px solid var(--smoke);
  border-radius: 12px;
  background: white;
  box-shadow: 0 18px 50px rgba(24, 39, 75, .14);
}
.topbar-profile-menu.visible { display: grid; }
.topbar-profile-menu a, .topbar-profile-menu button {
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--ash);
  background: transparent;
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
}
.topbar-profile-menu a:hover, .topbar-profile-menu button:hover { transform: none; background: var(--paper); color: var(--ink); opacity: 1; }

/* ---------- Единая загрузка страниц ---------- */

.app-loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: rgba(247, 249, 253, .78);
  backdrop-filter: blur(7px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .18s ease, visibility .18s ease;
}
.app-loading-overlay.visible { opacity: 1; visibility: visible; }
.app-loading-overlay.compact {
  display: block;
  background: transparent;
  backdrop-filter: none;
  pointer-events: none;
}
.app-loading-overlay.compact .app-loader-card {
  position: absolute;
  inset: 0 0 auto;
  display: block;
  width: 100%;
  height: 3px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: rgba(37, 99, 235, .10);
  box-shadow: none;
}
.app-loading-overlay.compact .app-loader-card > * { display: none; }
.app-loading-overlay.compact .app-loader-card::after {
  content: "";
  position: absolute;
  inset: 0 auto 0 -32%;
  width: 32%;
  border-radius: 999px;
  background: var(--grad);
  animation: route-progress 1s ease-in-out infinite;
}
.app-loader-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border: 1px solid var(--smoke);
  border-radius: 16px;
  background: white;
  box-shadow: 0 18px 60px rgba(37, 99, 235, .13);
}
.app-loader-card > div:last-child { display: grid; gap: 2px; }
.app-loader-card strong { font-size: 13px; }
.app-loader-card span { color: var(--pebble); font-size: 10px; }
.app-loader-mark {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--grad);
  color: white;
  animation: loader-pulse 1.1s ease-in-out infinite;
}
.app-loader-mark svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
@keyframes loader-pulse {
  0%, 100% { transform: scale(.92) rotate(0); box-shadow: 0 0 0 0 rgba(37, 99, 235, .16); }
  50% { transform: scale(1.06) rotate(8deg); box-shadow: 0 0 0 10px rgba(37, 99, 235, 0); }
}
@keyframes route-progress {
  0% { left: -32%; width: 32%; }
  55% { width: 46%; }
  100% { left: 100%; width: 24%; }
}

.page-header { margin-bottom: 28px; }

.page-header h1 {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.035em;
  margin: 0 0 6px;
}

.page-header h1 em {
  font-family: var(--serif);
  font-style: italic;
  font-weight: 400;
  background: var(--grad);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.page-header p { color: var(--pebble); margin: 0; font-size: 14px; line-height: 1.5; }

.eyebrow {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--pebble);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  margin-bottom: 14px;
}

@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; height: auto; position: static;
    flex-direction: row; overflow-x: auto;
    padding: 10px; border-right: none; border-bottom: 1px solid var(--smoke);
  }
  .sidebar .logo { display: none; }
  .sidebar a { white-space: nowrap; }
  .sidebar a.active { box-shadow: inset 0 -3px 0 var(--blue); }
  .sidebar-account { min-width: 220px; margin-top: 0; padding: 0 0 0 10px; border-top: none; border-left: 1px solid var(--smoke); }
  .sidebar-account-label { display: none; }
  .sidebar-user { display: none; }
  .main-content { padding: 22px 22px; }
  .app-topbar { margin: -22px -22px 24px; padding: 9px 16px; }
  .topbar-controls { gap: 12px; }
  .topbar-context { gap: 14px; }
  .topbar-project .lf-select { width: 135px; }
  .topbar-person, .topbar-chevron { display: none; }
  .page-header h1 { font-size: 24px; }
}

@media (max-width: 520px) {
  .topbar-balance > span { display: none; }
  .topbar-project > span { font-size: 8px; }
  .topbar-project .lf-select { width: 118px; }
  .topbar-project .lf-control-trigger { font-size: 12px; }
}

/* ---------- Карточки ---------- */

.card {
  background: var(--white);
  border: 1px solid var(--smoke);
  border-radius: var(--radius);
  padding: 24px;
  transition: border-color .3s var(--ease);
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

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

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .02em;
  color: var(--ash);
  margin-bottom: 7px;
  margin-top: 18px;
}

label:first-of-type { margin-top: 0; }

input[type="text"],
input[type="email"],
input[type="number"],
input[type="password"],
input[type="date"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  outline: none;
  background: var(--white);
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}

textarea { resize: vertical; line-height: 1.5; }

input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

input::placeholder, textarea::placeholder { color: var(--iron); }

/* ---------- Фирменные выпадающие списки и календарь ---------- */

.lf-control {
  position: relative;
  width: 100%;
  min-width: 0;
  display: inline-block;
  vertical-align: middle;
}

.lf-native-control {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.lf-control .lf-control-trigger {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--white);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(24, 39, 75, .025);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease), background .2s var(--ease);
}

.lf-control .lf-control-trigger:hover:not(:disabled) {
  transform: none;
  opacity: 1;
  border-color: #aebada;
  background: #fbfcff;
  box-shadow: 0 4px 14px rgba(37, 99, 235, .07);
}

.lf-control.open > .lf-control-trigger {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .1);
}

.lf-control-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lf-control-arrow { width: 17px; height: 17px; display: grid; place-items: center; flex: 0 0 17px; color: var(--iron); transition: transform .2s var(--ease); }
.lf-control-arrow svg, .lf-date-icon svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.lf-control.open .lf-control-arrow { transform: rotate(180deg); }

.lf-control-popover {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 120;
  display: none;
  min-width: 100%;
  padding: 7px;
  border: 1px solid var(--smoke);
  border-radius: 14px;
  background: rgba(255, 255, 255, .98);
  box-shadow: 0 20px 55px rgba(24, 39, 75, .16), 0 3px 12px rgba(24, 39, 75, .06);
  backdrop-filter: blur(16px);
  transform-origin: top center;
  animation: lf-popover-in .16s var(--ease);
}
.lf-control.open .lf-control-popover { display: block; }
@keyframes lf-popover-in { from { opacity: 0; transform: translateY(-5px) scale(.985); } to { opacity: 1; transform: none; } }

.lf-select-menu { max-height: 290px; overflow-y: auto; }
.lf-select-menu .lf-select-option {
  width: 100%;
  padding: 9px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-radius: 9px;
  background: transparent;
  color: var(--ash);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
}
.lf-select-menu .lf-select-option:hover:not(:disabled) { transform: none; opacity: 1; background: var(--linen); color: var(--ink); }
.lf-select-option[aria-selected="true"] { background: #eef4ff; color: var(--blue-deep); font-weight: 650; }
.lf-option-check { opacity: 0; color: var(--blue); font-weight: 800; }
.lf-select-option[aria-selected="true"] .lf-option-check { opacity: 1; }

.lf-date { width: 210px; }
.lf-date-trigger { justify-content: flex-start !important; }
.lf-date-icon { width: 18px; height: 18px; flex: 0 0 18px; color: var(--blue); }
.lf-calendar { width: 310px; padding: 12px; }
.lf-calendar-head { display: grid; grid-template-columns: 34px 1fr 34px; align-items: center; margin-bottom: 10px; }
.lf-calendar-head strong { text-align: center; font-size: 13px; text-transform: capitalize; }
.lf-calendar-head button, .lf-calendar-foot button {
  padding: 7px;
  border-radius: 8px;
  background: transparent;
  color: var(--ash);
  font-size: 13px;
}
.lf-calendar-head button:hover:not(:disabled), .lf-calendar-foot button:hover:not(:disabled) { transform: none; opacity: 1; background: var(--linen); color: var(--blue-deep); }
.lf-calendar-week, .lf-calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.lf-calendar-week { margin-bottom: 4px; }
.lf-calendar-week span { padding: 5px 0; color: var(--iron); font-size: 10px; font-weight: 700; text-align: center; }
.lf-calendar-grid > span { min-height: 34px; }
.lf-calendar-grid button {
  min-height: 34px;
  padding: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ash);
  font-size: 12px;
  font-weight: 550;
}
.lf-calendar-grid button:hover:not(:disabled) { transform: none; opacity: 1; background: var(--linen); color: var(--blue-deep); }
.lf-calendar-grid button.today { box-shadow: inset 0 0 0 1px #b8c8ee; }
.lf-calendar-grid button.selected { background: var(--grad); color: white; box-shadow: none; }
.lf-calendar-grid button:disabled { color: #d2d7e3; }
.lf-calendar-foot { display: flex; justify-content: space-between; margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--smoke); }
.lf-calendar-foot button { color: var(--blue-deep); font-size: 11px; font-weight: 650; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 5px 0;
  font-size: 14px;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] { width: auto; accent-color: var(--blue); }

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

button {
  padding: 11px 18px;
  border: none;
  border-radius: 10px;
  background: var(--grad);
  color: var(--white);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .25s var(--ease), transform .25s var(--ease);
}

button:hover:not(:disabled) { opacity: .88; transform: translateY(-1px); }
button:disabled { opacity: .45; cursor: not-allowed; }

button.secondary {
  background: var(--white);
  color: var(--ash);
  border: 1px solid var(--line);
}
button.secondary:hover:not(:disabled) { background: var(--paper); color: var(--ink); }

button.ghost {
  background: transparent;
  color: var(--pebble);
  border: none;
  padding: 8px 10px;
}
button.ghost:hover:not(:disabled) { background: var(--paper); color: var(--ink); transform: none; }

button.danger { background: var(--red); }
button.danger:hover:not(:disabled) { background: #b91c1c; }

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

.status { margin-top: 12px; font-size: 13px; }
.status.loading { color: var(--pebble); }
.status.error { color: var(--red); background: var(--red-bg); padding: 10px 12px; border-radius: 10px; }
.status.success { color: var(--green); background: var(--green-bg); padding: 10px 12px; border-radius: 10px; }

/* ---------- Таблицы ---------- */

table { width: 100%; border-collapse: collapse; }

th, td {
  text-align: left;
  padding: 13px 16px;
  border-bottom: 1px solid var(--smoke);
  font-size: 14px;
}

th {
  color: var(--iron);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
}

tbody tr { transition: background .2s var(--ease); }
tbody tr:hover { background: var(--linen); }
tbody tr:last-child td { border-bottom: none; }

/* ---------- Бейджи статусов ---------- */

.badge {
  display: inline-block;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .01em;
  white-space: nowrap;
}

.badge.new, .badge.draft { background: var(--smoke); color: var(--blue-deep); }
.badge.active, .badge.successful { background: var(--green-bg); color: var(--green); }
.badge.completed { background: #eef2ff; color: #4f46e5; }
.badge.interest { background: #f5f3ff; color: #6d28d9; }
.badge.contact { background: #eff6ff; color: var(--blue-deep); }
.badge.handed_to_operator, .badge.paused, .badge.awaiting, .badge.limited { background: var(--amber-bg); color: var(--amber); }
.badge.closed, .badge.bot, .badge.stopped { background: var(--paper); color: var(--pebble); }
.badge.banned { background: var(--red-bg); color: var(--red); }
.badge.needs_faq_answer { background: var(--red-bg); color: var(--red); }

/* ---------- Прочее ---------- */

.empty-state {
  text-align: center;
  color: var(--iron);
  padding: 44px 20px;
  font-size: 14px;
}

.hint { font-size: 12px; color: var(--pebble); margin: 6px 0 0; line-height: 1.5; }

hr.divider { border: none; border-top: 1px solid var(--smoke); margin: 24px 0; }
