:root {
  --bg: #f6f7f9;
  --bg-elev: #ffffff;
  --border: #e4e7eb;
  --border-strong: #cfd4da;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.04);
  --radius: 8px;
  --sidebar-w: 240px;
  --drawer-w: 480px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

#app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  height: 100dvh; /* динамика для мобильных */
}

/* Welcome screen */
#welcome {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, #ffffff 0%, #eef1f5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: welcome-in .3s ease;
}
#welcome.hiding {
  animation: welcome-out .3s ease forwards;
}
@keyframes welcome-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes welcome-out {
  from { opacity: 1; transform: scale(1); }
  to { opacity: 0; transform: scale(0.98); }
}
.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
  padding: 40px;
  max-width: 90vw;
}
.welcome-logo {
  max-width: 420px;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}
.welcome-sub {
  margin: 0;
  color: var(--text-muted);
  font-size: 15px;
  letter-spacing: .02em;
  text-transform: uppercase;
}
.welcome-enter {
  padding: 56px 224px;
  font-size: 64px;
  font-weight: 600;
  border-radius: 20px;
  box-shadow: 0 8px 24px rgba(37, 99, 235, .25);
  transition: transform .12s, box-shadow .12s;
}
.welcome-enter:hover {
  transform: translateY(-1px);
  box-shadow: 0 12px 30px rgba(37, 99, 235, .35);
}

