/* ============================================================
   assets/css/app.css — ElectoStore
   Mobile-first, адаптив для телефона/планшета/десктопа
   ============================================================ */

/* ---------- Переменные ---------- */
:root {
  --accent:      #1d6fbf;
  --accent-dark: #155a9a;
  --bg-page:     #f3f5f8;
  --bg-card:     #ffffff;
  --bg-input:    #f8f9fb;
  --bg-sidebar:  #1a2236;
  --bg-sidebar-hover:   #243047;
  --bg-sidebar-active:  #1d6fbf;
  --text:        #1a1f2e;
  --text-muted:  #6b7280;
  --text-sidebar:#b0bac9;
  --border:      #e2e6ed;
  --border-dark: #c9d0da;
  --green:  #16a34a; --green-bg:  #dcfce7;
  --yellow: #b45309; --yellow-bg: #fef9c3;
  --red:    #b91c1c; --red-bg:    #fee2e2;
  --blue:   #1d6fbf; --blue-bg:   #dbeafe;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.07);
  --radius:    8px;
  --radius-lg: 12px;
  --sidebar-w: 230px;
  --topbar-h:  56px;
}

/* ---------- Сброс ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg-page);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
img { max-width: 100%; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }

/* ---------- Лейаут ---------- */
.app-wrapper { display: flex; min-height: 100vh; }

/* === САЙДБАР === */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 300;
  transition: transform .28s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.sidebar-logo {
  padding: 20px 20px 16px;
  font-size: 19px; font-weight: 700; color: #fff;
  letter-spacing: -.3px;
  border-bottom: 1px solid rgba(255,255,255,.07);
  flex-shrink: 0;
}
.sidebar-logo span { color: #60a5fa; }
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 12px 20px;
  font-size: 14px; color: var(--text-sidebar);
  cursor: pointer; border: none; background: none;
  width: 100%; text-align: left;
  text-decoration: none;
  transition: background .15s, color .15s;
  -webkit-user-select: none; user-select: none;
}
.nav-link .nav-icon { font-size: 18px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-link:hover  { background: var(--bg-sidebar-hover); color: #fff; }
.nav-link.active { background: var(--bg-sidebar-active); color: #fff; font-weight: 600; }
.nav-section {
  display: block;
  padding: 14px 20px 4px;
  font-size: 10px; text-transform: uppercase;
  letter-spacing: 1.2px; color: rgba(255,255,255,.3);
}
.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: 13px; color: var(--text-sidebar);
  flex-shrink: 0;
}
.sidebar-user strong { display: block; color: #fff; font-size: 14px; margin-bottom: 2px; }
.sidebar-user a { color: #93c5fd; }
.sidebar-user a:hover { color: #fff; }

/* Оверлей мобильного меню */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 290;
}
.sidebar-overlay.open { display: block; }

/* === ОСНОВНОЙ КОНТЕНТ === */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* === ТОПБАР === */
.topbar {
  position: sticky; top: 0; z-index: 200;
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  gap: 10px;
}
.topbar-title { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Гамбургер */
.hamburger {
  display: none;
  background: none; border: none; cursor: pointer;
  padding: 8px; margin-right: 2px;
  color: var(--text);
  border-radius: var(--radius);
  -webkit-tap-highlight-color: transparent;
  min-width: 44px; min-height: 44px;
  align-items: center; justify-content: center;
}
.hamburger svg { display: block; }
.hamburger:active { background: var(--bg-page); }

/* === КОНТЕНТ === */
.content-area { padding: 20px; flex: 1; }

/* === МЕТРИКИ === */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}
.metric-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.metric-value { font-size: 26px; font-weight: 700; }
.metric-value.blue   { color: var(--blue); }
.metric-value.green  { color: var(--green); }
.metric-value.yellow { color: var(--yellow); }
.metric-value.red    { color: var(--red); }

/* === КНОПКИ === */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px;
  font-size: 14px; font-weight: 500;
  border: 1px solid var(--border-dark);
  border-radius: var(--radius);
  background: var(--bg-card); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background .15s;
  text-decoration: none;
  min-height: 40px;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover   { background: var(--bg-page); }
.btn:active  { opacity: .8; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger  { background: var(--red-bg); color: var(--red); border-color: #fca5a5; }
.btn-success { background: var(--green-bg); color: var(--green); border-color: #86efac; }
.btn-sm  { padding: 6px 12px; font-size: 13px; min-height: 36px; }
.btn-xs  { padding: 4px 9px;  font-size: 12px; min-height: 30px; }

/* === ТАБЛИЦЫ === */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
}
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  background: #f8f9fb;
  text-align: left; font-weight: 600; font-size: 12px;
  color: var(--text-muted);
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8f9fb; }

/* === БЕЙДЖИ === */
.badge {
  display: inline-block; padding: 3px 10px;
  border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge-green  { background: var(--green-bg);  color: var(--green); }
.badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-red    { background: var(--red-bg);    color: var(--red); }
.badge-blue   { background: var(--blue-bg);   color: var(--blue); }
.badge-gray   { background: #f1f5f9; color: var(--text-muted); }

/* === ЧИПЫ ХАРАКТЕРИСТИК === */
.spec-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px; }
.spec-chip {
  background: var(--bg-page); border: 1px solid var(--border);
  border-radius: 20px; padding: 2px 9px;
  font-size: 11px; color: var(--text-muted); white-space: nowrap;
}

/* === ФОРМЫ === */
.form-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 16px;
}
.form-section-title {
  font-size: 15px; font-weight: 600;
  margin-bottom: 16px; padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 10px 13px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input); color: var(--text);
  outline: none;
  transition: border-color .15s;
  width: 100%;
  min-height: 44px;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--accent);
  background: #fff;
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-actions {
  display: flex; gap: 10px;
  justify-content: flex-end;
  margin-top: 16px; flex-wrap: wrap;
}

/* ============================================================
   РЕДАКТОР ХАРАКТЕРИСТИК — mobile-first
   ============================================================ */
.specs-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}

/* Одна строка характеристики */
.se-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}
.se-row:last-of-type { border-bottom: none; }

/* Два поля рядом (ключ + значение) */
.se-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* Инпуты редактора */
.se-input {
  width: 100%;
  padding: 10px 13px;
  font-size: 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  outline: none;
  min-height: 44px;
  transition: border-color .15s;
}
.se-input:focus { border-color: var(--accent); background: #fff; }

/* Кнопка удаления строки */
.se-del-btn {
  align-self: flex-start;
  padding: 6px 12px;
  font-size: 13px;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  background: var(--red-bg);
  color: var(--red);
  cursor: pointer;
  min-height: 36px;
}
.se-del-btn:active { opacity: .75; }

/* Блок добавления */
.se-add-block {
  padding: 14px;
  background: #f8f9fb;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.se-add-label {
  font-size: 13px; font-weight: 600; color: var(--text-muted);
}

/* Кнопка добавить */
.se-add-btn {
  padding: 10px 18px;
  font-size: 14px; font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  min-height: 44px;
  width: 100%;
}
.se-add-btn:active { background: var(--accent-dark); }

/* === ФИЛЬТР-СТРОКА === */
.filter-bar {
  display: flex; flex-wrap: wrap;
  gap: 8px; margin-bottom: 16px; align-items: center;
}
.filter-bar input,
.filter-bar select {
  padding: 9px 13px; font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card); color: var(--text);
  outline: none; min-height: 42px;
}
.filter-bar input { flex: 1; min-width: 180px; }
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--accent); }

