/* ═══════════════════════════════════════
   ЛК Малярная продукция — Основные стили
   ═══════════════════════════════════════ */

:root {
    --primary: #1a56db;
    --primary-dark: #1242b0;
    --primary-light: #e8effc;
    --primary-50: rgba(26,86,219,.05);
    --accent: #f59e0b;
    --accent-light: #fef3c7;

    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --info: #2563eb;
    --info-bg: #eff6ff;

    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-focus: #94a3b8;

    --text: #1e293b;
    --text-2: #475569;
    --text-3: #94a3b8;
    --text-inverse: #ffffff;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1);

    --sidebar-w: 260px;
    --header-h: 60px;
    --font: 'Nunito', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

    --transition: .2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; -webkit-text-size-adjust: 100%; }
body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--primary-dark); }

img { max-width: 100%; height: auto; }

/* ─── Утилиты ─── */
.text-success { color: var(--success) !important; }
.text-danger  { color: var(--danger) !important; }
.text-warning { color: var(--warning) !important; }
.text-muted   { color: var(--text-3) !important; }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.mono { font-family: var(--font-mono); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: .5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ─── Layout: Sidebar + Main ─── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 200;
    transition: transform .3s ease;
}
.sidebar-logo {
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: .75rem;
}
.sidebar-logo .logo-icon {
    width: 36px; height: 36px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 800; font-size: 1.1rem;
}
.sidebar-logo .logo-text {
    font-weight: 800; font-size: .9rem; color: var(--text);
    line-height: 1.2;
}
.sidebar-logo .logo-text small {
    display: block; font-weight: 400; font-size: .65rem; color: var(--text-3);
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: .75rem 0; }
.nav-section { padding: .5rem 1.5rem .25rem; font-size: .6rem; text-transform: uppercase;
    letter-spacing: .08em; color: var(--text-3); font-weight: 700; }

.nav-item {
    display: flex; align-items: center; gap: .75rem;
    padding: .6rem 1.5rem; color: var(--text-2);
    font-size: .85rem; font-weight: 600;
    transition: all var(--transition); cursor: pointer;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--primary-50); color: var(--primary); }
.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    border-left-color: var(--primary);
}
.nav-item .nav-icon { width: 20px; text-align: center; font-size: 1rem; flex-shrink: 0; }
.nav-item .badge {
    margin-left: auto;
    background: var(--danger);
    color: #fff;
    font-size: .6rem;
    padding: .1rem .4rem;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
    font-weight: 700;
}

.sidebar-user {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    display: flex; align-items: center; gap: .6rem;
    font-size: .8rem;
}
.sidebar-user .avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary-light);
    color: var(--primary);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: .75rem; flex-shrink: 0;
}
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .user-role { font-size: .65rem; color: var(--text-3); }

/* Main content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-w);
    min-height: 100vh;
}

/* Header */
.top-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 2rem;
    position: sticky; top: 0; z-index: 100;
    box-shadow: var(--shadow-sm);
}
.header-left { display: flex; align-items: center; gap: 1rem; }
.header-left h1 { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.header-right { display: flex; align-items: center; gap: 1rem; }

.btn-burger {
    display: none; background: none; border: none;
    font-size: 1.3rem; color: var(--text-2); cursor: pointer;
    padding: .5rem;
}

/* Counterparty switcher */
.cp-switcher select {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: .35rem .8rem;
    font-size: .78rem;
    font-family: var(--font);
    color: var(--text);
    cursor: pointer;
}

/* Notification bell */
.notif-bell {
    position: relative; cursor: pointer;
    font-size: 1.2rem; color: var(--text-2);
    padding: .3rem;
}
.notif-bell .count {
    position: absolute; top: -4px; right: -6px;
    background: var(--danger); color: #fff;
    font-size: .55rem; font-weight: 800;
    min-width: 16px; height: 16px;
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    border: 2px solid var(--surface);
}

/* ─── Page container ─── */
.page { padding: 1.5rem 2rem 3rem; max-width: 1400px; }

/* ─── Cards ─── */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface-2);
}
.card-header h2 { font-size: .9rem; font-weight: 700; }
.card-body { padding: 1.25rem; }
.card-footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--border);
    background: var(--surface-2);
    font-size: .8rem;
}

