:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #e3e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; width: 100%; }
.main-area { flex: 1; padding: 24px 16px; }

.topbar { background: #fff; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { background: var(--accent); color: #fff; width: 30px; height: 30px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
.nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.nav a { padding: 6px 10px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: #f1f5f9; color: var(--text); text-decoration: none; }
.nav a.active { color: var(--accent); background: transparent; box-shadow: inset 0 0 0 1px var(--accent); }
.nav-user { color: var(--muted); padding: 0 6px; font-size: 14px; }

.btn { display: inline-block; background: var(--accent); color: #fff; border: none; padding: 8px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-outline { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-outline:hover { background: #f1f5f9; color: var(--text); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: #f1f5f9; color: var(--text); }
.btn-ghost:hover { background: #e2e8f0; }
.btn-block { width: 100%; }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 500; }
.flash-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.hero { text-align: center; padding: 28px 0 8px; }
.hero h1 { margin: 0 0 4px; font-size: 28px; }
.hero-sub { color: var(--muted); margin: 0 0 20px; }
.search-form { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 24px; }
.search-form input[type=text] { min-width: 280px; width: auto; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.card-cat { color: var(--accent); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card-title { margin: 0; font-size: 17px; }
.card-sku { color: var(--muted); font-size: 13px; }
.card-desc { margin: 0; color: var(--muted); font-size: 13px; }
.card-bottom { margin-top: auto; padding-top: 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.price { font-weight: 700; font-size: 18px; white-space: nowrap; }

.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-in { background: #ecfdf5; color: #065f46; }
.badge-low { background: #fffbeb; color: #92400e; }
.badge-out { background: #fef2f2; color: #991b1b; }
.badge-muted { background: #f1f5f9; color: var(--muted); }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { margin: 0; font-size: 22px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; }
.panel h2 { margin: 0 0 12px; font-size: 17px; }

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; font-size: 14px; vertical-align: middle; }
.table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:hover { background: #f8fafc; }
.table .num { text-align: right; white-space: nowrap; }
.table .actions { white-space: nowrap; text-align: right; }

label { display: block; margin-bottom: 12px; font-weight: 500; font-size: 14px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  margin-top: 4px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--accent); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.inline-form { display: inline; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat .stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .stat-value { font-size: 22px; font-weight: 700; margin-top: 4px; }

.auth-box { max-width: 420px; margin: 40px auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px; }
.auth-box h1 { margin: 0 0 16px; font-size: 20px; }

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

.welcome-hero { text-align: center; padding: 64px 16px; }
.welcome-text { font-size: 26px; font-weight: 700; margin: 8px 0; color: var(--text); }
.welcome-sub { color: var(--muted); margin: 0 0 20px; }

/* Чат в заявках */
.chat-panel h2 { margin-bottom: 10px; }
.chat-box { max-height: 320px; overflow-y: auto; padding: 4px 2px; margin-bottom: 12px; }
.chat-msg { background: #f1f5f9; border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; margin: 8px 0; max-width: 78%; }
.chat-mine { background: #e0f2fe; border-color: #bae6fd; margin-left: auto; text-align: right; }
.chat-head { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.chat-text { white-space: pre-wrap; }
.chat-form { display: flex; gap: 8px; align-items: flex-start; }
.chat-form textarea { flex: 1; resize: vertical; min-height: 48px; }

/* Уведомления на Обзоре */
.notes-list { margin: 8px 0 0; padding-left: 4px; list-style: none; }
.notes-list li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.notes-list li:last-child { border-bottom: none; }
.notes-list a { font-weight: 600; }

/* Печать прайс-листа */
@media print {
  .topbar, .page-head .toolbar, .footer { display: none !important; }
  body { background: #fff; }
  .panel { border: none; padding: 0; }
}

/* Групповая строка (сворачиваемая накладная) */
.group-row { background: #f8fafc; }
.group-row:hover { background: #eef2f7; }

/* ================== Тёмная тема ================== */
[data-theme="dark"] {
  --bg: #0f1420;
  --panel: #1a2233;
  --border: #2c3648;
  --text: #e5eaf2;
  --muted: #93a0b4;
  --accent: #3b82f6;
  --accent-dark: #2563eb;
}
[data-theme="dark"] body { background: var(--bg); color: var(--text); }
[data-theme="dark"] .topbar { background: var(--panel); border-color: var(--border); }
[data-theme="dark"] .brand { color: var(--text); }
[data-theme="dark"] .panel,
[data-theme="dark"] .card,
[data-theme="dark"] .stat { background: var(--panel); border-color: var(--border); }
[data-theme="dark"] .stat-value { color: var(--text); }
[data-theme="dark"] .table { color: var(--text); }
[data-theme="dark"] .table th { background: #232c3f; color: var(--muted); border-color: var(--border); }
[data-theme="dark"] .table td { border-color: var(--border); }
[data-theme="dark"] input[type=text], [data-theme="dark"] input[type=number],
[data-theme="dark"] input[type=password], [data-theme="dark"] input[type=date],
[data-theme="dark"] input[type=email], [data-theme="dark"] select, [data-theme="dark"] textarea {
  background: #232c3f; border-color: #374151; color: #e5eaf2;
}
[data-theme="dark"] input::placeholder, [data-theme="dark"] textarea::placeholder { color: #6b7a92; }
[data-theme="dark"] a { color: #7dd3fc; }
[data-theme="dark"] .badge-in { background: #14532d; color: #bbf7d0; }
[data-theme="dark"] .badge-out { background: #7f1d1d; color: #fecaca; }
[data-theme="dark"] .badge-low { background: #78350f; color: #fde68a; }
[data-theme="dark"] .badge-muted { background: #334155; color: #cbd5e1; }
[data-theme="dark"] .group-row { background: #202a3d; }
[data-theme="dark"] .group-row:hover { background: #27334a; }
[data-theme="dark"] .chat-msg { background: #232c3f; border-color: #374151; }
[data-theme="dark"] .chat-mine { background: #1e3a5f; border-color: #274b76; }
[data-theme="dark"] .hero { background: var(--panel); border-color: var(--border); }
[data-theme="dark"] .flash { background: #232c3f; border-color: #374151; color: #e5eaf2; }
[data-theme="dark"] .btn-ghost { background: #232c3f; color: #cbd5e1; }
[data-theme="dark"] .btn-outline { background: transparent; color: #7dd3fc; border-color: #2f4a6b; }
[data-theme="dark"] .btn-danger { background: #7f1d1d; }
[data-theme="dark"] select option:checked, [data-theme="dark"] select option:hover { background: #a16207; color: #fff; }
[data-theme="dark"] .nav a:hover { background: #232c3f; color: var(--text); }
[data-theme="dark"] .nav a.active { color: #7dd3fc; box-shadow: inset 0 0 0 1px #2f4a6b; }
[data-theme="dark"] .table tbody tr:hover { background: var(--panel); box-shadow: inset 0 0 0 1px var(--accent); }
[data-theme="dark"] .btn-outline:hover { background: #232c3f; color: var(--text); }

/* Гистограммы продаж за неделю (Отчёты): дни горизонтально, столбики вверх */
.week-row { display: flex; gap: 16px; align-items: flex-start; padding: 12px 0; border-bottom: 1px dashed var(--border); }
.week-row:last-child { border-bottom: none; }
.week-name { width: 240px; min-width: 180px; font-size: 14px; }
.week-name .card-sku { margin-top: 2px; }
.week-block { flex: 1; min-width: 240px; }
.week-chart { display: flex; align-items: flex-end; gap: 6px; height: 80px; border-bottom: 2px solid var(--border); padding: 0 2px; }
.week-cell { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; }
.week-bar { width: 72%; max-width: 44px; background: var(--accent); border-radius: 5px 5px 0 0; min-height: 3px; }
.week-bar.zero { background: #c9d3e0; }
.week-val { font-size: 11px; color: var(--text); line-height: 1.1; margin-bottom: 3px; font-weight: 600; }
.week-days { display: flex; gap: 6px; padding: 3px 2px 0; }
.week-days span { flex: 1; min-width: 0; text-align: center; font-size: 11px; color: var(--muted); }
@media print {
  .week-row { break-inside: avoid; }
}
@media (max-width: 760px) {
  .week-row { flex-direction: column; gap: 6px; }
  .week-name { width: auto; }
  .week-chart { height: 64px; }
}

.footer { border-top: 1px solid var(--border); background: #fff; padding: 14px 0; color: var(--muted); font-size: 13px; margin-top: 24px; }

/* ================== Мобильная версия ================== */
@media (max-width: 760px) {
  body { font-size: 16px; }
  .wrap { padding: 0 12px; }
  .main-area { padding: 16px 12px; }

  /* Меню — компактный скролл в один ряд */
  .nav { display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch; gap: 4px; padding-bottom: 4px; scrollbar-width: none; flex-wrap: nowrap; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 9px 12px; white-space: nowrap; flex: 0 0 auto; }

  /* Панели и заголовки */
  .page-head h1 { font-size: 20px; }
  .panel { padding: 14px; margin-bottom: 14px; }
  .hero { padding: 24px 8px; }

  /* Формы: удобный ввод, без автозума iOS */
  input[type=text], input[type=number], input[type=password], input[type=date], input[type=email], select, textarea {
    font-size: 16px;
    padding: 10px 12px;
    min-height: 44px;
  }
  input[type=text] { min-width: 0; width: 100%; max-width: 420px; }
  .btn { min-height: 44px; padding: 10px 16px; font-size: 16px; }
  .btn-sm { min-height: 38px; padding: 7px 12px; font-size: 14px; }
  label { margin-bottom: 10px; }

  /* Таблицы: компактнее, прокрутка в панели */
  .table { font-size: 14px; }
  .table th, .table td { padding: 8px; }
  .table .actions { white-space: nowrap; }

  /* Каталог и поиск */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 12px; }
  .search-form { align-items: stretch; }
  .search-form input { width: 100%; max-width: none; }
  .search-form select { flex: 1; }

  /* Чат */
  .chat-msg { max-width: 92%; }
  .chat-form { flex-direction: column; }
  .chat-form textarea { width: 100%; }
  .chat-form button { width: 100%; }
}

@media (max-width: 420px) {
  .cards { grid-template-columns: 1fr; }
}

/* Выбранная опция в выпадающих списках — жёлтая подсветка (в т.ч. выбор товара в заявках) */
select option:checked,
select option:hover {
  background: #fde68a;
  color: #1f2937;
}
