/* CRM сервисного центра — стили приложения */
/* Тёмная тема (по умолчанию) и светлая — переключение классом body.theme-light */
:root {
  --radius: 10px;
  /* тёмная тема */
  --bg: #0f1216;
  --bg-soft: #161b22;
  --bg-elev: #1b2735;
  --panel: #1c232c;
  --panel-2: #222b36;
  --border: #2e3947;
  --text: #e8edf2;
  --muted: #93a1b0;
  --accent: #3f8cff;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(63, 140, 255, 0.14);
  --green: #2fbf71;
  --amber: #f0a03c;
  --red: #e5484d;
  --shadow: 0 8px 28px rgba(0,0,0,.35);
  --kbd: rgba(255,255,255,.06);
}
body.theme-light {
  --bg: #f2f5f8;
  --bg-soft: #e9edf2;
  --bg-elev: #dbe4ee;
  --panel: #ffffff;
  --panel-2: #f0f3f7;
  --border: #d3dbe4;
  --text: #1a2430;
  --muted: #5b6b7c;
  --accent: #2563c9;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(37, 99, 201, 0.12);
  --green: #1a9e5a;
  --amber: #c07818;
  --red: #d13438;
  --shadow: 0 8px 24px rgba(30, 40, 60,.14);
  --kbd: rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
/* Глобальное правило: атрибут hidden всегда прячет элемент,
   даже если авторские стили задают display: flex/grid/block */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  transition: background .25s, color .25s;
}
button, input, select, textarea { font: inherit; color: var(--text); }
a { color: var(--accent); }
::placeholder { color: var(--muted); opacity: .7; }
select option { background: var(--panel); color: var(--text); }

/* ---------- Тумблер темы ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 8px; cursor: pointer;
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 8px; user-select: none; flex-shrink: 0;
}
.theme-toggle input { display: none; }
.theme-toggle .tt-track {
  width: 40px; height: 22px; border-radius: 999px; background: var(--kbd);
  border: 1px solid var(--border); position: relative; transition: background .25s;
  flex-shrink: 0;
}
.theme-toggle .tt-track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
  border-radius: 50%; background: var(--muted); transition: left .25s, background .25s;
}
.theme-toggle input:checked + .tt-track { background: var(--accent-soft); }
.theme-toggle input:checked + .tt-track::after { left: 20px; background: var(--accent); }
.theme-toggle .tt-icon { font-size: 13px; line-height: 1; }
.theme-toggle .tt-label { font-size: 12px; color: var(--muted); }
/* Тумблер и на экране логина */
.login-theme { position: absolute; top: 16px; right: 16px; }