/* ─── Metric cards (dashboard) ─── */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.metric-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.25rem;
    display: flex; align-items: flex-start; gap: 1rem;
}
.metric-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; flex-shrink: 0;
}
.metric-icon.blue   { background: var(--primary-light); color: var(--primary); }
.metric-icon.green  { background: var(--success-bg); color: var(--success); }
.metric-icon.red    { background: var(--danger-bg); color: var(--danger); }
.metric-icon.yellow { background: var(--accent-light); color: var(--warning); }
.metric-info { flex: 1; }
.metric-label { font-size: .7rem; color: var(--text-3); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.metric-value { font-size: 1.4rem; font-weight: 800; font-family: var(--font-mono); line-height: 1.2; margin-top: .15rem; }
.metric-sub { font-size: .72rem; color: var(--text-2); margin-top: .15rem; }

/* ─── Tables ─── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data-table {
    width: 100%; border-collapse: collapse; font-size: .82rem;
}
.data-table th {
    text-align: left; padding: .6rem 1rem;
    font-size: .65rem; text-transform: uppercase; letter-spacing: .05em;
    color: var(--text-3); font-weight: 700;
    background: var(--surface-2); border-bottom: 2px solid var(--border);
    white-space: nowrap; position: sticky; top: 0;
}
.data-table td {
    padding: .6rem 1rem; border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--primary-50); }
.data-table .num { text-align: right; font-family: var(--font-mono); font-size: .8rem; }
.data-table .center { text-align: center; }

/* ─── Status badges ─── */
.badge-status {
    display: inline-flex; align-items: center;
    padding: .15rem .55rem; border-radius: 4px;
    font-size: .65rem; font-weight: 700;
    text-transform: uppercase; letter-spacing: .03em;
    white-space: nowrap;
}
.badge-status.new       { background: var(--info-bg); color: var(--info); }
.badge-status.progress  { background: var(--warning-bg); color: var(--warning); }
.badge-status.done      { background: var(--success-bg); color: var(--success); }
.badge-status.cancelled { background: var(--danger-bg); color: var(--danger); }
.badge-status.paid      { background: #d1fae5; color: #065f46; }
.badge-status.debt-badge { background: #fef3c7; color: #92400e; }

/* ─── Forms ─── */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block; font-size: .72rem; font-weight: 700;
    color: var(--text-2); margin-bottom: .3rem;
    text-transform: uppercase; letter-spacing: .03em;
}
.form-control {
    width: 100%; padding: .55rem .85rem;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-xs); font-family: var(--font);
    font-size: .85rem; color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26,86,219,.12);
}
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

.form-row {
    display: flex; flex-wrap: wrap; gap: 1rem;
}
.form-row .form-group { flex: 1; min-width: 200px; }

/* ─── Buttons ─── */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1.2rem; border: none; border-radius: var(--radius-xs);
    font-family: var(--font); font-size: .82rem; font-weight: 700;
    cursor: pointer; transition: all var(--transition);
    white-space: nowrap; text-decoration: none;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary {
    background: var(--primary); color: var(--text-inverse);
}
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); box-shadow: var(--shadow-md); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { background: #047857; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-outline {
    background: transparent; border: 1px solid var(--border); color: var(--text-2);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-50); }
.btn-sm { padding: .35rem .75rem; font-size: .75rem; }
.btn-lg { padding: .7rem 2rem; font-size: .95rem; }
.btn-block { width: 100%; }

/* ─── Filters bar ─── */
.filters-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    display: flex; flex-wrap: wrap; gap: .75rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}
.filter-group { display: flex; flex-direction: column; gap: .2rem; flex: 1; min-width: 140px; }
.filter-group label { font-size: .6rem; text-transform: uppercase; color: var(--text-3); font-weight: 700; letter-spacing: .05em; }
.filter-group select,
.filter-group input {
    padding: .4rem .6rem; font-size: .8rem;
    border: 1px solid var(--border); border-radius: var(--radius-xs);
    font-family: var(--font); background: var(--surface-2); color: var(--text);
}
.filter-group select:focus,
.filter-group input:focus { border-color: var(--primary); outline: none; }

/* ─── Bonus progress bar ─── */
.bonus-bar {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 1.5rem;
}
.bonus-bar .bar-labels { display: flex; justify-content: space-between; font-size: .7rem; color: var(--text-3); font-weight: 700; margin-bottom: .4rem; }
.bonus-bar .bar-track { height: 24px; background: #e2e8f0; border-radius: 12px; overflow: hidden; position: relative; }
.bonus-bar .bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--accent));
    border-radius: 12px;
    transition: width .8s ease;
    position: relative;
}
.bonus-bar .bar-fill::after {
    content: attr(data-percent);
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    font-size: .65rem; font-weight: 800; color: #fff;
}
.bonus-bar .bonus-info { display: flex; justify-content: space-between; margin-top: .5rem; font-size: .8rem; }
.bonus-bar .bonus-amount { font-size: 1.3rem; font-weight: 800; color: var(--success); font-family: var(--font-mono); }

/* ─── Chat ─── */
.chat-container {
    display: flex; flex-direction: column;
    height: calc(100vh - var(--header-h) - 3rem);
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
}
.chat-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    display: flex; align-items: center; gap: .75rem;
}
.chat-messages {
    flex: 1; overflow-y: auto; padding: 1rem;
    display: flex; flex-direction: column; gap: .5rem;
}
.msg {
    max-width: 70%;
    padding: .6rem 1rem;
    border-radius: var(--radius-sm);
    font-size: .85rem;
    line-height: 1.5;
    position: relative;
}
.msg.mine {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 2px;
}
.msg.theirs {
    align-self: flex-start;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
}
.msg .msg-time { font-size: .6rem; opacity: .7; margin-top: .15rem; }
.chat-input {
    padding: .75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex; gap: .5rem;
    background: var(--surface-2);
}
.chat-input input {
    flex: 1; padding: .5rem .85rem;
    border: 1px solid var(--border); border-radius: 20px;
    font-family: var(--font); font-size: .85rem;
    outline: none;
}
.chat-input input:focus { border-color: var(--primary); }
.chat-input .btn { border-radius: 20px; }

