:root {
  --navy: #14283f;
  --navy-2: #1d3a5f;
  --accent: #2f6fb2;
  --accent-h: #275e97;
  --bg: #f2f5f9;
  --card: #ffffff;
  --text: #1a2433;
  --muted: #64748b;
  --line: #dde4ec;
  --green: #1d9e5f;
  --red: #d24545;
  --amber: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 32, 54, .08), 0 4px 16px rgba(16, 32, 54, .06);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14.5px;
  color: var(--text);
  background: var(--bg);
}
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }

/* ---------- Каркас ---------- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--navy), #0e1d2f);
  color: #cfe0f2;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.logo {
  padding: 20px 20px 16px;
  font-size: 20px; font-weight: 700; color: #fff; letter-spacing: .4px;
}
.logo small { display: block; font-size: 11px; font-weight: 400; color: #7f97b3; letter-spacing: 0; margin-top: 2px; }
.nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.nav-group { margin: 14px 10px 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .8px; color: #6f89a8; }
.nav a {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 12px; margin: 2px 0;
  color: #cfe0f2; border-radius: 8px; font-size: 14px;
}
.nav a:hover { background: rgba(255, 255, 255, .07); }
.nav a.active { background: var(--accent); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .85; }
.user-box {
  padding: 14px 16px; border-top: 1px solid rgba(255, 255, 255, .1);
  display: flex; align-items: center; gap: 10px;
}
.user-box .avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 600;
  flex-shrink: 0;
}
.user-box .info { flex: 1; min-width: 0; }
.user-box .info b { display: block; color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box .info span { font-size: 11.5px; color: #8fa6bf; }
.user-box .logout { background: none; border: 0; color: #8fa6bf; font-size: 16px; padding: 4px; }
.user-box .logout:hover { color: #fff; }

.main { flex: 1; padding: 26px 32px 60px; max-width: 1280px; min-width: 0; }

/* ---------- Заголовки, панели ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; font-weight: 650; }
.page-head .spacer { flex: 1; }
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px;
}
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 8px 14px; font-size: 13.5px; font-weight: 550;
  background: var(--accent); color: #fff;
  transition: background .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--accent-h); }
.btn.secondary { background: #fff; border-color: var(--line); color: var(--text); }
.btn.secondary:hover { background: #f4f7fa; }
.btn.danger { background: #fff; border-color: #eecaca; color: var(--red); }
.btn.danger:hover { background: #fdf1f1; }
.btn.success { background: var(--green); }
.btn.success:hover { background: #178a52; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; padding: 11px 14px;
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); border-bottom: 1px solid var(--line);
  background: #fafbfd; white-space: nowrap;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
th.sortable.sorted { color: var(--accent); }
th .sort-arrow { font-size: 9px; }
td { padding: 11px 14px; border-bottom: 1px solid #eef2f6; vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f6f9fc; }
td .sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.empty { padding: 36px; text-align: center; color: var(--muted); }

/* ---------- Бейджи статусов ---------- */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.new { background: #e3effd; color: #1d5ba6; }
.badge.confirmed { background: #ddf3e7; color: #147a48; }
.badge.done { background: #e8eaee; color: #4b5563; }
.badge.closed { background: #fbe4e4; color: #a83232; }
.badge.role { background: #edf1f6; color: #445; }

/* ---------- Фильтры-чипы ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 20px;
  padding: 6px 14px; font-size: 13px; color: var(--muted);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--navy-2); border-color: var(--navy-2); color: #fff; }

/* ---------- Формы ---------- */
.field { margin-bottom: 13px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: #3c4a5d; margin-bottom: 5px; }
.field label .req { color: var(--red); }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 11px; font-size: 14px; background: #fff;
  outline: none;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 111, 178, .13); }
textarea.input { resize: vertical; min-height: 64px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; min-width: 0; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------- Плечи маршрута в форме рейса ---------- */
.leg-head, .leg-row {
  display: grid;
  grid-template-columns: 22px 1fr 1fr 138px 76px 62px 34px;
  gap: 8px; align-items: start;
}
.leg-head {
  margin-top: 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .4px; color: var(--muted);
}
.leg-row {
  padding: 6px 0 2px; border-bottom: 1px dashed var(--line);
}
.leg-row:last-of-type { border-bottom: 0; }
.leg-num {
  font-size: 12.5px; font-weight: 700; color: var(--muted);
  padding-top: 10px; text-align: center;
}
.leg-hint { grid-column: 2 / -1; margin-top: -2px; }
@media (max-width: 860px) {
  .leg-head { display: none; }
  .leg-row { grid-template-columns: 22px 1fr 1fr; }
  .leg-row > input, .leg-row > button { grid-column: auto; }
  .leg-hint { grid-column: 1 / -1; }
}

/* ---------- Автодополнение аэропортов ---------- */
.ac { position: relative; }
.ac-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 4px);
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 260px; overflow-y: auto;
}
.ac-item { padding: 8px 12px; cursor: pointer; font-size: 13.5px; }
.ac-item:hover, .ac-item.hl { background: #eef5fc; }
.ac-item b { color: var(--navy-2); }
.ac-item .sub { font-size: 12px; color: var(--muted); }
.ac-item.empty-item { color: var(--muted); cursor: default; }
.ac-item.empty-item:hover { background: none; }
.ac.combo .input { padding-right: 28px; }
.ac-caret {
  position: absolute; right: 10px; top: 9px;
  color: var(--muted); font-size: 11px; pointer-events: none;
}

/* ---------- Модальные окна ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 28, 45, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px; z-index: 100; overflow-y: auto;
}
.modal {
  background: #fff; border-radius: 12px; box-shadow: 0 12px 48px rgba(0, 0, 0, .25);
  width: 100%; max-width: 560px; padding: 22px 24px;
  animation: pop .15s ease-out;
}
.modal.wide { max-width: 720px; }
@keyframes pop { from { transform: translateY(8px); opacity: .6; } to { transform: none; opacity: 1; } }
.modal h2 { font-size: 17px; margin-bottom: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- Тосты ---------- */
#toasts { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--navy); color: #fff; border-radius: 8px;
  padding: 11px 16px; font-size: 13.5px; box-shadow: var(--shadow);
  max-width: 360px; animation: pop .15s ease-out;
}
.toast.error { background: #a63030; }
.toast.success { background: var(--green); }

/* ---------- Вход ---------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, #0e1d2f 60%, #16324f 100%);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 14px; box-shadow: 0 16px 60px rgba(0, 0, 0, .35);
  padding: 34px 36px; width: 100%; max-width: 400px;
}
.login-card .logo-big { font-size: 26px; font-weight: 700; color: var(--navy); margin-bottom: 2px; }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-error { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.login-demo {
  margin-top: 18px; padding: 11px 13px; background: #f4f7fa; border-radius: 8px;
  font-size: 12px; color: var(--muted); line-height: 1.7;
}
.login-demo code { background: #e8edf3; border-radius: 4px; padding: 1px 5px; }

/* ---------- Карточка рейса ---------- */
.flight-head { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.route-big { font-size: 24px; font-weight: 700; color: var(--navy); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.route-big .arr { color: var(--accent); }
.route-big .city { font-size: 13px; font-weight: 400; color: var(--muted); display: block; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { font-weight: 500; }

.tabs { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 16px; }
.tab {
  padding: 9px 18px; border: 0; background: none; font-size: 14px; font-weight: 550;
  color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -2px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover { color: var(--accent); }

/* ---------- Предложения ---------- */
.offer {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px; background: #fff;
}
.offer.confirmed { border-color: var(--green); box-shadow: 0 0 0 1px var(--green); }
.offer-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.offer-title { font-size: 16px; font-weight: 650; }
.offer-price { margin-left: auto; font-size: 18px; font-weight: 700; color: var(--navy-2); white-space: nowrap; }
.offer-sub { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.offer-desc { margin-top: 8px; font-size: 13.5px; white-space: pre-wrap; }
.photos { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.photo {
  position: relative; width: 132px;
}
.photo img {
  width: 132px; height: 92px; object-fit: cover; border-radius: 7px;
  border: 1px solid var(--line); cursor: zoom-in; display: block;
}
.photo .cap { font-size: 11px; color: var(--muted); text-align: center; margin-top: 2px; }
.photo .del {
  position: absolute; top: 4px; right: 4px; width: 20px; height: 20px;
  border-radius: 50%; border: 0; background: rgba(20, 30, 45, .65); color: #fff;
  font-size: 11px; line-height: 20px; display: none;
}
.photo:hover .del { display: block; }
.offer-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.upload-row { display: flex; gap: 8px; align-items: center; margin-top: 10px; flex-wrap: wrap; }

/* ---------- Перетаскивание предложений ---------- */
.drag-handle {
  cursor: grab; color: #9aa8ba; font-size: 17px; line-height: 1;
  padding: 4px 6px 2px 0; user-select: none; align-self: flex-start; margin-top: 2px;
}
.drag-handle:hover { color: var(--accent); }
.drag-handle:active { cursor: grabbing; }
.offer.dragging { opacity: .55; border-style: dashed; border-color: var(--accent); }

/* ---------- Миниатюры фото в таблицах ---------- */
.thumbs { display: flex; gap: 4px; align-items: center; }
.thumbs img {
  width: 56px; height: 40px; object-fit: cover; border-radius: 5px;
  border: 1px solid var(--line); cursor: zoom-in;
}
.thumbs .more { font-size: 11.5px; color: var(--muted); padding-left: 2px; }

/* ---------- WYSIWYG-редактор шаблона КП ---------- */
.wys-toolbar { display: flex; gap: 6px; margin-bottom: 6px; flex-wrap: wrap; align-items: center; }
.wys-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.wys-color {
  width: 36px; height: 31px; padding: 2px;
  border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: pointer;
}
.wys-size { max-width: 130px; padding: 5px 8px; font-size: 12.5px; }
.wysiwyg {
  min-height: 130px; max-height: 320px; overflow-y: auto;
  padding: 10px 12px; line-height: 1.5; background: #fff;
}
.wysiwyg:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 111, 178, .13); }
.wysiwyg[contenteditable="false"] { background: #f4f6f9; color: var(--muted); }
.wysiwyg ul, .wysiwyg ol { margin: 4px 0 4px 20px; }

/* ---------- Предупреждения ---------- */
.warn-box {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  background: #fdf3df; border: 1px solid #ecd9a8; color: #7d5a12;
  border-radius: 8px; padding: 9px 12px; font-size: 13px; margin-top: 10px;
}

/* ---------- Лайтбокс ---------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(10, 16, 25, .88); z-index: 300;
  display: flex; align-items: center; justify-content: center; cursor: zoom-out;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .main { padding: 18px 14px; }
  .form-row { flex-direction: column; gap: 0; }
}