/* === АЛЕРТЫ === */
.alert { padding: 12px 16px; border-radius: var(--radius); font-size: 14px; margin-bottom: 14px; }
.alert-info    { background: var(--blue-bg);   color: var(--blue);   border: 1px solid #93c5fd; }
.alert-success { background: var(--green-bg);  color: var(--green);  border: 1px solid #86efac; }
.alert-warning { background: var(--yellow-bg); color: var(--yellow); border: 1px solid #fde68a; }
.alert-danger  { background: var(--red-bg);    color: var(--red);    border: 1px solid #fca5a5; }

/* === МОДАЛЬНОЕ ОКНО === */
.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 500;
  align-items: flex-start;
  justify-content: center;
  padding: 20px 12px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-backdrop.open { display: flex; }
.modal-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  width: 100%; max-width: 540px;
  padding: 22px;
  position: relative;
  margin: auto;
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 18px; padding-right: 30px; }
.modal-close {
  position: absolute; top: 16px; right: 16px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); font-size: 22px; line-height: 1;
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { color: var(--text); }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; flex-wrap: wrap; }

/* === ЦЕННИКИ — тоглы === */
.spec-toggle-list { display: flex; flex-direction: column; gap: 6px; }
.spec-toggle-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-page); font-size: 13px;
}
.spec-toggle-item.on { border-color: #93c5fd; background: var(--blue-bg); }
.spec-toggle-key  { flex: 1; font-weight: 600; }
.spec-toggle-val  { flex: 2; color: var(--text-muted); font-size: 12px; }
.toggle-sw { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-sw input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0;
  background: #d1d5db; border-radius: 11px;
  cursor: pointer; transition: background .2s;
}
.toggle-sw input:checked + .toggle-track { background: var(--accent); }
.toggle-track::after {
  content: '';
  position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff; border-radius: 50%;
  transition: transform .2s;
}
.toggle-sw input:checked + .toggle-track::after { transform: translateX(18px); }

/* === ПРЕДПРОСМОТР ЦЕННИКА === */
.pricetag-preview {
  border: 2px solid var(--text);
  border-radius: 6px;
  padding: 12px 14px;
  display: inline-block; min-width: 180px;
}
.pt-name  { font-size: 11.5px; color: var(--text-muted); margin-bottom: 2px; }
.pt-price { font-size: 26px; font-weight: 700; margin-bottom: 4px; }
.pt-specs { border-top: 1px solid var(--border); padding-top: 5px; margin-top: 5px; }
.pt-spec-row { display: flex; justify-content: space-between; font-size: 11px; gap: 8px; margin-bottom: 2px; }
.pt-spec-k { color: var(--text-muted); }
.pt-spec-v { font-weight: 600; }
.pt-sku    { font-size: 10.5px; color: var(--text-muted); margin-top: 4px; font-family: monospace; }
.pt-bar    { font-family: monospace; font-size: 11px; letter-spacing: 2.5px; margin-top: 3px; color: var(--text-muted); }

/* Карточки ценников */
.ptcard {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px; cursor: pointer; background: var(--bg-card);
}
.ptcard.selected { border: 2px solid var(--accent); background: var(--blue-bg); }

/* === LOW STOCK BOX === */
.low-stock-box {
  background: var(--yellow-bg);
  border: 1px solid #fde68a;
  border-radius: var(--radius-lg);
  padding: 14px 16px;
}
.low-stock-box .low-item {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 6px 0;
  border-bottom: 1px solid #fde68a;
  flex-wrap: wrap;
}
.low-stock-box .low-item:last-child { border-bottom: none; }

/* === УТИЛИТЫ === */
.text-muted   { color: var(--text-muted); }
.text-sm      { font-size: 13px; }
.font-mono    { font-family: 'SFMono-Regular', Consolas, monospace; }
.fw-600       { font-weight: 600; }
.mt-1         { margin-top: 8px; }
.mt-2         { margin-top: 16px; }
.d-flex       { display: flex; }
.gap-2        { gap: 8px; }
.gap-3        { gap: 12px; }
.flex-wrap    { flex-wrap: wrap; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-100        { width: 100%; }

/* ============================================================
   АДАПТИВ — планшет (≤ 900px)
   ============================================================ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; }
  .hamburger { display: inline-flex; }
  .content-area { padding: 14px; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
}

/* ============================================================
   АДАПТИВ — телефон (≤ 600px)
   ============================================================ */
@media (max-width: 600px) {
  html { font-size: 15px; }

  .topbar { padding: 0 10px; gap: 6px; }
  .topbar-title { font-size: 15px; }
  .topbar-actions .btn { padding: 8px 11px; font-size: 13px; }

  .content-area { padding: 10px; }

  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 14px; }
  .metric-card { padding: 12px; }
  .metric-value { font-size: 22px; }
  .metric-label { font-size: 11px; }

  /* Таблицы — горизонтальный скролл */
  .table-wrap { border-radius: var(--radius); }
  .table-wrap table { min-width: 560px; font-size: 13px; }
  thead th { padding: 9px 10px; }
  tbody td { padding: 9px 10px; }

  /* Формы — одна колонка */
  .form-grid { grid-template-columns: 1fr; gap: 12px; }
  .form-section { padding: 14px; }
  .form-group input,
  .form-group select,
  .form-group textarea { font-size: 16px; } /* 16px — убирает авtozoom на iOS */

  /* Кнопки крупнее для тач */
  .btn { min-height: 44px; padding: 10px 14px; font-size: 14px; }
  .btn-sm { min-height: 40px; padding: 8px 12px; }

  /* Редактор характеристик */
  .se-input { font-size: 16px; } /* без autozoom */

  /* Фильтр */
  .filter-bar { gap: 8px; }
  .filter-bar input { min-width: 0; font-size: 16px; }
  .filter-bar select { font-size: 16px; }

  /* Модалки — на весь экран снизу */
  .modal-backdrop { padding: 10px 0 0 0; align-items: flex-end; }
  .modal-box {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: 20px 16px 32px;
    max-height: 92vh;
    overflow-y: auto;
  }

  /* Ценники */
  .ptcard { padding: 12px; }
  .spec-toggle-val { display: none; } /* скрываем значение на мелком экране */

  /* form-actions */
  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; justify-content: center; }
}

/* ============================================================
   ПЕЧАТЬ
   ============================================================ */
@media print {
  .sidebar, .topbar, .filter-bar,
  .topbar-actions, .btn, .spec-toggle-list,
  .no-print { display: none !important; }
  body { background: #fff; }
  .main-content { margin: 0; }
  .content-area { padding: 0; }
  .pricetag-preview { page-break-inside: avoid; }
}
