/* ============================================================
   WB Полки — v2-дизайн, портирован из mp-system (style-v2.css).
   Верхний тулбар, две темы: data-theme="light" | "dark" на <html>.
   Секция 1 — токены и хром v2; секция 2 — компоненты WB Полки.
   ============================================================ */

:root, [data-theme="light"] {
    --accent: #5A4BF2;
    --accent-hover: #4A3CE0;
    --accent-soft: #EEEDFD;
    --accent-on-soft: #4A3CE0;
    --pos: #0E9F6E;
    --pos-bg: #E6F6EF;
    --neg: #E5484D;
    --neg-bg: #FCEDED;
    --info: #1F6BFF;
    --info-bg: #EAF1FF;
    --warn: #B97D12;
    --warn-bg: #FBF3E4;

    --bg: #F6F7F9;
    --topbar: #FFFFFF;
    --surface: #FFFFFF;
    --border: #ECEEF1;
    --border-strong: #E2E5EA;
    --row-sep: #F1F2F5;
    --text: #16181D;
    --text-2: #5A6072;
    --muted: #8B92A1;
    --col-head: #9AA0AB;
    --track: #EFF0F3;
    --menu-hover: #F5F6F8;

    --shadow-card: 0 1px 2px rgba(16,24,40,.04), 0 18px 44px -20px rgba(16,24,40,.16);
    --shadow-menu: 0 14px 36px -10px rgba(16,24,40,.28);
    --shadow-accent: 0 4px 14px -4px rgba(90,75,242,.6);

    --mono: 'JetBrains Mono', ui-monospace, monospace;
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: var(--shadow-card);
    --scrim: rgba(16,18,29,.4);
}

[data-theme="dark"] {
    --accent: #7E72FF;
    --accent-hover: #6E63FF;
    --accent-soft: #221E48;
    --accent-on-soft: #C9C3FF;
    --pos: #2BD68A;
    --pos-bg: #0F2A1E;
    --neg: #FF5A5F;
    --neg-bg: #2A1518;
    --info: #5B96FF;
    --info-bg: #14233B;
    --warn: #F0A23B;
    --warn-bg: #2A2113;

    --bg: #0C0D11;
    --topbar: #101116;
    --surface: #15161D;
    --border: #23252F;
    --border-strong: #2A2D38;
    --row-sep: #20222B;
    --text: #F4F4F8;
    --text-2: #9A9DAC;
    --muted: #7A7E8C;
    --col-head: #6B6E7D;
    --track: #2A2D38;
    --menu-hover: #23252F;

    --shadow-card: 0 1px 2px rgba(0,0,0,.2), 0 18px 50px -20px rgba(0,0,0,.5);
    --shadow-menu: 0 14px 36px -10px rgba(0,0,0,.5);
    --shadow-accent: 0 4px 14px -4px rgba(90,75,242,.6);
    --scrim: rgba(6,7,10,.62);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body.v2 {
    font-family: 'Golos Text', -apple-system, system-ui, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-variant-numeric: tabular-nums;
}
@keyframes v2fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Топ-бар ---------------- */
.v2-topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 11px 16px;
    background: var(--topbar);
    border-bottom: 1px solid var(--border);
    flex-wrap: nowrap;
    position: sticky; top: 0; z-index: 50;
}
.v2-brand { display: flex; align-items: center; gap: 9px; }
.v2-logo {
    width: 30px; height: 30px; border-radius: 9px;
    background: linear-gradient(135deg, #6E63FF, #5A4BF2);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 800; font-size: 15px;
}
.v2-brand-name { font-weight: 700; font-size: 16px; letter-spacing: -.01em; color: var(--text); white-space: nowrap; }
.v2-brand-tag { font-size: 10px; font-weight: 700; color: var(--accent-on-soft); background: var(--accent-soft); border-radius: 6px; padding: 2px 6px; white-space: nowrap; }

.v2-nav { display: flex; align-items: center; gap: 2px; flex-wrap: nowrap; }
.v2-nav a {
    font-size: 13px; font-weight: 500; color: var(--muted); white-space: nowrap;
    border-radius: 9px; padding: 6px 9px; cursor: pointer; text-decoration: none;
    user-select: none;
    transition: background .12s, color .12s;
}
.v2-nav a:hover { background: var(--menu-hover); color: var(--text); }
.v2-nav a.active { font-weight: 600; color: var(--accent-on-soft); background: var(--accent-soft); }

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

@media (max-width: 1280px) {
    .v2-topbar, .v2-nav, .v2-controls { flex-wrap: wrap; }
    .v2-spacer { flex-basis: 100%; height: 0; }
}

/* Контролы тулбара */
.v2-controls { display: flex; align-items: center; gap: 8px; flex-wrap: nowrap; }
.v2-tbtn {
    display: flex; align-items: center; gap: 7px; white-space: nowrap; flex-shrink: 0;
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: 11px; padding: 7px 10px; cursor: pointer;
    font: inherit; font-size: 13px; font-weight: 600; color: var(--text);
    text-decoration: none;
}
.v2-tbtn:hover { border-color: var(--accent); }
.v2-tbtn .caret { color: var(--muted); font-size: 10px; }
.v2-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }

