/* Reset & Base */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --bg: #f1f5f9;
    --sidebar-bg: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-active: #f8fafc;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-secondary: #64748b;
    --border: #e2e8f0;
    --primary: #3b82f6;
    --success: #22c55e;
    --warning: #f59e0b;
    --orange: #f97316;
    --danger: #ef4444;
    --critical: #dc2626;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Layout */
.layout {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
}

.sidebar-header h2 {
    color: var(--sidebar-active);
    font-size: 1.25rem;
    margin-bottom: 4px;
}

.sidebar-header .subtitle {
    font-size: 0.8rem;
    opacity: 0.6;
}

.nav-links {
    list-style: none;
    margin-top: 32px;
}

.nav-links li { margin-bottom: 4px; }

.nav-links a {
    display: block;
    padding: 10px 16px;
    color: var(--sidebar-text);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.2s;
}

.nav-links a:hover {
    background: rgba(255,255,255,0.1);
    color: var(--sidebar-active);
}

.nav-links a.active {
    background: var(--primary);
    color: #fff;
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 16px;
    font-size: 0.75rem;
    opacity: 0.5;
}

.content {
    flex: 1;
    margin-left: 260px;
    padding: 16px 32px;
    max-width: 1400px;
}

/* Page Header */
.page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.page-header h1 {
    font-size: 1.3rem;
    font-weight: 600;
}

.back-link {
    color: var(--primary);
    text-decoration: none;
    font-size: 0.9rem;
}

/* Summary Cards */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 10px;
    margin-bottom: 12px;
}

.card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 12px 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    border-left: none;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 5px;
}

.card-value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.2;
}

.card-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

