/* ============================================
   UIFlow Dashboard — Premium Minimal SaaS Style
   ============================================ */

/* Inter variable (pesos 100–900), subconjunto latino, auto-alojada.
   Origen: @fontsource-variable/inter@5.2.5 — licencia en assets/fonts/OFL.txt */
@font-face {
    font-family: "Inter";
    src: url("../fonts/inter-latin-wght.woff2") format("woff2");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

/* Todos los colores salen de estos tokens: .dark solo los redefine */
:root {
    --bg: #f5f7fb;
    --surface: #ffffff;          /* tarjetas, cajas */
    --surface-2: #f1f4f9;        /* cabecera de tabla, hover */
    --sidebar-bg: #ffffff;
    --input-bg: #ffffff;
    --text: #111827;
    --subtext: #6b7280;
    --border: #e5e7eb;
    --primary: #4b6bff;
    --primary-hover: #3a54d9;
    --primary-light: #eef1ff;
    --on-primary: #ffffff;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 14px rgba(16, 24, 40, 0.06);
    --shadow-hover: 0 8px 22px rgba(16, 24, 40, 0.10);
    --chart-grid: rgba(17, 24, 39, 0.06);
    --chart-text: #6b7280;
    --radius: 14px;
    --max-width: 1400px;
    color-scheme: light;
}

/* ===== DARK THEME: fondo azul pizarra, superficies un escalón más claras ===== */
.dark {
    --bg: #0b0d12;
    --surface: #141821;
    --surface-2: #1b2030;
    --sidebar-bg: #10131b;
    --input-bg: #0f121a;
    --text: #e6e8ef;
    --subtext: #9aa3b5;
    --border: #262c3a;
    --primary-light: rgba(75, 107, 255, 0.16);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 14px rgba(0, 0, 0, 0.35);
    --shadow-hover: 0 8px 22px rgba(0, 0, 0, 0.5);
    --chart-grid: rgba(230, 232, 239, 0.07);
    --chart-text: #9aa3b5;
    color-scheme: dark;
}

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

body {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    transition: background-color 0.25s, color 0.25s;
}

button,
input {
    font: inherit;
    color: inherit;
}

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ============================================
   SIDEBAR
   ============================================ */

.sidebar {
    width: 240px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    height: 100vh;
    padding: 25px 20px;
    position: fixed;
    top: 0;
    left: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 40px;
    color: inherit;
    text-decoration: none;
}

.sidebar-logo {
    width: 34px;
    height: 34px;
}

.sidebar-brand {
    font-size: 1.5rem;
    font-weight: 700;
}

.nav-item {
    display: block;
    width: 100%;
    padding: 14px;
    margin-bottom: 8px;
    text-align: left;
    background: none;
    border: none;
    color: var(--subtext);
    border-radius: var(--radius);
    transition: 0.25s;
    cursor: pointer;
}

.nav-item:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.nav-item.active,
.nav-item.active:hover {
    background: var(--primary);
    color: var(--on-primary);
}

/* ============================================
   MAIN CONTENT
   ============================================ */

.main {
    margin-left: 240px;
    padding: 30px 40px;
    flex: 1;
    min-width: 0;
    max-width: calc(var(--max-width) + 240px);
}

/* ============================================
   TOP BAR
   ============================================ */

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    margin-bottom: 32px;
}

.page-heading h1 {
    font-size: 1.75rem;
    line-height: 1.2;
}

.page-heading .subtext {
    margin-top: 4px;
}

.search,
.table-search {
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--input-bg);
    color: var(--text);
    outline: none;
    transition: border-color 0.25s, box-shadow 0.25s, background-color 0.25s;
}

.search {
    width: 240px;
}

.search::placeholder,
.table-search::placeholder {
    color: var(--subtext);
}

.search:focus,
.table-search:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

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

.theme-btn {
    display: grid;
    place-items: center;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--subtext);
    cursor: pointer;
    transition: 0.25s;
}

.theme-btn .icon-sun,
.dark .theme-btn .icon-moon {
    display: none;
}

.dark .theme-btn .icon-sun {
    display: block;
}

.theme-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.user-box {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Avatar de iniciales: no depende de ninguna imagen */
.user-avatar {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4b6bff, #8b5cf6);
    color: var(--on-primary);
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.user-name {
    font-weight: 500;
    white-space: nowrap;
}

/* ============================================
   CARDS
   ============================================ */

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 25px;
    margin-bottom: 40px;
}

.card {
    background: var(--surface);
    padding: 25px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    transition: transform 0.25s, box-shadow 0.25s;
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-hover);
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    white-space: nowrap;
    line-height: 1.2;
    margin-bottom: 8px;
}

.kpi-label {
    color: var(--subtext);
}

/* ============================================
   CHART SECTION
   ============================================ */

.chart-box {
    background: var(--surface);
    padding: 30px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 40px;
}