/* ---------- Логин ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 70% -10%, var(--bg-elev) 0%, var(--bg) 60%);
  padding: 20px;
}
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; box-shadow: var(--shadow);
}
.login-logo {
  font-weight: 800; letter-spacing: 2px; font-size: 13px; color: var(--accent);
  background: var(--accent-soft); display: inline-block; padding: 4px 10px; border-radius: 999px;
}
.login-card h1 { font-size: 22px; margin: 14px 0 4px; }
.login-sub { color: var(--muted); font-size: 12px; margin: 0 0 18px; }
.login-card label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
.login-card input {
  display: block; width: 100%; margin-top: 4px; padding: 10px 12px;
  background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
}
.login-card input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.login-error { color: var(--red); font-size: 13px; }
.login-hint { color: var(--muted); font-size: 11px; margin-top: 14px; }

/* ---------- Каркас ---------- */
.shell { display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
  display: flex; align-items: center; gap: 18px; padding: 0 18px; height: 54px;
  background: var(--bg-soft); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-brand { font-weight: 800; cursor: pointer; letter-spacing: 1px; color: var(--accent); }
.topbar-nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topbar-nav a {
  color: var(--muted); text-decoration: none; padding: 7px 12px; border-radius: 8px;
  white-space: nowrap; cursor: pointer;
}
.topbar-nav a.active { color: var(--text); background: var(--panel-2); }
.topbar-nav a:hover { color: var(--text); }
.topbar-user { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; }
.view { flex: 1; padding: 20px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- Кнопки ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  border-radius: 8px; padding: 8px 14px; cursor: pointer; transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Формы ---------- */
label.field { display: block; margin-bottom: 12px; color: var(--muted); font-size: 12px; }
label.field input, label.field select, label.field textarea {
  display: block; width: 100%; margin-top: 4px; padding: 9px 12px;
  background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
}
label.field textarea { min-height: 90px; resize: vertical; }
label.field input:focus, label.field select:focus, label.field textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.form-error { color: var(--red); margin: 8px 0; }

/* ---------- Таблица ---------- */
.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
table.orders { width: 100%; border-collapse: collapse; font-size: 13px; }
table.orders th, table.orders td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.orders th { color: var(--muted); font-weight: 600; font-size: 12px; position: sticky; top: 0; background: var(--panel); }
table.orders tr:hover td { background: var(--panel-2); }
table.orders tr.clickable { cursor: pointer; }
tr.overdue td { background: rgba(229, 72, 77, .08); }
.num-cell { font-family: ui-monospace, Consolas, monospace; font-weight: 600; color: var(--accent); white-space: nowrap; }

/* ---------- Бейджи статусов (адаптированы под тему) ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px;
  font-weight: 600; white-space: nowrap;
}
.badge-new { background: rgba(63,140,255,.15); color: var(--accent); }
.badge-packed { background: rgba(63,140,255,.22); color: var(--accent); }
.badge-sent { background: rgba(143,108,255,.15); color: #8f6cff; }
body.theme-light .badge-sent { color: #6a4fd0; }
.badge-received { background: rgba(240,160,60,.15); color: var(--amber); }
.badge-in_work { background: rgba(240,160,60,.22); color: var(--amber); }
.badge-ready { background: rgba(47,191,113,.15); color: var(--green); }
.badge-done { background: rgba(47,191,113,.22); color: var(--green); }
.badge-rejected, .badge-not_repairable { background: rgba(229,72,77,.15); color: var(--red); }
.badge-waiting_parts { background: rgba(229,72,77,.12); color: var(--red); }
.overdue-mark { color: var(--red); font-weight: 700; }
.overdue-mark { color: var(--red); font-weight: 700; }

/* ---------- Канбан ---------- */
/* Все 7 колонок всегда видны без горизонтальной прокрутки */
.kanban {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  padding-bottom: 8px;
  align-items: start;
  min-width: 0;
}
.kanban-col { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); min-height: 120px; min-width: 0; overflow: hidden; }
.kanban-col.dragover { border-color: var(--accent); }
.kanban-col-head { padding: 8px 6px; border-bottom: 1px solid var(--border); font-weight: 600; font-size: 11.5px; text-align: center; }
.kanban-col-head .hint { font-weight: 400; margin-left: 10px; display: inline-block; padding: 0 4px; }
.kanban-cards { padding: 6px; display: flex; flex-direction: column; gap: 6px; min-height: 40px; }
.kcard {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 8px;
  cursor: grab; transition: border-color .15s; overflow-wrap: anywhere;
}
.kcard:hover { border-color: var(--accent); }
.kcard.dragging { opacity: .45; }
.kcard .num { font-family: ui-monospace, Consolas, monospace; font-weight: 700; color: var(--accent); font-size: 11.5px; }
.kcard .client { font-weight: 600; margin: 3px 0; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcard .model { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kcard .branch { color: var(--muted); font-size: 10.5px; margin-top: 4px; }
/* Восклицательный знак при непрочитанных в карточке канбана */
.kcard .unread-mark { color: var(--red); font-weight: 800; margin-left: 4px; }
/* На очень узких экранах колонки сжимаются до минимума — карточки остаются читаемыми */
@media (max-width: 1100px) {
  .kanban { gap: 5px; }
  .kanban-col-head { font-size: 10px; padding: 6px 3px; }
  .kanban-col-head .hint { margin-left: 6px; }
  .kcard { padding: 6px; }
  .kcard .num { font-size: 10px; }
}

/* ---------- Фильтры ---------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center;
}
.filters select, .filters input {
  background: var(--bg-soft); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px;
}
.filters input[type="search"] { min-width: 220px; flex: 1; }

/* ---------- Модалка ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(5,8,12,.72); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 24px; overflow-y: auto;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  width: min(980px, 100%); box-shadow: var(--shadow); padding: 22px; margin: auto 0;
  max-width: 100%; min-width: 0; box-sizing: border-box;
  overflow-wrap: anywhere;
}
.modal h2 { margin-top: 0; font-size: 18px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 10px; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 22px; cursor: pointer; flex-shrink: 0; }

/* ---------- Чат ---------- */
.chat { display: flex; flex-direction: column; background: var(--bg-soft); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; min-width: 0; }
.chat-scroll { padding: 14px; overflow-y: auto; max-height: 420px; min-height: 180px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 78%; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; min-width: 0; }
.msg.mine { align-self: flex-end; background: var(--accent-soft); border-color: rgba(63,140,255,.4); }
.msg.system { align-self: center; background: transparent; border: 1px dashed var(--border); color: var(--muted); font-size: 12px; max-width: 100%; text-align: center; }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 3px; }
.msg .body { white-space: pre-wrap; word-break: break-word; }
.msg img { max-width: 100%; border-radius: 6px; margin-top: 6px; display: block; }
.msg video { max-width: 100%; border-radius: 6px; margin-top: 6px; display: block; }
.chat-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); min-width: 0; }
.chat-input textarea { flex: 1; min-width: 0; resize: none; height: 60px; resize: vertical; }
.chat-input input[type="file"] { display: none; }
.chat-attach-btn { position: relative; }

