:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --bg-body: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --success: #16a34a;
    --danger: #dc2626;
    --warning-bg: #fef9c3;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Inter', system-ui, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
.main-header { 
    margin-bottom: 24px; 
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.main-header h1 { margin: 0; font-size: 1.6rem; font-weight: 700; color: #1e293b; }
.main-header p { margin: 4px 0 0; color: var(--text-muted); font-size: 0.95rem; }

.header-nav {
    display: flex;
    gap: 8px;
    background: #e5e7eb;
    padding: 4px;
    border-radius: 8px;
}
.nav-link {
    text-decoration: none;
    color: var(--text-muted);
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
}
.nav-link:hover {
    color: var(--text-main);
    background: white;
}
.nav-link-active {
    background: white;
    color: var(--primary);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Utilities */
.hidden { display: none !important; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); font-weight: 500; }
.text-success { color: var(--success); font-weight: 600; }
.text-danger { color: var(--danger); font-weight: 600; }

.btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    font-size: 0.9rem;
    transition: all 0.2s;
}
.btn-sm { padding: 4px 12px; font-size: 0.85rem; }

.btn-xs {
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    background: white;
    cursor: pointer;
    margin-right: 4px;
    color: var(--text-muted);
}
.btn-xs:hover { background: #eff6ff; color: var(--primary); border-color: var(--primary); }

.btn-outline { background: white; border: 1px solid var(--border); color: var(--text-main); }
.btn-outline:hover { background: #f9fafb; border-color: #d1d5db; }
.btn-outline:disabled { color: #d1d5db; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-link { background: none; border: none; color: var(--primary); text-decoration: underline; cursor: pointer; }

/* Inputs */
.small-select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-main);
    background-color: white;
    cursor: pointer;
}

.header-controls {
    display: flex;
    gap: 8px;
}

/* Cards */
.card { background: var(--bg-card); border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); padding: 20px; margin-bottom: 24px; }
.card-body { margin-top: 16px; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.card-header h2, .card-header h3 { margin: 0; font-size: 1.1rem; color: #374151; }

/* Upload Section */
.upload-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.upload-box { border: 2px dashed var(--border); border-radius: 8px; padding: 24px; display: flex; align-items: flex-start; gap: 16px; transition: border-color 0.2s; }
.upload-box:hover { border-color: var(--primary); }
.upload-icon { font-size: 2rem; background: #eff6ff; width: 48px; height: 48px; display: flex; align-items: center; justify-content: center; border-radius: 8px; }
.file-input-label { display: inline-block; margin-top: 8px; }
.small-text { font-size: 0.8rem; color: var(--text-muted); margin: 4px 0 12px; }
.file-name { display: block; margin-top: 8px; font-size: 0.85rem; color: var(--success); font-weight: 600; word-break: break-all; }
.status-badge { padding: 4px 12px; background: #dbeafe; color: #1e40af; border-radius: 20px; font-size: 0.85rem; font-weight: 500; }

/* Stats Grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; margin-bottom: 24px; }
.stat-card { background: white; padding: 20px; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); display: flex; flex-direction: column; }
.stat-label { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 1.5rem; color: #111827; }

/* Filters */
.filters-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; align-items: end; }
.quick-dates { margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 4px; }
.form-group label { display: block; font-size: 0.85rem; margin-bottom: 4px; color: #374151; }
.form-control { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px; font-size: 0.9rem; }
.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-label input { width: 16px; height: 16px; cursor: pointer; }
.full-width-col { grid-column: 1 / -1; }

/* Charts */
.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(450px, 1fr)); gap: 24px; margin-bottom: 24px; }
.chart-container { position: relative; height: 300px; }
.table-scroll { overflow-x: auto; max-height: 400px; }
.clean-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.clean-table th { text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); color: var(--text-muted); font-weight: 600; position: sticky; top: 0; background: white; }
.clean-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.clean-table tr:hover { background-color: #f8fafc; }

/* Sorting */
.sortable { cursor: pointer; user-select: none; }
.sortable:hover { background-color: #f1f5f9; color: var(--primary); }

/* Main Data Table */
.table-wrapper-main { overflow-x: auto; max-height: 500px; border: 1px solid var(--border); border-radius: 8px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.data-table th { background: #f9fafb; padding: 12px; text-align: left; font-weight: 600; color: #374151; position: sticky; top: 0; border-bottom: 1px solid var(--border); z-index: 10; }
.data-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); color: #333; }
.data-table tr:hover { background-color: #f3f4f6; }
.row-warning { background-color: var(--warning-bg) !important; }

/* Puslapiavimas Footer */
.table-footer { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 12px 0; border-top: 1px solid var(--border); margin-top: 8px; 
}
.pagination-footer { justify-content: center; gap: 16px; font-size: 0.9rem; color: var(--text-muted); }

/* Loading Overlay */
.loading-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(255, 255, 255, 0.9);
    z-index: 1000;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
}
.spinner {
    width: 40px; height: 40px;
    border: 4px solid #e5e7eb; border-top: 4px solid var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 16px;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Išsaugotų serverio duomenų (istorinių laikotarpių) blokas */
.saved-period-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    align-items: center;
}

.saved-period-controls select {
    flex: 1 1 220px;
}

.saved-period-controls button {
    flex: 0 0 auto;
    white-space: nowrap;
}

#memory-period-info {
    margin-top: 6px;
}

/* Toast pranešimai */
.toast-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: min(420px, calc(100vw - 40px));
}
.toast {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: white;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.14);
    font-size: 0.9rem;
    color: var(--text-main);
}
.toast button {
    border: 0;
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 1.1rem;
    line-height: 1;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-warning { border-left: 4px solid #f59e0b; background: #fffbeb; }
.toast-error { border-left: 4px solid var(--danger); background: #fef2f2; }
.toast-info { border-left: 4px solid var(--primary); }

.status-success { background: #d1fae5; color: #065f46; }
.status-warning { background: #fef3c7; color: #92400e; }
.status-error { background: #fee2e2; color: #991b1b; }

.compact-checkbox {
    margin-top: 8px;
    font-size: 0.78rem;
    color: var(--text-muted);
    align-items: flex-start;
}
.compact-checkbox span { font-weight: 500; }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
}
.summary-item {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
    background: #f9fafb;
}
.summary-label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.summary-item strong {
    display: block;
    font-size: 0.95rem;
    word-break: break-word;
}
.warning-summary strong { color: #92400e; }

.profit-risk-card {
    border-color: var(--border);
}
.profit-risk-card small {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.78rem;
    line-height: 1.35;
}
.profit-risk-card.risk-low {
    background: #f0fdf4;
    border-color: #bbf7d0;
}
.profit-risk-card.risk-low strong {
    color: #166534;
}
.profit-risk-card.risk-medium {
    background: #fffbeb;
    border-color: #fde68a;
}
.profit-risk-card.risk-medium strong {
    color: #92400e;
}
.profit-risk-card.risk-high {
    background: #fef2f2;
    border-color: #fecaca;
}
.profit-risk-card.risk-high strong {
    color: #991b1b;
}
.summary-warnings {
    margin-top: 14px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f0fdf4;
    color: #166534;
    font-size: 0.88rem;
}
.summary-warnings-active {
    background: #fffbeb;
    color: #92400e;
}
.cost-status {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}
.cost-status-ok { background: #dcfce7; color: #166534; }
.cost-status-missing { background: #fef3c7; color: #92400e; }

.inline-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.btn-warning {
    background: #f59e0b;
    color: white;
}
.btn-warning:hover { background: #d97706; }

@media (max-width: 760px) {
    .main-header { flex-direction: column; align-items: flex-start; gap: 12px; }
    .charts-grid { grid-template-columns: 1fr; }
    .card-header { align-items: flex-start; flex-direction: column; gap: 10px; }
    .header-controls { flex-wrap: wrap; }
}

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg-body);
}
.login-card {
    width: min(420px, 100%);
    background: white;
    border-radius: 14px;
    box-shadow: 0 16px 45px rgba(15, 23, 42, 0.14);
    padding: 28px;
    border: 1px solid var(--border);
}
.login-card h1 {
    margin: 0 0 8px;
    font-size: 1.35rem;
    color: #1e293b;
}
.login-card p {
    margin: 0 0 18px;
    color: var(--text-muted);
    font-size: 0.92rem;
}
.login-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 14px;
    font-size: 0.9rem;
}
.login-submit {
    width: 100%;
    margin-top: 10px;
}
.login-card code {
    background: #f3f4f6;
    border-radius: 4px;
    padding: 1px 4px;
}

/* v4 hardening/admin additions */
.quality-grid {
    margin-bottom: 18px;
}
.quality-panels {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}
.quality-panel {
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    padding: 14px;
    background: #ffffff;
}
.quality-panel h4 {
    margin: 0 0 10px;
    font-size: 0.95rem;
    color: #111827;
}
.compact-scroll {
    max-height: 280px;
    overflow: auto;
}
.compact-table th,
.compact-table td {
    padding: 8px 10px;
    font-size: 0.85rem;
}
.audit-table td {
    vertical-align: top;
}
.audit-context {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    max-width: 680px;
    font-size: 0.78rem;
    line-height: 1.45;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 8px;
}
.small-stat {
    font-size: 0.85rem;
    line-height: 1.35;
    word-break: break-all;
}
.btn-sm {
    padding: 7px 10px;
    font-size: 0.84rem;
}

/* v5 hardening: users, retention, CSV/XLSX presets */
.column-preset-panel {
    margin-top: 20px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #f9fafb;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-actions {
    margin-top: 4px;
}

.settings-checkbox {
    margin-top: 26px;
}

.notice {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-weight: 500;
}
.notice-success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #86efac;
}
.notice-error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.small-inline-control {
    min-width: 180px;
    max-width: 360px;
}

.inline-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* v6 hardening: cron retention help and import-template editor */
.code-block {
    display: block;
    white-space: pre-wrap;
    word-break: break-word;
    background: #f6f8fb;
    border: 1px solid #e5e9f2;
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.5;
    color: #1f2937;
}

.cron-help-panel {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid #e5e9f2;
}

.preset-columns-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 14px;
    margin: 14px 0 18px;
}

.preset-details {
    border: 1px solid #e5e9f2;
    border-radius: 14px;
    padding: 14px 16px;
    margin: 12px 0;
    background: #fff;
}

.preset-details summary {
    cursor: pointer;
    font-weight: 600;
}

.delete-preset-form {
    margin-top: 12px;
}

.required-mark {
    color: #b42318;
    font-weight: 700;
}

/* v9 drill-down and focused exports */
.drilldown-card {
    cursor: pointer;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}
.drilldown-card:hover,
.drilldown-card:focus-visible {
    border-color: #93c5fd;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.12);
    outline: none;
    transform: translateY(-1px);
}
.btn-sm {
    padding: 7px 10px;
    font-size: 0.82rem;
}
.quality-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
}
.drilldown-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 0 0 12px;
    padding: 10px 12px;
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1e40af;
    border-radius: 10px;
    font-size: 0.9rem;
}
.table-link {
    appearance: none;
    border: 0;
    background: transparent;
    color: #2563eb;
    padding: 0;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.table-link:hover,
.table-link:focus-visible {
    color: #1d4ed8;
    outline: none;
}

/* v10 data-quality help section */
.header-title-with-help {
    display: flex;
    align-items: center;
    gap: 8px;
}
.inline-help-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1;
    cursor: help;
}
.inline-help-icon:focus-visible {
    outline: 2px solid #93c5fd;
    outline-offset: 2px;
}
.quality-help-box {
    margin: 0 0 16px;
    padding: 12px 14px;
    border: 1px solid #dbeafe;
    border-radius: 12px;
    background: #f8fbff;
    color: #374151;
}
.quality-help-box summary {
    cursor: pointer;
    color: #1f2937;
    font-size: 0.94rem;
    font-weight: 700;
}
.quality-help-content {
    margin-top: 10px;
    color: #4b5563;
    font-size: 0.91rem;
    line-height: 1.55;
}
.quality-help-content p {
    margin: 0 0 8px;
}
.quality-help-content p:last-child {
    margin-bottom: 0;
}

@media (max-width: 760px) {
    .quality-actions,
    .drilldown-banner {
        align-items: flex-start;
        flex-direction: column;
    }
}

/* v12 exact in-table expansion for multi-line orders */
.quality-order-summary.quality-row-expanded {
    background: #f8fafc;
}
.quality-expand-order {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.expand-marker {
    display: inline-block;
    width: 1em;
    color: #64748b;
    font-weight: 700;
}
.quality-order-detail-row > td {
    background: #f8fafc;
    border-top: 0;
    padding: 0 10px 12px;
}
.quality-order-detail {
    border: 1px solid #dbeafe;
    border-radius: 12px;
    background: #ffffff;
    padding: 12px;
}
.quality-order-detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    color: #1f2937;
}
.quality-order-lines-scroll {
    max-height: 260px;
    overflow: auto;
}
.nested-quality-table {
    min-width: 760px;
    background: #fff;
}
.nested-quality-table th,
.nested-quality-table td {
    font-size: 0.78rem;
}
.table-focus-link {
    white-space: nowrap;
}
@media (max-width: 760px) {
    .quality-order-detail-header {
        align-items: flex-start;
        flex-direction: column;
    }
    .nested-quality-table {
        min-width: 680px;
    }
}

/* v13 mobile data-quality layout: readable expanded order cards */
@media (max-width: 760px) {
    #data-quality-section {
        padding: 16px;
    }

    #data-quality-section .card-header {
        gap: 12px;
    }

    #data-quality-section .header-title-with-help {
        width: 100%;
        align-items: flex-start;
        justify-content: space-between;
    }

    #data-quality-section .quality-actions {
        width: 100%;
    }

    #data-quality-section .quality-actions .btn {
        width: 100%;
        justify-content: center;
        text-align: center;
        white-space: normal;
    }

    #data-quality-section .quality-help-box {
        padding: 12px;
    }

    #data-quality-section .quality-panels {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    #data-quality-section .quality-panel {
        padding: 12px;
        border-radius: 12px;
    }

    #data-quality-section .compact-scroll {
        max-height: none;
        overflow: visible;
    }

    #data-quality-section .quality-panel .clean-table,
    #data-quality-section .quality-panel .clean-table thead,
    #data-quality-section .quality-panel .clean-table tbody,
    #data-quality-section .quality-panel .clean-table tr,
    #data-quality-section .quality-panel .clean-table th,
    #data-quality-section .quality-panel .clean-table td {
        display: block;
        width: 100%;
    }

    #data-quality-section .quality-panel .clean-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
        clip-path: inset(50%);
    }

    #data-quality-section .quality-panel .clean-table tr {
        margin-bottom: 10px;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        background: #ffffff;
        overflow: hidden;
        box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
    }

    #data-quality-section .quality-panel .clean-table tr:hover {
        background: #ffffff;
    }

    #data-quality-section .quality-panel .clean-table td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 14px;
        padding: 9px 10px;
        border-bottom: 1px solid #edf2f7;
        text-align: right;
        word-break: break-word;
    }

    #data-quality-section .quality-panel .clean-table td:last-child {
        border-bottom: 0;
    }

    #data-quality-section .quality-panel .clean-table td::before {
        content: attr(data-label);
        flex: 0 0 38%;
        max-width: 46%;
        color: var(--text-muted);
        font-weight: 700;
        text-align: left;
    }

    #data-quality-section .quality-panel .clean-table td:not([data-label])::before {
        content: none;
    }

    #data-quality-section .quality-panel .clean-table td[colspan] {
        display: block;
        padding: 10px;
        text-align: left;
    }

    #data-quality-section .quality-panel .clean-table td[colspan]::before {
        content: none;
    }

    #data-quality-section .quality-expand-order {
        max-width: 100%;
        justify-content: flex-end;
        text-align: right;
        word-break: break-word;
    }

    #data-quality-section .quality-order-detail-row {
        border: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
        margin-top: -4px;
    }

    #data-quality-section .quality-order-detail-row > td {
        padding: 0 0 12px;
        background: transparent;
    }

    #data-quality-section .quality-order-detail {
        padding: 10px;
        border-radius: 12px;
    }

    #data-quality-section .quality-order-detail-header {
        gap: 8px;
        margin-bottom: 8px;
    }

    #data-quality-section .quality-order-lines-scroll {
        max-height: none;
        overflow: visible;
    }

    #data-quality-section .nested-quality-table {
        min-width: 0;
        width: 100%;
    }

    #data-quality-section .nested-quality-table tr {
        background: #f8fafc;
        border-color: #dbeafe;
    }

    #data-quality-section .nested-quality-table td {
        font-size: 0.82rem;
    }

    #data-quality-section .table-focus-link {
        width: 100%;
        text-align: left;
        white-space: normal;
    }
}

