/* ============================================================
   ConPDS OCR Admin Dashboard — Design System
   ============================================================ */

:root {
    --primary-color:  #083B70;
    --primary-hover:  #05294E;
    --accent-color:   #8DC5D6;
    --success-color:  #16a34a;
    --error-color:    #dc2626;
    --warning-color:  #f59e0b;
    --heatmap-credit:    #e88c30;
    --heatmap-unlimited: #3b82f6;
    --info-color:     #083B70;
    --bg-color:       #F1F9FD;
    --card-bg:        #ffffff;
    --border-color:   #E7EFF4;
    --text-color:     #1E1E1E;
    --text-secondary: #353535;
    --shadow:         0 1px 3px 0 rgba(8,59,112,.08), 0 1px 2px 0 rgba(8,59,112,.05);
}

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

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont,
                 "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    font-size: 16px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

/* ---- Header ---- */
.header {
    background: var(--primary-hover);
    color: #fff;
    padding: 0.65rem 0;
    border-bottom: 3px solid var(--accent-color);
}
.header__inner {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.header__logo {
    height: 30px;
    width: auto;
    object-fit: contain;
}
.header__divider {
    width: 1px;
    height: 24px;
    background: rgba(255,255,255,.1);
}
.header h1 {
    font-size: 1.1rem;
    font-weight: 600;
    white-space: nowrap;
}
.header__sub {
    font-size: 0.9rem;
    opacity: 0.75;
    white-space: nowrap;
}
.header__right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.header__user-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.8rem;
    padding: 0.25rem 0.65rem;
    border-radius: 1rem;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.12);
    color: rgba(255,255,255,.85);
}

.header__status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
    border-radius: 1rem;
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.15);
}
.header__status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #16a34a;
    animation: pulse-dot 2s ease-in-out infinite;
}
.header__status-dot--error {
    background: #dc2626;
    animation: none;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: .4; }
}

/* ---- Navigation Tabs ---- */
.page-nav {
    background: #fff;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: 0 1px 3px rgba(0,0,0,.04);
    min-height: 43px;
    transform: translateZ(0);
    backface-visibility: hidden;
}
.page-nav__inner {
    display: flex;
    gap: 0;
    overflow-x: auto;
    min-height: 43px;
}
.page-nav__tab {
    padding: 0.75rem 1.4rem;
    border: none;
    border-bottom: 3px solid transparent;
    background: none;
    font-size: 0.92rem;
    font-weight: 600;
    color: #64748b;
    cursor: pointer;
    transition: color .15s, border-color .15s, background .15s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.page-nav__tab:hover {
    color: var(--primary-color);
    background: #f8fafc;
}
.page-nav__tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--accent-color);
    background: #f0f7ff;
}
.page-nav__tab i {
    font-size: 0.88rem;
}
.page-nav__logout-wrap {
    display: inline-flex;
    flex-shrink: 0;
    margin-left: auto;
}
.page-nav__tab--logout {
    color: #64748b;
    text-decoration: none;
}
.page-nav__tab--logout:hover {
    color: var(--primary-color);
    background: #f8fafc;
}

/* ---- Main Content ---- */
.main-content {
    flex: 1;
    padding: 1.25rem 0;
}

/* ---- Cards ---- */
.card {
    background: var(--card-bg);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    padding: 1.25rem 1.5rem;
    margin-bottom: 1rem;
    animation: fadeIn 0.5s ease-out;
}
.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 0.5rem;
}
.card__title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.card__title i {
    font-size: 1rem;
    opacity: 0.7;
}

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

