/* Кронштейн · диспетчерская. Основа: токены, типографика, оболочка, кнопки, поля, диалоги, уведомления. */
:root {
  --bg: #F1F0ED;
  --surface: #FFFFFF;
  --well: #E8E6E1;
  --sunken: #F6F5F2;
  --line: rgba(27, 26, 23, 0.10);
  --line-strong: rgba(27, 26, 23, 0.18);
  --text: #1B1A17;
  --text-2: #53504A;
  --text-3: #736F67;
  --accent: #2D4BC0;
  --accent-hover: #2440AA;
  --accent-soft: #E6EAF8;
  --accent-line: rgba(45, 75, 192, 0.45);
  --danger: #B3261E;
  --danger-soft: #FBEAE7;
  --ok: #2B7148;
  --src-site: #2D4BC0;
  --src-bot: #18756F;
  --src-call: #9A6210;
  --src-avito: #8A4A9C;
  --ink: #1F1E1B;

  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --font-display: "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, ui-monospace, "SF Mono", Menlo, monospace;

  --r-control: 8px;
  --r-card: 10px;
  --r-panel: 14px;
  --ease: cubic-bezier(0.2, 0, 0, 1);
  --fast: 0.12s;
  --mid: 0.2s;
  --shadow-card: 0 1px 0 rgba(27, 26, 23, 0.04), 0 1px 2px rgba(27, 26, 23, 0.06);
  --shadow-float: 0 12px 32px rgba(27, 26, 23, 0.16), 0 2px 6px rgba(27, 26, 23, 0.08);
  --top-h: 60px;
  --foot-h: 44px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 14px/20px var(--font);
  font-feature-settings: "kern" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { font-weight: 600; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num, kbd, time { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--mono); font-size: 12px; letter-spacing: 0; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.sprite { position: absolute; }
.icon {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 5px;
  font: 500 11px/1 var(--mono);
  color: var(--text-2);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
}

/* ---------- оболочка ---------- */
.app {
  display: grid;
  grid-template-rows: var(--top-h) minmax(0, 1fr) var(--foot-h);
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
}
.top {
  display: flex; align-items: center; gap: 20px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-width: 0;
}
.top__brand { display: flex; align-items: center; gap: 10px; flex: none; }
.mark {
  display: grid; place-items: center;
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--accent);
}
.mark svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand__name { font: 600 16px/20px var(--font-display); letter-spacing: -0.01em; }
.brand__desk { color: var(--text-3); padding-left: 10px; border-left: 1px solid var(--line-strong); }

.views { display: flex; gap: 2px; padding: 3px; background: var(--sunken); border: 1px solid var(--line); border-radius: 10px; flex: none; }
.views__tab {
  display: inline-flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 10px 0 12px;
  border: 0; border-radius: 7px; background: transparent; color: var(--text-2);
  font-weight: 500;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.views__tab:hover { color: var(--text); }
.views__tab[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 0 0 1px var(--line), var(--shadow-card); }
.views__tab kbd { height: 18px; min-width: 18px; font-size: 10px; border-bottom-width: 1px; color: var(--text-3); }

.top__search { flex: 1 1 280px; min-width: 0; max-width: 420px; }
.search {
  display: flex; align-items: center; gap: 8px;
  height: 36px; padding: 0 8px 0 12px;
  background: var(--sunken); border: 1px solid var(--line); border-radius: var(--r-control);
  color: var(--text-3);
  transition: border-color var(--fast) var(--ease), background-color var(--fast) var(--ease);
}
.search:focus-within { background: var(--surface); border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; color: var(--text); }
.search input::placeholder { color: var(--text-3); }
.search input::-webkit-search-cancel-button { cursor: pointer; }
.search:focus-within .search__kbd { display: none; }

.top__actions { display: flex; align-items: center; gap: 8px; margin-left: auto; flex: none; }

/* ---------- кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--r-control);
  font-weight: 500; white-space: nowrap;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--quiet { background: var(--surface); border-color: var(--line-strong); color: var(--text); }
.btn--quiet:hover { background: var(--sunken); }
.btn--ghost { background: transparent; color: var(--text-2); }
.btn--ghost:hover { background: var(--sunken); color: var(--text); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #9C2019; }
.btn--sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.kbd--on-accent { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.3); color: #fff; height: 18px; min-width: 18px; margin-right: -4px; border-bottom-width: 1px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; flex: none;
  border: 0; border-radius: var(--r-control); background: transparent; color: var(--text-2);
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.icon-btn:hover { background: var(--sunken); color: var(--text); }
.link-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 8px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-2); font-size: 13px;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.link-btn:hover:not(:disabled) { background: var(--well); color: var(--text); }
.link-btn:disabled { opacity: 0.45; cursor: default; }
.link-btn kbd { height: 18px; font-size: 10px; border-bottom-width: 1px; }

/* ---------- поля ---------- */
.select { position: relative; display: inline-flex; }
.select select, .field select {
  appearance: none; -webkit-appearance: none;
  height: 32px; padding: 0 30px 0 10px;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23736F67' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 8px center / 14px;
  border: 1px solid var(--line-strong); border-radius: var(--r-control);
  cursor: pointer;
}
.field { display: grid; gap: 6px; min-width: 0; }
.field__label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.field__label small { font-weight: 400; color: var(--text-3); font-size: 12px; }
.field input, .field textarea, .field select {
  width: 100%; height: 36px; padding: 0 10px;
  background-color: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-control);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.field select { padding-right: 30px; }
.field textarea { height: auto; min-height: 76px; padding: 8px 10px; resize: vertical; line-height: 20px; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 0; border-color: var(--accent-line); box-shadow: 0 0 0 3px var(--accent-soft); }
.field [aria-invalid="true"] { border-color: var(--danger); }
.field [aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.field__error { font-size: 12px; line-height: 16px; color: var(--danger); min-height: 16px; }

/* ---------- подвал ---------- */
.foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 16px 0 20px;
  border-top: 1px solid var(--line);
  color: var(--text-3); font-size: 12px;
  min-width: 0;
}
.foot__actions { display: flex; gap: 4px; flex: none; }

/* ---------- диалоги ---------- */
.dialog {
  width: min(600px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 0; border-radius: var(--r-panel);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-float);
}
.dialog--narrow { width: min(440px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(27, 26, 23, 0.32); }
.dialog[open] { animation: rise var(--mid) var(--ease); }
.dialog__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 16px 12px 24px; }
.dialog__title { font: 600 18px/24px var(--font-display); }
.dialog__body { padding: 4px 24px 8px; }
.dialog__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px 20px; border-top: 1px solid var(--line); margin-top: 8px; }
.dialog__text { color: var(--text-2); }

.keys { display: grid; gap: 0; margin: 0; }
.keys__row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.keys__row:last-child { border-bottom: 0; }
.keys dt { color: var(--text-2); }
.keys dd { margin: 0; display: flex; gap: 4px; flex: none; }

/* ---------- уведомления ---------- */
.toasts {
  position: fixed; left: 20px; bottom: calc(var(--foot-h) + 12px); z-index: 60;
  display: grid; gap: 8px; width: min(420px, calc(100vw - 32px));
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 10px 10px 14px; min-height: 44px;
  background: var(--ink); color: #F4F2EE; border-radius: var(--r-card);
  box-shadow: var(--shadow-float);
  pointer-events: auto;
  animation: rise var(--mid) var(--ease);
}
.toast__text { flex: 1; min-width: 0; }
.toast__text b { font-weight: 600; }
.toast__action {
  flex: none; height: 28px; padding: 0 10px; border: 0; border-radius: 6px;
  background: rgba(255, 255, 255, 0.1); color: #fff; font-weight: 500; font-size: 13px;
  transition: background-color var(--fast) var(--ease);
}
.toast__action:hover { background: rgba(255, 255, 255, 0.18); }
.toast__action:focus-visible { outline-color: #9FB0F0; }
.toast.is-leaving { opacity: 0; transform: translateY(4px); transition: opacity var(--mid) var(--ease), transform var(--mid) var(--ease); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; scroll-behavior: auto !important; }
}

/* ---------- узкие экраны ---------- */
@media (max-width: 1180px) {
  .brand__desk { display: none; }
  .views__tab kbd, .btn--primary kbd { display: none; }
}
@media (max-width: 980px) {
  #bot-btn .btn__label { display: none; }
  #bot-btn { width: 36px; padding: 0; }
}
@media (max-width: 719px) {
  :root { --top-h: 104px; --foot-h: auto; }
  .top { display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: 52px 44px; gap: 0 8px; padding: 0 12px 8px; }
  .top__brand { grid-column: 1; }
  .views { grid-column: 2; justify-self: center; }
  .views__tab { height: 28px; padding: 0 10px; }
  .top__actions { grid-column: 3; }
  .top__search { grid-column: 1 / -1; grid-row: 2; max-width: none; }
  .brand__name { display: none; }
  .btn--primary .btn__label { display: none; }
  .btn--primary { width: 36px; padding: 0; }
  .search__kbd { display: none; }
  .foot { flex-direction: column; align-items: flex-start; gap: 4px; padding: 8px 12px 12px; }
  .foot__actions { flex-wrap: wrap; margin-left: -8px; }
  .foot__actions kbd, #keys-btn { display: none; }
  .toasts { left: 12px; right: 12px; bottom: 12px; width: auto; }
  .dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; }
  .dialog--narrow { height: auto; margin: auto auto 0; border-radius: var(--r-panel) var(--r-panel) 0 0; }
  .dialog__head { padding: 12px 12px 8px 16px; }
  .dialog__body { padding: 4px 16px 8px; }
  .dialog__foot { padding: 12px 16px 16px; }
}
