/* ═══════════════════════════════════════
   КАЛЬКУЛЯТОР ЗАКАЗА BK — v2.0
   Burger King Style: Sidebar Layout
   ═══════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  /* BK Brand */
  --bk-red: #D62300;
  --bk-red-dark: #A81D00;
  --bk-brown: #502314;
  --bk-brown-light: #8B5E34;
  --bk-orange: #FF8732;
  --bk-yellow: #F5EBDC;
  --bk-cream: #FFF8F0;

  /* UI Tokens */
  --bg: #f5f3ef;
  --card: #ffffff;
  --sidebar-bg: #2C1810;
  --sidebar-hover: #3D261B;
  --sidebar-active: #502314;
  --text: #2C1810;
  --text-secondary: #6B5344;
  --text-muted: #9B8B7E;
  --border: #E8E0D6;
  --border-light: #F0EBE4;
  --accent: var(--bk-red);
  --accent-hover: var(--bk-red-dark);
  --green: #2E7D32;
  --green-bg: #F1F8E9;
  --orange: var(--bk-orange);
  --orange-bg: #FFF3E0;
  --error: #D32F2F;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(44,24,16,0.06), 0 1px 2px rgba(44,24,16,0.04);
  --shadow-md: 0 4px 12px rgba(44,24,16,0.08);
  --shadow-lg: 0 8px 28px rgba(44,24,16,0.12);
  --transition: 0.15s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Plus Jakarta Sans', -apple-system, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ═══════ LOGIN ═══════ */
.login-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, var(--bk-brown) 0%, var(--bk-red-dark) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}

.login-box {
  background: white;
  border-radius: 20px;
  padding: 40px 36px 32px;
  width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.login-logo { font-size: 48px; margin-bottom: 4px; }

.login-box h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--bk-brown);
  margin-bottom: 4px;
}

.login-box p {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.login-box select,
.login-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: inherit;
  margin-bottom: 10px;
  color: var(--text);
  transition: border-color var(--transition);
}

.login-box select:focus,
.login-box input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(214,35,0,0.08);
}

.login-box .btn { width: 100%; margin-top: 6px; }

/* ═══════ APP LAYOUT ═══════ */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ═══════ SIDEBAR ═══════ */
.sidebar {
  width: 210px;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 16px 14px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-collapse-btn {
  margin-left: auto;
  background: none; border: none;
  color: rgba(255,255,255,0.3);
  cursor: pointer; font-size: 12px;
  padding: 4px;
  transition: color 0.15s;
}
.sidebar-collapse-btn:hover { color: rgba(255,255,255,0.7); }

/* Collapsed sidebar */
.sidebar.collapsed {
  width: 52px;
  overflow: hidden;
}
.sidebar.collapsed .sidebar-brand-text,
.sidebar.collapsed .sidebar-section,
.sidebar.collapsed .sidebar-entity-selector,
.sidebar.collapsed .sidebar-user-info,
.sidebar.collapsed .sidebar-version {
  display: none;
}
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 14px 8px; }
.sidebar.collapsed .sidebar-collapse-btn { display: none; }
.sidebar.collapsed .sidebar-nav { padding: 0 4px; }
.sidebar.collapsed .sidebar-item {
  justify-content: center; padding: 9px 6px;
  font-size: 0; /* скрываем текст */
  white-space: nowrap;
}
.sidebar.collapsed .sidebar-item .sidebar-icon { font-size: 16px; margin: 0; }
.sidebar.collapsed .sidebar-user { justify-content: center; }
.sidebar.collapsed .sidebar-bottom { padding: 8px 4px 12px; }

.sidebar-brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--bk-red), var(--bk-orange));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(214,35,0,0.3);
}

.sidebar-brand-text {
  font-size: 14px; font-weight: 800; color: white;
  line-height: 1.2;
}

.sidebar-brand-text small {
  font-size: 10px; font-weight: 500; color: rgba(255,255,255,0.35);
  display: block; margin-top: 1px;
}