@media (max-width: 480px) {
    .app-container {
        padding: 12px;
    }

    #data-quality-section .summary-grid {
        grid-template-columns: 1fr;
    }

    #data-quality-section .quality-panel .clean-table td {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        text-align: left;
    }

    #data-quality-section .quality-panel .clean-table td::before {
        flex-basis: auto;
        max-width: 100%;
    }

    #data-quality-section .quality-expand-order {
        justify-content: flex-start;
        text-align: left;
    }
}

/* v14 diagnosis/fix: data-quality panels can be narrow inside a wide desktop viewport.
   The previous v13 rules only used viewport breakpoints, so two compact tables could stay
   cramped and scroll-heavy even when each individual panel was too narrow. */
#data-quality-section .header-title-with-help {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
#data-quality-section .inline-help-icon {
    flex: 0 0 auto;
}
#data-quality-section .quality-panels {
    align-items: start;
}
#data-quality-section .quality-panel {
    min-width: 0;
}
#data-quality-section .quality-panel .clean-table {
    table-layout: auto;
}
#data-quality-section .quality-panel .compact-scroll {
    max-height: 360px;
}
#data-quality-section .quality-actions-cell {
    white-space: nowrap;
}
#data-quality-section .quality-expand-action {
    min-width: 92px;
}
#data-quality-section .quality-order-detail {
    min-width: 0;
}

