/* СТО CRM — базовые стили. Крупные элементы для работы с телефона (в том числе в перчатках). */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #667085;
  --border: #d9dde3;
  --primary: #1f5fbf;
  --primary-dark: #174a96;
  --danger: #c2362b;
  --warning-bg: #fff4d6;
  --warning-text: #7a5400;
  --success-bg: #e3f5e9;
  --success-text: #17643a;
  --error-bg: #fde8e6;
  --radius: 10px;
  --tap: 48px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 16px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }

/* Полоса тестовой копии CRM, чтобы её нельзя было спутать с рабочей */
.instance-banner { background: #c62828; color: #fff; font-weight: 700; text-align: center; padding: 6px 8px; letter-spacing: .05em; }

/* Шапка и навигация */
.topbar {
  background: #1c2430;
  color: #fff;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 16px;
  padding: 8px 16px;
}
.topbar a { color: #fff; }
.brand { font-weight: 700; margin-right: 8px; }
.brand small { font-weight: 400; color: #b8c0cc; margin-left: 6px; }
.nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.nav a { padding: 10px 12px; border-radius: 8px; min-height: var(--tap); display: inline-flex; align-items: center; }
.nav a:hover, .nav a.active { background: rgba(255, 255, 255, 0.12); text-decoration: none; }
.userbox { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.userbox form { margin: 0; }
.link-button { background: none; border: 0; color: #fff; cursor: pointer; font: inherit; padding: 10px 8px; text-decoration: underline; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
main.wide { max-width: none; }

/* Карточки и сетка */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.spread { justify-content: space-between; }
.stat { font-size: 2rem; font-weight: 700; }

/* Кнопки */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--primary); }
.btn.secondary:hover { background: #eef3fb; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn.block { width: 100%; }
form.inline { display: inline; margin: 0; }

/* Формы */
.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; }
.field .help { color: var(--muted); font-size: 0.85rem; margin-top: 2px; }
.field.checkbox label { display: flex; align-items: center; gap: 10px; font-weight: 400; min-height: var(--tap); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search],
input[type=tel], input[type=date], input[type=time], input[type=datetime-local], input[type=url], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
}
textarea { min-height: 80px; }
input[type=checkbox], input[type=radio] { width: 22px; height: 22px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.errorlist { list-style: none; margin: 4px 0 0; padding: 0; color: var(--danger); font-size: 0.9rem; }
.form-grid { display: grid; gap: 0 16px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; margin: 0 0 16px; }
legend { font-weight: 700; padding: 0 6px; }
ul.checkbox-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }

/* Поиск */
.search-box input { font-size: 1.15rem; min-height: 56px; }

/* Таблицы */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
tr:hover td { background: #fafbfc; }

/* Метки и сообщения */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 0.8rem; background: #e8ecf2; }
.badge.ok { background: var(--success-bg); color: var(--success-text); }
.badge.warn { background: var(--warning-bg); color: var(--warning-text); }
.badge.err { background: var(--error-bg); color: var(--danger); }
.messages { list-style: none; padding: 0; margin: 0 0 16px; }
.messages li, .alert { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 8px; background: #e8f0fc; }
.messages .success, .alert.success { background: var(--success-bg); color: var(--success-text); }
.messages .warning, .alert.warning { background: var(--warning-bg); color: var(--warning-text); }
.messages .error, .alert.error { background: var(--error-bg); color: var(--danger); }

.list { list-style: none; padding: 0; margin: 0; }
.list > li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.timeline .when { color: var(--muted); font-size: 0.85rem; }
.changes { margin: 4px 0 0; padding-left: 18px; font-size: 0.9rem; color: var(--muted); }

.pagination { display: flex; gap: 8px; align-items: center; margin-top: 12px; }

.login-wrap { max-width: 420px; margin: 8vh auto; }
.password-box { font: 700 1.6rem/1.2 ui-monospace, monospace; letter-spacing: 2px; padding: 16px; background: #f0f3f8;
  border-radius: var(--radius); text-align: center; user-select: all; }

@media (max-width: 640px) {
  main { padding: 12px; }
  .hide-mobile { display: none; }
  .topbar { padding: 6px 8px; justify-content: space-between; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .nav a { padding: 8px 10px; white-space: nowrap; }
  h1 { font-size: 1.3rem; }
  /* Таблица результатов превращается в карточки */
  table.stack thead { display: none; }
  table.stack tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--border); }
  table.stack td { display: block; border: 0; padding: 2px 0; }
}

/* ---------- Этап 2: наряды ---------- */
.totals { margin-top: 16px; padding-top: 12px; border-top: 2px solid var(--border); display: flex; flex-wrap: wrap;
  gap: 6px 24px; justify-content: flex-end; }
.totals .grand { font-size: 1.2rem; }
.line-proposed td { background: #fffaf0; }
.line-rejected td { color: var(--muted); text-decoration: line-through; }
.line-rejected td .badge { text-decoration: none; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.attachments img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }
.attachments video { width: 200px; max-width: 100%; border-radius: 8px; }
.attachments audio { max-width: 100%; }
.catalog-picker { margin-bottom: 12px; }
.picker-results { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.picker-item { text-align: left; min-height: var(--tap); padding: 10px 12px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #f8fafc; font: inherit; cursor: pointer; }
.picker-item:hover, .picker-item:focus { background: #eef3fb; border-color: var(--primary); }
.feed .when { color: var(--muted); font-size: 0.85rem; }
.feed .feed-event { color: var(--muted); font-size: 0.92rem; }
.feed .feed-client { border-left: 3px solid #e0a100; padding-left: 10px; }
.feed .feed-instruction { border-left: 3px solid var(--primary); padding-left: 10px; }
.list .unread { font-weight: 600; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.scheme-wrap { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; }
.car-scheme { width: 220px; max-width: 100%; cursor: crosshair; touch-action: manipulation; }
[data-readonly] .car-scheme { cursor: default; }
.signature canvas { width: 100%; max-width: 520px; height: 180px; border: 2px dashed var(--border); border-radius: var(--radius);
  background: #fff; touch-action: none; display: block; margin-bottom: 8px; }
.signature-img { max-width: 260px; height: auto; border: 1px solid var(--border); border-radius: 8px; }
.diag { max-width: 640px; margin: 0 auto; }
.diag .btn.block { min-height: 56px; font-size: 1.05rem; }
fieldset[disabled] { opacity: 0.75; }

/* ---------- Этап 2б: процесс цеха ---------- */
.subcard { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; background: #fbfcfd; }
.subcard h3, #process h3 { font-size: 1rem; margin: 0 0 8px; }
.subcard details { margin-top: 8px; }
.subcard input, .subcard select, .subcard textarea { margin-top: 6px; }
.inline-details { display: inline-block; vertical-align: top; }
.inline-details[open] { display: block; margin-top: 6px; }
.inline-details form { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 1px solid var(--border);
  border-radius: var(--radius); background: #fff; min-width: 240px; }
.tasks .task { border-left: 4px solid transparent; padding-left: 10px; }
.tasks .task-urgent { border-left-color: #e0a100; }
.tasks .task-client_waiting { border-left-color: var(--danger); }
.tasks .task-overdue { background: var(--error-bg); }
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(170px, 1fr); gap: 12px; overflow-x: auto;
  padding-bottom: 8px; margin: 12px 0; }
.board-col { background: #e9edf2; border-radius: var(--radius); padding: 10px; min-height: 120px; }
.board-col h2 { font-size: 0.95rem; }
.board-card { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 8px; color: var(--text); }
.board-card:hover { text-decoration: none; border-color: var(--primary); }
.board-overdue { border: 2px solid var(--danger); }
.text-danger { color: var(--danger); font-weight: 600; }
.mech { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.mech-busy { background: #fffaf0; }
.mech-free { background: var(--success-bg); }

/* Простой экран задачи цеха (телефон) */
.simple-car .row { padding: 4px 0; }
.simple-car .plate { font-size: 1.2rem; letter-spacing: 1px; }
label.pick { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
label.pick input { width: 22px; height: 22px; margin-top: 2px; flex: none; }
.btn.big { min-height: 52px; font-size: 1.1rem; }

/* Запись клиентов: календарь по постам */
.sched-nav { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.sched-nav form { margin: 0; flex: 0 1 auto; min-width: 0; }
.sched-nav input[type=date] { width: 11em; max-width: 100%; min-width: 0; }
.sched-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 12px; }
.sched-strip a { flex: 0 0 auto; display: flex; flex-direction: column; align-items: center; padding: 6px 10px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); min-width: 78px; }
.sched-strip a:hover { text-decoration: none; border-color: var(--primary); }
.sched-strip a.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.sched-strip a.weekend:not(.on) span { color: var(--danger); }
.sched-strip span, .sched-strip small { font-size: 0.75rem; }
.sched-wrap { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 12px; align-items: start; }
.sched-queue { position: sticky; top: 8px; max-height: 80vh; overflow-y: auto; }
.sched-queue .list li { padding: 8px 0; }
.sched-scroll { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.sched-grid { display: grid; position: relative; min-width: max-content; }
.sched-head { position: sticky; top: 0; z-index: 3; background: var(--surface); border-bottom: 1px solid var(--border);
  border-left: 1px solid var(--border); padding: 6px 10px; display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.sched-time { grid-column: 1; font-size: 0.75rem; color: var(--muted); padding: 2px 6px; border-top: 1px solid var(--border); }
.sched-cell { border-left: 1px solid var(--border); border-top: 1px solid #eef0f3; display: flex; align-items: center;
  justify-content: center; color: transparent; }
a.sched-cell:hover { background: #eef4ff; color: var(--primary); text-decoration: none; }
.sched-card { z-index: 2; margin: 2px 4px; padding: 4px 8px; border-radius: 8px; background: #e8efff; border: 1px solid #b9cdf5;
  color: var(--text); display: flex; flex-direction: column; overflow: hidden; line-height: 1.25; gap: 1px; }
.sched-card:hover { text-decoration: none; border-color: var(--primary); }
.sched-card.reserve { background: repeating-linear-gradient(45deg, #eceef1, #eceef1 8px, #f5f6f8 8px, #f5f6f8 16px); border-color: var(--border); }
.sched-card.st-arrived { background: var(--success-bg); border-color: #9fd3b2; }
.sched-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 4; pointer-events: none; }
.pick-row { display: block; padding: 6px 0; }
@media (max-width: 800px) {
  .sched-wrap { grid-template-columns: 1fr; }
  .sched-queue { position: static; max-height: none; order: 2; }
}

/* Подсказки клиентов */
.suggest { position: absolute; left: 0; right: 0; top: 100%; z-index: 20; margin: 4px 0 0; padding: 4px 0; list-style: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(16, 24, 40, .12); max-height: 60vh; overflow-y: auto; }
.suggest li { padding: 0; }
.suggest li.muted { padding: 8px 12px; }
.suggest a { display: block; padding: 8px 12px; color: var(--text); }
.suggest a:hover, .suggest a:focus { background: #eef4ff; text-decoration: none; }

/* Строки журналов: открыть документ кликом по любой части строки */
table.rowlink tbody tr:has(td:first-child a[href]) { cursor: pointer; }
table.rowlink tbody tr:has(td:first-child a[href]):hover td { background: #eef3fb; }
.attachments.pick .pick-item { position: relative; display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; cursor: pointer; }
.attachments.pick .pick-item input { position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; }
.attachments.pick video { width: 120px; height: 84px; object-fit: cover; }
#client svg { display: block; shape-rendering: crispEdges; }  /* без масштабирования: ровные квадраты легко читаются камерой с экрана */
.call-popup { position: fixed; right: 16px; bottom: 16px; z-index: 50; width: 300px; max-width: calc(100vw - 32px); background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary); border-radius: var(--radius); box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 10px 12px; }
.call-popup .call-name { font-weight: 600; font-size: 1.05rem; margin: 2px 0; }
.call-popup .call-close { position: absolute; top: 4px; right: 6px; border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--muted); }
.call-popup form { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.linklike { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; text-decoration: underline; text-underline-offset: 2px; }

/* Наряд: кнопки блоков в шапке и сворачивание */
.section-nav { position: sticky; top: 0; z-index: 5; display: flex; gap: 6px; overflow-x: auto; white-space: nowrap;
  background: var(--bg); padding: 8px 0; margin: -8px 0 8px; }
.section-nav .btn { flex: none; }
[data-section] { scroll-margin-top: 64px; }
[data-section] > .section-head { cursor: pointer; user-select: none; }
[data-section] > .section-head::after { content: "▾"; color: var(--muted); margin-left: 8px; font-size: 0.9rem; }
[data-section] > .section-head.row::after { margin-left: 0; }
[data-section].collapsed > .section-head::after { content: "▸"; }
[data-section].collapsed { padding-top: 10px; padding-bottom: 10px; }
[data-section].collapsed > .section-head { margin-bottom: 0; }
[data-section].collapsed > :not(.section-head) { display: none; }
.add-panel { margin-top: 12px; }
details.subcard > summary { cursor: pointer; }
.grid > [data-section].collapsed { align-self: start; }
[data-section].collapsed > .section-head h2 { margin-bottom: 0; }
table tr.group-row td { background: var(--bg); }

/* Наряд: товары и работы — панель кнопок над таблицей, итоги, правка прямо в строке */
.line-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin-bottom: 8px; }
.lines-summary { display: flex; flex-wrap: wrap; gap: 4px 20px; }
.btn.pressed { background: var(--primary-dark); box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.25); }
table.lines th, table.lines td { padding: 6px 6px; vertical-align: top; }
table.lines td.num { width: 28px; text-align: right; }
table.lines td.cell-del { width: 28px; }
.icon-del { background: none; border: 0; color: var(--danger); font-size: 1rem; cursor: pointer; padding: 4px; }
.cell-input { width: 90px; min-height: 34px; padding: 4px 6px; font: inherit; border: 1px solid var(--border); border-radius: 6px; }
.cell-input.narrow { width: 70px; }
.cell-input:focus { outline: 2px solid var(--primary); }
.add-panel + .add-panel { margin-top: 8px; }
.line-toolbar + .add-panel, .add-panel { margin-bottom: 12px; }
.cell-input { text-align: right; -moz-appearance: textfield; appearance: textfield; }
.cell-input::-webkit-outer-spin-button, .cell-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cell-input.narrow { width: 64px; }
table.lines .cell-input { width: 90px; }
table.lines .cell-input.narrow { width: 72px; }
.print-menu { position: relative; }
.print-menu > summary { list-style: none; }
.print-menu > summary::-webkit-details-marker { display: none; }
.print-menu-list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 220px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12); padding: 6px; }
.print-menu-list a { display: block; padding: 10px 12px; border-radius: 6px; }
.print-menu-list a:hover { background: #eef3fb; text-decoration: none; }
.progress-summary { margin-bottom: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.progress-bar { height: 8px; background: #e7eaee; border-radius: 4px; overflow: hidden; margin: 6px 0 8px; }
.progress-bar span { display: block; height: 100%; background: #2e9d5b; }
.progress-lines { list-style: none; margin: 0 0 6px; padding: 0; }
.progress-lines li { padding: 2px 0; }
.progress-lines .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; background: #b8c0cc; }
.dot.st-done { background: #2e9d5b; } .dot.st-in_progress { background: var(--primary); }
.dot.st-waiting_parts, .dot.st-waiting_client { background: #e0a800; } .dot.st-not_done { background: var(--danger); }