.sidebar-section {
  padding: 16px 14px 6px;
  font-size: 9px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: rgba(255,255,255,0.2);
}

.sidebar-nav { display: flex; flex-direction: column; gap: 1px; padding: 0 6px; }

.sidebar-item {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  color: rgba(255,255,255,0.5);
  cursor: pointer;
  transition: all var(--transition);
  border: none; background: none;
  width: 100%; text-align: left;
  font-family: inherit;
}

.sidebar-item:hover {
  background: var(--sidebar-hover);
  color: rgba(255,255,255,0.85);
}

.sidebar-item.active {
  background: var(--sidebar-active);
  color: white;
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--bk-orange);
}

.sidebar-icon { width: 18px; text-align: center; font-size: 14px; flex-shrink: 0; }

.sidebar-bottom {
  margin-top: auto;
  padding: 8px 8px 12px;
  border-top: 1px solid rgba(255,255,255,0.08);
  position: relative;
}

.sidebar-entity-selector {
  padding: 6px 8px 10px;
}

.sidebar-entity-selector label {
  display: block;
  font-size: 9px; font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(255,255,255,0.25);
  margin-bottom: 4px;
}

.sidebar-entity-selector select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  font-weight: 600;
  color: white;
  background: var(--sidebar-hover);
  cursor: pointer;
}

.sidebar-entity-selector select:focus {
  border-color: var(--bk-orange);
  outline: none;
}

.sidebar-entity-selector select option {
  background: var(--sidebar-bg);
  color: white;
}

.sidebar-user {
  display: flex; align-items: center; gap: 8px;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition);
}

.sidebar-user:hover { background: var(--sidebar-hover); }

.sidebar-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--bk-red), var(--bk-orange));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 11px;
  flex-shrink: 0;
}

.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { font-size: 12px; font-weight: 600; color: white; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role { font-size: 10px; color: rgba(255,255,255,0.3); }

/* User dropdown */
.user-dropdown {
  position: absolute;
  bottom: 68px;
  left: 6px;
  right: 6px;
  background: white;
  border-radius: var(--radius-sm);
  box-shadow: 0 -2px 16px rgba(0,0,0,0.2);
  overflow: hidden;
  z-index: 1000;
}

.user-dropdown-btn {
  display: block; width: 100%;
  padding: 10px 14px;
  border: none; background: none;
  font-size: 13px; font-family: inherit;
  color: var(--text);
  cursor: pointer; text-align: left;
}

.user-dropdown-btn:hover { background: var(--bg); }
.user-dropdown-btn.logout { color: var(--error); }
.user-dropdown-btn.logout:hover { background: #FEF2F2; }

/* ═══════ MAIN AREA ═══════ */
.main-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
  position: relative; /* для page-modal */
}

/* ─── Topbar ─── */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 46px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  z-index: 1;
}

.topbar-title {
  font-size: 17px; font-weight: 700; color: var(--text);
}

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

.topbar-badge-entity {
  font-size: 11px; font-weight: 700;
  color: var(--accent);
  background: rgba(214,35,0,0.06);
  padding: 4px 12px;
  border-radius: 6px;
}

.mobile-sidebar-toggle {
  display: none;
  background: none; border: none;
  font-size: 22px; color: var(--text);
  cursor: pointer; padding: 4px;
}

/* ─── Content Area ─── */
.content-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

/* ─── Params Strip (горизонтальная полоса параметров) ─── */
.params-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: flex-end;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.params-strip .param-group label {
  font-size: 9px;
}

.params-strip .btn-build {
  margin: 0;
  padding: 7px 16px;
  font-size: 12px;
}

