/* ============================================================
   SINTHESI — Design System
   Premium dark theme with glassmorphism & micro-animations
   ============================================================ */

/* ---------------------------------------------------------------------------
   CSS Custom Properties
   --------------------------------------------------------------------------- */
:root {
    /* Background */
    --bg-primary: #07080f;
    --bg-secondary: #0d0f1a;
    --bg-card: rgba(15, 17, 30, 0.7);
    --bg-card-hover: rgba(20, 23, 40, 0.85);
    --bg-input: rgba(20, 23, 42, 0.6);
    --bg-nav: rgba(10, 12, 22, 0.85);

    /* Glass */
    --glass-blur: 20px;
    --glass-border: rgba(255, 255, 255, 0.06);
    --glass-border-hover: rgba(255, 255, 255, 0.12);

    /* Accent colors */
    --cyan: #00d4ff;
    --cyan-dim: rgba(0, 212, 255, 0.15);
    --violet: #7c3aed;
    --violet-dim: rgba(124, 58, 237, 0.15);
    --emerald: #10b981;
    --emerald-dim: rgba(16, 185, 129, 0.15);
    --amber: #f59e0b;
    --amber-dim: rgba(245, 158, 11, 0.15);
    --rose: #f43f5e;
    --rose-dim: rgba(244, 63, 94, 0.15);
    --blue: #3b82f6;
    --blue-dim: rgba(59, 130, 246, 0.15);

    /* Rotation classes */
    --rot-a: #10b981;
    --rot-b: #f59e0b;
    --rot-c: #f43f5e;

    /* Text */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-accent: #00d4ff;

    /* Gradient */
    --grad-primary: linear-gradient(135deg, #00d4ff 0%, #7c3aed 100%);
    --grad-bg: radial-gradient(ellipse at 20% 50%, rgba(124, 58, 237, 0.08) 0%, transparent 50%),
               radial-gradient(ellipse at 80% 20%, rgba(0, 212, 255, 0.06) 0%, transparent 50%),
               radial-gradient(ellipse at 50% 80%, rgba(16, 185, 129, 0.04) 0%, transparent 50%);

    /* Spacing */
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;

    /* Shadows */
    --shadow-card: 0 4px 30px rgba(0, 0, 0, 0.3);
    --shadow-glow-cyan: 0 0 30px rgba(0, 212, 255, 0.1);
    --shadow-glow-violet: 0 0 30px rgba(124, 58, 237, 0.1);

    /* Transitions */
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ---------------------------------------------------------------------------
   Animations
   --------------------------------------------------------------------------- */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(24px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-12px); }
    to   { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-glow {
    0%, 100% { opacity: 0.6; }
    50%      { opacity: 1; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33%      { transform: translate(30px, -20px) scale(1.05); }
    66%      { transform: translate(-20px, 15px) scale(0.95); }
}

@keyframes counter {
    from { opacity: 0; transform: scale(0.5); }
    to   { opacity: 1; transform: scale(1); }
}

/* ---------------------------------------------------------------------------
   Login Page
   --------------------------------------------------------------------------- */
.login-page {
    background: var(--bg-primary);
    background-image: var(--grad-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.bg-animation {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 0;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    animation: float 20s ease-in-out infinite;
}

.bg-orb-1 {
    width: 400px; height: 400px;
    background: rgba(0, 212, 255, 0.08);
    top: -100px; left: -100px;
}

.bg-orb-2 {
    width: 350px; height: 350px;
    background: rgba(124, 58, 237, 0.08);
    top: 50%; right: -80px;
    animation-delay: -7s;
}

.bg-orb-3 {
    width: 300px; height: 300px;
    background: rgba(16, 185, 129, 0.06);
    bottom: -80px; left: 40%;
    animation-delay: -14s;
}

.login-container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 440px;
    animation: fadeInUp 0.7s ease-out;
}

.login-card {
    background: var(--bg-card);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 2.5rem;
    box-shadow: var(--shadow-card);
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.brand-icon {
    margin-bottom: 0.75rem;
    display: inline-block;
    animation: fadeIn 0.5s ease-out 0.2s both;
}

.brand-title {
    font-size: 2rem;
    font-weight: 800;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
    animation: fadeIn 0.5s ease-out 0.3s both;
}

.brand-subtitle {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.4rem;
    animation: fadeIn 0.5s ease-out 0.4s both;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
    transition: color var(--transition);
    pointer-events: none;
    flex-shrink: 0;
}

.form-input {
    width: 100%;
    padding: 0.85rem 1rem 0.85rem 2.75rem;
    background: var(--bg-input);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all var(--transition);
    outline: none;
}

.form-input:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px var(--cyan-dim);
}

.form-input:focus + .input-icon,
.form-input:focus ~ .input-icon {
    color: var(--cyan);
}

/* Select override */
select.form-input {
    padding-left: 1rem;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
}

.toggle-password {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    transition: color var(--transition);
}

.toggle-password:hover {
    color: var(--text-primary);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--grad-primary);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.2);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 25px rgba(0, 212, 255, 0.3);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-full {
    width: 100%;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-danger {
    color: var(--rose);
}

.btn-danger:hover {
    background: var(--rose-dim);
}

.login-footer {
    text-align: center;
    margin-top: 1.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* Flash messages */
.flash-messages {
    margin-bottom: 1.25rem;
}

.flash-msg {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-xs);
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
    animation: slideDown 0.3s ease-out;
}

.flash-icon {
    flex-shrink: 0;
    font-size: 1rem;
}

.flash-error {
    background: var(--rose-dim);
    color: var(--rose);
    border: 1px solid rgba(244, 63, 94, 0.2);
}

.flash-success {
    background: var(--emerald-dim);
    color: var(--emerald);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.flash-info {
    background: var(--cyan-dim);
    color: var(--cyan);
    border: 1px solid rgba(0, 212, 255, 0.2);
}

/* ---------------------------------------------------------------------------
   Top Navigation
   --------------------------------------------------------------------------- */
.top-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    background: var(--bg-nav);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-bottom: 1px solid var(--glass-border);
    z-index: 100;
    animation: slideDown 0.4s ease-out;
}

.nav-left, .nav-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    text-decoration: none;
    color: inherit;
}

.nav-title {
    font-size: 1.15rem;
    font-weight: 700;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Botón hamburguesa — visible cuando las pestañas están colapsadas */
.nav-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
}

.nav-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--glass-border-hover);
}

.nav-toggle .icon-close {
    display: none;
}

.top-nav.nav-open .nav-toggle .icon-open {
    display: none;
}

.top-nav.nav-open .nav-toggle .icon-close {
    display: block;
}

/* Menú desplegable (colapsado por defecto) */
.nav-center {
    position: absolute;
    top: 100%;
    left: 1rem;
    margin-top: 0.5rem;
    display: none;
    width: 260px;
    max-width: calc(100vw - 2rem);
    max-height: calc(100vh - 90px);
    overflow-y: auto;
    background: #0f111e;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-card);
    padding: 0.5rem;
    z-index: 120;
}

.top-nav.nav-open .nav-center {
    display: block;
    animation: fadeInUp 0.2s ease-out;
}

.nav-tabs {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    background: transparent;
    padding: 0;
    border: none;
    border-radius: 0;
}

.nav-tab {
    width: 100%;
    justify-content: flex-start;
}

.nav-tab {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.nav-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.05);
}