/* JS-applied fallback for panel-width based responsiveness. */
#data-quality-section .quality-panel.quality-panel-narrow .compact-scroll {
    max-height: none;
    overflow: visible;
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table,
#data-quality-section .quality-panel.quality-panel-narrow .clean-table thead,
#data-quality-section .quality-panel.quality-panel-narrow .clean-table tbody,
#data-quality-section .quality-panel.quality-panel-narrow .clean-table tr,
#data-quality-section .quality-panel.quality-panel-narrow .clean-table th,
#data-quality-section .quality-panel.quality-panel-narrow .clean-table td {
    display: block;
    width: 100%;
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    clip-path: inset(50%);
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table tr {
    margin-bottom: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #ffffff;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table tr:hover {
    background: #ffffff;
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    padding: 9px 10px;
    border-bottom: 1px solid #edf2f7;
    text-align: right;
    word-break: break-word;
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table td:last-child {
    border-bottom: 0;
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table td::before {
    content: attr(data-label);
    flex: 0 0 38%;
    max-width: 46%;
    color: var(--text-muted);
    font-weight: 700;
    text-align: left;
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table td:not([data-label])::before {
    content: none;
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table td[colspan] {
    display: block;
    padding: 0 0 12px;
    text-align: left;
    background: transparent;
}
#data-quality-section .quality-panel.quality-panel-narrow .clean-table td[colspan]::before {
    content: none;
}
#data-quality-section .quality-panel.quality-panel-narrow .quality-expand-order {
    max-width: 100%;
    justify-content: flex-end;
    text-align: right;
    word-break: break-word;
}
#data-quality-section .quality-panel.quality-panel-narrow .quality-actions-cell .btn {
    width: 100%;
    justify-content: center;
}
#data-quality-section .quality-panel.quality-panel-narrow .quality-order-detail-row {
    border: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
    margin-top: -4px;
}
#data-quality-section .quality-panel.quality-panel-narrow .quality-order-detail {
    padding: 10px;
    border-radius: 12px;
}
#data-quality-section .quality-panel.quality-panel-narrow .quality-order-detail-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
}
#data-quality-section .quality-panel.quality-panel-narrow .quality-order-lines-scroll {
    max-height: none;
    overflow: visible;
}
#data-quality-section .quality-panel.quality-panel-narrow .nested-quality-table {
    min-width: 0;
    width: 100%;
}
#data-quality-section .quality-panel.quality-panel-narrow .nested-quality-table tr {
    background: #f8fafc;
    border-color: #dbeafe;
}
#data-quality-section .quality-panel.quality-panel-narrow .nested-quality-table td {
    font-size: 0.82rem;
}
#data-quality-section .quality-panel.quality-panel-narrow .table-focus-link {
    width: 100%;
    text-align: left;
    white-space: normal;
}

/* Native CSS container-query version for browsers that support it; JS class above is the fallback. */
@supports (container-type: inline-size) {
    #data-quality-section .quality-panel {
        container-type: inline-size;
        container-name: quality-panel;
    }
    @container quality-panel (max-width: 760px) {
        .compact-scroll {
            max-height: none;
            overflow: visible;
        }
    }
}

