/* ── Design Tokens ─────────────────────────────────────────────────────────── */
:root {
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

    /* ── Surface & Border ── */
    --bg:            #f0f4f8;
    --surface:       #ffffff;
    --surface-2:     #f7f9fc;
    --border:        #dde3ec;
    --border-light:  #edf1f6;

    /* ── Text ── */
    --text:          #111827;
    --text-2:        #4b5563;
    --text-3:        #9ca3af;

    /* ── Primary accent – steel blue (professional, ERP-friendly) ── */
    --accent:        #2563eb;
    --accent-bg:     #eff6ff;
    --accent-hover:  #1d4ed8;

    /* ── Semantic colors ── */
    --success:       #059669;
    --success-bg:    #ecfdf5;
    --warning:       #d97706;
    --warning-bg:    #fffbeb;
    --danger:        #dc2626;
    --danger-bg:     #fef2f2;
    --neutral:       #6b7280;
    --neutral-bg:    #f3f4f6;

    /* ── Sidebar ── */
    --sidebar-w:      240px;
    --sidebar-bg:     #ffffff;
    --sidebar-text:   #9ca3af;
    --sidebar-hover:  #f0f9ff;
    --sidebar-active: #29abe2;

    /* ── Shape ── */
    --radius-sm: 6px;
    --radius:    10px;
    --radius-lg: 14px;

    /* ── Shadows ── */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .05);
    --shadow:    0 1px 3px 0 rgb(0 0 0 / .08), 0 1px 2px -1px rgb(0 0 0 / .06);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / .06), 0 2px 4px -2px rgb(0 0 0 / .04);
}

/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden; /* belt-and-suspenders: the shell controls all scrolling */
}

h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

code {
    font-size: 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1px 6px;
    color: var(--text);
    font-family: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', monospace;
}

/* ── Loading screen ────────────────────────────────────────────────────────── */
.app-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 16px;
}

.app-loading-spinner {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.app-loading-text {
    font-size: 13px;
    color: var(--text-3);
    font-weight: 500;
    letter-spacing: 0.02em;
    margin: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.app-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.app-card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.app-card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.app-card-body { padding: 20px; }

/* ── Page header ────────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
}

.page-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-2);
    margin: 2px 0 0;
}

/* ── Metric cards ───────────────────────────────────────────────────────────── */
.metric-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.15s;
    cursor: default;
}

.metric-card:hover { box-shadow: var(--shadow); }

.metric-label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 12px;
}

.metric-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    margin-bottom: 14px;
}

.metric-val {
    font-size: 28px;
    font-weight: 600;
    color: var(--text);
    line-height: 1;
}

.metric-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 20px;
    margin-bottom: 2px;
}

.metric-badge.warning { background: var(--warning-bg); color: #b45309; }
.metric-badge.danger  { background: var(--danger-bg);  color: #dc2626; }

.metric-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--accent);
    font-weight: 500;
    margin-top: 4px;
}

.metric-link:hover { color: var(--accent-hover); }

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.btn-app {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
    line-height: 1;
    font-family: var(--font);
    text-decoration: none;
}

.btn-app:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary-app {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary-app:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.btn-secondary-app {
    background: var(--surface);
    color: var(--text-2);
    border-color: var(--border);
}
.btn-secondary-app:hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
}

.btn-ghost-app {
    background: transparent;
    color: var(--text-2);
    border-color: transparent;
    padding: 7px 10px;
}
.btn-ghost-app:hover:not(:disabled) { background: var(--bg); color: var(--text); }

/* ── Status badges ──────────────────────────────────────────────────────────── */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 8px;
    border-radius: 20px;
    white-space: nowrap;
}