/* ---- Stats Grid ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--card-bg);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    padding: 1rem 1.25rem;
    animation: fadeIn 0.5s ease-out;
    border-left: 4px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.stat-card--primary  { border-left-color: var(--primary-color); }
.stat-card--success  { border-left-color: var(--success-color); }
.stat-card--warning  { border-left-color: var(--warning-color); }
.stat-card--error    { border-left-color: var(--error-color); }
.stat-card--info     { border-left-color: var(--accent-color); }

.stat-card__value {
    font-size: 1.8rem;
    font-weight: 700;
    color: #2d3748;
    line-height: 1.2;
}
.stat-card__label {
    font-size: 0.75rem;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}
.stat-card__detail {
    font-size: 0.78rem;
    color: #94a3b8;
    margin-top: 0.15rem;
}

/* ---- Buttons ---- */
.btn {
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 0.5rem;
    border: none;
    cursor: pointer;
    transition: all .15s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}
.btn-sm {
    padding: 0.35rem 0.9rem;
    font-size: 0.875rem;
}
.btn-xs {
    padding: 0.2rem 0.5rem;
    font-size: 0.72rem;
}

.btn-primary {
    background: var(--primary-color);
    color: #fff;
}
.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}
.btn-secondary {
    background: var(--warning-color);
    color: #fff;
}
.btn-secondary:hover {
    background: #d97706;
}
.btn-outline {
    background: transparent;
    color: #64748b;
    border: 1px solid var(--border-color);
}
.btn-outline:hover {
    background: #f8fafc;
    border-color: #94a3b8;
}
.btn-export {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #86efac;
}
.btn-export:hover {
    background: #dcfce7;
}
.btn-danger {
    background: #e53e3e;
    color: #fff;
    border: 1px solid #c53030;
}
.btn-danger:hover {
    background: #c53030;
    border-color: #9b2c2c;
}
.btn-warning {
    background: #dd6b20;
    color: #fff;
    border: none;
}
.btn-warning:hover {
    background: #c05621;
}
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* ---- Form Inputs ---- */
.filter-input, .form-input {
    padding: 0.45rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 0.375rem;
    font-size: 0.9rem;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    color: var(--text-color);
    font-family: inherit;
}
.filter-input:focus, .form-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(8,59,112,.15);
    outline: none;
}
.form-input--large {
    padding: 0.65rem 1rem;
    font-size: 1rem;
}
.form-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.35rem;
    display: block;
}
.form-group {
    margin-bottom: 1rem;
}
textarea.form-input {
    resize: vertical;
    min-height: 100px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    font-size: 0.82rem;
    line-height: 1.5;
}

/* ---- Tables ---- */
.records-table-wrap {
    overflow-x: auto;
    border-radius: 0.5rem;
    border: 1px solid var(--border-color);
}
.records-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
    font-size: 0.9rem;
}
.records-table thead th {
    background: var(--bg-color);
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--primary-color);
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
    white-space: nowrap;
}
.records-table thead th.sortable-th {
    cursor: pointer;
    user-select: none;
}
.records-table thead th.sortable-th:hover {
    color: var(--accent-color, var(--primary-color));
}
.records-table thead th .sort-arrow {
    font-weight: 400;
    color: var(--text-muted);
    margin-left: 0.2rem;
}
.records-table tbody tr {
    transition: background .1s;
}
.records-table tbody tr:hover {
    background: var(--bg-color);
}
.records-table tbody td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 250px;
}