.nav-tab.active {
    color: var(--text-primary);
    background: rgba(0, 212, 255, 0.1);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.1);
}

.nav-tab svg {
    flex-shrink: 0;
}

.nav-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all var(--transition);
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

.nav-btn-logout:hover {
    color: var(--rose);
    background: var(--rose-dim);
}

/* Filtro de fecha global */
.global-filter {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.global-filter-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 600;
}

.global-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.global-dates {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
}

.global-dates .table-search {
    width: auto;
}

/* Menú de exportación (Power BI) */
.export-menu {
    position: relative;
}

.export-menu summary {
    list-style: none;
    cursor: pointer;
}

.export-menu summary::-webkit-details-marker {
    display: none;
}

.export-menu-list {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    min-width: 220px;
    background: var(--bg-secondary, #1a1d24);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm, 8px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    padding: 0.4rem;
    z-index: 100;
}

.export-menu-title {
    display: block;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
    padding: 0.4rem 0.6rem 0.3rem;
}

.export-menu-list a {
    display: block;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.82rem;
    transition: background var(--transition);
}

.export-menu-list a:hover {
    background: rgba(255, 255, 255, 0.06);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.user-name {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* ---------------------------------------------------------------------------
   Dashboard Layout
   --------------------------------------------------------------------------- */
.dashboard-page {
    background: var(--bg-primary);
    background-image: var(--grad-bg);
    background-attachment: fixed;
}

.dashboard-main {
    padding: 80px 1.5rem 2rem;
    max-width: 1440px;
    margin: 0 auto;
    position: relative;
    min-height: 100vh;
}

/* Loading */
.loading-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(7, 8, 15, 0.85);
    z-index: 200;
    transition: opacity 0.4s ease;
}

.loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

.loading-spinner {
    text-align: center;
}

.spinner-ring {
    width: 48px;
    height: 48px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--cyan);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

.loading-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Sections */
.dash-section {
    display: none;
    animation: fadeInUp 0.5s ease-out;
}

.dash-section.active {
    display: block;
}

.section-header {
    margin-bottom: 1.5rem;
}

.section-header h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: var(--grad-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.section-subtitle {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.3rem;
}

/* ---------------------------------------------------------------------------
   KPI Cards
   --------------------------------------------------------------------------- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-grid-sm {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.kpi-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    background: var(--bg-card);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    transition: all var(--transition);
    animation: fadeInUp 0.5s ease-out both;
}

.kpi-card:nth-child(1) { animation-delay: 0.05s; }
.kpi-card:nth-child(2) { animation-delay: 0.1s; }
.kpi-card:nth-child(3) { animation-delay: 0.15s; }
.kpi-card:nth-child(4) { animation-delay: 0.2s; }
.kpi-card:nth-child(5) { animation-delay: 0.25s; }
.kpi-card:nth-child(6) { animation-delay: 0.3s; }

.kpi-card:hover {
    border-color: var(--glass-border-hover);
    transform: translateY(-3px);
    box-shadow: var(--shadow-card), var(--shadow-glow-cyan);
}

.kpi-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    border-radius: 12px;
    flex-shrink: 0;
}

.kpi-cyan .kpi-icon  { background: var(--cyan-dim);   color: var(--cyan); }
.kpi-violet .kpi-icon { background: var(--violet-dim); color: var(--violet); }
.kpi-emerald .kpi-icon { background: var(--emerald-dim); color: var(--emerald); }
.kpi-amber .kpi-icon { background: var(--amber-dim);  color: var(--amber); }
.kpi-rose .kpi-icon  { background: var(--rose-dim);   color: var(--rose); }
.kpi-blue .kpi-icon  { background: var(--blue-dim);   color: var(--blue); }

.kpi-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
    color: var(--text-primary);
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 0.2rem;
}

/* ---------------------------------------------------------------------------
   Chart Cards
   --------------------------------------------------------------------------- */
.charts-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.chart-card {
    background: var(--bg-card);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    animation: fadeInUp 0.5s ease-out 0.2s both;
}

.chart-card-half {
    flex: 1 1 45%;
    min-width: 380px;
}

.chart-card-full {
    flex: 1 1 100%;
}

.chart-card-third {
    flex: 1 1 30%;
    min-width: 300px;
}

.chart-card-two-thirds {
    flex: 1 1 60%;
    min-width: 400px;
}

.chart-header {
    padding: 1.25rem 1.5rem 0.75rem;
    border-bottom: 1px solid var(--glass-border);
}

.chart-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.chart-body {
    padding: 1.25rem 1.5rem;
    position: relative;
    height: 320px;
}

.chart-body-sm {
    height: 260px;
}

.chart-body-lg {
    height: 500px;
}

.chart-body canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ---------------------------------------------------------------------------
   Branch KPIs (sucursales comparison)
   --------------------------------------------------------------------------- */
.branch-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.branch-card {
    background: var(--bg-card);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    animation: fadeInUp 0.5s ease-out 0.3s both;
}

.branch-card-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.branch-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.branch-dot-santiago { background: var(--cyan); }
.branch-dot-concepcion { background: var(--violet); }

.branch-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

.branch-stat {
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-xs);
    border: 1px solid var(--glass-border);
}

.branch-stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.branch-stat-label {
    font-size: 0.72rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-top: 0.15rem;
}

/* ---------------------------------------------------------------------------
   Data Tables
   --------------------------------------------------------------------------- */
.table-card {
    background: var(--bg-card);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
    overflow: hidden;
    margin-bottom: 1.5rem;
    animation: fadeInUp 0.5s ease-out 0.3s both;
}

.table-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--glass-border);
    flex-wrap: wrap;
    gap: 0.75rem;
}