.status-badge::before {
    content: '';
    width: 5px;
    height: 5px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-created   { background: var(--success-bg); color: #065f46; }
.status-created::before { background: var(--success); }
.status-pending   { background: var(--warning-bg); color: #92400e; }
.status-pending::before { background: var(--warning); }
.status-failed    { background: var(--danger-bg);  color: #991b1b; }
.status-failed::before  { background: var(--danger); }
.status-skipped   { background: var(--neutral-bg); color: var(--neutral); }
.status-skipped::before { background: var(--neutral); }
.status-cancelled { background: #f1f5f9; color: #475569; }
.status-cancelled::before { background: #94a3b8; }
.status-cancelfailed { background: var(--danger-bg); color: #991b1b; }
.status-cancelfailed::before { background: var(--danger); }

/* ── Tables ─────────────────────────────────────────────────────────────────── */
.app-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.app-table thead tr {
    border-bottom: 1px solid var(--border);
}

.app-table th {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 8px 12px;
    white-space: nowrap;
    background: transparent;
}

.app-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    color: var(--text);
    vertical-align: middle;
}

.app-table tbody tr:last-child td { border-bottom: none; }

.app-table tbody tr:hover td { background: var(--surface-2); }

.app-table .col-key { font-family: monospace; font-size: 12px; color: var(--text-2); }
.app-table .col-error {
    max-width: 200px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: var(--danger);
    font-size: 12px;
}

/* ── Alert / notification ───────────────────────────────────────────────────── */
.app-alert {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid transparent;
}

.app-alert button { margin-left: auto; background: none; border: none; cursor: pointer; font-size: 16px; opacity: 0.5; }
.app-alert button:hover { opacity: 1; }

.app-alert-success { background: var(--success-bg); color: #065f46; border-color: #a7f3d0; }
.app-alert-danger  { background: var(--danger-bg);  color: #991b1b; border-color: #fecaca; }
.app-alert-warning { background: var(--warning-bg); color: #92400e; border-color: #fde68a; }
.app-alert-info    { background: var(--accent-bg);  color: #3730a3; border-color: #c7d2fe; }

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-3);
}

.empty-state-icon { font-size: 32px; margin-bottom: 12px; opacity: 0.5; }
.empty-state-text { font-size: 13px; }

/* ── Loading inline ─────────────────────────────────────────────────────────── */
.inline-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px;
    color: var(--text-3);
    font-size: 13px;
}

.inline-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

/* ── Section divider ────────────────────────────────────────────────────────── */
.section-gap { margin-top: 28px; }

.section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
    margin-bottom: 12px;
}

/* ── Log entries ────────────────────────────────────────────────────────────── */
.log-header {
    display: grid;
    grid-template-columns: 140px 180px 1fr 80px;
    gap: 12px;
    padding: 6px 16px 6px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-2);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 1px solid var(--border);
}

.log-entry {
    display: grid;
    grid-template-columns: 140px 180px 1fr 80px;
    gap: 12px;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    font-size: 12.5px;
}

.log-entry:last-child { border-bottom: none; }
.log-entry:hover { background: var(--surface-2); }

.log-time { color: var(--text-3); font-variant-numeric: tabular-nums; }
.log-job  { font-weight: 500; color: var(--text); }
.log-msg  { color: var(--text-2); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

.error-entry {
    padding: 12px 16px;
    border-left: 3px solid var(--danger);
    margin-bottom: 8px;
    background: var(--surface-2);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.error-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.error-job  { font-weight: 600; font-size: 12px; color: var(--text); }
.error-type { font-size: 11px; background: var(--danger-bg); color: #dc2626; padding: 1px 6px; border-radius: 4px; }
.error-time { font-size: 11px; color: var(--text-3); margin-left: auto; }
.error-msg  { font-size: 12px; color: var(--text-2); }

/* ── Blazor error overlay ───────────────────────────────────────────────────── */
#blazor-error-ui {
    background: #1e293b;
    color: #e2e8f0;
    bottom: 0;
    box-shadow: 0 -2px 12px rgb(0 0 0 / .2);
    display: none;
    left: 0;
    padding: 12px 24px;
    position: fixed;
    width: 100%;
    z-index: 9999;
    font-size: 13px;
    display: none;
    align-items: center;
    gap: 16px;
}

#blazor-error-ui a { color: #a5b4fc; }
#blazor-error-ui .dismiss { margin-left: auto; cursor: pointer; opacity: 0.6; }
#blazor-error-ui .dismiss:hover { opacity: 1; }

/* ── Tabs ───────────────────────────────────────────────────────────────────── */
.app-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 20px;
}

.app-tab {
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
    border: none;
    background: none;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.12s;
}

.app-tab:hover { color: var(--text); }
.app-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Full-Screen Detail Overlay ─────────────────────────────────────────────── */
.detail-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 300;
    display: flex;
    flex-direction: column;
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    transition: opacity 0.16s ease, transform 0.16s ease;
}
.detail-overlay.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.detail-overlay-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    min-height: 52px;
}

.detail-overlay-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-2);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 5px 12px;
    cursor: pointer;
    transition: color 0.1s, background 0.1s, border-color 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1;
    font-family: var(--font);
}
.detail-overlay-back:hover {
    color: var(--text);
    background: var(--bg);
    border-color: var(--text-3);
}

.detail-overlay-divider {
    width: 1px;
    height: 28px;
    background: var(--border);
    flex-shrink: 0;
}

.detail-overlay-meta { flex: 1; min-width: 0; }

.detail-overlay-category {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin: 0 0 2px;
}

.detail-overlay-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    margin: 0;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.detail-overlay-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px;
}

/* Content fills full width of the overlay */

.detail-overlay-body::-webkit-scrollbar { width: 12px; height: 12px; }
.detail-overlay-body::-webkit-scrollbar-track { background: transparent; }
.detail-overlay-body::-webkit-scrollbar-thumb {
    background: var(--border); border-radius: 6px;
    border: 2px solid transparent; background-clip: padding-box;
}
.detail-overlay-body::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }

/* ── Scrollable table wrapper – sticky header, viewport-locked height ────────── */
/*
 * Height strategy: calc(100vh - Xpx) keeps tables inside the viewport.
 * App layout is height:100vh / overflow:hidden so NO browser scroll ever happens.
 * X accounts for: sidebar brand(64) + page header(68) + tabs(46) + padding(56) + buffer(66)
 */
.table-scroll {
    min-height: 160px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
    overflow-x: auto;
}
.table-scroll { scrollbar-width: auto; }
.table-scroll::-webkit-scrollbar { width: 12px; height: 12px; }
.table-scroll::-webkit-scrollbar-track { background: transparent; }
.table-scroll::-webkit-scrollbar-thumb {
    background: var(--border); border-radius: 6px;
    border: 2px solid transparent; background-clip: padding-box;
}
.table-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }
.table-scroll::-webkit-scrollbar-corner { background: transparent; }

/* Etiqueta de rango de fecha en las barras de filtro */
.filter-daterange {
    display: inline-flex; align-items: center; gap: 6px;
    font-size: 12px; color: var(--text-2);
}
.filter-daterange .filter-input { width: 150px; }

/* Separate borders so position:sticky works correctly on thead */
.table-scroll .app-table {
    border-collapse: separate;
    border-spacing: 0;
}
.table-scroll .app-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-2);
    box-shadow: 0 1px 0 var(--border);
}
/* Prevent tbody from visually bleeding over the sticky header */
.table-scroll .app-table tbody tr { isolation: isolate; }

/* Line tables inside detail overlay sections */
.detail-section .table-scroll {
    min-height: 120px;
    max-height: calc(40vh - 40px);
}

/* Columnas provenientes de SAP — tinte azul para diferenciarlas de CrunchTime.
   El TH es sticky: su fondo debe ser OPACO (tinte compuesto sobre el fondo del
   header) para que los renglones no se transparenten al hacer scroll. */
.app-table td.sap-col { background: rgba(37, 99, 166, 0.09); }
.app-table th.sap-col {
    background: linear-gradient(rgba(37, 99, 166, 0.14), rgba(37, 99, 166, 0.14)), var(--surface-2);
    color: var(--info, #2563a6);
}
.app-table th.sap-col-start,
.app-table td.sap-col-start { border-left: 2px solid rgba(37, 99, 166, 0.45); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .app-table td.sap-col { background: rgba(127, 178, 234, 0.14); }
    :root:not([data-theme="light"]) .app-table th.sap-col {
        background: linear-gradient(rgba(127, 178, 234, 0.16), rgba(127, 178, 234, 0.16)), var(--surface-2);
    }
}
:root[data-theme="dark"] .app-table td.sap-col { background: rgba(127, 178, 234, 0.14); }
:root[data-theme="dark"] .app-table th.sap-col {
    background: linear-gradient(rgba(127, 178, 234, 0.16), rgba(127, 178, 234, 0.16)), var(--surface-2);
}

/*
 * Audit/Logs page: two cards stacked in the same view, so neither can claim the
 * full viewport. Each list scrolls on its own instead of growing the page.
 */
.log-scroll {
    max-height: 300px;
    overflow-y: auto;
}
.log-scroll::-webkit-scrollbar { width: 12px; height: 12px; }
.log-scroll::-webkit-scrollbar-track { background: transparent; }
.log-scroll::-webkit-scrollbar-thumb {
    background: var(--border); border-radius: 6px;
    border: 2px solid transparent; background-clip: padding-box;
}
.log-scroll::-webkit-scrollbar-thumb:hover { background: var(--text-3); background-clip: padding-box; }

.app-card > .table-scroll.log-scroll {
    min-height: 0;
    max-height: 380px;
}

/* ── Detail sections inside drawer ─────────────────────────────────────────── */
.detail-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    overflow: hidden;
}
.detail-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-3);
    padding: 10px 16px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border-light);
}
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(175px, 1fr));
    gap: 0;
    padding: 0;
}
.detail-field {
    padding: 10px 16px;
    border-right: 1px solid var(--border-light);
    border-bottom: 1px solid var(--border-light);
    min-width: 0;
}
.detail-field:last-child { border-right: none; }
.detail-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-3);
    margin-bottom: 3px;
}
.detail-value {
    font-size: 13px;
    color: var(--text);
    word-break: break-word;
    line-height: 1.4;
}
.detail-value.mono {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
}
.detail-value.muted { color: var(--text-3); font-style: italic; }