/* ---- Status Badges ---- */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}
.status-badge--ok      { background: #dcfce7; color: #16a34a; }
.status-badge--error   { background: #fee2e2; color: #dc2626; }
.status-badge--warning { background: #fef3c7; color: #f59e0b; }
.status-badge--info    { background: #d0e8f5; color: #083B70; }
.status-badge--neutral { background: #f1f5f9; color: #94a3b8; }

/* ---- Alert / Feedback Banners ---- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 0 6px 6px 0;
    margin-bottom: 1rem;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}
.alert--success {
    background: #f0fff4;
    color: #276749;
    border-left: 3px solid #48bb78;
}
.alert--error {
    background: #fff5f5;
    color: #c53030;
    border-left: 3px solid #e53e3e;
}
.alert--info {
    background: #ebf8ff;
    color: #2b6cb0;
    border-left: 3px solid #4299e1;
}
.alert--warning {
    background: #fffbeb;
    color: #92400e;
    border-left: 3px solid #f59e0b;
}
.alert i { margin-top: 2px; }

/* ---- Spinners ---- */
@keyframes spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}
.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    display: inline-block;
}
.spinner-inline {
    width: 14px;
    height: 14px;
    border: 2px solid #e2e8f0;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    display: inline-block;
}
.spinner-lg {
    width: 36px;
    height: 36px;
    border: 4px solid #e2e8f0;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loading-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    padding: 3rem;
    color: #64748b;
    font-size: 0.9rem;
}

/* ---- Toolbar ---- */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1rem;
    padding: 0.5rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}
.toolbar__divider {
    width: 1px;
    height: 1.2em;
    background: var(--border-color);
}

/* ---- Charts ---- */
.charts-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.chart-card {
    background: var(--card-bg);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    padding: 1.25rem 1.5rem;
    animation: fadeIn 0.5s ease-out;
}
.chart-card--wide {
    grid-column: 1 / -1;
}
.chart-card__title {
    font-size: 0.85rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.75rem;
}

/* ---- Monospace / Code ---- */
.mono {
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    font-size: 0.82em;
    background: #edf2f7;
    border: 1px solid #e2e8f0;
    border-radius: 3px;
    padding: 0.05em 0.35em;
    color: #2d3748;
    word-break: break-all;
}

/* ---- OCR Tester ---- */
.ocr-test-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.ocr-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: 0.5rem;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s, background .2s;
    background: #fafcfe;
}
.ocr-dropzone:hover, .ocr-dropzone--active {
    border-color: var(--accent-color);
    background: #f0f7ff;
}
.ocr-dropzone i {
    font-size: 2.5rem;
    color: var(--accent-color);
    margin-bottom: 0.5rem;
}
.ocr-dropzone__text {
    font-size: 0.9rem;
    color: #64748b;
}
.ocr-dropzone__hint {
    font-size: 0.78rem;
    color: #94a3b8;
    margin-top: 0.25rem;
}

.ocr-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 0.375rem;
    border: 1px solid var(--border-color);
    object-fit: contain;
    background: #f8fafc;
}

.ocr-result-box {
    background: #f8fafc;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    padding: 1rem;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
    font-size: 0.85rem;
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---- Detail Grid ---- */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.5rem;
}
.detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    padding: 0.5rem;
    background: #f8fafc;
    border-radius: 0.375rem;
}
.detail-item__label {
    font-size: 0.7rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.detail-item__value {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-color);
}

