/* ===== Админка: только дополнения к общим стилям сайта (base/app/liquid/kera.css) ===== */
.muted { color: var(--muted); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
[hidden] { display: none !important; }
.btn svg, .icon-btn svg { width: 18px; height: 18px; }

/* Вход */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login { width: min(400px, 100%); display: grid; gap: 14px; text-align: center; justify-items: center; animation: view-in .5s var(--ease-out) both; }
.login .brand-mark { width: 52px; height: 52px; }
.login h1 { font-size: 24px; }
.login .input { text-align: center; }

/* Каркас как у сайта: на компьютере меню слева, на телефоне шапка и нижняя панель */
body.admin .main { padding-top: calc(var(--s2) + env(safe-area-inset-top)); }
.rail nav .rail-link, .rail-foot .rail-link { position: relative; }
.tab-count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--danger); color: #fff;
  font-size: 11px; font-style: normal; font-weight: 800; display: grid; place-items: center; }
.tab .tab-count { position: absolute; top: 4px; right: calc(50% - 26px); margin: 0; }
.tabbar { right: 16px; max-width: 520px; margin: 0 auto; }
.tab { border: 0; background: none; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }
@media (max-width: 400px) { .tab { font-size: 10px; } }

/* ---- Заявки ---- */
.kstats { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 10px; margin: 0 -2px 6px; scrollbar-width: none; }
.kstats::-webkit-scrollbar { display: none; }
.kstat { flex: 1 0 110px; padding: 14px 16px; border-radius: var(--r-lg); cursor: pointer; text-align: left; color: var(--text); }
.kstat:active { transform: scale(.96); }
.kstat b { display: block; font-size: 26px; font-weight: 800; line-height: 1.1; }
.kstat span { font-size: 12px; color: var(--muted); font-weight: 600; }
.kstat.on { background: var(--accent-soft); border-color: rgba(var(--accent-rgb), .45); }
.tools { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; gap: 8px; margin-bottom: 10px; }
.tools .select { width: auto; min-width: 0; }
.tools .input { min-width: 0; }
@media (max-width: 560px) {
  .tools { grid-template-columns: 1fr 1fr; }
  .tools .input, .tools .select { grid-column: 1 / -1; width: 100%; }
  .tools .btn { padding: 0 12px; }
}
.notif-btn { display: flex; margin: 0 0 8px auto; min-height: 32px; }
.list { display: grid; gap: 10px; }
.lead { padding: 16px 18px; display: grid; grid-template-columns: 1.2fr 1fr 1.2fr auto; gap: 14px; align-items: start; border-radius: var(--r-lg);
  animation: view-in .45s var(--ease-out) both; animation-delay: calc(var(--i, 0) * 30ms); }