.v2-theme-btn {
    width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0;
    border: 1px solid var(--border-strong); background: var(--surface);
    color: var(--text-2); cursor: pointer; font-size: 15px;
    display: flex; align-items: center; justify-content: center;
}
.v2-theme-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Дропдаун */
.v2-menu-wrap { position: relative; }
.v2-menu {
    position: absolute; top: calc(100% + 6px); left: 0; z-index: 60;
    min-width: 212px; background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: 12px; box-shadow: var(--shadow-menu); padding: 6px;
    display: none; animation: v2fade .14s ease both;
}
.v2-menu.right { left: auto; right: 0; min-width: 232px; }
.v2-menu-wrap.open .v2-menu { display: block; }
.v2-menu-group { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 9px 10px 4px; }
.v2-menu a {
    display: flex; align-items: center; gap: 9px; width: 100%;
    border-radius: 8px; padding: 8px 10px; text-decoration: none; cursor: pointer;
    font-size: 13px; font-weight: 500; color: var(--text);
}
.v2-menu a:hover, .v2-menu a.sel { background: var(--menu-hover); }
.v2-menu a .check { margin-left: auto; color: var(--accent); font-size: 12px; }

/* ---------------- Контент ---------------- */
.v2-main { padding: 22px 24px 40px; max-width: 1160px; width: 100%; margin: 0 auto; flex: 1; animation: v2fade .5s both; }
.v2-page-head { margin-bottom: 18px; }
.v2-page-head h1 { font-size: 23px; font-weight: 700; letter-spacing: -.02em; margin: 0; color: var(--text); }
.v2-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

/* Футер */
.v2-footer { border-top: 1px solid var(--border); background: var(--topbar); }
.v2-footer-inner {
    max-width: 1160px; margin: 0 auto; padding: 14px 24px;
    display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
}
.v2-footer-brand { font-size: 13px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 7px; }
.v2-footer-meta { margin-left: auto; font-size: 12px; color: var(--muted); }

/* Тост */
.v2-toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); z-index: 240; background: #16181D; color: #fff; font-size: 13px; font-weight: 500; padding: 11px 18px; border-radius: 12px; box-shadow: 0 12px 30px -8px rgba(0,0,0,.45); display: none; align-items: center; gap: 10px; }
.v2-toast.show { display: flex; animation: v2fade .2s ease both; }
.v2-toast .v2-dot { background: #34D399; width: 8px; height: 8px; }

/* ============================================================
   ===== WB Полки components =====
   ============================================================ */

/* Панели (SPA) */
.panel { display: none; }
.panel.active { display: block; animation: v2fade .3s ease both; }

/* Формы */
.form-row { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; align-items: flex-end; }
.form-group { flex: 1; min-width: 160px; }
.form-group.narrow { max-width: 200px; }
.form-label {
    display: block; font-size: 11px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .07em;
    color: var(--col-head); margin-bottom: 6px;
}
select, input[type=text] {
    width: 100%; padding: 9px 12px;
    background: var(--surface); border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm); color: var(--text);
    font-family: inherit; font-size: 13.5px; outline: none;
    transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input::placeholder { color: var(--muted); }
input[type=checkbox] { accent-color: var(--accent); }

/* Кнопки */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px; background: var(--accent);
    border: none; border-radius: var(--radius-sm); color: #fff;
    font-family: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; white-space: nowrap;
    box-shadow: var(--shadow-accent);
    transition: background .15s, transform .1s;
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-sm { padding: 7px 13px; font-size: 12.5px; }
.btn-outline { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text-2); box-shadow: none; }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-on-soft); background: var(--accent-soft); }
.btn-danger { background: var(--neg); box-shadow: none; }
.btn-danger:hover { background: #D93036; }

/* Чипсы */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.chip {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 12px; background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: 20px;
    font-size: 12.5px; cursor: pointer; transition: all .15s;
    font-weight: 500; color: var(--text-2);
}
.chip:hover { border-color: var(--accent); color: var(--accent-on-soft); }
.chip .chip-label { font-family: var(--mono); font-size: 12px; color: var(--muted); }

/* Мета скана */
.scan-meta {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; padding: 12px 16px; margin-bottom: 20px;
    display: flex; justify-content: space-between; flex-wrap: wrap; gap: 6px;
    font-size: 12.5px; color: var(--muted);
}
.scan-meta span { font-family: var(--mono); font-weight: 500; color: var(--text); }

/* Стат-карточки */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 22px; }
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 14px; text-align: center;
    cursor: pointer; transition: border-color .15s, transform .1s;
}
.stat-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.stat-card.active { border-color: var(--accent); background: var(--accent-soft); }
.stat-card .label {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .07em; color: var(--col-head); margin-bottom: 8px;
}
.stat-card .value { font-family: var(--mono); font-size: 24px; font-weight: 700; line-height: 1; color: var(--text); }
.stat-card .pct { font-size: 12px; color: var(--muted); margin-top: 5px; font-family: var(--mono); }