/* ─── Order Page (заполняет всю рабочую область) ─── */
.order-page {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.order-page.hidden { display: none !important; }

.order-page .table-toolbar {
  flex-shrink: 0;
  margin: 0 16px;
  border-radius: var(--radius) var(--radius) 0 0;
  border: 1px solid var(--border-light);
  border-bottom: none;
  background: #FAFAF7;
}

.order-page .table-wrap {
  flex: 1;
  min-height: 0;
  max-height: none;
  overflow: auto;
  margin: 0 16px;
  border: 1px solid var(--border-light);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  background: var(--card);
}

/* ─── Bottom Bar (прибит к низу, итог + кнопки) ─── */
.order-bottom-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.bottom-summary {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  position: relative;
}

.summary-stat strong {
  color: var(--accent);
  font-weight: 800;
  font-size: 15px;
}

.summary-divider {
  color: var(--text-muted);
  font-size: 16px;
}

.summary-details-btn {
  margin-left: 8px;
  color: var(--text-muted) !important;
  font-size: 11px !important;
}

.summary-details-btn:hover { color: var(--accent) !important; }

.summary-details-panel {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.8;
  max-height: 300px;
  overflow-y: auto;
  min-width: 400px;
  max-width: 600px;
  z-index: 100;
}

.summary-details-panel b {
  color: var(--accent);
}

.bottom-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Когда page-modal открыта, скрываем content и topbar ПОД ней */

.container {
  padding: 20px 24px;
}

/* ═══════ CARDS ═══════ */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border-light);
}

.card h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
}

/* ─── Params ─── */
.param-group {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 0;
}

.param-group label {
  font-size: 9px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.4px;
}

.param-group select,
.param-group input,
select, input[type="date"], input[type="number"], input[type="text"], input[type="password"] {
  padding: 7px 10px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--card);
  transition: border-color var(--transition);
  line-height: 1.4;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(214,35,0,0.06);
}

.required { border-color: var(--error) !important; box-shadow: 0 0 0 2px rgba(211,47,47,0.1) !important; }

.safety-input-wrap {
  display: flex; align-items: center; gap: 0;
  position: relative;
}

.safety-input-wrap input { padding-right: 32px; width: 100%; }

.safety-calendar-icon {
  position: absolute; right: 4px;
  background: none; border: none;
  cursor: pointer; padding: 4px;
  opacity: 0.5;
  transition: opacity var(--transition);
}

.safety-calendar-icon:hover { opacity: 1; }



/* ═══════ BUTTONS ═══════ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn.primary, .btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 8px rgba(214,35,0,0.2);
}

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

.btn.secondary, .btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1.5px solid var(--border);
}

.btn.secondary:hover, .btn-secondary:hover { background: var(--bg); border-color: #ccc; }

.btn-ghost { background: none; color: var(--text-muted); border: none; }
.btn-ghost:hover { color: var(--text); background: var(--bg); }

.btn-danger { background: var(--error); color: white; }
.btn-danger-outline { background: none; color: var(--error); border: 1.5px solid #FFCDD2; }
.btn-danger-outline:hover { background: #FEF2F2; }

.btn-success { background: #217346; color: white; }

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

.btn img { vertical-align: -2px; }

/* ═══════ TABLE ═══════ */

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border-light);
  flex-wrap: wrap;
}

/* 2. Нейтральный фон для кнопок toolbar */
.table-toolbar .btn-ghost {
  background: var(--bg);
  border-radius: 6px;
  padding: 5px 10px;
}

.table-toolbar .btn-ghost:hover {
  background: var(--border);
}

.table-toolbar-title {
  font-size: 14px; font-weight: 700; color: var(--text);
}

.table-toolbar-count {
  font-size: 11px; color: var(--text-muted); font-weight: 600;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
}

.editing-badge {
  background: #FFF3E0;
  color: #E65100;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid #FFCC80;
  cursor: pointer;
  margin-left: 4px;
  animation: pulse-orange 2s infinite;
}

/* Режим просмотра — синий бейдж */
.view-only-mode .editing-badge,
.view-only-mode ~ .editing-badge {
  background: #E3F2FD;
  color: #1565C0;
  border-color: #90CAF9;
  animation: pulse-blue 2s infinite;
}