/* v15 exact missing periods + stronger mobile/responsive hardening */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

button,
.btn,
.nav-link,
.form-control,
.table-link,
.quality-order-expand-cell {
    touch-action: manipulation;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
[role="button"]:focus-visible {
    outline: 3px solid rgba(37, 99, 235, 0.35);
    outline-offset: 2px;
}

.app-container {
    width: min(100%, 1400px);
    padding-left: clamp(12px, 2vw, 20px);
    padding-right: clamp(12px, 2vw, 20px);
}

.main-header,
.card-header,
.header-actions,
.header-controls,
.quality-actions {
    min-width: 0;
}

.header-nav {
    max-width: 100%;
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.nav-link,
.btn,
.btn-xs,
.form-control {
    min-height: 40px;
}

.table-wrapper-main,
.table-scroll,
.compact-scroll,
.quality-order-lines-scroll {
    -webkit-overflow-scrolling: touch;
}

.incomplete-periods {
    margin-top: 12px;
    border: 1px solid #fde68a;
    background: #fffbeb;
    color: #78350f;
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.88rem;
}
.incomplete-periods strong {
    display: block;
    margin-bottom: 4px;
    color: #92400e;
}
.incomplete-periods p {
    margin: 0 0 8px;
}
.incomplete-periods ul {
    margin: 0;
    padding-left: 18px;
}
.incomplete-periods li {
    margin: 4px 0;
}
.incomplete-period-label {
    font-weight: 700;
    margin-right: 6px;
}
.incomplete-period-missing {
    color: #9a3412;
}

.quality-order-expand-cell {
    cursor: pointer;
    user-select: none;
}
.quality-order-expand-cell:hover,
.quality-order-summary:hover .quality-order-expand-cell {
    color: var(--primary);
}
.quality-order-main {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.quality-order-hint {
    display: block;
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 600;
}
.quality-order-detail-meta {
    display: block;
    color: var(--text-muted);
    font-size: 0.78rem;
    margin-top: 2px;
    font-weight: 600;
}

@media (max-width: 1024px) {
    .main-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }
    .header-nav {
        width: 100%;
    }
    .stats-grid,
    .summary-grid,
    .quality-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
    }
    .charts-grid,
    .quality-panels {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    body {
        background: #f8fafc;
    }
    .app-container {
        padding: 10px;
    }
    .card,
    .stat-card,
    .summary-item,
    .quality-panel {
        border-radius: 10px;
    }
    .card {
        padding: 14px;
        margin-bottom: 16px;
    }
    .main-header h1 {
        font-size: 1.25rem;
    }
    .main-header p {
        font-size: 0.86rem;
    }
    .header-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 6px;
        background: transparent;
        padding: 0;
    }
    .nav-link {
        background: #e5e7eb;
        text-align: center;
        padding: 9px 8px;
    }
    .nav-link-active {
        background: #ffffff;
    }
    .upload-grid,
    .filters-grid,
    .column-preset-panel,
    .stats-grid,
    .summary-grid,
    .quality-grid {
        grid-template-columns: 1fr !important;
    }
    .upload-box {
        padding: 14px;
        gap: 12px;
    }
    .upload-icon {
        width: 40px;
        height: 40px;
        font-size: 1.35rem;
    }
    .saved-period-controls,
    .inline-actions,
    .header-actions,
    .header-controls,
    .quality-actions {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .btn,
    .btn-sm,
    .btn-xs,
    .form-control {
        width: 100%;
        min-height: 44px;
    }
    .quick-dates {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 8px;
    }
    .toast-container {
        left: 10px;
        right: 10px;
        bottom: calc(10px + env(safe-area-inset-bottom));
        max-width: none;
    }
    .toast {
        width: 100%;
        align-items: flex-start;
    }
    .incomplete-periods {
        font-size: 0.84rem;
        padding: 10px;
    }
    .incomplete-periods li {
        display: flex;
        flex-direction: column;
        gap: 2px;
        margin: 8px 0;
    }
    .quality-order-expand-cell {
        align-items: flex-start !important;
        cursor: pointer;
    }
    .quality-order-main,
    .quality-order-hint {
        width: 100%;
    }
    .quality-actions-cell {
        text-align: left !important;
    }
    .table-footer,
    .pagination-footer {
        flex-direction: column;
        gap: 10px;
    }
}

@media (max-width: 420px) {
    .header-nav,
    .quick-dates {
        grid-template-columns: 1fr;
    }
    .stat-card,
    .summary-item {
        padding: 14px;
    }
    .stat-value {
        font-size: 1.2rem;
    }
    .clean-table,
    .data-table {
        font-size: 0.78rem;
    }
}

/* v16 compact data-quality previews: keep the section useful without overwhelming the page. */
#data-quality-section .compact-scroll {
    max-height: 260px;
}

#data-quality-section .quality-preview-note-row,
#data-quality-section .quality-preview-note-row:hover {
    background: transparent;
    box-shadow: none;
}

#data-quality-section .quality-preview-note-row > td {
    padding: 8px 0 0;
    border-bottom: 0;
}

#data-quality-section .quality-preview-note {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 10px;
    border: 1px dashed #cbd5e1;
    border-radius: 10px;
    background: #f8fafc;
    color: #475569;
    font-size: 0.82rem;
    line-height: 1.35;
}

#data-quality-section .quality-preview-toggle {
    flex: 0 0 auto;
    font-size: 0.82rem;
    font-weight: 700;
}

#data-quality-section .quality-panel.quality-panel-narrow .compact-scroll {
    max-height: 340px;
    overflow: auto;
}

#data-quality-section .quality-panel.quality-panel-narrow .quality-preview-note-row {
    border: 0;
    margin: 0;
    box-shadow: none;
}

#data-quality-section .quality-panel.quality-panel-narrow .quality-preview-note-row > td {
    display: block;
    padding: 6px 0 0;
}

#data-quality-section .quality-panel.quality-panel-narrow .quality-preview-note-row > td::before {
    content: none;
}

@media (max-width: 760px) {
    #data-quality-section {
        padding: 12px;
    }

    #data-quality-section .quality-panel {
        padding: 10px;
    }

    #data-quality-section .compact-scroll,
    #data-quality-section .quality-panel.quality-panel-narrow .compact-scroll {
        max-height: 360px;
        overflow: auto;
        overscroll-behavior: contain;
        border-radius: 10px;
    }

    #data-quality-section .quality-panel .clean-table tr,
    #data-quality-section .quality-panel.quality-panel-narrow .clean-table tr {
        margin-bottom: 7px;
        border-radius: 10px;
    }

    #data-quality-section .quality-panel .clean-table td,
    #data-quality-section .quality-panel.quality-panel-narrow .clean-table td {
        padding: 6px 8px;
        gap: 8px;
        font-size: 0.82rem;
    }

    #data-quality-section .quality-order-hint {
        font-size: 0.72rem;
    }

    #data-quality-section .quality-preview-note {
        flex-direction: column;
        align-items: stretch;
        padding: 8px;
    }

    #data-quality-section .quality-preview-toggle {
        width: 100%;
        min-height: 36px;
        text-align: left;
    }
}