/* ─── Empty state ─── */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--text-3); }
.empty-state .icon { font-size: 2.5rem; margin-bottom: .75rem; }
.empty-state .title { font-size: .95rem; font-weight: 700; color: var(--text-2); }
.empty-state .desc { font-size: .8rem; margin-top: .3rem; }

/* ─── Grid layout for catalog ─── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}
.product-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden;
    transition: all var(--transition);
}
.product-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.product-card .photo {
    height: 160px; background: var(--surface-2);
    display: flex; align-items: center; justify-content: center;
    color: var(--text-3); font-size: 2rem; overflow: hidden;
}
.product-card .photo img { width: 100%; height: 100%; object-fit: cover; }
.product-card .info { padding: .85rem; }
.product-card .name { font-size: .82rem; font-weight: 700; line-height: 1.3; margin-bottom: .3rem;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.product-card .sku { font-size: .65rem; color: var(--text-3); }
.product-card .price { font-size: 1rem; font-weight: 800; color: var(--primary); font-family: var(--font-mono); margin-top: .3rem; }
.product-card .stock { font-size: .7rem; margin-top: .25rem; }
.product-card .stock.in { color: var(--success); }
.product-card .stock.out { color: var(--danger); }

/* ─── Alerts ─── */
.alert {
    padding: .75rem 1rem; border-radius: var(--radius-xs);
    font-size: .82rem; margin-bottom: 1rem;
    display: flex; align-items: center; gap: .5rem;
}
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #a7f3d0; }
.alert-danger  { background: var(--danger-bg); color: var(--danger); border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #fde68a; }
.alert-info    { background: var(--info-bg); color: var(--info); border: 1px solid #bfdbfe; }

/* ─── Modal ─── */
.modal {
    display: none;
    position: fixed; inset: 0;
    z-index: 1000;
}
.modal.active {
    display: block;
}
.modal-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1001;
}
.modal-content {
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 90%; max-width: 560px;
    max-height: 85vh; overflow-y: auto;
    z-index: 1002;
}
.modal-content.modal-lg { max-width: 720px; }
.modal-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: .95rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.3rem; cursor: pointer; color: var(--text-3); padding: .25rem; }
.modal-body { padding: 1.25rem; }
.modal-footer {
    padding: .75rem 1.25rem;
    border-top: 1px solid var(--border);
    display: flex; justify-content: flex-end; gap: .5rem;
}

/* ─── Loading spinner ─── */
.spinner {
    width: 28px; height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .65s linear infinite;
    margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading { text-align: center; padding: 2rem; color: var(--text-3); }
.loading .spinner { margin-bottom: .5rem; }

/* ─── Login page ─── */
.login-page {
    min-height: 100vh;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #1e3a5f 0%, #1a56db 50%, #3b82f6 100%);
    padding: 2rem;
}
.login-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%; max-width: 420px;
}
.login-card .logo { text-align: center; margin-bottom: 2rem; }
.login-card .logo h1 { font-size: 1.3rem; font-weight: 800; color: var(--text); margin-top: .5rem; }
.login-card .logo p { font-size: .75rem; color: var(--text-3); }
.login-card .error { margin-bottom: 1rem; }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    :root { --sidebar-w: 0px; }
    .sidebar {
        transform: translateX(-280px);
        width: 280px;
    }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .btn-burger { display: block; }
    .page { padding: 1rem; }
    .top-header { padding: 0 1rem; }
    .metrics-grid { grid-template-columns: 1fr 1fr; }
    .product-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .msg { max-width: 85%; }
    .filters-bar { flex-direction: column; }
    .filter-group { min-width: 100%; }
    .form-row .form-group { min-width: 100%; }

    /* Mobile bottom nav */
    .bottom-nav {
        display: flex !important;
        position: fixed; bottom: 0; left: 0; right: 0;
        background: var(--surface);
        border-top: 1px solid var(--border);
        z-index: 300;
        justify-content: space-around;
        padding: .4rem 0 calc(.4rem + env(safe-area-inset-bottom));
        box-shadow: 0 -2px 10px rgba(0,0,0,.05);
    }
    .bottom-nav a {
        display: flex; flex-direction: column; align-items: center;
        font-size: .6rem; color: var(--text-3); padding: .3rem .5rem;
        text-decoration: none; font-weight: 600;
    }
    .bottom-nav a .icon { font-size: 1.2rem; margin-bottom: .1rem; }
    .bottom-nav a.active { color: var(--primary); }
}

@media (min-width: 769px) {
    .bottom-nav { display: none !important; }
}

/* ─── Sidebar overlay (mobile) ─── */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.3); z-index: 199;
}
.sidebar.open ~ .sidebar-overlay { display: block; }

/* ─── Print ─── */
@media print {
    .sidebar, .top-header, .bottom-nav, .filters-bar, .btn { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .page { padding: 0; }
}