/* Chart.js necesita un contenedor con posición relativa y alto fijo */
.chart-wrap {
    position: relative;
    height: 280px;
}

/* ====== FILTER BUTTONS ====== */

.chart-header h2,
.table-header h2 {
    font-size: 1.25rem;
}

.chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.range-group {
    display: flex;
    gap: 8px;
}

.range-btn {
    padding: 7px 14px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--subtext);
    cursor: pointer;
    transition: 0.25s;
    font-size: 0.85rem;
    font-weight: 500;
}

.range-btn:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
}

.range-btn[aria-pressed="true"] {
    background: var(--primary);
    color: var(--on-primary);
    border-color: var(--primary);
}

/* ============================================
   TABLE SECTION
   ============================================ */

.table-box {
    background: var(--surface);
    padding: 30px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.table-search {
    width: 220px;
}

/* Si la tabla no cabe, el scroll queda dentro de la tarjeta y no en la página */
.table-scroll {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

table thead {
    background: var(--surface-2);
}

table th {
    padding: 0;
    text-align: left;
}

.sort-btn {
    width: 100%;
    padding: 12px;
    text-align: left;
    background: none;
    border: none;
    color: var(--subtext);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}

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

.sort-icon {
    font-size: 0.7rem;
}

table td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
}

.empty-row {
    text-align: center;
    color: var(--subtext);
}

/* Status badges */
.status {
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 0.8rem;
    font-weight: 600;
    color: white;
}

.status.active { background: #10b981; }
.status.pending { background: #f59e0b; }
.status.inactive { background: #ef4444; }

/* Pagination */
.pagination {
    margin-top: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}

.page-btn {
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: 0.2s;
}

.page-btn:hover:not(:disabled) {
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

/* ===================== SPA VIEWS ===================== */

.view {
    display: none;
    animation: fade 0.3s ease;
}

.view.active {
    display: block;
}

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

/* ================= ANALYTICS ================= */

.subtext {
    color: var(--subtext);
}

.analytics-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 20px;
    margin: 20px 0 30px;
}

.a-card {
    background: var(--surface);
    padding: 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    text-align: center;
}

.a-card .kpi-value {
    font-size: 1.4rem;
    margin-bottom: 6px;
}

.a-filters {
    margin-bottom: 25px;
}

.analytics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 350px), 1fr));
    gap: 25px;
}

/* Revenue ocupa toda la fila; Users y Devices quedan lado a lado debajo */
.analytics-card-wide {
    grid-column: 1 / -1;
}

.analytics-card {
    background: var(--surface);
    padding: 25px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.analytics-card h2 {
    font-size: 1.1rem;
    margin-bottom: 14px;
}

.analytics-card .chart-wrap {
    height: 300px;
}

/* ============================================
   RESPONSIVE
   ============================================ */

/* Tablet y móvil: la sidebar pasa a ser una barra superior con pestañas */
@media (max-width: 900px) {
    body {
        display: block;
    }

    .sidebar {
        position: sticky;
        z-index: 10;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        width: 100%;
        height: auto;
        padding: 10px 16px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-header {
        margin-bottom: 0;
        gap: 8px;
    }

    .sidebar-logo {
        width: 28px;
        height: 28px;
    }

    .sidebar-brand {
        font-size: 1.15rem;
    }

    .sidebar-menu {
        display: flex;
        gap: 4px;
    }

    .nav-item {
        width: auto;
        margin-bottom: 0;
        padding: 8px 14px;
        border-radius: 10px;
    }

    .main {
        margin-left: 0;
        padding: 24px 20px;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
    }

    .search {
        flex: 1;
        min-width: 0;
        width: auto;
    }

    .kpi-value {
        font-size: 1.5rem;
    }
}

@media (max-width: 600px) {
    .main {
        padding: 20px 16px;
    }

    .page-heading h1 {
        font-size: 1.5rem;
    }

    .user-name {
        display: none;
    }

    .topbar-actions {
        gap: 10px;
    }

    .cards,
    .analytics-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 12px;
        margin-bottom: 24px;
    }

    .card,
    .a-card {
        padding: 16px;
    }

    .kpi-value,
    .a-card .kpi-value {
        font-size: 1.3rem;
    }

    .chart-box,
    .table-box,
    .analytics-card {
        padding: 18px;
    }

    .chart-box {
        margin-bottom: 24px;
    }

    .chart-header,
    .table-header {
        flex-wrap: wrap;
        gap: 12px;
    }

    .chart-wrap,
    .analytics-card .chart-wrap {
        height: 240px;
    }

    .table-search {
        width: 100%;
    }

    .table-scroll table {
        min-width: 460px;
    }

    .analytics-grid {
        gap: 16px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition: none !important;
        animation: none !important;
    }

    .card:hover {
        transform: none;
    }
}
