/* Adaptado de dashboard-frontend-kit (github.com/awesome-skills, ver
   ~/.claude/skills/dashboard-frontend-kit). Retema via las custom
   properties en :root / [data-theme="dark"], no reestructures las
   reglas que las consumen. */

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

:root {
    --blue: #146c94;
    --blue-light: #e3eef4;
    --green: #1a9b5c;
    --green-light: #e6f4ea;
    --amber: #f59e0b;
    --amber-light: #fef3c7;
    --red: #ef4444;
    --red-light: #fee2e2;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-600: #475569;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #ffffff;
    --bg-table-head: #f8fafc;
    --bg-table-hover: #e3eef4;
    --border: #e2e8f0;
    --topbar-bg: linear-gradient(135deg, #146c94, #0f4f6d);
    --topbar-shadow: rgba(20,108,148,.3);
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --transition: .25s cubic-bezier(.4,0,.2,1);
}

[data-theme="dark"] {
    --blue-light: #163a49;
    --green-light: #14332a;
    --amber-light: #3b2f1a;
    --red-light: #3b1c1c;
    --gray-50: #1e293b;
    --gray-100: #0f172a;
    --gray-200: #334155;
    --gray-300: #475569;
    --gray-400: #94a3b8;
    --gray-600: #cbd5e1;
    --gray-800: #e2e8f0;
    --gray-900: #f8fafc;
    --bg-body: #0b1120;
    --bg-card: #1e293b;
    --bg-sidebar: #151d2e;
    --bg-table-head: #1a2332;
    --bg-table-hover: #22323d;
    --border: #334155;
    --topbar-bg: linear-gradient(135deg, #0f3a52, #0a2536);
    --topbar-shadow: rgba(0,0,0,.4);
    --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
    --shadow-md: 0 4px 6px rgba(0,0,0,.3), 0 2px 4px rgba(0,0,0,.2);
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--gray-800);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    transition: background .3s ease, color .3s ease;
    overflow-x: hidden;
}

/* === Animations === */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .6; } }

.spin { animation: spin .8s linear infinite; }

/* === Topbar === */
.topbar {
    background: var(--topbar-bg);
    color: white;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px var(--topbar-shadow);
    transition: background .3s ease;
}

.topbar-brand { display: flex; align-items: center; gap: 12px; }

.sidebar-toggle {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition);
}

.sidebar-toggle:hover { background: rgba(255,255,255,.15); }
.sidebar-toggle .material-icons-outlined { font-size: 24px; }

.topbar-brand .material-icons-outlined { font-size: 28px; }
.topbar-title { font-weight: 600; font-size: 16px; display: block; }
.topbar-subtitle { font-size: 12px; opacity: .75; }

.topbar-actions { display: flex; align-items: center; gap: 16px; }

.btn-sync {
    background: rgba(255,255,255,.12);
    color: white;
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 8px;
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition);
    backdrop-filter: blur(4px);
}

.btn-sync:hover { background: rgba(255,255,255,.22); transform: translateY(-1px); }
.btn-sync .material-icons-outlined { font-size: 18px; }

/* === Layout === */
.layout { display: flex; min-height: calc(100vh - 56px); }

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 20px 0;
    flex-shrink: 0;
    transition: all var(--transition);
    overflow: hidden;
    position: sticky;
    top: 56px;
    height: calc(100vh - 56px);
    overflow-y: auto;
}

.sidebar-collapsed .sidebar { width: 0; padding: 0; border-right: none; }

.sidebar-section { margin-bottom: 24px; }

.sidebar-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--gray-400);
    padding: 0 20px;
    margin-bottom: 8px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    color: var(--gray-600);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-link:hover { background: var(--gray-50); color: var(--gray-800); }
.sidebar-link.active { background: var(--blue-light); color: var(--blue); font-weight: 600; border-left-color: var(--blue); }
.sidebar-link .material-icons-outlined { font-size: 20px; transition: transform var(--transition); }
.sidebar-link:hover .material-icons-outlined { transform: scale(1.1); }

.content { flex: 1; padding: 28px 32px; min-width: 0; animation: fadeIn .3s ease; }

/* === Detail header === */
.detail-header { margin-bottom: 20px; }
.detail-header h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }

/* === Filter form ===
   flex-wrap en vez de un grid de columnas fijas: los campos se acomodan
   solos segun el ancho disponible (sidebar abierto/cerrado, pantalla
   angosta, etc.) en lugar de depender de breakpoints exactos. */
.filter-form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 16px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.filter-form label {
    display: grid;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
    flex: 1 1 160px;
    min-width: 0;
}

.filter-form > button { flex: 0 0 auto; }

.filter-form select,
.filter-form input {
    min-width: 0;
    min-height: 38px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 10px;
    font: inherit;
    background: var(--bg-card);
    color: var(--gray-800);
}

.filter-form select:focus,
.filter-form input:focus {
    outline: none;
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(20,108,148,.15);
}

.filter-form button {
    min-height: 38px;
    border: 0;
    border-radius: 8px;
    padding: 0 16px;
    background: var(--blue);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition);
}

.filter-form button:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.filter-form button:disabled { opacity: .6; cursor: not-allowed; transform: none; }

/* === Combobox buscable (Periodo Canvas), sobre <details>/<summary> === */
/* min-width:0 es necesario: sin esto, un grid/flex item con contenido
   que no puede saltar de linea (.combo-value usa white-space:nowrap)
   se niega a encogerse mas alla de su ancho de contenido por defecto
   (min-width:auto) y se desborda encima del campo vecino. */
.combo { position: relative; min-width: 0; }

.combo-trigger {
    width: 100%;
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 10px;
    background: var(--bg-card);
    color: var(--gray-800);
    font: inherit;
    list-style: none;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.combo-trigger::-webkit-details-marker { display: none; }
.combo-trigger:hover { border-color: var(--blue); }
.combo[open] .combo-trigger { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20,108,148,.15); }

.combo-value { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.combo-caret { font-size: 18px; color: var(--gray-400); transition: transform var(--transition); flex-shrink: 0; }
.combo[open] .combo-caret { transform: rotate(180deg); }

.combo-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 20;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    overflow: hidden;
    transform-origin: top;
    animation: comboPanelIn .16s ease both;
}

@keyframes comboPanelIn {
    from { opacity: 0; transform: translateY(-6px) scaleY(.98); }
    to { opacity: 1; transform: translateY(0) scaleY(1); }
}

.combo-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}

.combo-search .material-icons-outlined { font-size: 18px; color: var(--gray-400); }

.combo-search-input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: 0;
    background: transparent;
    font: inherit;
    color: var(--gray-800);
}

.combo-list { list-style: none; margin: 0; padding: 6px; max-height: 220px; overflow-y: auto; }

.combo-option {
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.combo-option:hover { background: var(--blue-light); color: var(--blue); }
.combo-option.selected { font-weight: 600; }
.combo-option[hidden] { display: none; }

.combo-tag {
    margin-left: 8px;
    font-size: 10px;
    font-weight: 700;
    color: var(--green);
    background: var(--green-light);
    padding: 1px 7px;
    border-radius: 8px;
}

.combo-empty { padding: 14px 10px; text-align: center; color: var(--gray-400); font-size: 12px; }

/* === Selector de fecha (dia-mes-año, editable a mano) === */
.date-field { position: relative; min-width: 0; }

.date-native {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.date-input {
    display: flex;
    align-items: stretch;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.date-input:focus-within {
    border-color: var(--blue);
    box-shadow: 0 0 0 3px rgba(20,108,148,.15);
}

.date-text {
    flex: 1;
    min-width: 0;
    min-height: 38px;
    border: 0;
    outline: 0;
    background: transparent;
    padding: 0 10px;
    font: inherit;
    color: var(--gray-800);
}

.date-calendar-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    border: 0;
    border-left: 1px solid var(--border);
    background: transparent;
    color: var(--gray-400);
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
}

.date-calendar-btn:hover { color: var(--blue); background: var(--blue-light); }
.date-calendar-btn .material-icons-outlined { font-size: 18px; }

/* === Loading overlay === */
.results-wrap { position: relative; }

.loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 40px;
    background: color-mix(in srgb, var(--bg-body) 70%, transparent);
    backdrop-filter: blur(1px);
    border-radius: var(--radius);
    animation: fadeIn .15s ease both;
}

/* El atributo HTML `hidden` y esta clase tienen la misma especificidad
   (0,1,0); sin este selector, `display: flex` de arriba le gana al
   `display: none` del user-agent y el overlay queda visible siempre,
   sin importar lo que haga el JS con `.hidden`. */
.loading-overlay[hidden] { display: none; }

.loading-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--blue);
    color: #fff;
    font-weight: 600;
    font-size: 13px;
    padding: 12px 22px;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

