/* Bedolaga Fleet — стили интерфейса. Тёмная тема по умолчанию, светлая — переключателем. */

:root, [data-theme="dark"] {
  --bg: #0F1117; --surface: #171A23; --surface2: #1F2330; --border: #2A2F3D;
  --text: #E7E9F0; --muted: #9AA1B4; --accent: #5B8DEF; --accent-text: #0B1222;
  --accent-soft: rgba(91,141,239,.18); --ok: #3DBE7E; --warn: #E6A23C; --err: #F0625A;
  --ok-soft: rgba(61,190,126,.16); --warn-soft: rgba(230,162,60,.18); --err-soft: rgba(229,83,75,.16);
  --shadow: 0 1px 2px rgba(0,0,0,.4); --term: #0A0C12; --mono-text: #C9D1E3;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #F3F4F8; --surface: #FFFFFF; --surface2: #F6F7FA; --border: #E1E4EC;
  --text: #171A22; --muted: #5C6375; --accent: #2F63D1; --accent-text: #FFFFFF;
  --accent-soft: rgba(47,99,209,.12); --ok: #1E7F52; --warn: #A05F00; --err: #C3372F;
  --ok-soft: rgba(30,142,90,.12); --warn-soft: rgba(176,106,0,.12); --err-soft: rgba(200,58,50,.1);
  --shadow: 0 1px 2px rgba(20,24,40,.06); --term: #1B1F2A; --mono-text: #C9D1E3;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 Inter, "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; letter-spacing: -.02em; margin: 0; line-height: 1.2; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 15px; margin: 0; }
p { margin: 0; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* ---------- каркас */
.app { display: flex; min-height: 100vh; }
.nav {
  width: 240px; flex: 0 0 240px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 16px; color: var(--text); }
.brand:hover { text-decoration: none; }
.logo {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-text);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: 0 0 32px;
}
.nav a.item {
  display: flex; align-items: center; gap: 10px; padding: 0 12px; min-height: 42px; border-radius: 8px;
  color: var(--muted); font-weight: 500; font-size: 14px;
}
.nav a.item:hover { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav a.item[aria-current="page"] { background: var(--accent-soft); color: var(--text); }
.nav .grow { flex: 1; }
.nav .me { border-top: 1px solid var(--border); margin-top: 8px; padding: 12px 10px 0; display: flex; gap: 10px; align-items: center; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--surface2); display: flex;
  align-items: center; justify-content: center; font-weight: 600; font-size: 13px; flex: 0 0 32px;
}
.ico { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 18px; }
.main { flex: 1; min-width: 0; padding: 24px 32px 48px; display: flex; flex-direction: column; gap: 20px; }
.topbar { display: none; }

.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.page-head .title { margin-right: auto; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.crumbs { font-size: 13px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- элементы */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); min-width: 0; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-h h2 { margin-right: auto; }
.card-b { padding: 16px; }
.grid { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.split { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 20px; align-items: start; }
.split.chats { grid-template-columns: minmax(260px, 1fr) minmax(0, 2fr); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--err); }
.btn.sm { min-height: 34px; font-size: 13px; padding: 0 12px; }
.btn.icon { width: 40px; padding: 0; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.neutral { background: var(--surface2); color: var(--muted); }
.badge.info { background: var(--accent-soft); color: var(--accent); }
.badge.plain::before { display: none; }

.table-wrap { overflow-x: auto; position: relative; } /* position: держит внутри и скрытые подписи .sr-only */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; padding: 10px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface2); }
td .sub { font-size: 12px; color: var(--muted); }

.kv { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv > :first-child { color: var(--muted); }
.kv > :last-child { text-align: right; min-width: 0; overflow-wrap: anywhere; }

.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 4px; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.kpi .l { font-size: 13px; color: var(--muted); font-weight: 500; }

/* ---------- формы */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: 13px; font-weight: 600; }
.field .hint, .hint { font-size: 12.5px; color: var(--muted); }
.field .error { font-size: 12.5px; color: var(--err); }
input:not([type]), input[type=url], input[type=text], input[type=email], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%; min-height: 42px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg);
  color: var(--text); font: inherit; font-size: 14px; padding: 8px 12px;
}
textarea { min-height: 96px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.check { display: flex; gap: 10px; align-items: center; font-size: 14px; min-height: 36px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- уведомления и проблемы */
.flash { border-radius: 10px; padding: 12px 14px; font-size: 14px; border: 1px solid var(--border); background: var(--surface); }
.flash.ok { border-color: var(--ok); background: var(--ok-soft); }
.flash.err { border-color: var(--err); background: var(--err-soft); }
.problem { border: 1px solid var(--border); border-left: none; border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; background: var(--surface); }
.problem.error { border-color: var(--err); background: var(--err-soft); }
.problem.warning { border-color: var(--warn); background: var(--warn-soft); }
.problem.info { border-color: var(--accent); background: var(--accent-soft); }
.problem.ok-note { border-color: var(--ok); background: var(--ok-soft); }
.problem .t { font-weight: 700; }
.problem .a { font-size: 14px; }
details summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.term { background: var(--term); color: var(--mono-text); border-radius: 10px; padding: 12px 14px; font-family: ui-monospace, Menlo, monospace; font-size: 12px; line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 360px; overflow: auto; }

/* ---------- мастер */
.wizard { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px; align-items: start; }
.steps { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 16px; }
.steps > a, .steps > span { display: flex; align-items: center; gap: 12px; padding: 8px 10px; border-radius: 10px; color: var(--muted); font-size: 14px; font-weight: 500; min-height: 44px; }
.steps > a:hover { background: var(--surface2); text-decoration: none; }
.steps .n { width: 26px; height: 26px; border-radius: 50%; flex: 0 0 26px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; border: 1.5px solid var(--border); }
.steps .done .n { background: var(--ok); border-color: var(--ok); color: #06140C; }
.steps [aria-current="step"] { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.steps [aria-current="step"] .n { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.wizard-foot { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 16px; }
.wizard-foot .spacer, .row .spacer, .spacer { margin-right: auto; }
.mono { overflow-wrap: anywhere; }
.danger-zone { border-color: var(--err); }
.inline { display: inline; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }

.choice { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.choice label { border: 1px solid var(--border); border-radius: 12px; padding: 14px; display: flex; gap: 12px; cursor: pointer; background: var(--surface); }
.choice label:hover { border-color: var(--accent); }
.choice input { margin-top: 3px; accent-color: var(--accent); }
.choice input:checked + div .t { color: var(--accent); }

/* ---------- прогресс задачи */
.progress { height: 10px; border-radius: 999px; background: var(--surface2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .4s; }
.progress.ok > span { background: var(--ok); }
.progress.err > span { background: var(--err); }
.jstep { display: flex; gap: 14px; align-items: flex-start; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.jstep:last-child { border-bottom: none; }
.jstep .st { width: 28px; height: 28px; border-radius: 50%; flex: 0 0 28px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--border); color: var(--muted); }
.jstep .st svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.jstep.done .st { background: var(--ok); border-color: var(--ok); color: #06140C; }
.jstep.failed .st { background: var(--err); border-color: var(--err); color: #fff; }
.jstep.running .st { border-color: var(--accent); border-top-color: transparent; animation: spin 1s linear infinite; }
.jstep.skipped { opacity: .55; }
.jstep .t { font-weight: 600; }
.jstep.pending .t { color: var(--muted); font-weight: 500; }
.jstep .eta { margin-left: auto; font-size: 12.5px; color: var(--muted); white-space: nowrap; padding-top: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .jstep.running .st { animation: none; } .progress > span { transition: none; } }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login .card { width: 100%; max-width: 400px; }

/* ---------- узкие экраны */
@media (max-width: 1100px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .split, .split.chats { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .nav { position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%); transition: transform .2s, visibility .2s; height: 100vh; visibility: hidden; }
  body.nav-open .nav { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); visibility: visible; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
  .main { padding: 16px 16px 40px; }
  .wizard { grid-template-columns: minmax(0, 1fr); }
  .steps { position: static; flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 4px; }
  .steps > a, .steps > span { flex: 0 0 auto; }
  .steps .lbl { display: none; }
  .steps [aria-current="step"] .lbl { display: inline; }
  .cols-2, .cols-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .v { font-size: 22px; }
  h1 { font-size: 21px; }
  .page-head .btn { flex: 1 1 auto; }
}

/* переключатель темы: солнце в тёмной, луна в светлой */
[data-theme="dark"] .when-light, [data-theme="light"] .when-dark { display: none; }
.when-dark, .when-light { display: inline-flex; }
.nav #theme-toggle { justify-content: flex-start; margin: 6px 0; border-color: transparent; color: var(--muted); font-weight: 500; }
.topbar .brand { padding: 0; gap: 8px; }
.inline-form { display: inline; }
.names-table input[type=text] { min-height: 36px; }
.preview-names { display: flex; flex-wrap: wrap; gap: 6px; }
.preview-names span { background: var(--surface2); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.color-input { width: 64px; min-height: 42px; padding: 2px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.mt { margin-top: 4px; }

.more-pay > summary { list-style: none; width: 100%; justify-content: center; }
.more-pay > summary::-webkit-details-marker { display: none; }
.more-pay[open] > summary { display: none; }
code.copy { display: block; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; user-select: all; overflow-wrap: anywhere; }

/* ---------- переписка поддержки */
.chat { display: flex; flex-direction: column; gap: 12px; }
.msg { max-width: 85%; border-radius: 14px; padding: 10px 14px; background: var(--surface2); border: 1px solid var(--border); }
.msg.admin { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.msg .meta { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.nav .count { margin-left: auto; min-width: 22px; height: 22px; padding: 0 7px; border-radius: 999px; background: var(--warn); color: #1A1200; font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

/* ---------- редактор сайта */
.site-editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.site-editor .preview { position: sticky; top: 16px; overflow: hidden; }
.site-editor iframe { display: block; width: 100%; height: 70vh; border: 0; border-top: 1px solid var(--border); background: #fff; }
@media (max-width: 1100px) { .site-editor { grid-template-columns: minmax(0, 1fr); } .site-editor .preview { position: static; } .site-editor iframe { height: 520px; } }
@media (max-width: 520px) { .hide-sm { display: none; } }

/* ---------- тексты бота: предпросмотр как в Telegram */
.tg-tools { display: flex; gap: 6px; flex-wrap: wrap; }
.tg-tools .btn { min-width: 38px; justify-content: center; }
.tg-input { font-family: inherit !important; font-size: 15px !important; line-height: 1.5; }
.tg-preview { display: flex; flex-direction: column; gap: 8px; }
.tg-bubble { background: var(--surface2); border: 1px solid var(--border); border-radius: 16px 16px 16px 4px; padding: 12px 14px; white-space: normal; overflow-wrap: anywhere; line-height: 1.5; }
.tg-bubble a { text-decoration: underline; }
.tg-bubble blockquote { margin: 6px 0; padding-left: 10px; border-left: 3px solid var(--accent); }
.tg-spoiler { background: var(--muted); color: transparent; border-radius: 4px; }
.tg-spoiler:hover { background: transparent; color: inherit; }
.tg-keyboard { display: flex; flex-direction: column; gap: 6px; }
.tg-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tg-key { flex: 1 1 0; min-width: 0; text-align: center; padding: 10px 8px; border-radius: 8px; background: var(--accent-soft); font-size: 14px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-cond { flex: 0 0 100%; font-size: 11.5px; color: var(--muted); margin-top: -2px; }
.menu-edit { display: flex; gap: 10px; align-items: flex-end; }
.clamp { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.term.logs { max-height: 70vh; font-size: 12px; white-space: pre-wrap; }
.term .lerr { color: #FF8A80; }
.term .lwarn { color: #FFD180; }

.qr svg { display: block; width: 180px; height: 180px; border-radius: 8px; }
.code-input { font-size: 22px !important; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }

/* выбор файла (картинка/видео для рассылки и закрепа) */
input[type=file] { font: inherit; font-size: 14px; color: var(--muted, inherit); max-width: 100%; }
input[type=file]::file-selector-button { font: inherit; font-size: 14px; font-weight: 600; margin-right: 10px; padding: 8px 14px;
  border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text, inherit); cursor: pointer; }
input[type=file]::file-selector-button:hover { border-color: var(--accent); }
.sub { font-size: 12px; color: var(--muted); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.tile { display: block; padding: 14px 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: inherit; text-decoration: none; }
.tile:hover { border-color: var(--accent); }
.tile[aria-current] { border-color: var(--accent); background: var(--accent-soft); }
.tile .cc { font-family: var(--mono, ui-monospace, monospace); font-size: 12px; color: var(--muted); }