/* Sidebar */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
}
.brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 4px 18px;
}
.brand-logo {
  width: 100%;
  height: auto;
  max-width: 100%;
  user-select: none;
  -webkit-user-drag: none;
}
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
  width: 100%;
}
.nav-item:hover { background: #f0f2f5; }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.nav-group { margin-top: 12px; }
.nav-group-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  padding: 6px 10px 4px;
}
/* Main */
.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  padding: 16px 24px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}
.topbar h1 { margin: 0; font-size: 18px; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.mobile-menu-btn {
  display: none;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  font-size: 20px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 14;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.sidebar-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.content {
  padding: 20px 24px;
  overflow-y: auto;
  flex: 1;
}

/* Buttons & controls */
.btn {
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .12s;
}
.btn:hover { background: #f0f2f5; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: #f0f2f5; }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.icon-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius);
  border: 0; background: transparent;
  cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: #f0f2f5; }

input, select, textarea {
  font: inherit;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  color: var(--text);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
textarea { min-height: 70px; resize: vertical; }
.search {
  max-width: 260px;
}

/* Tabs / filters */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}
.tab {
  padding: 8px 14px;
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  font: inherit;
  margin-bottom: -1px;
}
.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
.tab:hover { color: var(--text); }

/* Table */
.table-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  background: #fafbfc;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
tbody tr { cursor: pointer; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Month group row in orders */
tr.month-row td {
  background: #fdf2dc;
  font-weight: 700;
  font-size: 13px;
  padding: 12px 14px;
  color: #7c5b1e;
  border-bottom: 1px solid #f1d9a8;
}
tr.month-row {
  cursor: default;
}
tr.month-row:hover td { background: #fdf2dc; }

/* Status colors for order rows */
tr.status-in_progress td { background: #fde2e2; }
tr.status-in_progress:hover td { background: #fbcfcf; }
tr.status-waiting_shipment td { background: #dde8f7; }
tr.status-waiting_shipment:hover td { background: #c9dcf2; }

.orders-table table { font-size: 13px; }
.orders-table td { padding: 8px 14px; }

.photo-col { text-align: center; width: 50px; }
.photo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  background: #f0f2f5;
  border: 0;
  cursor: pointer;
  font: inherit;
  font-size: 16px;
  transition: background .12s, transform .12s;
}
.photo-link:hover {
  background: var(--accent-soft);
  transform: scale(1.08);
}

/* Photo modal (lightbox) */
.photo-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .85);
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 40px;
  cursor: zoom-out;
  animation: photo-modal-in .15s ease;
}
.photo-modal.open { display: flex; }
@keyframes photo-modal-in {
  from { opacity: 0; }
  to { opacity: 1; }
}
.photo-modal-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 60px rgba(0,0,0,.5);
  cursor: default;
}
.photo-modal-close {
  position: absolute;
  top: 16px; right: 16px;
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff;
  border: 0;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  transition: background .12s;
}
.photo-modal-close:hover {
  background: rgba(255,255,255,.3);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: #f0f2f5;
  color: var(--text-muted);
}
.badge.new { background: #e0f2fe; color: #0369a1; }
.badge.in_progress, .badge.in_production { background: #fef3c7; color: #92400e; }
.badge.ready, .badge.done { background: #dcfce7; color: #166534; }
.badge.with_photo { background: #f3e8ff; color: #6b21a8; }
.badge.waiting_shipment { background: #dde8f7; color: #1e40af; }
.badge.delivered { background: #e0e7ff; color: #4338ca; }
.badge.cancelled { background: #fee2e2; color: #991b1b; }
.badge.queued { background: #f1f5f9; color: #475569; }
.badge.planned { background: #e0f2fe; color: #0369a1; }
.badge.ordered { background: #fef3c7; color: #92400e; }
.badge.received { background: #dcfce7; color: #166534; }
.badge.income { background: #dcfce7; color: #166534; }
.badge.expense { background: #fee2e2; color: #991b1b; }

.empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* Home toolbar */
.home-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.home-month-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}
.home-month-select {
  width: auto;
  min-width: 180px;
}

/* Wizard (новый заказ — 3 шага) */
.wiz-steps {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 18px;
  padding: 4px 2px 14px;
  border-bottom: 1px solid var(--border);
}
.wiz-step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  user-select: none;
  position: relative;
}
.wiz-step + .wiz-step::before {
  content: '';
  position: absolute;
  left: -50%; top: 14px;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: -1;
}
.wiz-step.done + .wiz-step::before,
.wiz-step.done::before {
  background: var(--accent);
}
.wiz-step-num {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: #f1f5f9;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  border: 2px solid var(--border);
  transition: background .15s, color .15s;
}
.wiz-step.active .wiz-step-num {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, .15);
}
.wiz-step.done .wiz-step-num {
  background: #fff;
  color: var(--accent);
  border-color: var(--accent);
}
.wiz-step-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 600;
}
.wiz-step.active .wiz-step-label { color: var(--accent); }
.wiz-step.done .wiz-step-label { color: var(--text); }
.wiz-body { min-height: 200px; }
.wiz-nav { margin-top: 20px; }

/* Picker (выбор моделей) */
.picker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(86px, 1fr));
  gap: 8px;
  max-height: 300px;
  overflow-y: auto;
  padding: 4px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.picker-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  cursor: pointer;
  transition: transform .12s, border-color .12s, box-shadow .12s;
  text-align: center;
}
.picker-card:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  box-shadow: 0 4px 10px rgba(0,0,0,.06);
}
.picker-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .2);
}
.picker-image {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 6px;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  margin-bottom: 4px;
}
.picker-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.picker-check {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 2px 4px rgba(0,0,0,.2);
}
.picker-name {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text);
  word-break: break-word;
}
.picker-sku {
  font-size: 9px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: .04em;
}

/* Список выбранных моделей */
.sel-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}
.sel-row {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: grid;
  grid-template-columns: 44px 1fr auto auto;
  gap: 10px;
  align-items: center;
}
.sel-thumb {
  width: 44px;
  height: 44px;
  border-radius: 6px;
  background: #f3f4f6;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sel-thumb img { width: 100%; height: 100%; object-fit: cover; }
.sel-meta { min-width: 0; }
.sel-name { font-size: 13px; font-weight: 600; line-height: 1.3; word-break: break-word; }
.sel-qty {
  display: flex;
  align-items: center;
  gap: 4px;
}
.sel-qty .btn { padding: 4px 10px; font-size: 14px; min-width: 28px; }
.sel-qty-input {
  width: 56px;
  text-align: center;
  padding: 4px;
  font-weight: 700;
}
.sel-total {
  margin-top: 8px;
  text-align: right;
  font-size: 13px;
  color: var(--text-muted);
}
.sel-total b { color: var(--text); font-size: 14px; }

/* Сводка перед сохранением */
.wiz-summary {
  margin-top: 20px;
  padding: 14px 16px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
}

/* Warehouse */
.wh-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.wh-stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.wh-stat.warn { background: #fef3c7; border-color: #fde68a; }
.wh-stat-num { font-size: 24px; font-weight: 700; line-height: 1; color: var(--text); }
.wh-stat-lbl { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.wh-stat.warn .wh-stat-num { color: #92400e; }

.wh-card .model-image { position: relative; }
.wh-stock {
  position: absolute;
  top: 8px; right: 8px;
  min-width: 36px;
  height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  background: rgba(255, 255, 255, .95);
  color: var(--text);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .15);
}
.wh-stock.ok { background: #dcfce7; color: #166534; }
.wh-stock.low { background: #fef3c7; color: #92400e; }
.wh-stock.empty { background: #fee2e2; color: #991b1b; }
.wh-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 8px;
}
.wh-controls .btn { padding: 4px 12px; font-size: 16px; font-weight: 700; min-width: 36px; }
.wh-stock-mini { font-size: 12px; color: var(--text-muted); flex: 1; text-align: center; }

/* Models / Catalog */
.models-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}
.model-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.model-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, .08);
  border-color: var(--border-strong);
}
.model-image {
  width: 100%;
  aspect-ratio: 1;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.model-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.model-placeholder {
  font-size: 56px;
  opacity: .25;
}
.model-info {
  padding: 12px 14px 14px;
}
.model-sku {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: .04em;
  margin-bottom: 4px;
}
.model-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.3;
}

/* Model upload (in drawer) */
.model-upload { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.model-upload-preview {
  width: 200px;
  height: 200px;
  border-radius: 12px;
  background: #f3f4f6;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--border);
}
.model-upload-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Production summary hero block */
.prod-summary {
  background: linear-gradient(135deg, #f9fafb 0%, #eef2ff 60%, #fef3c7 100%);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px 26px 22px;
  margin-bottom: 24px;
  position: relative;
  overflow: hidden;
}
.prod-summary::before {
  content: '';
  position: absolute;
  right: -60px; top: -60px;
  width: 220px; height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(99,102,241,.18), transparent 70%);
  pointer-events: none;
}
.prod-summary-header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  position: relative;
}
.prod-summary-emoji {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 4px 12px rgba(0,0,0,.06);
}
.prod-summary-title { font-size: 18px; font-weight: 700; color: var(--text); }
.prod-summary-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.prod-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  position: relative;
}
.prod-tile {
  background: rgba(255, 255, 255, .85);
  border: 1px solid rgba(255, 255, 255, .6);
  backdrop-filter: blur(8px);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.prod-tile.note { background: rgba(254, 243, 199, .8); }
.prod-tile.warn { background: rgba(254, 226, 226, .8); }
.prod-tile.ok { background: rgba(220, 252, 231, .8); }
.prod-tile-icon { font-size: 22px; flex-shrink: 0; line-height: 1.2; }
.prod-tile-text { font-size: 13px; line-height: 1.45; color: var(--text); }
.prod-tile-text strong { font-size: 14px; font-weight: 700; }
.prod-tile-text .muted { color: var(--text-muted); display: block; margin-top: 2px; }

/* Months chart */
.months-chart-wrap {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px 12px;
  margin-bottom: 24px;
  box-shadow: 0 2px 8px rgba(0,0,0,.04);
}
.months-chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}
.months-chart-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.months-chart-legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.months-chart-legend .dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.08);
}
.months-chart-legend .dot.blue  { background: #1d4ed8; }
.months-chart-legend .dot.green { background: #047857; }
.months-chart {
  width: 100%;
  height: auto;
  max-height: 280px;
  display: block;
}

/* KPI cards (Home / Dashboard) — round wells */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
  padding: 12px 0;
  justify-items: center;
}
.kpi-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 240px;
  cursor: default;
}
.kpi-well {
  width: 220px;
  height: 220px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 30%, #2d3748, #1a202c);
  position: relative;
  box-shadow: 0 10px 28px rgba(15, 23, 42, .2);
  transition: transform .15s, box-shadow .15s;
}
.kpi-card:hover .kpi-well {
  transform: translateY(-3px);
  box-shadow: 0 18px 38px rgba(15, 23, 42, .28);
}
.kpi-rings {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.kpi-rings.blue    { color: #818cf8; }
.kpi-rings.green   { color: #4ade80; }
.kpi-rings.emerald { color: #34d399; }
.kpi-rings.teal    { color: #5eead4; }
.kpi-rings.orange  { color: #fdba74; }
.kpi-rings.purple  { color: #c084fc; }
.kpi-rings.red     { color: #fca5a5; }
.kpi-well-content {
  position: absolute;
  inset: 50px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  color: #fff;
}

.kpi-icon-box {
  font-size: 20px;
  margin-bottom: 4px;
  opacity: 0.95;
}
.kpi-value {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
  text-align: center;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .25);
}
.kpi-label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  text-align: center;
  line-height: 1.3;
}

/* Stats cards */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}
.card-label { color: var(--text-muted); font-size: 12px; margin-bottom: 4px; }
.card-value { font-size: 20px; font-weight: 700; }
.card-value.income { color: var(--success); }
.card-value.expense { color: var(--danger); }

/* Drawer */
.drawer {
  position: fixed;
  top: 0; right: 0;
  width: var(--drawer-w);
  max-width: 100vw;
  height: 100vh;
  height: 100dvh; /* динамическая высота — учитывает URL-бар мобильных браузеров */
  background: var(--bg-elev);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(0,0,0,.08);
  transform: translateX(100%);
  transition: transform .2s ease;
  z-index: 20;
  display: flex;
  flex-direction: column;
  /* Учёт нижней панели iPhone (home indicator) */
  padding-bottom: env(safe-area-inset-bottom, 0);
  box-sizing: border-box;
}
.drawer.open { transform: translateX(0); }
.drawer-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.drawer-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.drawer-body { padding: 20px 20px 32px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
  z-index: 19;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-row { display: grid; gap: 4px; }
.form-row label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}
.form-actions {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  margin: 20px 0 10px;
}

.muted { color: var(--text-muted); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

@media (max-width: 900px) {
  html, body { overflow-x: hidden; }
  #app {
    grid-template-columns: 1fr;
  }
  .main { min-width: 0; overflow-x: hidden; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    z-index: 15;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 2px 0 16px rgba(0, 0, 0, .12);
  }
  .sidebar.open { transform: translateX(0); }
  .mobile-menu-btn { display: inline-flex; }
  .topbar {
    padding: 10px 14px;
    gap: 10px;
    flex-wrap: wrap;
  }
  .topbar h1 { font-size: 16px; flex: 1; min-width: 0; }
  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }
  .topbar-actions .search { max-width: none; flex: 1; min-width: 120px; }
  .content { padding: 14px 14px calc(40px + env(safe-area-inset-bottom)); }
  .drawer { width: 100vw; }
  .welcome-logo { max-width: 90vw; }
  .brand-logo { max-width: 80%; }
  .table-wrap { overflow-x: auto; }

  /* KPI wells на мобильном — два в ряд, поменьше */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
    justify-items: center;
  }
  .kpi-card { max-width: 100%; }
  .kpi-well { width: 150px; height: 150px; border-width: 12px; }
  .kpi-well-content { inset: 36px; }
  .kpi-icon-box { font-size: 16px; }
  .kpi-value { font-size: 12px; }
  .kpi-label { font-size: 10px; }

  /* Сводка по производству — плитки в одну колонку */
  .prod-tiles { grid-template-columns: 1fr; }
  .prod-summary { padding: 16px 14px; }
  .prod-summary-emoji { width: 42px; height: 42px; font-size: 22px; }
  .prod-summary-title { font-size: 16px; }

  /* Заголовки секций тоньше */
  .section-title { font-size: 12px; }

  /* Тулбар главной — в колонку */
  .home-toolbar { flex-wrap: wrap; gap: 8px; }
  .months-chart-head { flex-direction: column; align-items: flex-start; gap: 6px; }
  .months-chart-wrap { padding: 14px 12px; }

  /* Tabs — горизонтальный скролл вместо переноса */
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
  }
  .tab { white-space: nowrap; padding: 8px 10px; font-size: 13px; }
}

/* Заказы как карточки на мобильном */
@media (max-width: 700px) {
  .orders-table { border: 0; box-shadow: none; background: transparent; overflow: visible; width: 100%; max-width: 100%; box-sizing: border-box; }
  .orders-table table,
  .orders-table thead,
  .orders-table tbody,
  .orders-table tr,
  .orders-table td {
    display: block;
    box-sizing: border-box;
    max-width: 100%;
  }
  .orders-table table { width: 100%; }
  .orders-table thead { display: none; }
  .orders-table tbody { display: flex; flex-direction: column; gap: 10px; width: 100%; }
  .orders-table tr[data-id] {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, .04);
    width: 100%;
  }
  .orders-table tr[data-id] td {
    padding: 4px 0;
    border: 0;
    display: grid;
    grid-template-columns: 90px minmax(0, 1fr);
    gap: 12px;
    text-align: right;
    width: 100%;
  }
  .orders-table tr[data-id] td .td-val {
    overflow-wrap: anywhere;
    word-break: break-word;
    min-width: 0;
    text-align: right;
  }
  .orders-table tr[data-id] td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: .04em;
    text-align: left;
    padding-top: 2px;
  }
  .orders-table tr[data-id] td.empty { display: none; }
  /* Заголовок месяца — отдельной плашкой, без data-label */
  .orders-table tr.month-row {
    background: #fdf2dc !important;
    border-radius: 8px;
    padding: 10px 14px !important;
    border: 1px solid #f1d9a8 !important;
    margin-top: 6px;
  }
  .orders-table tr.month-row td {
    padding: 0;
    color: #7c5b1e;
    font-weight: 700;
    font-size: 13px;
    text-align: left !important;
    justify-content: flex-start !important;
  }
  .orders-table tr.month-row td::before { display: none; }

  /* Цветные бэкграунды строк по статусу — на всю карточку */
  .orders-table tr[data-id].status-in_progress { background: #fde2e2; }
  .orders-table tr[data-id].status-waiting_shipment { background: #dde8f7; }
}

/* Очень узкие экраны — колодцы в одну колонку */
@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .kpi-well { width: 180px; height: 180px; }
}
