/* =====================================================
   RUSIK WORK MASTER — Analytics Page Styles
   ===================================================== */

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

body {
    font-family: Tahoma, Verdana, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: #333;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 20px 40px;
    width: 100%;
    flex: 1;
}

/* ── Tab Bar ────────────────────────────────────────── */

.tab-bar {
    position: sticky;
    top: 59px; /* header 56px + accent 3px */
    z-index: 90;
    background: #fff;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 0;
    padding: 0 20px;
}

.tab-btn {
    padding: 12px 18px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all .2s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover {
    color: #111;
}

.tab-badge {
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 2px;
    line-height: 1.4;
}

.tab-badge:empty {
    display: none;
}

/* ── Tab Content ────────────────────────────────────── */

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* ── Summary KPI Row ────────────────────────────────── */

.summary-row {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.summary-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}

.summary-chip .chip-num {
    font-weight: 800;
    font-size: 15px;
}

/* ── Toolbar ────────────────────────────────────────── */

.toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.toolbar-spacer {
    flex: 1;
}

.search-input {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #fafafa;
    transition: border .2s;
    min-width: 200px;
}

.search-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, .08);
    background: #fff;
}

.filter-select {
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #fff;
    cursor: pointer;
    color: #374151;
    min-width: 110px;
}

.filter-select:focus {
    border-color: var(--primary);
}

.count-label {
    font-size: 13px;
    color: #9ca3af;
    font-weight: 600;
    white-space: nowrap;
}

/* ── Period Pills ───────────────────────────────────── */

.period-pills {
    display: flex;
    gap: 4px;
}

.pill {
    padding: 5px 12px;
    border: 1.5px solid var(--border);
    border-radius: 6px;
    background: #fff;
    font-size: 12px;
    font-weight: 600;
    color: #6b7280;
    cursor: pointer;
    font-family: inherit;
    transition: all .16s;
}

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

.pill.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ── Data Table ─────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.data-table thead {
    background: #f9fafb;
}

.data-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 10px 10px;
    border-bottom: 2px solid #e5e7eb;
    white-space: nowrap;
}