@media (max-width: 420px) {
    #data-quality-section .compact-scroll,
    #data-quality-section .quality-panel.quality-panel-narrow .compact-scroll {
        max-height: 330px;
    }

    #data-quality-section .quality-panel .clean-table td,
    #data-quality-section .quality-panel.quality-panel-narrow .clean-table td {
        padding: 6px 7px;
    }
}

/* v17 dashboard editor and monthly trend chart */
.dashboard-editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 0 0 18px;
    padding: 12px 14px;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.dashboard-editor-toolbar > div:first-child {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dashboard-editor-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.dashboard-section-controls {
    display: none;
    grid-column: 1 / -1;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    padding: 8px 10px;
    border: 1px dashed #93c5fd;
    border-radius: 10px;
    background: #eff6ff;
    color: #1e3a8a;
}

.dashboard-editing [data-dashboard-section] {
    position: relative;
    outline: 2px dashed #bfdbfe;
    outline-offset: 2px;
}

.dashboard-editing .dashboard-section-controls {
    display: flex;
}

.dashboard-section-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: #dbeafe;
    font-weight: 700;
    color: #1d4ed8;
}

.dashboard-section-control-spacer {
    flex: 1 1 auto;
}

.charts-grid-single {
    grid-template-columns: 1fr;
}

.chart-card-wide {
    min-width: 0;
}

.chart-subtitle {
    margin: 4px 0 0;
}

.chart-container-tall {
    height: 340px;
}

@media (max-width: 760px) {
    .dashboard-editor-toolbar {
        align-items: stretch;
        flex-direction: column;
        padding: 12px;
    }

    .dashboard-editor-actions {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
    }

    .dashboard-section-controls {
        align-items: stretch;
        flex-wrap: wrap;
        gap: 6px;
    }

    .dashboard-section-control-spacer {
        display: none;
    }

    .dashboard-section-controls .btn {
        flex: 1 1 140px;
        min-height: 38px;
    }

    .chart-container-tall {
        height: 300px;
    }
}

/* v18 dashboard drag/drop, section visibility and universal table sorting */
body:not(.dashboard-editing) [data-dashboard-section].dashboard-section-user-hidden {
    display: none !important;
}

.dashboard-editing [data-dashboard-section].dashboard-section-user-hidden {
    opacity: 0.52;
    filter: grayscale(0.2);
}

.dashboard-editing [data-dashboard-section].dashboard-section-user-hidden::after {
    content: "Paslėpta";
    position: absolute;
    top: 8px;
    right: 10px;
    z-index: 2;
    padding: 3px 8px;
    border-radius: 999px;
    background: #fee2e2;
    color: #991b1b;
    font-size: 0.72rem;
    font-weight: 700;
}

.dashboard-section-handle {
    cursor: grab;
    touch-action: none;
}

.dashboard-section-handle:active {
    cursor: grabbing;
}

.dashboard-section-dragging {
    opacity: 0.45;
    transform: scale(0.995);
}

.dashboard-section-visibility-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 4px 8px;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    background: #ffffff;
    color: #1e40af;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}

.dashboard-section-visibility-toggle input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

table th[data-sort],
table th.sortable {
    position: relative;
    cursor: pointer;
    user-select: none;
    padding-right: 22px;
}

table th[data-sort]:hover,
table th.sortable:hover {
    background: #f1f5f9;
    color: var(--primary);
}

table th[data-sort]::after,
table th.sortable::after {
    content: "↕";
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 0.72rem;
    line-height: 1;
}

table th.sort-active.sort-asc::after {
    content: "↑";
    color: var(--primary);
}

table th.sort-active.sort-desc::after {
    content: "↓";
    color: var(--primary);
}

table th.no-sort,
table th.no-sort:hover {
    cursor: default;
    padding-right: 12px;
}

table th.no-sort::after {
    content: none;
}

@media (max-width: 760px) {
    .dashboard-section-visibility-toggle {
        flex: 1 1 120px;
        justify-content: center;
    }

    .dashboard-section-handle {
        width: 36px;
        height: 36px;
    }

    .dashboard-editing [data-dashboard-section].dashboard-section-user-hidden::after {
        top: 6px;
        right: 6px;
    }

    table th[data-sort]::after,
    table th.sortable::after {
        right: 4px;
    }
}


/* v19: table-level period controls */
.card-header .header-controls .date-filter-select { min-width: 128px; }
#table-section .card-header .header-controls { flex-wrap: wrap; justify-content: flex-end; }
.quality-actions .date-filter-select { max-width: 145px; }
@media (max-width: 760px) {
  .card-header .header-controls, .quality-actions { width: 100%; justify-content: stretch; gap: 8px; }
  .card-header .header-controls .date-filter-select,
  .quality-actions .date-filter-select,
  #table-section .card-header .header-controls .btn { width: 100%; max-width: none; }
}

/* =========================================
   v20: Naujos diagramos ir lentelės
   ========================================= */

