/* ==========================================================================
   Малярный цех — оформление
   Базовые классы берутся из styles.css, здесь — современная тема.
   ========================================================================== */

:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --blue-soft: #eff6ff;
  --green: #16a34a;
  --green-soft: #ecfdf5;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --grey: #64748b;
  --ink: #0f172a;
  --ink-soft: #64748b;
  --bg: #f5f7fb;
  --card: #ffffff;
  --border: #cbd5e1;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --field: #ffffff;
  --border-soft: #e2e8f0;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, .06);
  --shadow-md: 0 8px 28px rgba(15, 23, 42, .08);
}


/* ---------- Тёмная тема --------------------------------------------------- */

[data-theme="dark"] {
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --blue-soft: #16263f;
  --green: #34d399;
  --green-soft: #10291c;
  --red: #f87171;
  --red-soft: #2b1618;
  --amber: #fbbf24;
  --amber-soft: #2a2110;
  --grey: #8b9ab3;
  --ink: #e8eefb;
  --ink-soft: #9aabc4;
  --bg: #0b1220;
  --card: #121c2e;
  --surface: #121c2e;
  --surface-2: #18233a;
  --surface-3: #223049;
  --field: #1a2438;
  --border: #26344c;
  --border-soft: #1e2a40;
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, .5);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, .45);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, .55);
}

[data-theme="dark"] body { color-scheme: dark; }

[data-theme="dark"] tr.unread td { background: rgba(59, 130, 246, .16); }
[data-theme="dark"] tr.unread:hover td { background: rgba(59, 130, 246, .24); }

[data-theme="dark"] .order-card.unread {
  background: rgba(59, 130, 246, .14);
  border-color: #2f4d7d;
}

[data-theme="dark"] .topbar { background: var(--surface); }
[data-theme="dark"] .lightbox { background: rgba(3, 7, 18, .93); }
[data-theme="dark"] .photo img,
[data-theme="dark"] .msg-photo { background: var(--surface-3); }

/* Кнопка переключения темы */
.login-theme-btn { position: fixed; top: 18px; right: 18px; z-index: 5; }

.theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0 !important;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  box-shadow: none;
}

.theme-btn:hover { color: var(--ink); border-color: var(--blue); background: var(--surface-2); }

.theme-btn .icon-moon { display: block; }
.theme-btn .icon-sun { display: none; }

[data-theme="dark"] .theme-btn .icon-moon { display: none; }
[data-theme="dark"] .theme-btn .icon-sun { display: block; }

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  height: auto;
  overflow: auto;
  padding: 0;
  margin: 0;
}

.hidden { display: none !important; }

::selection { background: rgba(37, 99, 235, .18); }

/* ---------- Верхняя панель ------------------------------------------------ */

.topbar {
  display: flex;
  align-items: center;
  gap: 20px;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  font-size: 15.5px;
  letter-spacing: -.01em;
  white-space: nowrap;
}

.brand::before {
  content: "";
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: url('/favicon.ico') center / contain no-repeat;
}

.nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }

.nav-btn {
  background: transparent;
  border: none;
  color: var(--grey);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s, color .15s;
}

.nav-btn:hover { background: var(--surface-3); color: var(--ink); }
.nav-btn.active { background: var(--blue-soft); color: var(--blue); font-weight: 600; }

.userbox {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  color: var(--ink-soft);
  white-space: nowrap;
}

#userName { color: var(--ink); font-weight: 500; }

.role-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--grey);
  text-transform: lowercase;
}

.role-badge.admin { background: var(--red-soft); color: var(--red); }
.role-badge.manager { background: var(--blue-soft); color: var(--blue); }
.role-badge.master { background: var(--green-soft); color: var(--green); }
.role-badge.store { background: var(--amber-soft); color: var(--amber); }

/* ---------- Основная область --------------------------------------------- */

.main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px 24px 80px;
}