.card-critical::before { background: var(--critical); }
.card-critical { border-color: #fecaca; background: #fef2f2; }
.card-critical .card-value { color: var(--critical); }

.card-red::before { background: var(--danger); }
.card-red { border-color: #fecaca; background: #fef2f2; }
.card-red .card-value { color: var(--danger); }

.card-orange::before { background: var(--orange); }
.card-orange { border-color: #fed7aa; background: #fff7ed; }
.card-orange .card-value { color: var(--orange); }

.card-yellow::before { background: var(--warning); }
.card-yellow { border-color: #fde68a; background: #fffbeb; }
.card-yellow .card-value { color: var(--warning); }

.card-green::before { background: var(--success); }
.card-green { border-color: #bbf7d0; background: #f0fdf4; }
.card-green .card-value { color: var(--success); }

.card-total::before { background: var(--primary); }
.card-total { border-color: #bfdbfe; background: #eff6ff; }
.card-total .card-value { color: var(--primary); }

.card-inactive::before { background: #6b7280; }
.card-inactive { border-color: #d1d5db; background: #f9fafb; }
.card-inactive .card-value { color: #6b7280; }

/* Tables */
.table-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    background: #f8fafc;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.data-table th.sort-asc::after { content: " ▲"; font-size: 0.6rem; }
.data-table th.sort-desc::after { content: " ▼"; font-size: 0.6rem; }

.data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.data-table tbody tr {
    cursor: pointer;
    transition: background 0.15s;
}

.data-table tbody tr:hover {
    background: #f8fafc;
}

.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.runway-danger {
    color: var(--danger);
    font-weight: 600;
}

.supplier-cell {
    font-size: 0.8rem;
    color: var(--text-secondary);
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px !important;
    font-style: italic;
}

/* Tier row highlights */
.tier-critical { border-left: 3px solid var(--critical); }
.tier-red { border-left: 3px solid var(--danger); }
.tier-orange { border-left: 3px solid var(--orange); }
.tier-yellow { border-left: 3px solid var(--warning); }

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #a16207; }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-red { background: #fee2e2; color: #dc2626; }
.badge-critical { background: #dc2626; color: #fff; animation: pulse 1.5s infinite; }
.badge-inactive { background: #e5e7eb; color: #6b7280; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Trends */
.trend-up { color: var(--danger); font-weight: 600; }
.trend-down { color: var(--success); font-weight: 600; }
.trend-flat { color: var(--text-secondary); }

/* Charts */
.chart-container {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.chart-container h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

/* Sections */
.section {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 24px;
}

.section h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
}

/* Filters */
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.filter-btn {
    padding: 8px 16px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 0.85rem;
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    transition: all 0.2s;
}

.filter-btn:hover, .filter-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Forms / Settings */
.description {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.input-field {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.5;
    width: 100%;
}

.input-narrow { width: 100px; }

.form-actions {
    margin-top: 24px;
    display: flex;
    justify-content: flex-end;
}

.btn {
    padding: 7px 20px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.5;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: #2563eb;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 24px;
    font-size: 0.9rem;
}

.pagination a {
    color: var(--primary);
    text-decoration: none;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 200px;
        padding: 16px 8px;
    }
    .content {
        margin-left: 200px;
        padding: 16px;
    }
    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .sidebar {
        position: static;
        width: 100%;
    }
    .content {
        margin-left: 0;
    }
    .layout {
        flex-direction: column;
    }
}

/* Controls Bar */
.controls-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    gap: 10px;
    flex-wrap: wrap;
}

.search-form {
    display: flex;
    gap: 8px;
    align-items: center;
    flex: 1;
    max-width: 600px;
}

.search-input {
    flex: 1;
    min-width: 180px;
    max-width: 300px;
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: #f1f5f9;
}

.per-page-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.per-page-btn {
    padding: 4px 12px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 0.85rem;
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.per-page-btn.active, .per-page-btn:hover {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* Alert Legend */
.alert-legend {
    margin-top: 0;
    margin-bottom: 12px;
    padding: 6px 16px;
}

.alert-legend[open] {
    padding: 12px 20px;
}

.legend-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.legend-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px;
    background: #f8fafc;
    border-radius: 6px;
}

.legend-item .badge {
    flex-shrink: 0;
    margin-top: 2px;
}

.legend-item p {
    font-size: 0.85rem;
    color: var(--text);
    line-height: 1.4;
    margin: 0;
}

.legend-note {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 8px;
    font-style: italic;
}

/* Bitrix link */
.bitrix-link {
    display: inline-flex;
    align-items: center;
    margin-left: 8px;
    color: #2fc6f6;
    text-decoration: none;
    opacity: 0.35;
    transition: opacity 0.2s;
    vertical-align: middle;
}

.bitrix-link:hover {
    opacity: 1;
}

tr:hover .bitrix-link {
    opacity: 0.7;
}

tr:hover .bitrix-link:hover {
    opacity: 1;
}

/* Clickable summary cards */
.summary-cards a.card {
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    cursor: pointer;
}

.summary-cards a.card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}

.summary-cards a.card:active {
    transform: translateY(0);
}

.summary-cards a.card.card-active {
    box-shadow: 0 0 0 3px var(--primary), 0 4px 12px rgba(59,130,246,0.25);
}

.summary-cards a.card.card-active.card-critical { box-shadow: 0 0 0 3px var(--critical), 0 4px 12px rgba(220,38,38,0.25); }
.summary-cards a.card.card-active.card-red { box-shadow: 0 0 0 3px var(--danger), 0 4px 12px rgba(239,68,68,0.25); }
.summary-cards a.card.card-active.card-orange { box-shadow: 0 0 0 3px var(--orange), 0 4px 12px rgba(249,115,22,0.25); }
.summary-cards a.card.card-active.card-yellow { box-shadow: 0 0 0 3px var(--warning), 0 4px 12px rgba(245,158,11,0.25); }
.summary-cards a.card.card-active.card-green { box-shadow: 0 0 0 3px var(--success), 0 4px 12px rgba(34,197,94,0.25); }
.summary-cards a.card.card-active.card-inactive { box-shadow: 0 0 0 3px #6b7280, 0 4px 12px rgba(107,114,128,0.25); }

/* Bulk action bar */
.bulk-bar {
    position: fixed;
    bottom: 0;
    left: 260px;
    right: 0;
    background: var(--sidebar-bg);
    color: #fff;
    padding: 12px 32px;
    box-shadow: 0 -4px 12px rgba(0,0,0,0.2);
    z-index: 200;
}

.bulk-bar-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 1400px;
}

.bulk-bar-inner span {
    font-weight: 600;
    min-width: 80px;
    flex-shrink: 0;
}

.bulk-bar .ss-picker {
    min-width: 220px;
}

.bulk-bar .input-narrow {
    min-width: 130px;
}

.bulk-bar .input-field {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
    color: #fff;
}

.bulk-bar .btn-primary {
    background: var(--success);
}

.bulk-bar .btn-secondary {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: #fff;
}

/* Supplier Picker - custom select */
.ss-picker {
    position: relative;
    min-width: 180px;
}

.ss-display {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--card-bg);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    line-height: 1.5;
    transition: border-color 0.2s;
    gap: 8px;
}

.ss-display:hover {
    border-color: var(--primary);
}

.ss-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ss-arrow {
    color: var(--text-secondary);
    font-size: 0.7rem;
    flex-shrink: 0;
}

.ss-display-dark {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
    color: #fff;
}

/* Picker modal */
.sp-overlay {
    position: fixed;
    inset: 0;
    z-index: 300;
}

.sp-modal {
    position: fixed;
    z-index: 301;
    width: 280px;
    max-height: 320px;
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sp-search {
    padding: 12px 16px;
    border: none;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    outline: none;
    background: #f8fafc;
}

.sp-search:focus {
    background: #fff;
}

.sp-list {
    overflow-y: auto;
    flex: 1;
    max-height: 260px;
}

.sp-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: 0.85rem;
}

.sp-item:hover {
    background: #eff6ff;
}

.sp-item-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.75rem;
    flex-shrink: 0;
}

.sp-item-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