/* ---- Toast Notifications ---- */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.toast {
    background: #276749;
    color: #fff;
    padding: 0.65rem 1.25rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(0,0,0,.2);
    animation: slideIn 0.25s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.toast--error { background: #c53030; }
.toast--warning { background: #dd6b20; }
.toast--info { background: var(--primary-color); }

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

/* ---- Tabs within pages ---- */
.sub-tabs {
    display: flex;
    gap: 0.25rem;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 1.25rem;
}
.sub-tabs__tab {
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    padding: 0.55rem 1.1rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: #6b7280;
    cursor: pointer;
    border-radius: 4px 4px 0 0;
    transition: color .15s, border-color .15s;
}
.sub-tabs__tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    font-weight: 600;
}
.sub-tabs__tab:hover:not(.active) {
    color: var(--primary-color);
    background: #f8fafc;
}

/* ---- Footer ---- */
.footer {
    background: var(--primary-hover);
    color: #fff;
    padding: 0.75rem 0;
    border-top: 3px solid var(--accent-color);
    text-align: center;
    font-size: 0.82rem;
    opacity: 0.9;
}

/* ---- Copy Button ---- */
.copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 0.1rem 0.3rem;
    margin-left: 0.25rem;
    color: #a0aec0;
    cursor: pointer;
    font-size: 0.72rem;
    transition: color .12s, background .12s, border-color .12s;
}
.copy-btn:hover {
    color: var(--primary-color);
    background: #ebf8ff;
    border-color: #90cdf4;
}
.copy-btn--done {
    color: #38a169 !important;
    background: #f0fff4 !important;
    border-color: #9ae6b4 !important;
}

/* ---- Engine/License detail cards ---- */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr));
    gap: 1rem;
}
.info-card {
    background: var(--card-bg);
    border-radius: 0.5rem;
    box-shadow: var(--shadow);
    padding: 1.25rem 1.5rem;
    animation: fadeIn 0.5s ease-out;
}
.info-card__title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--primary-color);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    border-bottom: 1px solid #f1f5f9;
    font-size: 0.88rem;
}
.dashboard-table {
    border-collapse: collapse;
    font-size: 0.8rem;
}
.dashboard-table th,
.dashboard-table td {
    padding: 0.35rem 0.5rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color, #e2e8f0);
}
.dashboard-table th {
    color: var(--text-muted, #64748b);
    font-weight: 600;
}
.dashboard-table .insights-no-data {
    color: var(--text-muted, #94a3b8);
    font-style: italic;
    padding: 0.5rem;
}
.info-row:last-child { border-bottom: none; }
.info-row__key {
    color: #64748b;
    font-weight: 500;
}
.info-row__val {
    font-weight: 600;
    color: var(--text-color);
}

/* ---- Memory Card ---- */
.memory-card {
    border-left: 4px solid var(--accent-color);
}
.mem-section {
    margin-bottom: 0.75rem;
}
.mem-section__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.3rem;
}
.mem-section__label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #64748b;
}
.mem-section__value {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--text-color);
}
.mem-bar {
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}
.mem-bar__fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.6s ease;
    min-width: 2px;
}
.mem-section__detail {
    font-size: 0.75rem;
    color: #94a3b8;
    margin-top: 0.2rem;
}

/* ---- Dashboard Insights (OCR, security, revalidation) ---- */
.insights-section {
    margin-top: 1.5rem;
    min-height: 220px;
}
.insights-card.insights-card {
    grid-column: 1 / -1;
}
.insights-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-top: 0.75rem;
}
.insights-block {
    background: var(--bg-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.85rem 1rem;
}
.insights-block__title {
    font-size: 0.8rem;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.insights-block__title i {
    color: var(--primary-color);
}
.insights-block__row {
    font-size: 0.85rem;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}
.insights-label {
    color: #64748b;
}
.insights-hint {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-top: 0.6rem;
    margin-bottom: 0;
    line-height: 1.4;
}

.text-danger { color: #ef4444; }

.ban-table {
    width: 100%;
    font-size: 0.75rem;
    border-collapse: collapse;
    margin-top: 0.5rem;
}
.ban-table th,
.ban-table td {
    padding: 0.2rem 0.4rem;
    border-bottom: 1px solid #e2e8f0;
    text-align: left;
}
.ban-table th {
    font-weight: 600;
    color: #64748b;
    font-size: 0.7rem;
}

.insights-bar-group {
    margin-top: 0.75rem;
    margin-bottom: 0.5rem;
}
.insights-bar-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    margin-bottom: 0.35rem;
}
.insights-bar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
    font-size: 0.8rem;
}
.insights-bar-legend {
    width: 2rem;
    color: #64748b;
    flex-shrink: 0;
}
.insights-bar-track {
    flex: 1;
    min-width: 0;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}
.insights-bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.35s ease;
}
.insights-bar-fill--min,
.insights-bar-fill--max {
    background: #64748b;
}

