/* ── Тема: Синяя (по умолчанию) ── */
:root, body.theme-blue {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-btn-text: #fff;
    --success: #16a34a;
    --warning: #f59e0b;
    --danger: #dc2626;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --sidebar-bg: #1e293b;
    --sidebar-text: #e2e8f0;
    --sidebar-hover: #334155;
    --sidebar-border: #334155;
    --sidebar-muted: #94a3b8;
    --sidebar-link: #cbd5e1;
    --sidebar-section: #64748b;
    --focus-ring: rgba(37, 99, 235, 0.15);
}

/* ── Тема: Жёлтая ── */
body.theme-yellow {
    --primary: #eab308;
    --primary-dark: #ca8a04;
    --primary-btn-text: #1c1917;
    --bg: #fefce8;
    --text: #1c1917;
    --text-muted: #78716c;
    --border: #e7e5e4;
    --sidebar-bg: #292524;
    --sidebar-text: #e7e5e4;
    --sidebar-hover: #44403c;
    --sidebar-border: #44403c;
    --sidebar-muted: #a8a29e;
    --sidebar-link: #d6d3d1;
    --sidebar-section: #78716c;
    --focus-ring: rgba(234, 179, 8, 0.2);
}

/* ── Тема: Красная ── */
body.theme-red {
    --primary: #dc2626;
    --primary-dark: #b91c1c;
    --primary-btn-text: #fff;
    --bg: #fef2f2;
    --text: #1c1917;
    --text-muted: #78716c;
    --border: #e7e5e4;
    --sidebar-bg: #1c1917;
    --sidebar-text: #fecaca;
    --sidebar-hover: #44403c;
    --sidebar-border: #44403c;
    --sidebar-muted: #a8a29e;
    --sidebar-link: #d6d3d1;
    --sidebar-section: #78716c;
    --focus-ring: rgba(220, 38, 38, 0.15);
}


* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 20px 0;
    flex-shrink: 0;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
}

.sidebar .logo {
    padding: 0 20px 20px;
    font-size: 18px;
    font-weight: 700;
    border-bottom: 1px solid var(--sidebar-border);
    margin-bottom: 10px;
}

.sidebar .logo small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--sidebar-muted);
    margin-top: 2px;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--sidebar-link);
    text-decoration: none;
    font-size: 14px;
    transition: background 0.15s;
}

.sidebar nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar nav a.active { background: var(--primary); color: var(--primary-btn-text); }
.sidebar nav a .icon { width: 20px; text-align: center; }

.sidebar .nav-section {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--sidebar-section);
    padding: 15px 20px 5px;
}

/* Main */
.main {
    margin-left: 240px;
    flex: 1;
    padding: 24px 32px;
    min-height: 100vh;
}

/* Page header */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 {
    font-size: 24px;
    font-weight: 700;
}

/* Cards */
.card {
    background: var(--card);
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    padding: 20px;
    margin-bottom: 20px;
}