.table-header h2 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.table-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.table-search-wrap {
    display: flex;
    align-items: center;
}

.table-search {
    padding: 0.5rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
    transition: all var(--transition);
    width: 200px;
}

.table-search:focus {
    border-color: var(--cyan);
    box-shadow: 0 0 0 3px var(--cyan-dim);
}

.table-filter {
    padding: 0.5rem 0.85rem;
    background: var(--bg-input);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.82rem;
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 2rem;
}

.table-scroll {
    overflow-x: auto;
}

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

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.82rem;
    border-bottom: 1px solid var(--glass-border);
    white-space: nowrap;
}

.data-table th {
    color: var(--text-secondary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-size: 0.72rem;
    background: rgba(255, 255, 255, 0.02);
    position: sticky;
    top: 0;
}

.data-table td {
    color: var(--text-primary);
}

.data-table th.num,
.data-table td.num {
    text-align: right;
}

.data-table tbody tr {
    transition: background var(--transition-fast);
}

.data-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Rotation class badges */
.class-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    font-weight: 700;
    font-size: 0.8rem;
}

.class-badge-A { background: rgba(16, 185, 129, 0.15); color: var(--emerald); }
.class-badge-B { background: rgba(245, 158, 11, 0.15); color: var(--amber); }
.class-badge-C { background: rgba(244, 63, 94, 0.15); color: var(--rose); }