/* ---- Load heatmap card ---- */
.heatmap-card {
    margin-top: 1rem;
}
.heatmap-block {
    margin-top: 0.75rem;
}
.heatmap-strip-wrap {
    margin-bottom: 1rem;
}
.heatmap-strip-wrap:last-of-type {
    margin-bottom: 0;
}
.heatmap-strip {
    display: flex;
    gap: 2px;
    margin-top: 0.35rem;
    min-height: 24px;
}
.heatmap-strip--24 .heatmap-cell {
    flex: 1;
    min-width: 0;
}
.heatmap-strip--7 .heatmap-cell {
    flex: 1;
    min-width: 20px;
}
.heatmap-cell {
    background: var(--heatmap-unlimited);
    border-radius: 3px;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    transition: opacity 0.2s ease;
}
.heatmap-cell--empty {
    background: transparent;
}
.heatmap-color-legend {
    display: flex;
    gap: 1rem;
    font-size: 0.72rem;
    color: #64748b;
    margin-bottom: 0.5rem;
    align-items: center;
}
.heatmap-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 3px;
    vertical-align: middle;
}
.heatmap-strip {
    background: #e2e8f0;
    border-radius: 4px;
    padding: 2px;
}
.heatmap-cell[title]:hover {
    outline: 1px solid var(--primary-color);
}
.heatmap-legend--hours {
    padding: 0 1px;
}
.heatmap-legend--hours span:last-child {
    margin-left: auto;
}
.heatmap-legend {
    font-size: 0.7rem;
    color: #94a3b8;
    margin-top: 0.25rem;
    display: flex;
    justify-content: space-between;
}
.heatmap-legend--weekdays span {
    flex: 1;
    text-align: center;
}

/* 2D weekday x hour heatmap grid */
.heatmap-grid {
    margin-top: 0.35rem;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.heatmap-grid-row {
    display: flex;
    align-items: center;
    gap: 4px;
}
.heatmap-grid-label {
    width: 28px;
    font-size: 0.65rem;
    color: #64748b;
    text-align: right;
    flex-shrink: 0;
}
.heatmap-grid-total {
    width: 28px;
    font-size: 0.6rem;
    color: #94a3b8;
    text-align: left;
    flex-shrink: 0;
}
.heatmap-grid-cells {
    display: flex;
    gap: 1px;
    flex: 1;
    min-width: 0;
    background: #e2e8f0;
    border-radius: 2px;
    padding: 1px;
}
.heatmap-grid-cell {
    flex: 1;
    min-width: 0;
    aspect-ratio: 1;
    background: var(--heatmap-unlimited);
    border-radius: 1px;
    transition: opacity 0.15s ease;
}
.heatmap-grid-cell--empty {
    background: transparent;
}
.heatmap-grid-cell:hover {
    outline: 1px solid var(--primary-color);
    z-index: 1;
}
.heatmap-legend--grid-hours {
    font-size: 0.6rem;
    color: #94a3b8;
    display: flex;
    margin-top: 2px;
    padding-left: 32px;
    padding-right: 32px;
}
.heatmap-legend--grid-hours span {
    flex: 1;
    min-width: 0;
    text-align: left;
}
.insights-bar-fill--avg {
    background: var(--primary-color);
}
.insights-bar-value {
    min-width: 4.5rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--text-color);
}
.insights-bar-extra {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 0.35rem;
    font-weight: 400;
}
.insights-bar-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
}
.insights-bar-link {
    font-size: 0.75rem;
    color: var(--primary-color);
    text-decoration: none;
}
.insights-bar-link:hover {
    text-decoration: underline;
}
.insights-bar-row--has-preview {
    position: relative;
}
.insights-bar-preview {
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 0.35rem;
    display: none;
    z-index: 100;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    background: var(--bg-color);
}
.insights-bar-row--has-preview:hover .insights-bar-preview {
    display: block;
}
.insights-bar-preview img {
    display: block;
    max-width: 280px;
    max-height: 200px;
    object-fit: contain;
}
.insights-no-data {
    font-size: 0.8rem;
    color: #94a3b8;
    margin: 0.25rem 0 0 0;
}