.view { animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

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

.toolbar input[type=text],
.toolbar input[type=search] {
  flex: 1;
  min-width: 220px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}

.toolbar input:focus,
.field input:focus,
.field select:focus,
.field textarea:focus,
.add-box input:focus,
table.lines input:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}

h1.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -.02em;
  margin: 0 0 18px;
}

/* ---------- Таблица заказов ---------------------------------------------- */

.table-wrap {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.grid th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--grey);
  padding: 12px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.grid td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

table.grid tbody tr { cursor: pointer; transition: background .12s; }
table.grid tbody tr:hover { background: var(--surface-2); }
table.grid tbody tr:last-child td { border-bottom: none; }

.num { text-align: right; white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); font-size: 12px; }

.order-number { font-weight: 600; letter-spacing: -.01em; }

/* ---------- Статусы ------------------------------------------------------ */

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-accepted { background: var(--blue-soft); color: var(--blue); }
.status-in_work  { background: var(--amber-soft); color: var(--amber); }
.status-ready    { background: var(--green-soft); color: var(--green); }
.status-closed   { background: var(--surface-3); color: var(--grey); }
.status-cancelled{ background: var(--red-soft); color: var(--red); }
.status-draft    { background: #f3f0ff; color: #6f42c1; }

/* ---------- Карточки ----------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  padding: 20px 22px;
  margin-bottom: 18px;
}

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

.card-head h2 {
  border: none;
  padding: 0;
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.card-title-sub { font-size: 13px; color: var(--ink-soft); margin-top: 5px; }

.kv {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px 24px;
}

.kv .k {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--grey);
  margin-bottom: 3px;
}

.kv .v { font-size: 14px; }

.actions-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.actions-row .spacer { flex: 1; }

/* ---------- Кнопки ------------------------------------------------------- */

button,
button.btn {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  padding: 9px 16px;
  color: #fff;
  background: var(--blue);
  transition: background .15s, box-shadow .15s, transform .05s;
  box-shadow: var(--shadow-xs);
}

button:hover, button.btn:hover { background: var(--blue-dark); }
button:active, button.btn:active { transform: translateY(1px); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--blue); }
.btn-success { background: var(--green); }
.btn-success:hover { background: #15803d; }
.btn-grey { background: var(--grey); }

button.btn.btn-outline {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.btn.btn-outline:hover { background: var(--surface-2); border-color: #cbd5e1; }

button.btn.btn-danger-outline {
  background: var(--surface);
  color: var(--red);
  border: 1px solid #fecaca;
  box-shadow: none;
}

button.btn.btn-danger-outline:hover { background: var(--red-soft); }

.btn-sm { padding: 6px 11px; font-size: 12.5px; }

/* Кнопки из старой вёрстки */
.btn-left { background: var(--blue); }
.btn-right { background: var(--green); }
.btn-left:hover, .btn-right:hover { filter: brightness(.94); }

.row-del {
  background: transparent;
  border: none;
  color: var(--red);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  padding: 3px 7px;
  border-radius: 8px;
  opacity: .75;
  box-shadow: none;
}

.row-del:hover { opacity: 1; background: var(--red-soft); }

/* ---------- Таблицы внутри карточки -------------------------------------- */

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin: 22px 0 10px;
}

.section-head h3 {
  margin: 0;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--grey);
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--grey);
  margin: 14px 0 8px;
}

table.lines { width: 100%; border-collapse: collapse; font-size: 14px; }

table.lines th {
  text-align: left;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--grey);
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

table.lines td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
}

table.lines tbody tr:hover { background: var(--surface-2); }

table.lines input[type=number] {
  width: 90px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  text-align: right;
  font-family: inherit;
}

table.lines .code-cell {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 11.5px;
  color: var(--grey);
  white-space: nowrap;
}

.empty-line {
  padding: 18px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
}

/* ---------- Итоги -------------------------------------------------------- */

.totals {
  display: flex;
  justify-content: flex-end;
  gap: 32px;
  padding: 18px 4px 4px;
  margin-top: 14px;
  border-top: 1px solid var(--border-soft);
  flex-wrap: wrap;
}

