:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --border: #cbd5e1;
  --border-light: #e2e8f0;
  --text: #0f172a;
  --text-muted: #475569;
  --primary: #1d4ed8;
  --primary-hover: #1e40af;
  --primary-soft: #eff6ff;
  --brand-red: #b91c1c;

  /* Цвета цехов: оранжевый и тёмно-оранжевый разведены максимально контрастно */
  --orange-accent: #f97316;
  --orange-bg: #fff7ed;
  --orange-border: #fb923c;
  --orange-text: #9a3412;

  --yellow-accent: #eab308;
  --yellow-bg: #fefce8;
  --yellow-border: #facc15;
  --yellow-text: #854d0e;

  --dark-orange-accent: #7c2d12;
  --dark-orange-bg: #f5ebe6;
  --dark-orange-border: #7c2d12;
  --dark-orange-text: #ffffff;

  --green-accent: #15803d;
  --green-bg: #f0fdf4;
  --green-border: #4ade80;
  --green-text: #166534;

  /* Красный — только статус заказа «Изготовлен и выдан / отправлен» */
  --red-accent: #dc2626;
  --red-bg: #fef2f2;
  --red-border: #f87171;
  --red-text: #991b1b;

  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  font-size: 14px;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

.topbar {
  background: #111827;
  color: #f8fafc;
  border-bottom: 3px solid var(--brand-red);
  position: sticky;
  top: 0;
  z-index: 30;
}

.topbar-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--brand-red);
  color: #fff;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.03em;
}

.brand-title {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.brand-subtitle {
  font-size: 11px;
  color: #94a3b8;
}

.nav-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.nav-tab {
  border: 1px solid #374151;
  background: #1f2937;
  color: #e2e8f0;
  padding: 7px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.nav-tab:hover {
  background: #374151;
}

.nav-tab.active {
  background: #ffffff;
  color: #0f172a;
  border-color: #ffffff;
}

.nav-tab-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.nav-tab-primary:hover {
  background: var(--primary-hover);
}

.nav-tab-primary.active {
  background: #ffffff;
  color: var(--primary);
  border-color: #ffffff;
}

.user-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.user-pill {
  text-align: right;
  line-height: 1.25;
}

.user-pill-name {
  font-weight: 700;
  color: #f8fafc;
}

.user-pill-role {
  color: #cbd5e1;
  font-size: 11px;
}

.btn-logout {
  border: 1px solid #4b5563;
  background: transparent;
  color: #f8fafc;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 600;
  font-size: 12px;
}

.btn-logout:hover {
  background: #374151;
}

.page-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
}

.page-subtitle {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 13px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn:hover {
  background: var(--surface-muted);
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface-muted);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.muted {
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.info-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e3a8a;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 14px;
  font-size: 13px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.urgent-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #f59e0b;
}

.meta-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: #f1f5f9;
  color: #334155;
  border: 1px solid #e2e8f0;
}

/* Авторизация и быстрый вход */
.login-shell {
  max-width: 820px;
  margin: 24px auto;
}

.quick-login-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.quick-login-card {
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-muted);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.quick-login-card:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

/* Выпадающий список клиентов и авто */
.autocomplete-wrap {
  position: relative;
}

.dropdown-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 280px;
  overflow-y: auto;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.14);
  z-index: 25;
}

.dropdown-item {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  border-bottom: 1px solid var(--border-light);
  background: #ffffff;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.dropdown-item:hover {
  background: var(--primary-soft);
}

.dropdown-item:last-child {
  border-bottom: none;
}

.dropdown-action {
  background: #f8fafc;
  color: var(--primary);
  font-weight: 700;
}

.selected-client-box {
  margin-top: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.inline-subcard {
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
}

/* Бейджи цветов цехов */
.workshop-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1.5px solid transparent;
  white-space: nowrap;
}

.workshop-badge.color-orange {
  background: var(--orange-bg);
  border-color: var(--orange-border);
  color: var(--orange-text);
}

.workshop-badge.color-yellow {
  background: var(--yellow-bg);
  border-color: var(--yellow-border);
  color: var(--yellow-text);
}

.workshop-badge.color-dark_orange {
  background: var(--dark-orange-accent);
  border-color: #431407;
  color: var(--dark-orange-text);
  border-radius: 6px;
}