/* ---- Empty State ---- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #94a3b8;
}
.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.4;
}
.empty-state__text {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}
.empty-state__hint {
    font-size: 0.82rem;
}

/* ================================================================
   CREDITS — key rows (full api_key / license_key display)
================================================================ */
.key-pill-row {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    min-width: 0;
}
.key-pill__tag {
    flex-shrink: 0;
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: .04em;
    background: var(--primary-color);
    color: #fff;
    border-radius: 3px;
    padding: 1px 4px;
    line-height: 1.4;
}
.key-pill__val {
    font-size: 0.72rem;
    color: var(--text-secondary);
    word-break: break-all;
    line-height: 1.4;
    user-select: all;
}
/* Give the identity cell enough room to show full UUIDs */
#creditsLimitedTable td:first-child,
#creditsUnlimitedTable td:first-child {
    min-width: 340px;
}
.client-name-input {
    width: 100%;
    max-width: 220px;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}
.form-input--sm {
    min-height: 0;
}

/* ================================================================
   CREDITS — progress bar
================================================================ */
.credit-bar {
    display: inline-block;
    width: 90px;
    height: 8px;
    background: var(--border-color);
    border-radius: 4px;
    vertical-align: middle;
    overflow: hidden;
}
.credit-bar__fill {
    height: 100%;
    border-radius: 4px;
    transition: width .3s ease;
}
.credit-bar__fill--ok      { background: var(--success-color); }
.credit-bar__fill--warning { background: var(--warning-color); }
.credit-bar__fill--danger  { background: var(--error-color); }
.credit-bar__label {
    display: inline-block;
    margin-left: 0.4rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
    vertical-align: middle;
}

/* ================================================================
   MODAL
================================================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(8, 59, 112, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal {
    background: var(--card-bg);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(8,59,112,.18);
    width: 420px;
    max-width: 95vw;
    display: flex;
    flex-direction: column;
}
.modal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem 0.75rem;
    border-bottom: 1px solid var(--border-color);
}
.modal__title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary-color);
    margin: 0;
}
.modal__close {
    background: none;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0 0.25rem;
}
.modal__close:hover { color: var(--error-color); }
.modal__body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.modal__footer {
    padding: 0.75rem 1.25rem 1rem;
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    border-top: 1px solid var(--border-color);
}

/* ---- Engine Switch Modal ---- */
.engine-switch-modal {
    width: 460px;
}
.engine-switch-progress {
    height: 22px;
    background: var(--border-color);
    border-radius: 11px;
    overflow: hidden;
}
.engine-switch-progress__bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-color) 0%, var(--accent-color) 100%);
    border-radius: 11px;
    transition: width 0.5s ease;
}
.engine-switch-progress__bar--complete {
    background: linear-gradient(90deg, var(--success-color) 0%, #22c55e 100%);
}
.engine-switch-progress__bar--error {
    background: var(--error-color);
}
@keyframes engine-switch-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}
.engine-switch-modal .modal__title .fa-sync-alt {
    animation: engine-switch-pulse 1.5s ease-in-out infinite;
}
.engine-switch-modal--done .modal__title .fa-sync-alt {
    animation: none;
}

/* ---- Live indicator ---- */
.live-indicator {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--success-color);
    margin-bottom: 0.75rem;
}
.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
    animation: live-pulse 2s ease-in-out infinite;
    flex-shrink: 0;
}
@keyframes live-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.35; transform: scale(0.8); }
}
.live-ts {
    color: var(--text-muted);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}