/* User badges */
.user-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--grad-primary);
    color: white;
    font-weight: 700;
    font-size: 0.75rem;
    margin-right: 0.5rem;
}

.role-tag {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-xs);
    font-size: 0.75rem;
    font-weight: 600;
}

.role-admin { background: var(--violet-dim); color: var(--violet); }
.role-user  { background: var(--cyan-dim);   color: var(--cyan); }

.text-muted { color: var(--text-muted); }

/* ---------------------------------------------------------------------------
   Rotation Legend
   --------------------------------------------------------------------------- */
.rotation-legend {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.rotation-class {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--glass-border);
    transition: all var(--transition);
}

.rotation-class:hover {
    border-color: var(--glass-border-hover);
    background: rgba(255, 255, 255, 0.02);
}

.rotation-badge {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 800;
    flex-shrink: 0;
}

.rotation-a .rotation-badge { background: rgba(16,185,129,0.15); color: var(--emerald); }
.rotation-b .rotation-badge { background: rgba(245,158,11,0.15); color: var(--amber); }
.rotation-c .rotation-badge { background: rgba(244,63,94,0.15);  color: var(--rose); }

.rotation-info {
    flex: 1;
    min-width: 0;
}

.rotation-info strong {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.rotation-info p {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 0.15rem;
}

.rotation-count {
    display: inline-block;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-primary);
    animation: counter 0.4s ease-out;
}

/* ---------------------------------------------------------------------------
   Trends Section
   --------------------------------------------------------------------------- */

/* Filter layout */
.trends-filters {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-end;
}

/* Preset buttons row */
.trends-presets {
    display: flex;
    gap: 0.35rem;
}

.preset-btn, .cat-preset-btn {
    padding: 0.4rem 0.9rem;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.preset-btn:hover, .cat-preset-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    border-color: var(--glass-border-hover);
}

.preset-btn.active, .cat-preset-btn.active {
    background: var(--grad-primary);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 12px rgba(0, 212, 255, 0.25);
}

/* Analyze button */
.btn-filter-trends {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid rgba(0, 212, 255, 0.25);
    border-radius: var(--radius-xs);
    color: var(--cyan);
    font-family: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.btn-filter-trends:hover {
    background: rgba(0, 212, 255, 0.2);
    border-color: var(--cyan);
    box-shadow: 0 0 16px rgba(0, 212, 255, 0.15);
}

/* Close detail button */
.btn-close-detail {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-xs);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
}

.btn-close-detail:hover {
    background: var(--rose-dim);
    color: var(--rose);
    border-color: rgba(244, 63, 94, 0.3);
}

/* Detail chart animation */
.trends-detail-chart {
    animation: slideDetailIn 0.4s ease-out both;
    margin-bottom: 1.5rem;
}

@keyframes slideDetailIn {
    from { opacity: 0; transform: translateY(-16px); max-height: 0; }
    to   { opacity: 1; transform: translateY(0); max-height: 500px; }
}

/* Selectable table rows */
.data-table.trends-clickable tbody tr {
    cursor: pointer;
    transition: all var(--transition-fast);
}

.data-table.trends-clickable tbody tr:hover {
    background: rgba(0, 212, 255, 0.06);
}

.data-table.trends-clickable tbody tr.selected-row {
    background: rgba(0, 212, 255, 0.1);
    box-shadow: inset 3px 0 0 var(--cyan);
}