/* Bendra: tekstas */
.text-warning { color: #c2410c; font-weight: 600; }
.muted { color: var(--text-muted); font-size: 0.9rem; }

/* --- Pareto / koncentracijos santrauka --- */
.concentration-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 12px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.concentration-pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #ffffff;
    border: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-main);
    white-space: nowrap;
}
.concentration-pill strong { color: var(--primary); }
.concentration-pill.concentration-high {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}
.concentration-pill.concentration-high strong { color: #b91c1c; }
.concentration-pill.concentration-mid {
    background: #fffbeb;
    border-color: #fde68a;
    color: #92400e;
}
.concentration-pill.concentration-mid strong { color: #b45309; }
.concentration-pill.concentration-ok {
    background: #f0fdf4;
    border-color: #bbf7d0;
    color: #166534;
}
.concentration-pill.concentration-ok strong { color: #15803d; }

/* --- Savaitės dienos × valandos šilumos žemėlapis --- */
.heatmap-wrapper {
    width: 100%;
    overflow-x: auto;
    padding: 6px 2px 12px;
}
.heatmap-grid {
    border-collapse: separate;
    border-spacing: 2px;
    font-size: 0.7rem;
    margin: 0 auto;
}
.heatmap-grid th,
.heatmap-grid td {
    text-align: center;
    padding: 0;
    border: none;
    background: transparent;
}
.heatmap-grid .heatmap-corner {
    width: 38px;
    background: transparent;
}
.heatmap-grid .heatmap-hour-label {
    width: 26px;
    height: 18px;
    color: var(--text-muted);
    font-size: 0.65rem;
    font-weight: 500;
}
.heatmap-grid .heatmap-day-label {
    width: 38px;
    text-align: right;
    padding-right: 6px;
    color: var(--text-main);
    font-weight: 600;
    background: transparent;
}
.heatmap-grid .heatmap-total-label {
    width: 92px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    padding-left: 6px;
    text-align: left;
}
.heatmap-grid .heatmap-cell {
    width: 26px;
    height: 26px;
    border-radius: 3px;
    font-size: 0.62rem;
    line-height: 1;
    font-weight: 600;
    border: 1px solid rgba(0,0,0,0.04);
    cursor: default;
    transition: transform 0.1s ease;
}
.heatmap-grid .heatmap-cell:hover {
    transform: scale(1.18);
    z-index: 2;
    box-shadow: 0 1px 6px rgba(0,0,0,0.18);
    border-color: rgba(0,0,0,0.2);
}
.heatmap-grid .heatmap-total {
    width: 92px;
    text-align: left;
    padding-left: 8px;
    color: var(--text-main);
    font-size: 0.78rem;
    background: #f8fafc;
    border-radius: 3px;
}
.heatmap-grid tr.heatmap-weekend .heatmap-day-label {
    color: #92400e;
}
.heatmap-grid tr.heatmap-weekend .heatmap-total {
    background: #fef3c7;
}
.heatmap-summary {
    margin-top: 8px;
    padding: 8px 12px;
    background: #f8fafc;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-main);
}
.heatmap-summary strong { color: var(--primary); }

/* --- Apmokėjimo būdo lentelė --- */
.payment-variant-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    background: #fef3c7;
    border: 1px solid #fde68a;
    border-radius: 4px;
    font-size: 0.7rem;
    color: #92400e;
    cursor: help;
    white-space: nowrap;
}
.payment-method-quality {
    margin-top: 10px;
}
.payment-method-quality .data-quality-note {
    display: inline-block;
    padding: 6px 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 6px;
    font-size: 0.82rem;
    color: #1e40af;
}

/* --- Išsaugotų laikotarpių laiko juosta (overlap ribbon) --- */
.period-overlap-block {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
}
.period-overlap-block .card-header {
    margin-bottom: 6px;
    padding: 0;
    border: none;
    background: transparent;
}
.period-overlap-block .card-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}
.period-overlap-block .small-text {
    margin: 4px 0 12px;
    color: var(--text-muted);
    font-size: 0.82rem;
    line-height: 1.45;
}
.period-overlap-svg-container {
    width: 100%;
    overflow-x: auto;
    background: #ffffff;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 4px;
    min-height: 80px;
}
.period-overlap-svg-container svg {
    display: block;
    min-width: 600px;
    max-width: 100%;
    height: auto;
}
.period-overlap-summary {
    margin-top: 10px;
}
.period-overlap-summary .period-overlap-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}
.period-overlap-warning {
    margin: 8px 0 0;
    padding: 10px 12px;
    background: #fff7ed;
    border: 1px solid #fed7aa;
    border-left: 4px solid #f97316;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #7c2d12;
    line-height: 1.5;
}

/* Mažo ekrano patobulinimai */
@media (max-width: 760px) {
    .heatmap-grid { font-size: 0.62rem; }
    .heatmap-grid .heatmap-cell { width: 20px; height: 20px; }
    .heatmap-grid .heatmap-hour-label { width: 20px; }
    .heatmap-grid .heatmap-total,
    .heatmap-grid .heatmap-total-label { width: 70px; }
    .concentration-summary { gap: 6px; padding: 8px; }
    .concentration-pill { font-size: 0.72rem; padding: 3px 8px; }
}

/* --- v22 chart drilldowns, low-margin filter, export controls --- */
.clickable-table-row,
.heatmap-cell-clickable {
    cursor: pointer;
}
.clickable-table-row:hover,
.clickable-table-row:focus,
.heatmap-cell-clickable:hover,
.heatmap-cell-clickable:focus {
    outline: 2px solid rgba(37, 99, 235, 0.25);
    outline-offset: -2px;
    background-color: #eff6ff;
}
.low-margin-filter-panel {
    margin: -4px 0 12px;
    padding: 10px 12px;
    border: 1px solid #dbeafe;
    background: #f8fbff;
    border-radius: 10px;
}
.low-margin-filter-panel .checkbox-label {
    margin-bottom: 8px;
}
.low-margin-inputs {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: end;
}
.low-margin-inputs label {
    display: grid;
    gap: 4px;
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}
.small-number-input {
    width: 140px;
    min-height: 34px;
}
#low-margin-filter-summary {
    margin: 8px 0 0;
    color: var(--text-muted);
}
.period-overlap-info {
    margin: 8px 0 0;
    padding: 10px 12px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-left: 4px solid #2563eb;
    border-radius: 6px;
    font-size: 0.85rem;
    color: #1e3a8a;
    line-height: 1.5;
}
.header-controls .btn-sm {
    white-space: nowrap;
}
.chart-card-wide .header-controls {
    flex-wrap: wrap;
}

@media (max-width: 760px) {
    .low-margin-inputs {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }
    .small-number-input {
        width: 100%;
    }
    .header-controls .btn-sm,
    .chart-card-wide .header-controls .btn-sm {
        width: 100%;
    }
    .payment-method-quality .data-quality-note,
    .period-overlap-info,
    .period-overlap-warning {
        font-size: 0.78rem;
    }
}

@media (max-width: 460px) {
    .low-margin-inputs {
        grid-template-columns: 1fr;
    }
}

/* --- v23 responsive analytics layout and chart usability pass --- */
.app-container {
    max-width: 1480px;
    padding-left: clamp(12px, 2vw, 24px);
    padding-right: clamp(12px, 2vw, 24px);
}
.card,
.chart-card,
.summary-item,
.stat-card,
.quality-panel {
    min-width: 0;
}
.card-header {
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-start;
}
.card-header > div:first-child {
    min-width: 0;
}
.header-controls {
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    min-width: 0;
}
.header-controls .btn,
.header-controls .small-select {
    min-height: 36px;
}
#charts-section {
    min-width: 0;
}
#charts-section .charts-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr));
    gap: clamp(16px, 1.6vw, 22px);
    align-items: stretch;
}
#charts-section .charts-grid-single {
    grid-template-columns: minmax(0, 1fr);
}
#charts-section .card,
#charts-section .chart-card {
    min-width: 0;
    overflow: hidden;
}
#charts-section .chart-card {
    display: flex;
    flex-direction: column;
}
#charts-section .chart-card .card-header {
    margin-bottom: 12px;
}
#charts-section .chart-card .card-header h3 {
    line-height: 1.25;
}
.chart-subtitle {
    max-width: 72ch;
    line-height: 1.35;
}
#charts-section .chart-container {
    height: clamp(300px, 30vw, 390px);
    min-height: 300px;
    width: 100%;
}
#charts-section .chart-container-tall {
    height: clamp(340px, 34vw, 430px);
}
#charts-section canvas {
    max-width: 100%;
}
.chart-interaction-hint {
    margin: 8px 0 0;
    padding: 7px 10px;
    border: 1px solid #dbeafe;
    background: #eff6ff;
    color: #1e40af;
    border-radius: 8px;
    font-size: 0.78rem;
    line-height: 1.35;
}
.concentration-summary {
    align-items: flex-start;
}
.concentration-pill {
    line-height: 1.35;
}
.heatmap-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}
.heatmap-grid {
    width: max-content;
    min-width: 100%;
}
.payment-method-quality,
.heatmap-summary,
.concentration-summary {
    overflow-wrap: anywhere;
}
#payment-method-table th,
#payment-method-table td {
    white-space: nowrap;
}
#payment-method-table td:first-child,
#payment-method-table th:first-child {
    white-space: normal;
    min-width: 180px;
}
.low-margin-filter-panel {
    overflow: hidden;
}
.period-overlap-block {
    overflow: hidden;
}
.period-overlap-svg-container {
    -webkit-overflow-scrolling: touch;
}
.drilldown-banner {
    flex-wrap: wrap;
}
.table-wrapper-main,
.table-scroll {
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 1280px) {
    #charts-section .charts-grid:not(.charts-grid-single) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    #charts-section .chart-card-wide {
        grid-column: 1 / -1;
    }
    #charts-section .chart-card-wide .chart-container,
    #charts-section .chart-card-wide.chart-card .chart-container {
        height: 390px;
    }
}