/* ---------- Мессенджер (вкладка «Чаты») ---------- */
.messenger { display: grid; grid-template-columns: 320px 1fr; gap: 12px; height: calc(100vh - 120px); min-height: 420px; }
.msg-list {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
}
.msg-list-head { padding: 10px 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.msg-list-head input[type="search"] {
  background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.msg-list-head label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; cursor: pointer; }
.msg-list-scroll { flex: 1; overflow-y: auto; }
.dialog {
  padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 10px; align-items: center;
  transition: background .12s;
}
.dialog:hover { background: var(--panel-2); }
.dialog.active { background: var(--accent-soft); }
.dialog .avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 13px; color: var(--accent);
  flex-shrink: 0; overflow: hidden;
}
.dialog .avatar img { width: 100%; height: 100%; object-fit: cover; }
.dialog .d-body { flex: 1; min-width: 0; }
.dialog .d-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.dialog .d-num { font-family: ui-monospace, Consolas, monospace; font-weight: 700; font-size: 12px; color: var(--accent); }
.dialog .d-time { color: var(--muted); font-size: 10.5px; white-space: nowrap; }
.dialog .d-name { font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog .d-last { color: var(--muted); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dialog .d-last.system-row { font-style: italic; }
.dialog .d-badge { background: var(--red); color: #fff; border-radius: 999px; font-size: 10.5px; font-weight: 700; padding: 1px 7px; flex-shrink: 0; }
.msg-pane {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
}
.msg-pane-head {
  padding: 10px 14px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px;
  background: var(--bg-soft);
}
.msg-pane-head .mp-title { font-weight: 700; font-family: ui-monospace, Consolas, monospace; color: var(--accent); }
.msg-pane-head .mp-sub { color: var(--muted); font-size: 12px; }
.msg-pane-scroll { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; background: var(--bg-soft); }
.msg-pane-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 14px; }
.msg-pane-input { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); background: var(--panel); }
.msg-pane-input textarea { flex: 1; resize: none; height: 64px; background: var(--bg-soft); color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.msg-pane-input input[type="file"] { display: none; }
@media (max-width: 900px) {
  .messenger { grid-template-columns: 1fr; height: auto; }
  .msg-list { max-height: 260px; }
  .msg-pane { height: 60vh; }
}

/* ---------- История статусов ---------- */
.timeline { list-style: none; padding-left: 18px; border-left: 2px solid var(--border); margin: 0; min-width: 0; }
.timeline li { position: relative; padding: 4px 0 10px 14px; overflow-wrap: anywhere; }
.timeline li::before {
  content: ''; position: absolute; left: -24px; top: 10px; width: 10px; height: 10px;
  background: var(--accent); border-radius: 50%; border: 2px solid var(--bg);
}
.timeline .tl-title { font-weight: 600; }
.timeline .tl-meta { color: var(--muted); font-size: 12px; }
.timeline .tl-comment { color: var(--text); font-size: 13px; background: var(--panel-2); padding: 4px 8px; border-radius: 6px; display: inline-block; margin-top: 2px; max-width: 100%; box-sizing: border-box; }
/* Свёрнутая история: показываем только последний статус (первый в обратном порядке) */
.timeline.timeline-collapsed li:not(:first-child) { display: none; }
.timeline.timeline-collapsed { padding-bottom: 2px; }
.hist-toggle {
  display: flex; justify-content: space-between; align-items: center; cursor: pointer;
  padding: 10px 12px; margin: -16px -16px 12px; background: var(--panel-2);
  border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0;
  user-select: none;
}
.hist-toggle:hover { background: var(--accent-soft); }
.hist-toggle-title { font-weight: 700; font-size: 13px; }
.hist-last { color: var(--muted); font-weight: 400; font-size: 12px; }
.hist-toggle-arrow { color: var(--muted); font-size: 15px; transition: transform .2s; }

/* ---------- Карточка заявки: читаемая структура ---------- */
/* Грид сжимается до содержимого: без min-width:0 колонки распирают модалку и чат/история вылезают за края */
.order-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; min-width: 0; }
.order-layout > div { min-width: 0; overflow-wrap: anywhere; }
.order-layout .card { min-width: 0; }
.order-layout table, .order-layout .chat, .order-layout .timeline { max-width: 100%; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 18px 0 10px; font-size: 12.5px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: .6px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.card h3:first-child { margin-top: 0; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
/* Строки деталей — отделены друг от друга */
.kv-separated { gap: 0 12px; }
.kv-separated dt, .kv-separated dd {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.kv-separated dt { border-bottom-color: transparent; }
.kv-separated .kv-row-last dt, .kv-separated .kv-row-last dd { border-bottom: none; }
.order-number-big { font-family: ui-monospace, Consolas, monospace; font-size: 22px; font-weight: 800; color: var(--accent); }

/* Клиент — крупный блок с телефоном */
.client-brief { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.client-brief-name { font-size: 17px; font-weight: 700; }
.client-brief-phone { font-size: 15px; font-weight: 600; color: var(--accent); text-decoration: none; white-space: nowrap; }
.client-brief-phone:hover { text-decoration: underline; }

/* Товар — крупное название + чипы атрибутов */
.model-brief { display: flex; flex-direction: column; gap: 8px; }
.model-brief-name { font-size: 15px; font-weight: 700; line-height: 1.4; }
.model-brief .chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  background: var(--panel-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 2px 10px; font-size: 11.5px; color: var(--muted); white-space: nowrap;
}

/* Описание проблемы — выделенная плашка */
.problem-box {
  background: var(--accent-soft); border-left: 3px solid var(--accent); border-radius: 8px;
  padding: 10px 14px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
}

/* Результат работ с ТСД — зелёная плашка */
.result-box {
  background: rgba(47, 191, 113, .1); border-left: 3px solid var(--green); border-radius: 8px;
  padding: 10px 14px; font-size: 13.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word;
  margin-bottom: 10px;
}
.result-box .rb-title {
  font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--green); margin-bottom: 4px;
}

/* ---------- Дашборд ---------- */
.dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.stat .v { font-size: 26px; font-weight: 800; }
.stat .l { color: var(--muted); font-size: 12px; }
.stat.warn .v { color: var(--red); }
.stat.ok .v { color: var(--green); }
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 220px 1fr 40px; align-items: center; gap: 10px; font-size: 13px; }
.bar-track { background: var(--bg-soft); border-radius: 6px; height: 12px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 6px; }

/* ---------- Автокомплит ---------- */
.autocomplete { position: relative; }
.ac-list {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 30; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; max-height: 220px; overflow-y: auto;
}
.ac-item { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 13px; }
.ac-item:hover, .ac-item.active { background: var(--accent-soft); }
.ac-item .sku { color: var(--muted); font-size: 11px; }

/* ---------- Дропзона ---------- */
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px;
  text-align: center; color: var(--muted); cursor: pointer; transition: border-color .15s;
}
.dropzone.dragover { border-color: var(--accent); color: var(--text); }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.attach-chip { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.attach-chip button { background: none; border: none; color: var(--muted); cursor: pointer; }

/* ---------- Тосты ---------- */
.toast-wrap { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--green);
  border-radius: 8px; padding: 10px 16px; box-shadow: var(--shadow); animation: slide-in .2s ease;
}
.toast.error { border-left-color: var(--red); }
@keyframes slide-in { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Клиентский автопоиск ---------- */
.client-hint {
  background: var(--accent-soft); border: 1px solid rgba(63,140,255,.35); border-radius: 8px;
  padding: 10px 12px; font-size: 13px; margin-bottom: 12px;
}
.client-hint .hist { color: var(--muted); font-size: 12px; margin-top: 4px; }

.unread-badge {
  background: var(--red); color: #fff; border-radius: 999px; font-size: 11px;
  font-weight: 700; padding: 1px 7px; margin-left: 6px; display: inline-block;
}
.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.page-head h1 { font-size: 20px; margin: 0; }
.hint { color: var(--muted); font-size: 12px; }

/* ---------- Тач-меню канбана (П26) ---------- */
.touch-menu {
  position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); min-width: 220px; padding: 6px;
}
.touch-menu-title { font-size: 12px; color: var(--muted); padding: 6px 10px 8px; font-family: ui-monospace, Consolas, monospace; }
.touch-menu-item {
  display: block; width: 100%; text-align: left; background: transparent; color: var(--text);
  border: none; border-radius: 8px; padding: 11px 10px; font-size: 14px; cursor: pointer;
}
.touch-menu-item:active { background: var(--accent-soft); }

/* ---------- Скелетоны загрузки (№1) ---------- */
.skeleton {
  height: 13px; border-radius: 6px; margin: 3px 0;
  background: var(--kbd);
  background-image: linear-gradient(90deg, transparent 0%, rgba(128,128,128,.14) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}
.skel-circle {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--kbd);
  background-image: linear-gradient(90deg, transparent 0%, rgba(128,128,128,.14) 50%, transparent 100%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease infinite;
}
@keyframes skeleton-shimmer {
  0% { background-position: 150% 0; }
  100% { background-position: -50% 0; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton, .skel-circle { animation: none; }
}

/* ---------- Печать: только документ ---------- */
.print-root { display: none; }
@media print {
  body.printing .shell, body.printing .modal-overlay, body.printing .toast-wrap, body.printing .login-screen { display: none !important; }
  body.printing .print-root { display: block; }
  body.printing { background: #fff; color: #000; }
}

/* ---------- Адаптив ---------- */
@media (max-width: 900px) {
  .order-layout { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .view { padding: 10px; }
  .topbar { padding: 0 10px; gap: 8px; }
  .msg { max-width: 92%; }
}

/* ---------- Мобильные карточки заявок (вместо таблицы) ---------- */
.mobile-only { display: none; }
@media (max-width: 720px) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
  .orders-cards { display: flex; flex-direction: column; gap: 8px; }
  .order-card {
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    padding: 12px 14px; cursor: pointer; transition: border-color .15s;
  }
  .order-card:active { border-color: var(--accent); background: var(--panel-2); }
  .order-card.overdue { border-left: 3px solid var(--red); }
  .oc-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
  .oc-top .num-cell { font-size: 12px; }
  .oc-client { font-weight: 600; font-size: 14px; margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .oc-model { color: var(--muted); font-size: 12.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .oc-bottom { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; font-size: 11.5px; }
}

/* ---------- Мобильная версия (телефоны) ---------- */
@media (max-width: 720px) {
  /* Топбар: бренд и юзер в один ряд, навигация — вторым рядом с прокруткой */
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 8px 10px 0;
    gap: 6px;
    row-gap: 0;
  }
  .topbar-brand { order: 1; font-size: 13px; }
  .topbar-user { order: 2; margin-left: auto; gap: 7px; font-size: 12px; }
  .topbar-user #whoami { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-nav {
    order: 3;
    width: 100%;
    padding-bottom: 7px;
    margin-bottom: -1px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .topbar-nav::-webkit-scrollbar { display: none; }
  .topbar-nav a { padding: 7px 10px; font-size: 13px; }
  .theme-toggle { transform: scale(.85); }

  /* Заголовки страниц */
  .page-head h1 { font-size: 17px; }
  .page-head .btn { width: 100%; }
  .page-head { flex-direction: column; align-items: stretch; }

  /* Таблица заявок: крупнее и плотнее */
  .view { padding: 8px; }
  table.orders { font-size: 12.5px; }
  table.orders th, table.orders td { padding: 8px 8px; }
  .table-wrap { border-radius: 10px; }

  /* Фильтры: вертикально, по всей ширине */
  .filters { gap: 6px; }
  .filters select, .filters input { width: 100%; min-width: 0; flex-basis: 100%; padding: 9px 10px; font-size: 14px; }
  .filters input[type="search"] { min-width: 0; }

  /* Карточка заявки: kv-таблица в столбик (не 150px сбоку — на телефоне это смещало строки) */
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv dt { font-size: 11px; text-transform: uppercase; letter-spacing: .3px; margin-top: 6px; }
  .kv dd { font-size: 13.5px; }
  .kv-separated dt, .kv-separated dd { padding: 3px 0; }
  .kv-separated dd { border-bottom: 1px solid var(--border); }

  .order-number-big { font-size: 17px; }
  .client-brief { flex-direction: column; align-items: flex-start; gap: 4px; }
  .client-brief-name { font-size: 15.5px; }
  .model-brief-name { font-size: 14px; }

  /* Модалки: почти на весь экран */
  .modal-overlay { padding: 8px; }
  .modal { width: 100%; padding: 14px; border-radius: 12px; }
  .modal h2 { font-size: 16px; }

  /* Чат внутри карточки */
  .chat-input { flex-wrap: wrap; }
  .chat-input textarea { width: 100%; flex-basis: 100%; height: 56px; }
  .chat-input .btn { flex: 1; }

  /* Мессенджер: компактный список диалогов */
  .messenger { grid-template-columns: 1fr; height: auto; min-height: 0; gap: 8px; }
  .msg-list { max-height: 45vh; }
  .msg-pane { height: 58vh; min-height: 320px; }
  .msg-pane-input { align-items: flex-end; }
  .msg-pane-input textarea { height: 56px; font-size: 14px; }
  .dialog { padding: 8px 10px; }
  .dialog .avatar { width: 36px; height: 36px; font-size: 12px; }
  .dialog .d-name { font-size: 12px; }
  .dialog .d-last { font-size: 11px; }

  /* Таблица пользователей: кнопки в столбик */
  table.orders td:last-child { white-space: normal; }
  table.orders td:last-child .btn { margin: 2px 4px 2px 0; display: inline-block; }

  /* Дашборд */
  .dash-stats { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat .v { font-size: 20px; }
  .stat { padding: 10px; }
  .bar-row { grid-template-columns: 1fr; gap: 2px; }
  .bar-row .bar-count { order: -1; }

  /* Форма заявки */
  label.field input, label.field select, label.field textarea { font-size: 15px; padding: 10px 12px; }
  .dropzone { padding: 12px; font-size: 12.5px; }

  /* Тосты — сверху, чтобы не мешали пальцам */
  .toast-wrap { top: 60px; right: 8px; bottom: auto; left: 8px; }
  .toast { font-size: 13px; padding: 9px 12px; }

  /* Тач-меню канбана — не шире экрана */
  .touch-menu { left: 8px !important; right: 8px; min-width: 0; max-width: calc(100vw - 16px); }

  /* Канбан: на телефоне 7 колонок в ряд нечитаемы — 2 ряда по вертикали прокруткой */
  .kanban {
    grid-template-columns: repeat(7, minmax(150px, 1fr));
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .kanban-col { min-width: 150px; }
  .kanban-col-head { font-size: 11px; padding: 7px 5px; }

  /* Логин */
  .login-screen { padding: 16px; }
  .login-card { padding: 20px 16px; }
  .login-card h1 { font-size: 19px; }
  .login-sub { font-size: 11.5px; }
  .login-hint { display: none; }
  .login-theme { top: 10px; right: 10px; }
}

/* Очень узкие экраны */
@media (max-width: 400px) {
  .dash-stats { grid-template-columns: 1fr; }
  .topbar-user #whoami { max-width: 90px; }
  .topbar-user .btn-sm { padding: 4px 8px; font-size: 12px; }
}