/* ── Filter bar ─────────────────────────────────────────────────────────────── */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}
.filter-input {
    flex: 1;
    min-width: 200px;
    max-width: 380px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 12px;
    font-size: 13px;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: border-color 0.12s;
}
.filter-input:focus { border-color: var(--accent); }
.filter-input::placeholder { color: var(--text-3); }
.filter-select {
    height: 34px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0 10px;
    font-size: 13px;
    font-family: var(--font);
    color: var(--text);
    background: var(--surface);
    outline: none;
    cursor: pointer;
}
.filter-select:focus { border-color: var(--accent); }
.filter-count {
    font-size: 12px;
    color: var(--text-3);
    margin-left: auto;
    white-space: nowrap;
}

/* ── Selected row highlight ─────────────────────────────────────────────────── */
.app-table tbody tr.selected-row td {
    background: var(--accent-bg) !important;
}

/* ── DataTable ──────────────────────────────────────────────────────────────── */
.datatable-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.datatable-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    gap: 12px;
    flex-wrap: wrap;
}

.datatable-info {
    font-size: 12px;
    color: var(--text-2);
}
.datatable-info strong { color: var(--text); }

.datatable-pagesize-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-2);
    white-space: nowrap;
}
.datatable-pagesize-label .filter-select {
    height: 28px;
    font-size: 12px;
    padding: 0 8px;
}

.datatable-container > .table-scroll {
    border: 1px solid var(--border);
    background: var(--surface);
    min-height: 160px;
    /* More chrome: filter-bar(52) + dt-topbar(52) + pagination(52) + page-header(68) + padding(56) */
    max-height: calc(100vh - 430px);
}

.datatable-container .app-table { border-radius: 0; }
.datatable-container .app-table thead tr { background: var(--surface-2); }

/* Table inside an app-card – accounts for tabs (46px) overhead */
.app-card > .table-scroll {
    border: none;
    min-height: 160px;
    max-height: calc(100vh - 320px);
}

.datatable-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius) var(--radius);
}

.dt-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 30px;
    height: 30px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text-2);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
    line-height: 1;
}
.dt-btn:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.dt-btn:disabled { opacity: 0.35; cursor: default; }
.dt-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}
.dt-ellipsis {
    color: var(--text-3);
    font-size: 13px;
    padding: 0 4px;
    line-height: 30px;
}

/* ── Sortable column headers ────────────────────────────────────────────────── */
.th-sort {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
.th-sort:hover { color: var(--text); }
.th-sort .sort-icon {
    display: inline-block;
    margin-left: 5px;
    font-size: 10px;
    color: var(--text-3);
    vertical-align: middle;
}
.th-sort.sort-active .sort-icon { color: var(--accent); }

/* SAP chip in table cells */
.sap-chip {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 4px;
    background: rgba(99,102,241,.1);
    color: var(--accent);
    font-family: 'JetBrains Mono', monospace;
    white-space: nowrap;
}
.sap-chip.unmapped {
    background: var(--neutral-bg);
    color: var(--text-3);
    font-family: var(--font);
    font-weight: 500;
}

/* ── Confirmation dialog ────────────────────────────────────────────────────── */
.confirm-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.confirm-dialog {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgb(0 0 0 / .22);
    width: 100%;
    max-width: 400px;
    overflow: hidden;
    animation: confirm-in 0.15s ease;
}

@keyframes confirm-in {
    from { opacity: 0; transform: scale(0.96) translateY(-6px); }
    to   { opacity: 1; transform: scale(1)    translateY(0); }
}

.confirm-dialog-inner {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 22px 22px 18px;
}

.confirm-icon-wrap {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--warning-bg);
    border: 1px solid #fde68a;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--warning);
    flex-shrink: 0;
}