/* Прогресс + пороговые цвета */
.progress-bar { height: 4px; background: var(--track); border-radius: 2px; margin-top: 10px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 2px; transition: width .5s ease; }
.pf-5   { background: var(--pos); }
.pf-10  { background: var(--info); }
.pf-30  { background: var(--accent); }
.pf-50  { background: var(--warn); }
.pf-100 { background: var(--neg); }

/* Дельты */
.delta { font-family: var(--mono); font-size: 11.5px; margin-top: 4px; font-weight: 600; }
.d-up { color: var(--pos); }
.d-dn { color: var(--neg); }
.d-eq { color: var(--muted); }

/* Карточка с таблицей */
.detail-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    margin-bottom: 20px; animation: v2fade .25s ease both;
}
.detail-header {
    padding: 14px 20px; border-bottom: 1px solid var(--row-sep);
    display: flex; justify-content: space-between; align-items: center;
    gap: 10px; flex-wrap: wrap;
}
.detail-header h3 { font-size: 14px; font-weight: 700; margin: 0; }
.badge {
    font-family: var(--mono); font-size: 12px; font-weight: 600;
    background: var(--accent-soft); color: var(--accent-on-soft);
    padding: 3px 10px; border-radius: 12px;
}

.detail-card table { width: 100%; border-collapse: collapse; }
.detail-card th {
    text-align: left; padding: 11px 20px;
    font-size: 11px; font-weight: 600; color: var(--col-head);
    text-transform: uppercase; letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
}
.detail-card td { padding: 10px 20px; font-size: 13.5px; border-bottom: 1px solid var(--row-sep); }
.detail-card tr:last-child td { border-bottom: none; }
.detail-card tbody tr:hover td { background: var(--menu-hover); }
.pos-c { font-family: var(--mono); font-weight: 600; color: var(--pos); width: 50px; }
.nm-c  { font-family: var(--mono); font-weight: 500; }
.nm-c a { color: var(--accent); text-decoration: none; }
.nm-c a:hover { text-decoration: underline; }
.br-c  { color: var(--muted); }

/* Теги статусов */
.tag { font-size: 11px; padding: 2px 10px; border-radius: 12px; display: inline-block; font-weight: 600; }
.tag-new  { background: var(--pos-bg);  color: var(--pos); }
.tag-up   { background: var(--info-bg); color: var(--info); }
.tag-down { background: var(--neg-bg);  color: var(--neg); }
.tag-gone { background: var(--neg-bg);  color: var(--neg); }
.tag-same { background: var(--track);   color: var(--muted); }