@keyframes pulse-blue {
  0%, 100% { box-shadow: 0 0 0 0 rgba(21,101,192,0.2); }
  50% { box-shadow: 0 0 0 6px rgba(21,101,192,0); }
}

/* Блокировка ввода в режиме просмотра заказа */
/* 1. Блокируем ВСЕ интерактивные элементы внутри content-area */
.view-only-mode input,
.view-only-mode select,
.view-only-mode textarea,
.view-only-mode button,
.view-only-mode .btn,
.view-only-mode .drag-handle,
.view-only-mode .inline-add-row {
  pointer-events: none !important;
  opacity: 0.4;
}
/* 2. Разрешаем: селекторы отображения (шт/кор, транзит, запас, проверка) */
.view-only-mode #unit,
.view-only-mode #hasTransit,
.view-only-mode #showStockColumn,
.view-only-mode #dataValidation {
  pointer-events: auto !important;
  opacity: 1 !important;
}
/* 3. Разрешаем: кнопки экспорта/копирования/поделиться + дочерние share dropdown */
.view-only-mode #copyOrder,
.view-only-mode #shareOrderBtn,
.view-only-mode #shareOrderBtn *,
.view-only-mode #exportExcelBtn {
  pointer-events: auto !important;
  opacity: 1 !important;
}
/* 4. Разрешаем: бейдж просмотра (чтобы выйти) */
.view-only-mode .editing-badge {
  pointer-events: auto !important;
  opacity: 1 !important;
}
/* 5. Разрешаем: клик по названию товара и кнопку "Подробнее" */
.view-only-mode .item-name {
  pointer-events: auto !important;
  opacity: 1 !important;
}
.view-only-mode .summary-details-btn {
  pointer-events: auto !important;
  opacity: 1 !important;
}

@keyframes pulse-orange {
  0%, 100% { box-shadow: 0 0 0 0 rgba(230,81,0,0.2); }
  50% { box-shadow: 0 0 0 6px rgba(230,81,0,0); }
}

.table-toolbar-spacer { flex: 1; min-width: 8px; }

.table-toolbar-divider {
  width: 1px; height: 20px;
  background: var(--border);
  margin: 0 2px;
}

.toolbar-search {
  min-width: 280px;
  max-width: 500px;
  flex: 1;
  margin: 0 !important;
}

/* ─── Table ─── */
.table-wrap {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 70vh;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead {
  background: linear-gradient(90deg, var(--bk-brown), var(--bk-brown-light), var(--bk-brown));
  color: white;
  position: sticky;
  top: 0;
  z-index: 10;
}

thead th {
  padding: 9px 10px;
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  position: sticky;
  top: 0;
  background: transparent;
  z-index: 10;
}

/* Товар — выравнивание влево */
thead th:nth-child(2) { text-align: left; }

td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-light);
  font-weight: 500;
  vertical-align: middle;
  text-align: center;
}