@media (max-width: 1180px) {
    #charts-section .charts-grid {
        grid-template-columns: minmax(0, 1fr);
    }
    #charts-section .chart-container,
    #charts-section .chart-container-tall {
        height: 340px;
    }
    .chart-card .header-controls,
    #charts-section .header-controls {
        justify-content: flex-start;
    }
}

@media (max-width: 760px) {
    body {
        font-size: 14px;
    }
    .app-container {
        padding: 10px;
    }
    .main-header {
        align-items: flex-start;
        gap: 12px;
    }
    .main-header h1 {
        font-size: 1.25rem;
    }
    .header-nav {
        width: 100%;
        overflow-x: auto;
        flex-wrap: nowrap;
        justify-content: flex-start;
    }
    .nav-link {
        white-space: nowrap;
    }
    .card {
        padding: 14px;
        border-radius: 10px;
        margin-bottom: 16px;
    }
    .card-header {
        display: grid;
        grid-template-columns: 1fr;
        gap: 10px;
        margin-bottom: 12px;
    }
    .header-actions,
    .header-controls,
    .quality-actions,
    .dashboard-editor-actions {
        width: 100%;
        justify-content: stretch;
    }
    .header-controls > *,
    .header-actions > *,
    .quality-actions > *,
    .dashboard-editor-actions > * {
        flex: 1 1 auto;
        min-width: min(100%, 150px);
    }
    .small-select,
    .btn,
    .btn-sm {
        min-height: 40px;
        font-size: 0.86rem;
    }
    .stats-grid,
    .summary-grid,
    .quality-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    #charts-section .chart-container,
    #charts-section .chart-container-tall {
        height: 310px;
        min-height: 290px;
    }
    .chart-interaction-hint {
        font-size: 0.74rem;
    }
    .heatmap-wrapper {
        margin-left: -4px;
        margin-right: -4px;
    }
    .heatmap-grid .heatmap-cell {
        min-width: 22px;
    }
    #payment-method-table th,
    #payment-method-table td {
        white-space: normal;
    }
    .low-margin-filter-panel {
        padding: 10px;
    }
    .low-margin-inputs {
        grid-template-columns: 1fr;
    }
    .toast-container {
        left: 10px;
        right: 10px;
        bottom: 10px;
        width: auto;
    }
}

@media (max-width: 480px) {
    #charts-section .chart-container,
    #charts-section .chart-container-tall {
        height: 285px;
    }
    .chart-subtitle,
    .small-text {
        font-size: 0.75rem;
    }
    .chart-interaction-hint {
        display: none;
    }
    .dashboard-editor-toolbar {
        padding: 12px;
    }
}

/* v24: chart drilldown reset shortcuts and main-table column visibility */
.chart-reset-drilldown {
    white-space: nowrap;
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1d4ed8;
}
.chart-reset-drilldown:not(.hidden):hover,
.chart-reset-drilldown:not(.hidden):focus-visible {
    background: #dbeafe;
    color: #1e40af;
}
.table-column-controls {
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #f9fafb;
    margin: 0 0 12px 0;
    overflow: hidden;
}
.table-column-controls > summary {
    cursor: pointer;
    list-style: none;
    padding: 11px 14px;
    font-weight: 700;
    color: #374151;
    user-select: none;
}
.table-column-controls > summary::-webkit-details-marker {
    display: none;
}
.table-column-controls > summary::before {
    content: '▸';
    display: inline-block;
    margin-right: 8px;
    transition: transform .16s ease;
}
.table-column-controls[open] > summary::before {
    transform: rotate(90deg);
}
.table-column-controls-body {
    padding: 0 14px 14px;
    border-top: 1px solid #e5e7eb;
}
.table-column-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(155px, 1fr));
    gap: 8px 14px;
    padding-top: 12px;
}
.table-column-grid label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: .88rem;
    color: #374151;
    min-height: 34px;
}
.table-column-grid input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: #2563eb;
}
.table-column-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-top: 12px;
}
.table-col-hidden {
    display: none !important;
}
#data-table th[hidden],
#data-table td[hidden] {
    display: none !important;
}

@media (max-width: 760px) {
    .chart-reset-drilldown {
        flex-basis: 100%;
    }
    .table-column-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .table-column-actions > .btn {
        flex: 1 1 140px;
    }
}

@media (max-width: 480px) {
    .table-column-grid {
        grid-template-columns: 1fr;
    }
    .table-column-controls > summary,
    .table-column-controls-body {
        padding-left: 10px;
        padding-right: 10px;
    }
}


/* v25: aiškesnis klientų koncentracijos paaiškinimas */
.pareto-explanation-box {
    display: grid;
    gap: 6px;
    margin: 10px 0 8px;
    padding: 10px 12px;
    border: 1px solid #bfdbfe;
    background: #eff6ff;
    border-radius: 8px;
    color: #1e3a8a;
    font-size: 0.86rem;
    line-height: 1.45;
}
.pareto-explanation-box strong {
    color: #172554;
}
.pareto-explanation-box span {
    display: block;
}
@media (max-width: 760px) {
    .pareto-explanation-box {
        font-size: 0.82rem;
        padding: 9px 10px;
    }
    .concentration-pill {
        width: 100%;
        justify-content: space-between;
        white-space: normal;
    }
}

/* v26: deduplikacijos auditas, paaiškinimai ir lentelės tankis */
.dedupe-audit-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-top: 12px;
    padding: 12px 14px;
    border: 1px solid #bfdbfe;
    border-left: 4px solid #2563eb;
    background: #eff6ff;
    border-radius: 8px;
    color: #1e3a8a;
}
.dedupe-audit-panel strong {
    color: #172554;
}
.dedupe-audit-panel p {
    margin: 4px 0 0;
}
.chart-explanation-box {
    display: grid;
    gap: 6px;
    margin: 10px 0 8px;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-left: 4px solid #60a5fa;
    background: #f8fafc;
    border-radius: 8px;
    color: #374151;
    font-size: 0.86rem;
    line-height: 1.45;
}
.chart-explanation-box strong {
    color: #111827;
}
.chart-explanation-box span {
    display: block;
}
.data-density-compact #data-table th,
.data-density-compact #data-table td {
    padding-top: 6px;
    padding-bottom: 6px;
    font-size: 0.82rem;
    line-height: 1.25;
}
.data-density-compact #data-table td:nth-child(4) {
    max-width: 420px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.data-density-normal #data-table th,