/* === Error banner === */
.error-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--red-light);
    border: 1px solid var(--red);
    color: var(--red);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 13px;
}

/* === Toolbar === */
.toolbar { display: flex; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-left { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.results-info { font-size: 12px; color: var(--gray-400); }

/* === Filas por pagina (arriba y abajo de la tabla) === */
.page-size-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--gray-600);
    white-space: nowrap;
}

.page-size-select {
    min-height: 30px;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0 6px;
    font: inherit;
    font-size: 12px;
    background: var(--bg-card);
    color: var(--gray-800);
    cursor: pointer;
}

.page-size-select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(20,108,148,.15); }

.btn-export {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--green);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    white-space: nowrap;
    transition: all var(--transition);
}

.btn-export:hover { background: var(--green-light); border-color: var(--green); transform: translateY(-1px); }
.btn-export .material-icons-outlined { font-size: 18px; }

/* === Data Table === */
.table-wrapper {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.data-table thead {
    background: var(--bg-table-head);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table th {
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--gray-400);
    white-space: nowrap;
    text-align: left;
}

.data-table td {
    padding: 10px 14px;
    font-size: 13px;
    border-bottom: 1px solid var(--gray-100);
    color: var(--gray-600);
    transition: background var(--transition);
}

.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg-table-hover); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* === Pagination === */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.page-nav { display: flex; align-items: center; gap: 16px; margin-left: auto; }

.page-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-card);
    color: var(--gray-600);
    cursor: pointer;
    transition: all var(--transition);
}

.page-btn:hover:not(:disabled) { background: var(--blue-light); color: var(--blue); border-color: var(--blue); }
.page-btn:disabled { opacity: .4; cursor: not-allowed; }
.page-btn .material-icons-outlined { font-size: 20px; }

.page-info { font-size: 13px; color: var(--gray-600); }

/* === Empty State === */
.empty-state { text-align: center; padding: 80px 20px; color: var(--gray-400); animation: fadeIn .5s ease; }
.empty-state .material-icons-outlined { font-size: 64px; margin-bottom: 16px; animation: pulse 2s ease infinite; }
.empty-state h3 { color: var(--gray-600); margin-bottom: 8px; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* === Responsive === */
@media (max-width: 1024px) {
    .data-table { font-size: 12px; }
    .data-table th, .data-table td { padding: 8px 10px; }
}

@media (max-width: 768px) {
    .topbar { height: 50px; }
    .sidebar {
        position: fixed;
        top: 50px;
        left: 0;
        bottom: 0;
        z-index: 99;
        width: 260px;
        transform: translateX(-100%);
        box-shadow: none;
        border-right: 1px solid var(--border);
    }
    .sidebar-overlay { top: 50px; }
    .sidebar-collapsed .sidebar { transform: translateX(-100%); width: 260px; padding: 20px 0; border-right: 1px solid var(--border); }
    .sidebar-open .sidebar {
        transform: translateX(0) !important;
        box-shadow: 4px 0 20px rgba(0,0,0,.2);
        width: 260px;
        padding: 20px 0;
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 50px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,.4);
        z-index: 98;
    }
    .sidebar-open .sidebar-overlay { display: block; }
    .content { padding: 16px; }
    .topbar-subtitle { display: none; }
    .filter-form label { flex-basis: 100%; }
    .filter-form > button { flex-basis: 100%; justify-content: center; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .btn-export { justify-content: center; }
    .detail-header h2 { font-size: 18px; }
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; border-radius: 0; }
    .data-table { min-width: 600px; }
}

@media (max-width: 480px) {
    .topbar { padding: 0 10px; }
    .topbar-title { font-size: 13px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .topbar-brand .material-icons-outlined { font-size: 22px; }
    .topbar-brand { gap: 8px; min-width: 0; }
    .content { padding: 10px; }
    .detail-header h2 { font-size: 16px; }
    .data-table th { font-size: 9px; padding: 6px 6px; }
    .data-table td { font-size: 11px; padding: 6px; }
    .empty-state { padding: 40px 16px; }
    .empty-state .material-icons-outlined { font-size: 48px; }
}