.totals .t-k {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--grey);
  text-align: right;
}

.totals .t-v {
  font-size: 16px;
  font-weight: 700;
  text-align: right;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}

.totals .t-v.grand { font-size: 22px; color: var(--blue); }

/* ---------- Добавление материала ----------------------------------------- */

.add-box {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-top: 12px;
}

.add-box input[type=text] {
  width: 100%;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  margin-bottom: 10px;
  font-family: inherit;
}

.search-results {
  max-height: 320px;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.search-results .row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
}

.search-results .row:hover { background: var(--surface-2); }
.search-results .row:last-child { border-bottom: none; }
.search-results .row .name { flex: 1; min-width: 0; font-size: 13px; }
.search-results .row .code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 11px;
  color: var(--grey);
}

.mode-tabs { display: flex; gap: 6px; margin-bottom: 10px; }

.mode-tabs button {
  background: var(--surface-3);
  color: var(--grey);
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: none;
}

.mode-tabs button.active { background: var(--blue); color: #fff; }
.mode-tabs button:hover { background: var(--surface-3); }
.mode-tabs button.active:hover { background: var(--blue-dark); }

/* ---------- Формы -------------------------------------------------------- */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
}

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

.field label {
  font-size: 12px;
  font-weight: 500;
  color: var(--grey);
}

.field input,
.field select,
.field textarea {
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}

.field .hintline { font-size: 11px; color: #94a3b8; }
.help-line { font-size: 12px; color: var(--ink-soft); margin-top: 10px; }

/* ---------- Чипы фильтров ------------------------------------------------ */

.chips {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}

.chips::-webkit-scrollbar { display: none; }

.chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--grey);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 13px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s;
  box-shadow: none;
}

.chip:hover { border-color: #cbd5e1; color: var(--ink); }
.chip.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* ---------- Отчёт -------------------------------------------------------- */

.report-period { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; font-size: 13px; color: var(--grey); }

.report-period input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
}

/* ---------- История ------------------------------------------------------ */

ul.history { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }

ul.history li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}

ul.history li:last-child { border-bottom: none; }
ul.history .muted { font-size: 11.5px; margin-bottom: 2px; }

/* ---------- Вход --------------------------------------------------------- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(1200px 600px at 50% -10%, var(--blue-soft) 0%, var(--bg) 55%);
  padding: 20px;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  padding: 30px 28px;
  width: 100%;
  max-width: 370px;
}

.login-box h1 { font-size: 22px; letter-spacing: -.02em; margin: 0 0 6px; }
.login-box p.sub { font-size: 13px; color: var(--ink-soft); margin: -4px 0 22px; text-align: center; }
.login-box .field { margin-bottom: 14px; }

.login-logo {
  display: block;
  width: 100%;
  max-width: 250px;
  height: auto;
  margin: 0 auto 12px;
}

.pin-logo { height: 36px; width: auto; display: block; margin: 0 auto; }

.login-error {
  background: var(--red-soft);
  color: #b91c1c;
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---------- Вход по ПИН-коду --------------------------------------------- */

.pin-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(900px 500px at 50% 0%, var(--blue-soft) 0%, var(--bg) 60%);
}

.pin-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
  padding: 28px 26px 22px;
  width: 330px;
  text-align: center;
}

.pin-brand { font-size: 12px; color: var(--ink-soft); margin-bottom: 18px; letter-spacing: .02em; }
.pin-title { font-size: 21px; font-weight: 700; letter-spacing: -.02em; }
.pin-sub { font-size: 13px; color: var(--grey); margin: 7px 0 20px; }

.pin-dots { display: flex; justify-content: center; gap: 15px; margin-bottom: 20px; }

.pin-dots span {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--surface-3);
  transition: background .12s, transform .12s;
}

.pin-dots span.filled { background: var(--blue); transform: scale(1.12); }

.pin-error {
  color: var(--red);
  font-size: 13px;
  margin-bottom: 12px;
  min-height: 18px;
}

.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }

.pin-pad button {
  padding: 16px 0;
  font-size: 20px;
  font-weight: 500;
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--border);
  cursor: pointer;
  box-shadow: none;
}

.pin-pad button:hover { background: var(--surface-3); }
.pin-pad button:active { background: var(--surface-3); transform: translateY(1px); }
.pin-pad button.pin-fn { font-size: 16px; color: var(--grey); }

.pin-exit {
  margin-top: 18px;
  background: none;
  border: none;
  color: var(--grey);
  font-size: 12px;
  cursor: pointer;
  text-decoration: underline;
  box-shadow: none;
}

.pin-exit:hover { background: none; color: var(--ink); }
.pin-hint { font-size: 11px; color: #94a3b8; margin-top: 10px; line-height: 1.4; }

.pin-shake { animation: pin-shake .3s; }
@keyframes pin-shake {
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

/* ---------- Модальные окна ----------------------------------------------- */

.modal {
  background: rgba(15, 23, 42, .45);
  backdrop-filter: blur(3px);
}

.modal-box {
  border-radius: 18px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  animation: modal-in .18s ease-out;
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(.99); }
  to { opacity: 1; transform: none; }
}

.modal-close {
  border-radius: 10px;
  background: var(--surface-3);
  color: var(--grey);
  box-shadow: none;
}

.modal-close:hover { background: var(--surface-3); color: var(--ink); }

/* ---------- Уведомления -------------------------------------------------- */

.toast {
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  font-size: 13.5px;
  font-weight: 500;
}

/* ---------- Чат ---------------------------------------------------------- */

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin-left: 6px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}

.chat-card {
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}

.chat-messages {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px 20px;
  background: var(--surface-2);
  min-height: 320px;
  max-height: 58vh;
  overflow-y: auto;
}

.chat-messages--inline {
  min-height: 140px;
  max-height: 320px;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-top: 4px;
}

.msg {
  align-self: flex-start;
  max-width: 76%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px 14px 14px 4px;
  padding: 9px 13px;
}

.msg.own {
  align-self: flex-end;
  background: var(--blue-soft);
  border-color: #dbeafe;
  border-radius: 14px 14px 4px 14px;
}

.msg-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 3px;
  font-size: 11.5px;
}