.data-density-normal #data-table td {
    padding-top: 10px;
    padding-bottom: 10px;
}
.data-density-detailed #data-table th,
.data-density-detailed #data-table td {
    padding-top: 14px;
    padding-bottom: 14px;
    font-size: 0.94rem;
    line-height: 1.55;
    vertical-align: top;
}
.data-density-detailed #data-table td:nth-child(4) {
    min-width: 280px;
    white-space: normal;
}
#data-table-density-select {
    min-width: 150px;
}
@media (max-width: 760px) {
    .dedupe-audit-panel {
        align-items: stretch;
        flex-direction: column;
    }
    .dedupe-audit-panel .btn {
        width: 100%;
    }
    .chart-explanation-box {
        font-size: 0.82rem;
        padding: 9px 10px;
    }
    #data-table-density-select {
        width: 100%;
    }
}

/* v27: selected-payment analytics refinements */
.chart-container-compact {
    min-height: 260px;
    height: 300px;
}

#credit-client-usage-table,
#credit-share-table {
    min-width: 760px;
}

#credit-client-usage-table tbody tr,
#credit-share-table tbody tr {
    cursor: pointer;
}

.credit-analytics-note,
#credit-trend-summary,
#client-payment-mix-summary,
#credit-share-summary {
    margin-top: 10px;
    font-size: 13px;
    color: #475569;
    line-height: 1.45;
}

#credit-share-min-select {
    min-width: 92px;
}

@media (max-width: 900px) {
    .chart-container-compact {
        height: 260px;
        min-height: 240px;
    }

    #credit-client-usage-table,
    #credit-share-table {
        min-width: 0;
    }

    #credit-client-usage-table thead,
    #credit-share-table thead {
        display: none;
    }

    #credit-client-usage-table tr,
    #credit-share-table tr {
        display: block;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        margin-bottom: 10px;
        padding: 8px 10px;
        background: #fff;
    }

    #credit-client-usage-table td,
    #credit-share-table td {
        display: flex;
        justify-content: space-between;
        gap: 12px;
        border: 0;
        padding: 6px 0;
        text-align: right !important;
        white-space: normal;
    }

    #credit-client-usage-table td::before,
    #credit-share-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        text-align: left;
    }
}

/* v29: all-analytics workbook export */
.analytics-export-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    border: 1px solid #dbeafe;
    background: linear-gradient(135deg, #ffffff 0%, #eff6ff 100%);
}
.analytics-export-toolbar h3 {
    margin: 0 0 4px 0;
}
.analytics-export-toolbar .small-text {
    margin: 0;
    max-width: 760px;
}
.analytics-export-toolbar .btn {
    white-space: nowrap;
}
@media (max-width: 760px) {
    .analytics-export-toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .analytics-export-toolbar .btn {
        width: 100%;
    }
}

/* v31: dashboard PDF export action */
.analytics-export-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
    min-width: 260px;
}
.analytics-export-actions .btn {
    min-height: 40px;
}
@media (max-width: 760px) {
    .analytics-export-actions {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }
    .analytics-export-actions .btn {
        width: 100%;
    }
}


/* v32 — Delivery analytics */
.delivery-logic-note {
    margin: 18px 0;
}
.delivery-summary-grid {
    margin: 18px 0 22px;
}
.delivery-summary-grid .summary-item strong {
    font-size: 1.08rem;
}
#delivery-method-cost-table td,
#delivery-method-cost-table th {
    vertical-align: middle;
}
@media (max-width: 900px) {
    #shipping-summary-section .charts-grid {
        grid-template-columns: 1fr;
    }
    #delivery-method-cost-table thead {
        display: none;
    }
    #delivery-method-cost-table tr {
        display: block;
        border: 1px solid #e5e7eb;
        border-radius: 14px;
        padding: 10px 12px;
        margin-bottom: 10px;
        background: #fff;
    }
    #delivery-method-cost-table td {
        display: flex;
        justify-content: space-between;
        gap: 16px;
        border: 0;
        padding: 6px 0;
        text-align: right;
    }
    #delivery-method-cost-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        text-align: left;
    }
}

/* v34 — configurable analytics rules, delivery audit and friendlier delivery charts */
.analytics-settings-box,
.delivery-audit-box {
    margin: 16px 0;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #f8fafc;
    padding: 12px 14px;
}
.analytics-settings-box summary,
.delivery-audit-box summary {
    cursor: pointer;
    font-weight: 700;
    color: #111827;
    min-height: 34px;
    display: flex;
    align-items: center;
}
.analytics-settings-box[open],
.delivery-audit-box[open] {
    background: #fff;
    border-color: #bfdbfe;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}
.settings-table input,
.settings-table textarea {
    width: 100%;
}
.small-text-input {
    min-width: 160px;
}
.delivery-methods-textarea {
    min-width: 280px;
    resize: vertical;
    line-height: 1.35;
}
.settings-actions {
    margin-top: 12px;
    gap: 10px;
    flex-wrap: wrap;
}
#delivery-raw-audit-table td:first-child,
#delivery-raw-audit-table th:first-child {
    max-width: 360px;
}
#delivery-raw-audit-table td {
    vertical-align: top;
}
#chart-delivery-method-cost {
    cursor: pointer;
}
@media (min-width: 901px) {
    #shipping-summary-section .charts-grid .chart-card {
        min-height: 430px;
    }
    #shipping-summary-section .chart-container {
        min-height: 285px;
    }
}
@media (max-width: 900px) {
    .analytics-settings-box,
    .delivery-audit-box {
        padding: 10px;
    }
    .settings-actions .btn,
    .analytics-settings-box .btn,
    .delivery-rules-box .btn {
        width: 100%;
    }
    #payment-normalization-rules-table thead,
    #delivery-cost-rules-table thead,
    #delivery-raw-audit-table thead {
        display: none;
    }
    #payment-normalization-rules-table tr,
    #delivery-cost-rules-table tr,
    #delivery-raw-audit-table tr {
        display: block;
        border: 1px solid #e5e7eb;
        border-radius: 14px;
        padding: 10px 12px;
        margin-bottom: 10px;
        background: #fff;
    }
    #payment-normalization-rules-table td,
    #delivery-cost-rules-table td,
    #delivery-raw-audit-table td {
        display: block;
        border: 0;
        padding: 6px 0;
        text-align: left !important;
        max-width: none !important;
    }
    #delivery-raw-audit-table td[data-label] {
        display: flex;
        justify-content: space-between;
        gap: 12px;
        text-align: right !important;
    }
    #delivery-raw-audit-table td[data-label]::before {
        content: attr(data-label);
        font-weight: 600;
        color: #64748b;
        text-align: left;
    }
    .small-text-input,
    .delivery-methods-textarea {
        min-width: 0;
    }
}

/* v35 — delivery summary clarification and current taxi-cost default */
.delivery-summary-context {
    margin: -6px 0 14px;
    padding: 10px 12px;
    border: 1px solid #bfdbfe;
    border-left: 4px solid #2563eb;
    background: #eff6ff;
    color: #1e3a8a;
    border-radius: 10px;
    line-height: 1.45;
}
.delivery-summary-context strong {
    color: #1d4ed8;
}
@media (max-width: 640px) {
    .delivery-summary-context {
        margin-top: 8px;
        font-size: 12px;
    }
}