.lead.removing { opacity: 0; transform: scale(.97); transition: opacity .3s, transform .3s; }
.lead .n { font-weight: 800; font-size: 16px; }
.lead .m { color: var(--muted); font-size: 13px; }
.lead a { color: var(--accent-hi); text-decoration: none; font-weight: 600; }
.lead .textarea { min-height: 44px; padding: 10px 12px; font-size: 14px; }
.lead .acts { display: grid; gap: 4px; justify-items: end; }
.lead .select { padding: 8px 12px; font-size: 14px; width: auto; min-height: 40px; }
.lead .when { font-weight: 800; color: var(--accent-hi); margin-bottom: 2px; }
.lead .link-btn { min-height: 32px; font-size: 13px; padding: 0; }
.lead .del-btn { color: var(--muted); }
.lead .del-btn:hover { color: var(--danger); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.st-new .dot { background: var(--danger); box-shadow: 0 0 10px var(--danger); }
.st-contacted .dot { background: var(--warn); }
.st-enrolled .dot { background: var(--ok); }
.st-done .dot { background: var(--muted); }
.st-rejected, .st-cancelled { opacity: .6; }
.st-rejected .dot, .st-cancelled .dot { background: var(--muted-2); }
/* телефон: карточка заявки сверху вниз, статус и действия — строкой внизу */
@media (max-width: 760px) {
  .lead { grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 16px; }
  .lead .acts { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-start; gap: 6px 16px; padding-top: 10px; border-top: 1px solid var(--line); }
  .lead .acts .select { flex: 1 1 100%; width: 100%; }
}

.quick { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.qbtn { min-width: 34px; height: 32px; padding: 0 9px; border-radius: 10px; display: grid; place-items: center; font-size: 12px; font-weight: 800;
  text-decoration: none; color: var(--text) !important; background: var(--glass-2); border: 1px solid var(--line-2); cursor: pointer; }
.qbtn:hover { background: var(--accent-soft); border-color: rgba(var(--accent-rgb), .4); }
.qbtn:active { transform: scale(.92); }

/* ---- Расписание ---- */
.sch-tools { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.sch-tools .select { width: auto; }
.sch-tools .btn { min-height: 44px; }
.sch-tools [data-add] { margin-left: auto; }
.sch-day { padding: 16px 18px; border-radius: var(--r-lg); margin-bottom: 10px; animation: view-in .4s var(--ease-out) both; }
.sch-day header { display: flex; align-items: center; gap: 10px; }
.sch-day h3 { font-size: 16px; }
.sch-day header .link-btn { margin-left: auto; min-height: 32px; }
.sch-day.empty-day { opacity: .55; padding: 10px 18px; }
.sch-city h4 { font-size: 12px; color: var(--muted); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .06em; }
.sch-slot { display: grid; grid-template-columns: 64px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.sch-time b { display: block; font-size: 17px; }
.sch-time span { font-size: 12px; font-weight: 700; color: var(--ok); }
.sch-time span.full { color: var(--danger); }
.sch-list { display: grid; gap: 8px; }
.sch-person { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px; }
.sch-person .who b { display: block; font-size: 15px; }
.sch-person .who small { color: var(--muted); font-size: 12px; }
.sch-person .quick { margin: 0; }
.sch-person .link-btn { min-height: 32px; font-size: 13px; }
.sch-nodate { padding: 16px 18px; border-radius: var(--r-lg); margin-bottom: 10px; display: grid; gap: 10px; }
.sch-nodate > b { color: var(--accent-hi); }
.sch-day header > span, .sch-day header .link-btn { white-space: nowrap; }
@media (max-width: 640px) {
  .sch-day { padding: 14px; }
  .sch-day header { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; row-gap: 0; align-items: center; }
  .sch-day header h3 { grid-column: 1; font-size: 15px; }
  .sch-day header > span { grid-column: 1; grid-row: 2; font-size: 12px; }
  .sch-day header .link-btn { grid-column: 2; grid-row: 1 / 3; margin: 0; }
  .sch-slot { grid-template-columns: 48px minmax(0, 1fr); gap: 10px; }
  .sch-time b { font-size: 15px; }
  .sch-person { grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; }
  .sch-person .quick { grid-column: 2 / -1; grid-row: 2; }
  .sch-tools .btn { padding: 0 12px; }
  .sch-tools [data-add] { flex: 1 1 100%; margin: 0; }
  .sch-tools .select { flex: 1 1 100%; }
}

/* Окно заявки — как шторка записи на сайте */
.lead-dlg { margin: auto; width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 24px); overflow: auto; padding: var(--s3); color: var(--text);
  border: 1px solid var(--line-2); border-radius: var(--r-xl); background: linear-gradient(180deg, rgba(30, 44, 70, .97), rgba(9, 16, 30, .99)); box-shadow: var(--shadow); }
.lead-dlg::backdrop { background: rgba(2, 6, 14, .62); backdrop-filter: blur(4px); }
.lead-dlg[open] { animation: view-in .4s var(--ease-out) both; }
.dlg-form { display: grid; gap: 14px; }
.dlg-form h2 { font-size: 22px; }
.dlg-acts { justify-content: flex-end; }
.dlg-load { font-size: 13px; margin: -4px 0 0 4px; }
.dlg-load.bad { color: var(--danger); }
.lead-dlg input[type=date] { color-scheme: dark; }

/* ---- ИИ-помощник: настройки агента + чат с агентом ---- */
.ai-split { display: grid; gap: 16px; align-items: start; }
.ai-col { display: grid; gap: 16px; min-width: 0; }
@media (min-width: 1200px) {
  body.admin:has(#v-ai:not([hidden])) .main { max-width: none; }
  .ai-split { grid-template-columns: minmax(0, 1fr) minmax(380px, 46%); }
  .agent-chat { position: sticky; top: 16px; height: calc(100dvh - 40px); }
}
.card-title { font-size: 18px; }
.agent-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 8px; }
.agent-row .icon-btn { width: 40px; height: 40px; }
.agent-chat { display: flex; flex-direction: column; min-height: 520px; padding: 0; overflow: hidden; border-radius: var(--r-xl); }
@media (max-width: 1199px) { .agent-chat { height: 72dvh; } }
.agent-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px 16px; border-bottom: 1px solid var(--line); }
.agent-modes { display: flex; gap: 6px; flex-wrap: wrap; }
.agent-modes .chip.is-active { background: var(--accent); border-color: var(--accent); color: #fff; }
.agent-head .icon-btn { margin-left: auto; }
.agent-hint { font-size: 13px; padding: 10px 16px 0; }
.agent-log { flex: 1; min-height: 0; }
.agent-chat .msg { white-space: pre-wrap; }
.agent-chat .as-form .send svg { width: 20px; height: 20px; }
.ai-card { display: grid; gap: 16px; }
.ai-key { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.ai-note { font-size: 13px; }
.ai-prov { display: grid; gap: 16px; }
.two-col { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
@media (max-width: 560px) { .two-col { grid-template-columns: 1fr; } }
#ai-key-state.ok { color: var(--ok); } #ai-key-state.bad { color: var(--danger); }

/* Переключатель (свой класс .tgl, чтобы не конфликтовать с .switch сайта) */
.tgl-row { display: flex; gap: 12px; align-items: center; font-weight: 600; cursor: pointer; }
.tgl { appearance: none; width: 48px; height: 28px; margin: 0; border-radius: var(--pill); background: var(--glass-3); border: 1px solid var(--line-2); position: relative; cursor: pointer; flex: none; transition: background-color .2s; }
.tgl::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .25s var(--spring); }
.tgl:checked { background: var(--accent); border-color: var(--accent); }
.tgl:checked::after { transform: translateX(20px); }

/* ---- Редактор ---- */
.ed-split { display: grid; gap: 18px; }
.ed-forms { min-width: 0; }
.ed-nav { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 12px; scrollbar-width: none; position: sticky; top: 0; z-index: 5; background: linear-gradient(var(--bg-0) 70%, transparent); }
.ed-nav::-webkit-scrollbar { display: none; }
.ed-nav .chip { white-space: nowrap; flex: none; }
.ed-nav .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.ed-sec { padding: var(--s3); margin-bottom: 14px; display: grid; gap: 14px; scroll-margin-top: 70px; border-radius: var(--r-xl); }
.ed-sec > h2 { font-size: 20px; }
.ed-group { display: grid; gap: 12px; }
.ed-list { display: grid; gap: 10px; }
.ed-item { padding: 16px; border-radius: var(--r-md); background: rgba(255, 255, 255, .03); border: 1px solid var(--line); display: grid; gap: 10px; }
.ed-item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; font-weight: 800; color: var(--muted); }
.ed-item-head .row button { width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line-2); background: var(--glass-2); color: var(--text); cursor: pointer; }
.ed-item-head .row button:hover { background: var(--glass-3); }
.ed-item-head .row button:disabled { opacity: .35; cursor: default; }
.ed-item-head .row .del:hover { background: rgba(255, 107, 120, .2); color: var(--danger); }
.ed-add { justify-self: start; }
.ed-check { display: flex; gap: 12px; align-items: center; font-weight: 600; cursor: pointer; }
.ed-img { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.ed-img img, .ed-img .ph { width: 72px; height: 72px; border-radius: var(--r-md); object-fit: cover; background: var(--glass); border: 1px solid var(--line); }
.ed-img .ph { display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.ed-img label { cursor: pointer; }
.ed-img input[type=file] { display: none; }
.ed-block-name { font-weight: 800; font-size: 16px; }
.ed-layout { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.ed-layout .ed-item { gap: 6px; }

.ed-preview { display: none; border-radius: var(--r-xl); overflow: hidden; flex-direction: column; padding: 0; }
.ed-preview iframe { flex: 1; width: 100%; border: 0; background: var(--bg-0); }
.pv-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 8px 8px 18px; font-size: 13px; font-weight: 700; color: var(--muted); }
.fab-pv { position: fixed; z-index: 38; right: 16px; bottom: calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); min-height: 42px; }
@media (min-width: 1101px) { .fab-pv { bottom: 100px; } }
@media (min-width: 1400px) {
  body.admin:has(#v-edit:not([hidden])) .main { max-width: none; }
  .ed-split { grid-template-columns: minmax(0, 1fr) minmax(380px, 44%); align-items: start; }
  .ed-preview { display: flex; position: sticky; top: 16px; height: calc(100dvh - 130px); }
  .pv-head .icon-btn, .fab-pv { display: none !important; }
}
@media (max-width: 1399px) {
  body.pv-open .ed-preview { display: flex; position: fixed; z-index: 120; inset: calc(10px + env(safe-area-inset-top)) 10px calc(10px + env(safe-area-inset-bottom)); animation: view-in .35s var(--ease-out) both; }
  body.pv-open .fab-pv { display: none; }
}

/* Плашка «Сохранить» — над нижней панелью на телефоне, внизу экрана на компьютере */
.savebar {
  position: fixed; z-index: 45; left: 50%; bottom: calc(var(--tabbar-h) + 28px + env(safe-area-inset-bottom));
  width: min(560px, calc(100% - 32px)); padding: 8px 8px 8px 20px; border-radius: var(--pill); transform: translateX(-50%);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: rgba(14, 24, 44, .86); border: 1px solid var(--line-2); box-shadow: var(--shadow); backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur);
}
.savebar span { font-size: 14px; font-weight: 600; color: var(--muted); }
.savebar.dirty { border-color: rgba(var(--accent-rgb), .5); }
.savebar.dirty span { color: var(--accent-hi); }
.savebar .btn { min-height: 42px; padding: 0 18px; font-size: 14px; }
@media (min-width: 1101px) { .savebar { bottom: 24px; left: calc(50% + (var(--rail-w) + 16px) / 2); } }
@media (max-width: 440px) {
  .savebar { width: calc(100% - 24px); padding: 6px 6px 6px 14px; gap: 6px; }
  .savebar span { font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .savebar .row { gap: 6px; flex: none; }
  .savebar .btn { min-height: 40px; padding: 0 12px; font-size: 13px; }
}