.msg-author { font-weight: 600; color: var(--ink); }
.msg-time { color: #94a3b8; }
.msg-body { font-size: 14px; white-space: pre-wrap; word-break: break-word; }

.chat-form {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.chat-form input {
  flex: 1;
  padding: 10px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
}

.chat-form input:focus {
  outline: none;
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}

.chat-empty {
  padding: 30px;
  text-align: center;
  color: #94a3b8;
  font-size: 13px;
}

/* ---------- Списание: слева ввод, справа список ---------------------------- */

.material-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.material-entry {
  position: sticky;
  top: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.material-entry .add-box {
  margin: 0;
  border: none;
  background: transparent;
  padding: 0;
}

.material-list { min-width: 0; }

@media (max-width: 1100px) {
  .material-layout { grid-template-columns: 1fr; }

  .material-entry {
    position: static;
    padding: 12px;
  }
}

/* ---------- Вкладки внутри заказа ----------------------------------------- */

.order-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px 2px 12px;
  scrollbar-width: none;
}

.order-tabs::-webkit-scrollbar { display: none; }

.order-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
}

.order-tab:hover { border-color: #b6c2d1; color: var(--ink); }

.order-tab.active {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.order-tab .tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(15, 23, 42, .08);
  font-size: 11.5px;
  font-weight: 700;
}

.order-tab .tab-count:empty { display: none; }
.order-tab.active .tab-count { background: rgba(255, 255, 255, .25); }

/* Рабочее окно списания — просторнее обычной карточки */
.material-workspace .add-box--wide { margin-bottom: 18px; }
.material-workspace .add-box--wide input[type="text"] { font-size: 15px; padding: 12px 14px; }
.material-workspace .lines td { padding: 11px 10px; }
.material-workspace .totals { margin-top: 16px; }

/* ---------- Фотографии ---------------------------------------------------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}

.photo {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface);
}

.photo img {
  display: block;
  width: 100%;
  height: 120px;
  object-fit: cover;
  cursor: zoom-in;
  background: var(--surface-3);
}

.photo figcaption {
  padding: 6px 8px;
  font-size: 11.5px;
  color: var(--grey);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-photo {
  display: block;
  max-width: 260px;
  max-height: 260px;
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: zoom-in;
  background: var(--surface-3);
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, .88);
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

.attach-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

/* ---------- Заказ с новым сообщением ------------------------------------- */

.notify-line { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

.notify {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.5;
  color: #fff;
  white-space: nowrap;
}

.notify-chat { background: var(--blue); }
.notify-edit { background: #d97706; }

tr.unread td { background: #eff6ff; }
tr.unread td:first-child { box-shadow: inset 3px 0 0 var(--blue); }
tr.unread:hover td { background: #e3efff; }

.order-card.unread {
  background: #eff6ff;
  border-color: #bfdbfe;
  box-shadow: inset 3px 0 0 var(--blue);
}

/* ---------- Поле пароля с «глазом» --------------------------------------- */

.password-wrap { position: relative; display: block; }

.password-wrap input { padding-right: 44px; }

.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--grey);
  cursor: pointer;
  box-shadow: none;
}

.password-toggle:hover { background: var(--surface-3); color: var(--ink); }
.password-toggle:active { transform: translateY(-50%); }

.password-toggle .eye-closed { display: none; }
.password-toggle.is-on .eye-open { display: none; }
.password-toggle.is-on .eye-closed { display: block; }

/* ---------- Подсказка «как установить» ----------------------------------- */

.link-btn {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 0;
  background: none;
  border: none;
  color: var(--blue);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  box-shadow: none;
}

.link-btn:hover { background: none; color: var(--blue-dark); }

.login-box .install-steps { margin-top: 12px; font-size: 12.5px; }

.install-steps {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
  font-size: 13.5px;
}

.install-steps > div {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

/* ---------- Мелочи ------------------------------------------------------- */

.spinner { text-align: center; padding: 34px; color: #94a3b8; font-size: 13px; }

.badge {
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

/* ---------- Мобильный вид ------------------------------------------------ */

@media (max-width: 780px) {
  .main { padding: 14px 12px 70px; }

  .topbar { gap: 8px 10px; padding: 8px 12px; flex-wrap: wrap; }
  .brand { font-size: 14.5px; }
  .userbox { font-size: 12px; gap: 6px; margin-left: auto; }
  #userName { display: inline-block; max-width: 124px; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .role-badge { font-size: 10px !important; padding: 2px 6px !important; }
  .brand { font-size: 13.5px; }
  .brand img, .brand svg { height: 24px; }
  #nav .btn { padding: 7px 11px !important; font-size: 12.5px !important; white-space: nowrap; }
  #navInstall, #btnPassword { padding: 5px 9px !important; font-size: 12px !important; }

  /* Меню уезжает во вторую строку и прокручивается вбок */
  .nav { flex-basis: 100%; order: 3; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .nav::-webkit-scrollbar { display: none; }
  .nav-btn { padding: 7px 11px; font-size: 13px; white-space: nowrap; }

  .card { padding: 14px; border-radius: 12px; }

  /* Список заказов — карточками вместо таблицы */
  .table-wrap { display: none; }

  .order-cards { display: flex; flex-direction: column; gap: 10px; }

  .order-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 14px;
    box-shadow: var(--shadow-xs);
    cursor: pointer;
  }

  .order-card:active { background: var(--surface-2); }

  .oc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
  .oc-car { font-size: 14.5px; font-weight: 600; }
  .oc-master { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
  .oc-bottom { display: flex; justify-content: space-between; align-items: baseline; margin-top: 8px; font-size: 13px; }
  .oc-bottom .mono { font-weight: 700; }

  /* Таблицы внутри карточки заказа — в столбик, с подписями слева */
  table.lines thead { display: none; }
  table.lines tbody, table.lines tr, table.lines td { display: block; width: auto; }

  table.lines tr { border-bottom: 1px solid var(--border-soft); padding: 8px 0; }
  table.lines tr:last-child { border-bottom: none; }

  table.lines td {
    border: none;
    padding: 3px 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    text-align: right;
  }

  table.lines td::before {
    content: attr(data-label);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--grey);
    text-align: left;
  }

  table.lines td[data-label=""]::before { content: none; }
  table.lines td.empty-line { display: block; text-align: center; }
  table.lines td.empty-line::before { content: none; }

  .totals { gap: 14px; justify-content: space-between; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }

  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); }
  .photo img { height: 100px; }
  .msg-photo { max-width: 210px; max-height: 210px; }

  .chat-messages { min-height: 220px; max-height: 55vh; padding: 12px; }
  .msg { max-width: 88%; }

  .actions-row .btn { flex: 1 1 auto; }
}

/* Шапки таблиц берут цвет из палитры, а не из старого стиля */
table.grid th,
table.lines th { background: var(--surface-2); }

/* Поля ввода: цвет из палитры, чтобы работали в обеих темах */
input[type="text"],
input[type="search"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="email"],
input[type="tel"],
select,
textarea {
  background: var(--field);
  color: var(--ink);
  border: 1px solid var(--border);
}

input::placeholder,
textarea::placeholder { color: #94a3b8; }

[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: #6f7f99; }

/* Пустые строки таблиц — в цвет палитры */
td.empty-line,
.empty-line {
  background: var(--surface-2);
  color: var(--ink-soft);
}

[data-theme="dark"] td.empty-line,
[data-theme="dark"] .empty-line { background: rgba(255, 255, 255, .03); }

/* Ловушка для автозаполнения: невидима и недоступна */
.autofill-trap {
  position: absolute;
  left: -9999px;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* Тёмная тема: добиваем светлые поверхности из старого файла стилей */
[data-theme="dark"] .chat-messages,
[data-theme="dark"] .add-box { background: var(--surface-2); border-color: var(--border); }

[data-theme="dark"] .search-results,
[data-theme="dark"] .modal-box { background: var(--surface); }

[data-theme="dark"] table.grid,
[data-theme="dark"] table.lines { background: transparent; }

[data-theme="dark"] td { background-color: transparent; }

[data-theme="dark"] td.empty-line { background: rgba(255, 255, 255, .03); }

/* Строка результата поиска: код, наименование, две кнопки — по своим местам */
.search-results .row {
  display: grid;
  grid-template-columns: minmax(70px, 100px) minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

.search-results .row .code {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-results .row .name {
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.3;
}

.search-results .row .btn { white-space: nowrap; }

/* Таблицы списания: колонки с оговорённой шириной, чтобы ничего не сминалось */
.material-workspace table.lines th:nth-child(1),
.material-workspace table.lines td:nth-child(1) { width: 96px; }

.material-workspace table.lines th:nth-child(3),
.material-workspace table.lines td:nth-child(3) { width: 118px; white-space: nowrap; }

.material-workspace table.lines th:nth-child(4),
.material-workspace table.lines td:nth-child(4) { width: 110px; }

.material-workspace table.lines th:nth-child(5),
.material-workspace table.lines td:nth-child(5) { width: 58px; text-align: center; padding-right: 10px; }

.material-workspace table.lines input[type="number"] { width: 68px; }

.material-workspace table.lines th { white-space: nowrap; }
/* Кнопка-иконка (тема, звук) */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0 !important;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--border);
  box-shadow: none;
}

.icon-btn:hover { color: var(--ink); border-color: var(--blue); background: var(--surface-2); }

.sound-btn .icon-sound-off { display: none; }
[data-sound="off"] .sound-btn .icon-sound-on { display: none; }
[data-sound="off"] .sound-btn .icon-sound-off { display: block; }
[data-sound="off"] .sound-btn { color: var(--grey); }