.workshop-badge.color-green {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: var(--green-text);
}

.color-swatch {
  width: 11px;
  height: 11px;
  display: inline-block;
  flex-shrink: 0;
}

.color-orange .color-swatch {
  border-radius: 999px;
  background: var(--orange-accent);
}

.color-yellow .color-swatch {
  border-radius: 999px;
  background: var(--yellow-accent);
}

.color-dark_orange .color-swatch {
  border-radius: 2px;
  background: #fed7aa;
  border: 1px solid #fff;
}

.color-green .color-swatch {
  border-radius: 2px;
  transform: rotate(45deg);
  width: 9px;
  height: 9px;
  background: var(--green-accent);
}

/* Кнопки выбора цвета цеха */
.color-picker-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.color-choice-btn {
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 2px solid var(--border-light);
  background: #ffffff;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.color-choice-btn:hover {
  border-color: #94a3b8;
}

.color-choice-dot {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 1px solid rgba(15, 23, 42, 0.2);
}

.color-choice-btn.choice-orange .color-choice-dot {
  border-radius: 999px;
  background: var(--orange-accent);
}

.color-choice-btn.choice-yellow .color-choice-dot {
  border-radius: 999px;
  background: var(--yellow-accent);
}

.color-choice-btn.choice-dark_orange .color-choice-dot {
  border-radius: 3px;
  background: var(--dark-orange-accent);
}

.color-choice-btn.choice-green .color-choice-dot {
  border-radius: 3px;
  background: var(--green-accent);
}

.color-choice-btn.selected.choice-orange {
  background: var(--orange-bg);
  border-color: var(--orange-accent);
  box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.22);
}

.color-choice-btn.selected.choice-yellow {
  background: var(--yellow-bg);
  border-color: var(--yellow-accent);
  box-shadow: 0 0 0 2px rgba(234, 179, 8, 0.25);
}

.color-choice-btn.selected.choice-dark_orange {
  background: var(--dark-orange-accent);
  border-color: #431407;
  color: #ffffff;
  box-shadow: 0 0 0 2px rgba(124, 45, 18, 0.35);
}

.color-choice-btn.selected.choice-dark_orange .choice-sub {
  color: #ffedd5;
}

.color-choice-btn.selected.choice-green {
  background: var(--green-bg);
  border-color: var(--green-accent);
  box-shadow: 0 0 0 2px rgba(21, 128, 61, 0.22);
}

.choice-title {
  font-weight: 700;
  font-size: 13px;
  display: block;
}

.choice-sub {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
}

/* Подсказки из истории и типовые детали */
.suggestions-box {
  margin-top: 8px;
  padding: 9px 11px;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
}

.suggestions-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-btn {
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: var(--text);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.chip-btn:hover {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.chip-btn.chip-combo {
  border-color: #93c5fd;
  background: #eff6ff;
}

/* Позиции в форме и списке заказов */
.position-card {
  border: 1px solid var(--border);
  border-left: 5px solid #94a3b8;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  background: #ffffff;
}

.position-card.pos-color-orange {
  border-left-color: var(--orange-accent);
}

.position-card.pos-color-yellow {
  border-left-color: var(--yellow-accent);
}

.position-card.pos-color-dark_orange {
  border-left-color: var(--dark-orange-accent);
  background: #fdf9f7;
}

.position-card.pos-color-green {
  border-left-color: var(--green-accent);
}

.position-card-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

/* Статус заказа и карточки заказов */
.order-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-left: 5px solid #64748b;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 12px;
}

.order-card.order-red {
  border-left-color: var(--red-accent);
  background: #fffafa;
}

.order-card.order-highlight {
  box-shadow: 0 0 0 3px rgba(29, 78, 216, 0.25);
}

.order-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.order-number {
  font-size: 16px;
  font-weight: 800;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #e2e8f0;
  color: #1e293b;
}

.status-badge.status-accepted {
  background: #e0f2fe;
  color: #075985;
}

.status-badge.status-in_production {
  background: #ede9fe;
  color: #5b21b6;
}

.status-badge.status-ready {
  background: #dcfce7;
  color: #166534;
}

.status-badge.status-completed {
  background: var(--red-bg);
  color: var(--red-text);
  border: 1.5px solid var(--red-border);
}

.status-red-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--red-accent);
  display: inline-block;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: top;
}