tbody tr { transition: background 0.1s; }
tbody tr:hover { background: #FFF8F0; }

/* sticky first column */
td.item-name {
  text-align: left;
  font-weight: 600;
  max-width: 360px;
  padding-left: 14px;
  position: sticky;
  left: 0;
  background: white;
  z-index: 5;
  box-shadow: 2px 0 6px rgba(44,24,16,0.04);
  font-size: 13px;
}

th:first-child {
  position: sticky;
  left: 0;
  background: var(--bk-brown);
  z-index: 11;
}

tbody tr:hover td.item-name { background: #FFF8F0; }

td.item-name b { color: var(--bk-orange); margin-right: 4px; font-weight: 700; }

.item-meta {
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 500;
  margin-top: 1px;
}

.shortage-info { font-size: 10px; color: var(--error); margin-top: 2px; }

/* Transit / Stock columns */
.transit-col { display: table-cell; }
.transit-col.hidden { display: none; }
.stock-col { display: table-cell; }
.stock-col.hidden { display: none; }

td.stock-display { font-size: 11px; color: var(--text); font-weight: 600; }

/* Order highlight */
td.order-highlight {
  background: rgba(214,35,0,0.03);
  font-weight: 700;
}

/* ─── Table action buttons ─── */
.btn.small {
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.round-to-pallet {
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 600;
  background: var(--bg);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  font-family: inherit;
  transition: all var(--transition);
}

.round-to-pallet:hover { background: var(--orange-bg); color: var(--orange); border-color: var(--orange); }

.calc-to-order {
  padding: 2px 8px;
  font-size: 10px;
  font-weight: 600;
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid #C8E6C9;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
}

.calc-to-order:hover { background: #C8E6C9; }

.delete-item-x {
  width: 26px; height: 26px;
  border: none;
  background: var(--bg);
  color: var(--text-muted);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}

.delete-item-x:hover { background: #FFEBEE; color: var(--error); }

td.delete-cell { text-align: center; }

.drag-handle {
  cursor: grab;
  user-select: none;
  color: var(--text-muted);
  font-size: 14px;
  opacity: 0.4;
  transition: opacity var(--transition);
}

.drag-handle:hover { opacity: 1; }

input[type="number"] {
  width: 72px;
  min-width: 72px;
  padding: 6px 4px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  font-family: inherit;
  color: var(--text);
  background: #FAFAF7;
  transition: border-color var(--transition);
}

/* Авто-расширение через JS, не CSS */

input[type="number"]:focus {
  border-color: var(--accent);
  background: white;
  box-shadow: 0 0 0 3px rgba(214,35,0,0.06);
}



/* ═══════ SEARCH ═══════ */
.search {
  position: relative;
  margin-bottom: 12px;
}

.search input {
  width: 100%;
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  color: var(--text);
  background: var(--card);
}

.search input:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(214,35,0,0.06);
}


.search-clear {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 50%;
  width: 20px; height: 20px;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.search-clear.hidden { display: none; }

.search-results {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 300px;
  overflow-y: auto;
  z-index: 200;
  box-shadow: var(--shadow-md);
  display: none;
}

.search-results.open,
.search-results:not(:empty) { display: block; }

.search-results div {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
  transition: background var(--transition);
}

.search-results div:hover { background: var(--bg); }

/* ═══════ MODALS ═══════ */

/* Обычные модалки (подтверждение, ред. карточки, сохранение) */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(44,24,16,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  backdrop-filter: blur(4px);
}

/* PAGE-МОДАЛКИ: заменяют content-area внутри main-area */
.modal.page-modal {
  position: static;
  background: var(--bg);
  backdrop-filter: none;
  z-index: auto;
  /* flex child в main-area: заполняет всё доступное пространство */
  flex: 1 1 0;
  min-height: 0; /* критично для flex overflow */
  overflow: hidden;
}

.modal.page-modal .modal-box,
.modal.page-modal .modal-box.large {
  width: 100% !important;
  max-width: 100% !important;
  height: 100%;
  max-height: 100%;
  border-radius: 0;
  box-shadow: none;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  animation: none;
  padding: 0;
  overflow: hidden;
}

.modal.page-modal .modal-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  margin-bottom: 0;
  flex-shrink: 0;
}

.modal.page-modal .modal-header h2 { font-size: 17px; margin: 0; }
.modal.page-modal .modal-close { background: var(--bg); }

/* Контент: всё кроме header скроллится вместе */
.modal.page-modal .modal-box > *:not(.modal-header):not(.db-tabs):not(.db-tab-content) {
  flex-shrink: 0;
  padding-left: 24px;
  padding-right: 24px;
}

/* Основные скролл-контейнеры page-модалок */
.modal.page-modal #orderHistory,
.modal.page-modal #analyticsContainer,
.modal.page-modal #calendarContainer,
.modal.page-modal #planTableContainer {
  flex: 1 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  padding-left: 24px;
  padding-right: 24px;
}

/* БД: промежуточные контейнеры тоже flex */
.modal.page-modal .db-tabs {
  flex-shrink: 0;
  padding: 0 24px;
}

.modal.page-modal .db-tab-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 0 24px;
}

.modal.page-modal .db-tab-content.hidden { display: none; }

.modal.page-modal .db-tab-content > div:first-child {
  flex-shrink: 0;
}

.modal.page-modal #databaseList,
.modal.page-modal #supplierList {
  flex: 1 !important;
  min-height: 0 !important;
  overflow-y: auto !important;
}

.modal-box {
  background: white;
  border-radius: 16px;
  padding: 24px;
  width: 460px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease;
}

.modal-box.large {
  width: min(900px, 96vw);
  max-height: 90vh;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-header h2 {
  font-size: 18px; font-weight: 700; color: var(--text);
  margin: 0; flex: 1;
}

.modal-close {
  width: 32px; height: 32px;
  border: none; background: var(--bg);
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
}

.modal-close:hover { background: #FFEBEE; color: var(--error); }

.modal-box input,
.modal-box select,
.modal-box textarea {
  width: 100% !important;
  min-width: 0 !important;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-family: inherit;
  margin-bottom: 8px;
  color: var(--text);
  background: var(--card);
  line-height: 1.4;
  text-align: left;
  box-sizing: border-box;
}

.modal-box input:focus,
.modal-box select:focus,
.modal-box textarea:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px rgba(214,35,0,0.06);
}

.modal-box label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.modal-box label select,
.modal-box label input {
  margin-top: 4px;
  text-transform: none;
  letter-spacing: 0;
}

.modal-row-2 {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}

.modal-row-2 .modal-field {
  flex: 1;
}

.modal-field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.modal-row-2 input {
  margin-bottom: 0 !important;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

/* ═══════ HISTORY ═══════ */
.history-order {
  border-bottom: 2px solid var(--border);
  transition: all var(--transition);
  margin-bottom: 4px;
  background: var(--card);
  border-radius: var(--radius-sm);
}

.history-order:hover { background: #FFF8F0; box-shadow: var(--shadow); }

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  cursor: pointer;
  gap: 10px;
}

.history-title {
  flex: 1; min-width: 0;
  font-size: 14px; font-weight: 600; color: var(--text);
}

.history-meta {
  font-size: 11px; font-weight: 400; color: var(--text-muted);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}

.history-actions {
  display: flex; gap: 4px; flex-shrink: 0;
}

.history-actions .btn.small {
  padding: 5px 9px; font-size: 13px;
  border-radius: var(--radius-sm);
  border: none; cursor: pointer;
  background: var(--bg);
  transition: background var(--transition);
}

.history-actions .btn.small:nth-child(1) { background: #E3F2FD; }
.history-actions .btn.small:nth-child(2) { background: #FFF3E0; }
.history-actions .btn.small:nth-child(3) { background: #F3E5F5; }
.history-actions .btn.small:nth-child(4) { background: #FFEBEE; }
.history-actions .btn.small:hover { filter: brightness(0.92); }

.history-items {
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border-light);
  background: #FAFAF7;
  animation: expandDown 0.2s ease;
}

.history-items > div {
  padding: 6px 0;
  border-bottom: 1px dashed var(--border);
}

.history-items > div:last-child { border-bottom: none; }

@keyframes expandDown {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 600px; }
}

/* Audit log */
.audit-log-panel {
  padding: 10px 16px;
  background: #FAF5FF;
  border-top: 1px solid #E8E0F0;
  max-height: 200px;
  overflow-y: auto;
}

/* ═══════ DATABASE TABS ═══════ */
.db-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 16px;
}

.db-tab {
  padding: 10px 20px;
  border: none; background: none;
  font-size: 13px; font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-family: inherit;
  transition: all var(--transition);
}

.db-tab:hover { color: var(--text); }
.db-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.db-tab-content { display: flex; flex-direction: column; }
.db-tab-content.hidden { display: none; }

/* ═══════ TOAST ═══════ */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: 0 8px 32px rgba(44,24,16,0.15);
  border-left: 4px solid var(--accent);
  max-width: 340px;
  min-width: 260px;
  animation: toastIn 0.25s ease;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--error); }
.toast.info { border-left-color: var(--bk-orange); }

.toast-icon { font-size: 18px; flex-shrink: 0; line-height: 1; }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 700; font-size: 13px; margin-bottom: 1px; color: var(--text); }
.toast-message { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

.toast-close {
  background: none; border: none;
  color: var(--text-muted); cursor: pointer;
  font-size: 16px; padding: 0; line-height: 1;
  flex-shrink: 0;
}
.toast-close:hover { color: var(--text); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ═══════ LOADING ═══════ */
.loading-spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════ VERSION IN SIDEBAR ═══════ */
.sidebar-version {
  font-size: 10px;
  color: rgba(255,255,255,0.2);
  text-align: center;
  padding: 6px 0 2px;
  font-weight: 600;
}

/* ═══════ RESPONSIVE ═══════ */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -210px;
    top: 0; bottom: 0;
    z-index: 1000;
    transition: left 0.25s ease;
  }

  .sidebar.open { left: 0; }

  .mobile-sidebar-toggle { display: block; }

  .topbar { padding: 0 14px; }
  .container { padding: 14px 10px; }
  .footer { left: 0; }

  .params-bar { gap: 8px; }
  .param-group { flex: 1; min-width: 120px; }

  .table-toolbar { flex-wrap: wrap; gap: 4px; }
  .toolbar-search { min-width: 100%; order: -1; }

  .modal-box { width: calc(100% - 16px) !important; }
  .modal-box.large { width: calc(100% - 16px) !important; }
}

@media (max-width: 480px) {
  .param-group { min-width: 100%; }

  td.item-name { position: static !important; box-shadow: none !important; }
  th:first-child { position: static !important; box-shadow: none !important; }

  input[type="number"] { font-size: 16px !important; min-height: 36px; }
  input, select { font-size: 16px !important; }
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
}

.sidebar-overlay.visible { display: block; }
/* ═══════ WELCOME SCREEN ═══════ */
.welcome-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  background: linear-gradient(135deg, #2C1810 0%, #502314 50%, #8B5E34 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: welcomeFadeIn 0.3s ease;
}
.welcome-overlay.welcome-fade-out {
  animation: welcomeFadeOut 0.4s ease forwards;
}
.welcome-content {
  text-align: center;
  color: white;
  animation: welcomeSlideUp 0.5s ease;
}
.welcome-logo {
  font-size: 56px;
  margin-bottom: 16px;
  animation: welcomePulse 1.2s ease infinite;
}
.welcome-name {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: 0.3px;
}
.welcome-entity {
  font-size: 14px;
  opacity: 0.7;
  font-weight: 500;
}
@keyframes welcomeFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes welcomeFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes welcomeSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes welcomePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

/* ═══════ WELCOME SCREEN ═══════ */
.welcome-overlay {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2C1810 0%, #502314 50%, #8B5E34 100%);
  opacity: 0;
  transition: opacity 0.3s ease;
}
.welcome-overlay.welcome-visible { opacity: 1; }
.welcome-overlay.welcome-fade { opacity: 0; transition: opacity 0.4s ease; }

.welcome-content {
  text-align: center;
  animation: welcomeSlide 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

.welcome-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 26px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  border: 2px solid rgba(255,255,255,0.25);
}

.welcome-name {
  color: white;
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
  letter-spacing: -0.3px;
}

.welcome-entity {
  color: rgba(255,255,255,0.6);
  font-size: 14px;
  font-weight: 500;
}

@keyframes welcomeSlide {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
/* Inline add row */
.inline-add-row td { border-top: 1px dashed #e0e0e0 !important; background: #fafbfc; }
.inline-add-row:hover td { background: #f5f6f8; }
.inline-add-input::placeholder { color: #bbb; }
.inline-add-results div:last-child { border-bottom: none !important; }

/* Режим просмотра планирования */
.plan-view-only .plan-input,
.plan-view-only .plan-edit-input,
.plan-view-only .plan-td-result,
.plan-view-only select,
.plan-view-only input {
  pointer-events: none !important;
  opacity: 0.7;
}
.plan-view-only #planSaveBtn,
.plan-view-only #planClearBtn,
.plan-view-only #planImportBtn,
.plan-view-only #planFillConsumptionBtn,
.plan-view-only #planLoadBtn,
.plan-view-only #planLoadProducts,
.plan-view-only .plan-order-btn {
  pointer-events: none !important;
  opacity: 0.3;
}
/* Разрешаем переключение шт/кор в просмотре плана */
.plan-view-only #planUnit {
  pointer-events: auto !important;
  opacity: 1 !important;
}
/* Разрешаем бейдж просмотра/редактирования */
.plan-view-only #planBadge {
  pointer-events: auto !important;
  opacity: 1 !important;
}
/* Разрешаем кнопки экспорта в просмотре */
.plan-view-only #planExcelBtn,
.plan-view-only #planCopyBtn {
  pointer-events: auto !important;
  opacity: 1 !important;
}

/* Бейдж просмотра в планировании — синий */
.plan-badge-view {
  background: #E3F2FD !important;
  color: #1565C0 !important;
  border-color: #90CAF9 !important;
  animation: pulse-blue 2s infinite !important;
}

/* ===== ТУЛТИПЫ ДЛЯ ПАРАМЕТРОВ ===== */
/* Иконка ? рядом с названием параметра */
.param-q {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--brown-light, #9e8070);
  color: #fff;
  font-size: 8px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  opacity: 0.55;
  vertical-align: middle;
  margin-left: 2px;
  transition: opacity 0.15s;
  flex-shrink: 0;
}
.param-q:hover {
  opacity: 1;
}

/* ===== ТУЛТИПЫ (универсальные, через JS fixed-позиционирование) ===== */
.tip-popup {
  position: fixed;
  z-index: 999999;
  min-width: 220px;
  max-width: 280px;
  background: #2c2825;
  color: #f5f0eb;
  font-size: 11px;
  font-weight: 400;
  line-height: 1.55;
  padding: 8px 12px;
  border-radius: 7px;
  box-shadow: 0 4px 18px rgba(0,0,0,0.38);
  pointer-events: none;
  white-space: normal;
}
.tip-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 2px;
}
.tip-row:last-child { margin-bottom: 0; }
.tip-lbl { color: #b0ada8; }
.tip-val { font-weight: 600; white-space: nowrap; }
.tip-hr {
  border: none;
  border-top: 1px solid rgba(255,255,255,0.15);
  margin: 5px 0;
}

/* Элементы с тултипом — курсор */
[data-tip], .calc-wrap, .plan-period-tip {
  cursor: default;
}

/* Старые классы — оставляем пустыми для совместимости */
.param-tip { position: relative; }
.calc-wrap { position: relative; display: inline-block; }
.calc-wrap .calc-tip { display: none; }
.plan-period-tip { position: relative; }
.plan-period-tip .plan-tip { display: none; }
.calc-tip-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.calc-tip-lbl { color: #b0ada8; }
.calc-tip-val { font-weight: 600; white-space: nowrap; }
.calc-tip-hr { border: none; border-top: 1px solid rgba(255,255,255,0.15); margin: 5px 0; }
.plan-tip-row { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.plan-tip-lbl { color: #b0ada8; }
.plan-tip-val { font-weight: 600; white-space: nowrap; }
.plan-tip-hr { border: none; border-top: 1px solid rgba(255,255,255,0.15); margin: 5px 0; }