.card h3 {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* Summary cards row */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--card);
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.summary-card .label {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.summary-card .value {
    font-size: 28px;
    font-weight: 700;
}

.summary-card .value.primary { color: var(--primary); }
.summary-card .value.success { color: var(--success); }
.summary-card .value.warning { color: var(--warning); }

/* Grid layout */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* Tables */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

thead th {
    text-align: left;
    padding: 10px 12px;
    background: #f8fafc;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

tbody tr:hover { background: #eef2ff; }
tbody tr[style*="cursor"] td:first-child { border-left: 3px solid transparent; }
tbody tr[style*="cursor"]:hover td:first-child { border-left: 3px solid var(--primary); }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-nowrap { white-space: nowrap; }
.text-muted { color: var(--text-muted); }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
}

.btn-primary { background: var(--primary); color: var(--primary-btn-text); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: #f8fafc; }

.btn-sm { padding: 4px 10px; font-size: 12px; }

.btn-group { display: flex; gap: 8px; }

/* Status badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-draft { background: #e2e8f0; color: #475569; }
.badge-sent { background: #dbeafe; color: #1d4ed8; }
.badge-partial { background: #fef3c7; color: #b45309; }
.badge-done { background: #dcfce7; color: #15803d; }
.badge-cancelled { background: #fee2e2; color: #dc2626; }

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

select.form-control { appearance: auto; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

/* Flash messages */
.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.flash-success { background: #dcfce7; color: #166534; }
.flash-warning { background: #fef3c7; color: #92400e; }
.flash-error { background: #fee2e2; color: #991b1b; }

/* Dynamic items table */
.items-table { width: 100%; margin-top: 10px; }
.items-table td { padding: 6px 4px; }
.items-table .form-control { min-width: 80px; }
.items-table select.form-control { min-width: 200px; }

.add-item-btn {
    margin-top: 8px;
    cursor: pointer;
    color: var(--primary);
    font-size: 14px;
    border: none;
    background: none;
    font-weight: 600;
}

.add-item-btn:hover { text-decoration: underline; }

/* Chart container */
.chart-container {
    position: relative;
    height: 250px;
}

/* Responsive */
@media (max-width: 1024px) {
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* Burger button (mobile) */
.burger {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1100;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 8px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    font-size: 22px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.sidebar-overlay {
    display: none;
}

@media (max-width: 768px) {
    .burger { display: flex; }
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 1050;
    }
    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 1040;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { opacity: 1; pointer-events: auto; }
    .main { margin-left: 0; padding: 60px 16px 16px; }
}

/* Stock colors */
.stock-ok { color: var(--success); }
.stock-low { color: var(--warning); font-weight: 700; }
.stock-out { color: var(--danger); font-weight: 700; }

/* File upload */
.file-upload {
    border: 2px dashed var(--border);
    border-radius: 10px;
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s;
}

.file-upload:hover { border-color: var(--primary); }

.file-upload input[type="file"] {
    display: block;
    margin: 12px auto 0;
}

/* Price dynamics */
.price-alert-up { background: #fef2f2 !important; }
.price-alert-up:hover { background: #fee2e2 !important; }
.price-alert-down { background: #f0fdf4 !important; }
.price-alert-down:hover { background: #dcfce7 !important; }

/* Chat widget */
#chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
}

#chat-toggle {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.15s;
}

#chat-toggle:hover { transform: scale(1.08); }

#chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

#chat-box {
    position: absolute;
    bottom: 62px;
    right: 0;
    width: 360px;
    height: 460px;
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    flex-direction: column;
    overflow: hidden;
}

#chat-header {
    background: var(--primary);
    color: var(--primary-btn-text);
    padding: 12px 16px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.chat-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.4;
    background: #f1f5f9;
    align-self: flex-start;
    word-break: break-word;
}

.chat-msg b {
    display: block;
    font-size: 11px;
    color: var(--primary);
    margin-bottom: 2px;
}

.chat-msg.mine {
    background: var(--primary);
    color: var(--primary-btn-text);
    align-self: flex-end;
}

.chat-msg.mine .chat-time { opacity: 0.7; }

.chat-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-left: 6px;
    white-space: nowrap;
}

.chat-msg.mine .chat-time { color: inherit; }

#chat-input-wrap {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
}

#chat-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    font-size: 13px;
    outline: none;
}

#chat-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--focus-ring);
}

@media (max-width: 768px) {
    #chat-widget { bottom: 16px; right: 16px; }
    #chat-box {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 70vh;
        border-radius: 12px 12px 0 0;
    }
    #chat-toggle { width: 46px; height: 46px; }
}

/* Theme switcher */
.theme-switcher {
    display: flex;
    gap: 8px;
    padding: 8px 16px;
}
.theme-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.2);
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
}
.theme-dot:hover { transform: scale(1.2); }
.theme-dot.active { border-color: #fff; transform: scale(1.2); }
.theme-dot-blue { background: #2563eb; }
.theme-dot-yellow { background: #eab308; }
.theme-dot-red { background: #dc2626; }

/* Products toolbar */
.products-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.products-toolbar input { flex: 1; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }
.products-toolbar input:focus { outline: none; border-color: var(--primary); }
.products-toolbar select { padding: 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; }
.products-summary { display: flex; gap: 16px; margin-bottom: 16px; }
.summary-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-green { background: var(--success); }
.dot-yellow { background: var(--warning); }
.dot-red { background: var(--danger); }
.col-status { width: 12px; padding-right: 0 !important; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status-red { background: var(--danger); box-shadow: 0 0 6px rgba(220,38,38,0.4); }
.status-yellow { background: var(--warning); box-shadow: 0 0 6px rgba(245,158,11,0.3); }
.status-green { background: var(--success); }
.status-gray { background: #d6d3d1; }
.product-row { cursor: pointer; transition: background 0.1s; }
.product-row:hover { background: #f8fafc; }
.row-out { background: #fef2f2; }
.row-out:hover { background: #fee2e2 !important; }
.row-low { background: #fffbeb; }
.row-low:hover { background: #fef3c7 !important; }
.cat-tag { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: #f1f5f9; color: var(--text-muted); margin-left: 6px; vertical-align: middle; }
.stock-cell { font-weight: 600; }
.badge { font-size: 14px; font-weight: 400; color: var(--text-muted); margin-left: 8px; }
.num { font-variant-numeric: tabular-nums; }

/* Products layout with tree */
.products-layout { display: flex; gap: 16px; align-items: flex-start; }
.groups-tree {
    width: 220px; flex-shrink: 0;
    background: var(--card); border-radius: 8px; border: 1px solid var(--border);
    padding: 6px 0; max-height: 75vh; overflow-y: auto; font-size: 12px;
    position: sticky; top: 20px;
}
.groups-tree a.root { display: block; padding: 6px 12px; color: var(--text); text-decoration: none; font-weight: 600; border-bottom: 1px solid var(--border); }
.tree-node { border: none; }
.tree-node summary { list-style: none; cursor: pointer; padding: 3px 12px; }
.tree-node summary::-webkit-details-marker { display: none; }
.tree-node details { padding-left: 12px; }
.tree-item { display: inline; padding: 3px 6px; border-radius: 4px; color: var(--text); text-decoration: none; font-size: 12px; }
.tree-item:hover { background: #f1f5f9; }
.tree-item.active { background: var(--primary); color: #fff; font-weight: 600; }
.products-content { flex: 1; min-width: 0; overflow-x: auto; }
.products-table td, .products-table th { padding: 4px 8px; font-size: 12px; white-space: nowrap; }
.products-table td strong { font-weight: 500; }
.current-group-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 10px; padding: 6px 12px;
    background: #dbeafe; border-radius: 6px; font-weight: 600; font-size: 14px; color: #1d4ed8;
}
.current-group-header a { color: #1d4ed8; text-decoration: none; font-size: 16px; }

@media (max-width: 900px) {
    .products-layout { flex-direction: column; }
    .groups-tree { width: 100%; max-height: 180px; position: static; }
}