.confirm-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin: 0 0 6px;
}

.confirm-msg {
    font-size: 13px;
    color: var(--text-2);
    margin: 0;
    line-height: 1.55;
}

.confirm-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 14px 22px;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
}

/* ── Enlarged action buttons in tables ──────────────────────────────────────── */
.btn-table-action {
    padding: 8px 16px !important;
    font-size: 13px !important;
    min-height: 36px;
}

/* ── Tooltip ─────────────────────────────────────────────────────────────────── */
#app-tooltip {
    position: fixed;
    z-index: 9999;
    background: #1e293b;
    color: #f8fafc;
    font-size: 12px;
    line-height: 1.4;
    padding: 6px 10px;
    border-radius: 6px;
    width: 220px;
    white-space: normal;
    pointer-events: none;
    box-shadow: 0 4px 12px rgb(0 0 0 / .18);
    opacity: 0;
    transition: opacity 0.15s;
}


/* ════════════════════════════════════════════════════════════════════════════
   SIDEBAR — Replica del diseño de referencia
   - Fondo blanco con esquinas redondeadas
   - Items aireados, texto gris medio
   - Item activo: barra azul cyan a todo el ancho, texto blanco bold
   ════════════════════════════════════════════════════════════════════════════ */

/* ── Tokens específicos del sidebar (sobrescriben los del :root para este componente) ── */
:root {
    --sidebar-w: 260px;
    --sidebar-bg: #ffffff;
    --sidebar-text: #9ca3af; /* gris medio para items inactivos */
    --sidebar-text-hover: #6b7280;
    --sidebar-active-bg: #29abe2; /* cyan brillante de la imagen */
    --sidebar-active-text: #ffffff;
    --sidebar-brand: #29abe2;
}

/* ── Contenedor ─────────────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    height: 100vh;
    background: var(--sidebar-bg);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--border-light);
    overflow: hidden;
}

/* ── Brand / encabezado ─────────────────────────────────────────────────────── */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 22px 22px 18px;
    border-bottom: 1px solid var(--border-light);
    flex-shrink: 0;
}

.sidebar-logo-wrap {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--sidebar-active-bg);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
    flex: 1;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: #4b5563;
    letter-spacing: 0.01em;
}

.sidebar-sub {
    font-size: 11px;
    color: var(--sidebar-text);
    margin-top: 2px;
    font-weight: 500;
}

.sidebar-toggle {
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
}

    .sidebar-toggle:hover {
        background: #f3f4f6;
        color: var(--sidebar-active-bg);
    }

/* ── Navegación ─────────────────────────────────────────────────────────────── */
.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 14px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

    .sidebar-nav::-webkit-scrollbar {
        width: 4px;
    }

    .sidebar-nav::-webkit-scrollbar-track {
        background: transparent;
    }

    .sidebar-nav::-webkit-scrollbar-thumb {
        background: var(--border);
        border-radius: 2px;
    }

/* ── Item de navegación ─────────────────────────────────────────────────────── */
.sidebar-link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 24px;
    font-size: 14px;
    font-weight: 500;
    color: var(--sidebar-text);
    text-decoration: none;
    border: none;
    border-radius: 0;
    transition: background 0.15s ease, color 0.15s ease;
    position: relative;
    white-space: nowrap;
}

    .sidebar-link:hover {
        background: #f9fafb;
        color: var(--sidebar-text-hover);
    }

.sidebar-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    stroke: currentColor;
}

/* ── Estado activo: barra azul cyan completa + texto blanco bold ────────────── */
.sidebar-link.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 700;
}

    .sidebar-link.active:hover {
        background: var(--sidebar-active-bg);
        color: var(--sidebar-active-text);
    }

    .sidebar-link.active .sidebar-icon {
        stroke: #ffffff;
    }

/* ── Footer ─────────────────────────────────────────────────────────────────── */
.sidebar-footer {
    padding: 14px 24px;
    font-size: 11px;
    color: var(--sidebar-text);
    border-top: 1px solid var(--border-light);
    text-align: center;
    font-weight: 500;
    letter-spacing: 0.02em;
    flex-shrink: 0;
}

/* ── Responsive: sidebar colapsable en pantallas pequeñas ───────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        z-index: 200;
        box-shadow: 4px 0 16px rgb(0 0 0 / .08);
    }

        .sidebar.sidebar-open {
            transform: translateX(0);
        }
}