.data-table td {
    padding: 8px 10px;
    border-bottom: 1px solid #f3f4f6;
    vertical-align: middle;
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

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

.td-time {
    color: #9ca3af;
    font-size: 12px;
    white-space: nowrap;
}

.td-articul {
    font-weight: 700;
    color: #111;
    font-family: 'Courier New', monospace;
    font-size: 13px;
}

.td-arrow {
    color: #d1d5db;
    text-align: center;
    font-weight: 700;
}

.td-delta {
    font-weight: 700;
    font-size: 12px;
}

.td-delta.positive {
    color: #16a34a;
}

.td-delta.negative {
    color: #dc2626;
}

.td-details {
    color: #6b7280;
    font-size: 12px;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Event Type Badges ──────────────────────────────── */

.ev-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    display: inline-block;
}

.ev-new { background: #dcfce7; color: #166534; }
.ev-removed { background: #fee2e2; color: #991b1b; }
.ev-increase { background: #dbeafe; color: #1e40af; }
.ev-decrease { background: #fed7aa; color: #9a3412; }
.ev-sold { background: #fecaca; color: #991b1b; }
.ev-back { background: #bbf7d0; color: #166534; }
.ev-price-up { background: #e9d5ff; color: #6b21a8; }
.ev-price-down { background: #fef9c3; color: #854d0e; }

/* ── Staggered Pair Cards ───────────────────────────── */

.stag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
    gap: 14px;
}

.stag-card {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    display: flex;
    gap: 12px;
    align-items: center;
    transition: box-shadow .16s;
}

.stag-card:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, .06);
}

.stag-wheel {
    flex: 1;
    padding: 10px;
    border-radius: 8px;
    background: #f9fafb;
    min-width: 0;
}

.stag-wheel-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #9ca3af;
    margin-bottom: 4px;
}

.stag-wheel-art {
    font-weight: 700;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    color: #111;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stag-wheel-name {
    font-size: 12px;
    color: #6b7280;
    line-height: 1.3;
    margin-bottom: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.stag-wheel-meta {
    font-size: 11px;
    color: #9ca3af;
}

.stag-wheel-meta span {
    margin-right: 8px;
}

.stag-wheel-meta .in-stock {
    color: #16a34a;
    font-weight: 600;
}

.stag-wheel-meta .out-stock {
    color: #dc2626;
    font-weight: 600;
}

.stag-vs {
    font-size: 18px;
    font-weight: 800;
    color: #d1d5db;
    flex-shrink: 0;
}

.stag-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.stag-tag {
    font-size: 10px;
    font-weight: 700;
    color: #9ca3af;
    text-align: center;
    margin-bottom: 2px;
}

.stag-tag.auto {
    color: var(--primary);
}

/* ── Stop-list Reason Badges ────────────────────────── */

.reason-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
    display: inline-block;
}

.reason-defect { background: #fee2e2; color: #991b1b; }
.reason-quality { background: #fed7aa; color: #9a3412; }
.reason-duplicate { background: #e0e7ff; color: #3730a3; }
.reason-other { background: #f3f4f6; color: #374151; }

/* ── Alert Sections ─────────────────────────────────── */

.alert-section {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 12px;
    overflow: hidden;
}

.alert-header {
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    transition: background .12s;
}

.alert-header:hover {
    background: #f9fafb;
}

.alert-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-title {
    font-size: 14px;
    font-weight: 700;
    color: #111;
}

.alert-count {
    background: #f3f4f6;
    color: #6b7280;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
}

.alert-count.has-items {
    background: #fee2e2;
    color: #991b1b;
}

.alert-chevron {
    transition: transform .2s;
    color: #9ca3af;
    flex-shrink: 0;
}

.alert-section.open .alert-chevron {
    transform: rotate(180deg);
}

.alert-body {
    padding: 0 18px 14px;
    display: none;
}

.alert-section.open .alert-body {
    display: block;
}

.alert-empty {
    color: #9ca3af;
    font-size: 13px;
    padding: 8px 0;
}

.alert-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid #f3f4f6;
    font-size: 13px;
}

.alert-item:last-child {
    border-bottom: none;
}

.alert-item-art {
    font-weight: 700;
    font-family: 'Courier New', monospace;
    color: #111;
    min-width: 100px;
}

.alert-item-text {
    color: #6b7280;
    flex: 1;
}

.alert-item-time {
    color: #9ca3af;
    font-size: 11px;
    white-space: nowrap;
}

/* ── Pagination ─────────────────────────────────────── */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin-top: 20px;
}

.pagination:empty {
    display: none;
}

.pg-btn {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #fff;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    cursor: pointer;
    font-family: inherit;
    transition: all .16s;
}

.pg-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.pg-btn:disabled {
    opacity: .4;
    cursor: default;
    pointer-events: none;
}

/* ── Empty State ────────────────────────────────────── */

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: #9ca3af;
    font-size: 14px;
}

.empty-state svg {
    margin-bottom: 12px;
}

/* ── Buttons ────────────────────────────────────────── */

.btn-primary {
    background: var(--primary-grad);
    color: #fff;
    border: none;
    padding: 8px 18px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    font-family: inherit;
    transition: filter .16s, transform .16s;
    white-space: nowrap;
}

.btn-primary:hover {
    filter: brightness(1.12);
    transform: translateY(-1px);
}

.btn-primary:disabled {
    opacity: .5;
    cursor: default;
    transform: none;
    filter: none;
}

.btn-secondary {
    background: #fff;
    color: #374151;
    border: 1.5px solid var(--border);
    padding: 8px 18px;
    border-radius: 7px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all .16s;
}

.btn-secondary:hover {
    border-color: #9ca3af;
    background: #f9fafb;
}

.btn-danger-sm {
    background: none;
    border: 1px solid #fecaca;
    color: #dc2626;
    padding: 4px 10px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all .16s;
}

.btn-danger-sm:hover {
    background: #fef2f2;
    border-color: #dc2626;
}

/* ── Modal ──────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 200;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: #fff;
    border-radius: 14px;
    width: 440px;
    max-width: 92vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .2);
    animation: modalIn .2s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(16px) scale(.97); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 20px 14px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 16px;
    font-weight: 700;
    color: #111;
}

.modal-close {
    background: none;
    border: none;
    font-size: 22px;
    color: #9ca3af;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
    transition: color .12s;
}

.modal-close:hover {
    color: #111;
}

.modal-body {
    padding: 18px 20px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px 18px;
    border-top: 1px solid var(--border);
}

.form-label {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: #374151;
    margin-bottom: 4px;
    margin-top: 12px;
}

.form-label:first-child {
    margin-top: 0;
}

.form-input {
    width: 100%;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 7px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: #fafafa;
    transition: border .2s;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(5, 150, 105, .08);
    background: #fff;
}

.form-textarea {
    min-height: 70px;
    resize: vertical;
}

/* ── Toast ──────────────────────────────────────────── */

.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: #1f2937;
    color: #fff;
    padding: 12px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 4px 20px rgba(0, 0, 0, .25);
    animation: toastIn .25s ease-out;
    max-width: 360px;
}

.toast.success { border-left: 4px solid #22c55e; }
.toast.error { border-left: 4px solid #ef4444; }
.toast.info { border-left: 4px solid #3b82f6; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 600px) {
    .tab-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tab-btn {
        padding: 10px 12px;
        font-size: 13px;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .search-input {
        min-width: 0;
        width: 100%;
    }

    .stag-grid {
        grid-template-columns: 1fr;
    }

    .stag-card {
        flex-direction: column;
        text-align: center;
    }

    .stag-vs {
        transform: rotate(90deg);
    }

    .summary-row {
        flex-direction: column;
    }
}