/* Sparkline canvas cell */
.sparkline-cell {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

.sparkline-cell canvas {
    display: block;
}

/* Concentration bar */
.concentration-bar {
    display: flex;
    width: 60px;
    height: 6px;
    border-radius: 3px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.06);
}

.concentration-bar .bar-stgo {
    background: var(--cyan);
    height: 100%;
    transition: width 0.3s ease;
}

.concentration-bar .bar-ccp {
    background: var(--violet);
    height: 100%;
    transition: width 0.3s ease;
}

.concentration-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

/* Frequency badge */
.freq-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.freq-high   { background: rgba(16, 185, 129, 0.15); color: var(--emerald); }
.freq-medium { background: rgba(245, 158, 11, 0.15); color: var(--amber); }
.freq-low    { background: rgba(244, 63, 94, 0.15); color: var(--rose); }

/* ---------------------------------------------------------------------------
   Users Page
   --------------------------------------------------------------------------- */
.users-page {
    background: var(--bg-primary);
    background-image: var(--grad-bg);
    background-attachment: fixed;
}

.users-main {
    padding: 80px 1.5rem 2rem;
    max-width: 1000px;
    margin: 0 auto;
}

.users-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 1.5rem;
    align-items: start;
}

.user-form {
    padding: 1.5rem;
}

.user-form .form-input {
    padding-left: 1rem;
}

/* ---------------------------------------------------------------------------
   Responsive
   --------------------------------------------------------------------------- */
/* Tablet: gráficos a un tercio / dos tercios pasan a ancho completo */
@media (max-width: 1024px) {
    .chart-card-third,
    .chart-card-two-thirds {
        flex: 1 1 100%;
        min-width: 100%;
    }
}

/* Tablet / móvil grande */
@media (max-width: 768px) {
    .top-nav {
        padding: 0 0.75rem;
    }
    .charts-row {
        flex-direction: column;
    }
    .chart-card-half,
    .chart-card-third,
    .chart-card-two-thirds {
        flex-basis: 100%;
        min-width: 100%;
    }
    .kpi-grid,
    .kpi-grid-sm {
        grid-template-columns: repeat(2, 1fr);
    }
    .branch-kpis {
        grid-template-columns: 1fr;
    }
    .users-layout {
        grid-template-columns: 1fr;
    }
    /* Encabezados con filtros (Margen, Catálogo, Rentables): apilar título y controles */
    .section-header > div {
        flex-direction: column;
        align-items: stretch !important;
    }
    .section-header h1 {
        font-size: 1.4rem;
    }
    .trends-filters,
    .trends-presets,
    .table-controls {
        flex-wrap: wrap;
    }
    .table-header {
        align-items: stretch;
    }
    .table-search {
        width: 100%;
    }
    .chart-body {
        height: 300px;
    }
    .chart-body-lg {
        height: 380px;
    }
    .dashboard-main {
        padding: 76px 1rem 2rem;
    }
}

/* Móvil */
@media (max-width: 480px) {
    .kpi-grid,
    .kpi-grid-sm {
        grid-template-columns: 1fr;
    }
    .dashboard-main {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }
    .section-header h1 {
        font-size: 1.25rem;
    }
    .nav-title {
        font-size: 1rem;
    }
    .chart-header,
    .chart-body,
    .table-header {
        padding-left: 1rem;
        padding-right: 1rem;
    }
    .chart-body-lg {
        height: 340px;
    }
    .login-card {
        padding: 1.5rem;
    }
    .kpi-card {
        padding: 1rem 1.15rem;
    }
}

/* Escritorio amplio: pestañas en línea (sin toggle) */
@media (min-width: 1500px) {
    .nav-toggle {
        display: none;
    }
    .nav-center {
        position: static;
        display: flex;
        justify-content: center;
        flex: 1 1 auto;
        width: auto;
        max-width: none;
        margin: 0 1rem;
        margin-top: 0;
        max-height: none;
        overflow: visible;
        background: transparent;
        border: none;
        border-radius: 0;
        box-shadow: none;
        padding: 0;
        z-index: auto;
    }
    .nav-tabs {
        flex-direction: row;
        background: rgba(255, 255, 255, 0.03);
        padding: 4px;
        border: 1px solid var(--glass-border);
        border-radius: var(--radius-sm);
    }
    .nav-tab {
        width: auto;
        justify-content: center;
    }
}