.data-table th {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  background: var(--surface-muted);
}

.diff-box {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

.diff-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.diff-before {
  text-decoration: line-through;
  color: #991b1b;
  background: #fef2f2;
  padding: 1px 6px;
  border-radius: 4px;
}

.diff-after {
  color: #166534;
  background: #f0fdf4;
  padding: 1px 6px;
  border-radius: 4px;
  font-weight: 600;
}

.event-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
}

.event-badge.event-created {
  background: #dbeafe;
  color: #1e40af;
}

.event-badge.event-updated {
  background: #fef3c7;
  color: #92400e;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: 10px;
  padding: 12px 14px;
}

.stat-value {
  font-size: 22px;
  font-weight: 800;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* Права доступа */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 6px;
}

.perm-check-label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border-light);
  background: var(--surface-muted);
  cursor: pointer;
  font-size: 12.5px;
}

.perm-badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.perm-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #bfdbfe;
}

.perm-badge.perm-admin {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

/* Готовность позиций, долги и план MAX */
.pos-status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}

.pos-status-queued {
  background: #f1f5f9;
  color: #334155;
}

.pos-status-in_work {
  background: #fef3c7;
  color: #92400e;
}

.pos-status-done {
  background: #dcfce7;
  color: #166534;
}

.debt-value {
  color: #b91c1c;
  font-weight: 800;
}

.paid-value {
  color: #15803d;
  font-weight: 700;
}

.max-message-card {
  border: 1px solid var(--border);
  border-left: 5px solid #64748b;
  border-radius: 10px;
  padding: 14px;
  background: #ffffff;
}

.max-message-card.pos-color-orange {
  border-left-color: var(--orange-accent);
}

.max-message-card.pos-color-yellow {
  border-left-color: var(--yellow-accent);
}

.max-message-card.pos-color-dark_orange {
  border-left-color: var(--dark-orange-accent);
}

.max-message-card.pos-color-green {
  border-left-color: var(--green-accent);
}

.max-preview-pre {
  margin: 10px 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #0f172a;
  color: #f8fafc;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  line-height: 1.45;
}

/* Крайние сроки (дедлайны) и напоминания */
.deadline-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #334155;
}

.deadline-badge.deadline-overdue {
  background: #fef2f2;
  border-color: #ef4444;
  color: #991b1b;
}

.deadline-badge.deadline-today {
  background: #fff7ed;
  border-color: #f97316;
  color: #9a3412;
}

.deadline-badge.deadline-tomorrow,
.deadline-badge.deadline-soon {
  background: #fefce8;
  border-color: #eab308;
  color: #854d0e;
}

.deadline-badge.deadline-ok {
  background: #f0fdf4;
  border-color: #86efac;
  color: #166534;
}

.reminders-panel {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-left: 5px solid #f59e0b;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
}

.reminders-panel.has-overdue {
  background: #fef2f2;
  border-color: #fca5a5;
  border-left-color: #dc2626;
}

.reminder-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #ffffff;
  border: 1px solid #e2e8f0;
  margin-top: 8px;
}

.bell-btn {
  border: 1px solid #4b5563;
  background: #1f2937;
  color: #f8fafc;
  padding: 6px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-weight: 700;
  font-size: 12px;
}

.bell-btn.bell-alert {
  background: #b91c1c;
  border-color: #f87171;
  color: #ffffff;
}

.bell-btn.bell-warn {
  background: #b45309;
  border-color: #fbbf24;
  color: #ffffff;
}

/* Модальное окно и уведомления */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-panel {
  width: 100%;
  max-width: 720px;
  max-height: 92vh;
  overflow-y: auto;
  background: #ffffff;
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}

.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.25);
  max-width: 380px;
  font-size: 13px;
}

.toast.toast-error {
  background: #b91c1c;
}

.toast.toast-success {
  background: #15803d;
}

@media (max-width: 860px) {
  .grid-2,
  .grid-3,
  .grid-4,
  .stats-grid,
  .color-picker-grid,
  .perm-grid {
    grid-template-columns: 1fr;
  }
}