/* Загрузка */
.loading { display: none; text-align: center; padding: 48px; }
.spinner {
    width: 24px; height: 24px;
    border: 2.5px solid var(--border-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 0 auto 10px;
}
.loading-text { color: var(--muted); font-size: 13px; }

/* Мои артикулы */
.art-form { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; }
.art-form input { flex: 1; min-width: 160px; }
.art-table { width: 100%; }
.art-table td { padding: 12px 20px; }
.art-table .art-nm { font-family: var(--mono); color: var(--accent); font-size: 13.5px; font-weight: 500; }
.art-table .art-label { color: var(--muted); font-size: 13px; }
.art-table .art-actions { text-align: right; }

/* ============================================================
   Мобильная версия (≤640px): бургер + drawer, липкая строка
   с выбором базы, нижняя шторка. Десктоп не меняется.
   ============================================================ */
.v2-burger, .v2-mobile-bar, .v2-drawer, .v2-sheet, .v2-scrim { display: none; }

@media (max-width: 640px) {
    .v2-main { padding: 16px 14px 34px; }
    body.v2-lock { overflow: hidden; }

    /* Шапка: бургер + лого */
    .v2-topbar { flex-wrap: nowrap; gap: 10px; padding: 9px 14px; }
    .v2-nav, .v2-controls { display: none; }
    .v2-spacer { flex: 1; flex-basis: auto; height: auto; min-width: 0; }
    .v2-burger {
        display: flex; flex-direction: column; justify-content: center; gap: 4px;
        width: 38px; height: 38px; flex-shrink: 0; padding: 0 9px;
        background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; cursor: pointer;
    }
    .v2-burger span { display: block; height: 2px; border-radius: 2px; background: var(--text); }

    /* Липкая строка: выбор базы */
    .v2-mobile-bar {
        display: flex; align-items: center; gap: 10px;
        position: sticky; top: 56px; z-index: 40;
        padding: 9px 14px; background: var(--bg); border-bottom: 1px solid var(--border);
    }
    .v2-mobile-bar .v2-tbtn { flex: 1; min-width: 0; }
    .v2-mobile-bar .v2-tbtn span:nth-child(2) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .v2-mobile-bar .v2-tbtn .caret { margin-left: auto; }

    /* Затемнение */
    .v2-scrim {
        display: block; position: fixed; inset: 0; z-index: 90; background: var(--scrim);
        opacity: 0; visibility: hidden; transition: opacity .25s;
    }
    .v2-scrim.show { opacity: 1; visibility: visible; }

    /* Drawer навигации */
    .v2-drawer {
        display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0;
        width: 82%; max-width: 320px; z-index: 100; overflow-y: auto;
        background: var(--surface); border-right: 1px solid var(--border-strong);
        transform: translateX(-100%); transition: transform .28s cubic-bezier(.4,0,.2,1);
    }
    .v2-drawer.open { transform: none; }
    .v2-drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
    .v2-x { background: none; border: none; color: var(--muted); font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px; }
    .v2-drawer-nav { flex: 1; padding: 8px; overflow-y: auto; }
    .v2-drawer-nav a { display: block; padding: 11px 12px; border-radius: 10px; text-decoration: none; font-size: 14px; font-weight: 500; color: var(--text-2); cursor: pointer; }
    .v2-drawer-nav a:active { background: var(--menu-hover); }
    .v2-drawer-nav a.active { font-weight: 600; color: var(--accent-on-soft); background: var(--accent-soft); }
    .v2-drawer-group { font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: 14px 12px 5px; }
    .v2-drawer-foot { padding: 14px 16px; border-top: 1px solid var(--border); font-size: 12px; color: var(--muted); }

    /* Нижняя шторка: выбор базы + тема */
    .v2-sheet {
        display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 100;
        background: var(--surface); border-top: 1px solid var(--border-strong);
        border-radius: 22px 22px 0 0; box-shadow: var(--shadow-menu);
        padding: 8px 16px calc(18px + env(safe-area-inset-bottom)); max-height: 84vh; overflow-y: auto;
        transform: translateY(100%); transition: transform .3s cubic-bezier(.4,0,.2,1);
    }
    .v2-sheet.open { transform: none; }
    .v2-sheet-handle { width: 40px; height: 4px; border-radius: 3px; background: var(--border-strong); margin: 4px auto 10px; }
    .v2-sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 16px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
    .v2-sheet-block { padding: 12px 0; border-top: 1px solid var(--row-sep); }
    .v2-sheet-block:first-of-type { border-top: none; }
    .v2-sheet-label { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 9px; }
    .v2-sheet-stores { display: flex; flex-direction: column; gap: 2px; }
    .v2-sheet-store { display: flex; align-items: center; gap: 10px; padding: 11px 10px; border-radius: 10px; text-decoration: none; font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer; }
    .v2-sheet-store.sel { background: var(--menu-hover); }
    .v2-sheet-store .check { margin-left: auto; color: var(--accent); }
    .v2-sheet-row {
        display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
        padding: 12px 10px; border-radius: 10px; background: none; border: none;
        font: inherit; font-size: 14px; font-weight: 500; color: var(--text); cursor: pointer;
    }

    /* Компоненты приложения на мобилке */
    .v2-page-head h1 { font-size: 21px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-grid > .stat-card:last-child:nth-child(odd) { grid-column: 1 / -1; }
    .form-row { flex-direction: column; align-items: stretch; }
    .form-group.narrow { max-width: 100%; }
    .detail-card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .detail-card table { min-width: 560px; }
    .detail-card th, .detail-card td { padding: 10px 12px; }

    /* Футер компактный */
    .v2-footer-inner { flex-direction: column; gap: 8px; text-align: center; padding: 16px 14px; }
    .v2-footer-meta { margin-left: 0; }
}

/* Планшет: слегка ужимаем отступы */
@media (min-width: 641px) and (max-width: 1024px) {
    .v2-main { padding: 20px 18px 36px; }
}