/* ---- Badge variants ---- */
.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.5;
    white-space: nowrap;
}
.badge--primary  { background: #d0e8f5; color: #083B70; }
.badge--success  { background: #dcfce7; color: #16a34a; }
.badge--danger   { background: #fee2e2; color: #dc2626; }
.badge--warning  { background: #fef3c7; color: #f59e0b; }
.badge--default  { background: #f1f5f9; color: #64748b; }

/* ---- Extra small button ---- */
.btn-xs {
    padding: 0.2rem 0.45rem;
    font-size: 0.72rem;
    border-radius: 5px;
}
.btn-success { background: var(--success-color); color: #fff; border: none; cursor: pointer; }
.btn-success:hover { opacity: 0.85; }

/* ---- Responsive ---- */
@media (max-width: 900px) {
    .charts-container { grid-template-columns: 1fr; }
    .ocr-test-layout { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .info-grid { grid-template-columns: 1fr; }
    .header h1 { font-size: 0.95rem; }
    .header__sub { display: none; }

    .header__inner { gap: 0.5rem; }
    .header__divider { display: none; }
    .header__user-badge { font-size: 0.72rem; padding: 0.2rem 0.5rem; }
    .header__status { font-size: 0.72rem; padding: 0.2rem 0.45rem; }

    .page-nav__inner {
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .page-nav__inner::-webkit-scrollbar { display: none; }
    .page-nav__tab { padding: 0.65rem 0.9rem; font-size: 0.82rem; }

    .container { padding: 0 12px; }
    .card { padding: 1rem; }
    .info-card { padding: 1rem; }

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

    .toolbar { flex-wrap: wrap; gap: 0.4rem 0.5rem; padding: 0.5rem 0.75rem; }

    .resp-grid-2col { grid-template-columns: 1fr !important; }
    .resp-grid-4col { grid-template-columns: 1fr !important; }
    .resp-flex-stack { flex-direction: column !important; align-items: stretch !important; }

    .modal { width: 95vw; }
    .modal__body { padding: 1rem; }

    .btn-xs { padding: 0.35rem 0.65rem; min-height: 36px; }
    .btn-sm { padding: 0.45rem 0.85rem; min-height: 40px; }
    .btn { min-height: 44px; }

    .detail-grid { grid-template-columns: repeat(2, 1fr); }

    .toast-container { right: 0.75rem; left: 0.75rem; bottom: 0.75rem; }
    .toast { font-size: 0.82rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .insights-grid { grid-template-columns: 1fr; }

    .header__inner { flex-wrap: wrap; gap: 0.35rem; }
    .header h1 { font-size: 0.88rem; }
    .header__right { width: 100%; justify-content: flex-end; gap: 0.4rem; }
    .header__logo { height: 24px; }

    .page-nav__tab { padding: 0.55rem 0.7rem; font-size: 0.78rem; gap: 0.3rem; }
    .page-nav__tab i { font-size: 0.82rem; }

    .card { padding: 0.75rem; margin-bottom: 0.75rem; }
    .card__header { flex-wrap: wrap; }
    .card__title { font-size: 0.95rem; }
    .info-card { padding: 0.75rem; }

    .stat-card { padding: 0.75rem 1rem; }
    .stat-card__value { font-size: 1.4rem; }
    .stat-card__label { font-size: 0.72rem; }

    .form-label { font-size: 0.72rem; }
    .filter-input, .form-input { font-size: 0.88rem; padding: 0.55rem 0.65rem; }

    .records-table { font-size: 0.82rem; }
    .records-table thead th { font-size: 0.75rem; padding: 0.5rem 0.5rem; }
    .records-table tbody td { padding: 0.4rem 0.5rem; font-size: 0.8rem; }

    .ocr-dropzone { padding: 1.25rem; }
    .ocr-dropzone i { font-size: 2rem; }

    .toolbar { font-size: 0.82rem; }

    .sub-tabs { gap: 0; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .sub-tabs__tab { font-size: 0.8rem; padding: 0.5rem 0.75rem; white-space: nowrap; }

    .footer { font-size: 0.75rem; padding: 0.5rem 0; }

    .resp-grid-2col { grid-template-columns: 1fr !important; }

    .security-page { padding: 0 0.75rem; margin: 1rem auto; }
    .security-section { padding: 1rem; }
    .security-table { font-size: 0.8rem; }
    .security-table th, .security-table td { padding: 0.4rem 0.5rem; }
}
