/* ==========================================================================
   VentaRD - Modern SaaS Design System
   WCAG 2.2 AA Compliant
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    /* ── Tipografía ── */
    --font-family-base: 'Inter', system-ui, -apple-system, sans-serif;
    
    /* Font Sizes */
    --text-xs: 0.75rem;     /* 12px */
    --text-sm: 0.875rem;    /* 14px */
    --text-base: 1rem;      /* 16px */
    --text-lg: 1.125rem;    /* 18px */
    --text-xl: 1.25rem;     /* 20px */
    --text-2xl: 1.5rem;     /* 24px */
    --text-3xl: 1.875rem;   /* 30px */
    --text-4xl: 2.25rem;    /* 36px */

    /* Font Weights */
    --font-light: 300;
    --font-regular: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;
    --font-extrabold: 800;

    /* ── Espaciado (Linear Scale) ── */
    --space-1: 0.25rem;  /* 4px */
    --space-2: 0.5rem;   /* 8px */
    --space-3: 0.75rem;  /* 12px */
    --space-4: 1rem;     /* 16px */
    --space-5: 1.25rem;  /* 20px */
    --space-6: 1.5rem;   /* 24px */
    --space-8: 2rem;     /* 32px */
    --space-10: 2.5rem;  /* 40px */
    --space-12: 3rem;    /* 48px */
    --space-16: 4rem;    /* 64px */

    /* ── Bordes y Radius ── */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 24px;
    --radius-full: 9999px;

    /* ── Base Color Palette (Brand: Indigo) ── */
    --primary-50:  #eef2ff;
    --primary-100: #e0e7ff;
    --primary-200: #c7d2fe;
    --primary-300: #a5b4fc;
    --primary-400: #818cf8;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;
    --primary-800: #3730a3;
    --primary-900: #312e81;

    /* ── Grayscale (Slate) ── */
    --gray-50:  #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    /* ── Semantic Colors (Success - Emerald) ── */
    --success-50:  #ecfdf5;
    --success-500: #10b981;
    --success-700: #047857;
    
    /* ── Semantic Colors (Warning - Amber) ── */
    --warning-50:  #fffbeb;
    --warning-500: #f59e0b;
    --warning-700: #b45309;

    /* ── Semantic Colors (Danger - Rose) ── */
    --danger-50:  #fff1f2;
    --danger-500: #f43f5e;
    --danger-700: #be123c;
    
    /* ── Shadows ── */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
}

/* ==========================================================================
   TEMA CLARO (Default Light Mode)
   ========================================================================== */
[data-theme="light"], :root {
    --bg-app: #f8fafc;           /* App background */
    --bg-card: #ffffff;          /* Card background */
    --bg-elevated: #ffffff;      /* Modals, Dropdowns */
    
    --text-primary: var(--gray-900);
    --text-secondary: var(--gray-600);
    --text-tertiary: var(--gray-400);
    
    --border-subtle: var(--gray-200);
    --border-strong: var(--gray-300);
    --border-focus: var(--primary-500);

    --btn-primary-bg: var(--primary-600);
    --btn-primary-hover: var(--primary-700);
    --btn-primary-text: #ffffff;

    --btn-secondary-bg: var(--gray-100);
    --btn-secondary-hover: var(--gray-200);
    --btn-secondary-text: var(--gray-800);

    --input-bg: #ffffff;
    --input-border: var(--gray-300);
    --input-text: var(--gray-900);
    --input-placeholder: var(--gray-400);
    
    --sidebar-bg: #ffffff;
    --sidebar-border: var(--gray-200);
    --sidebar-item-hover: var(--gray-100);
    --sidebar-item-active: var(--primary-50);
    --sidebar-text: var(--gray-700);
    --sidebar-text-active: var(--primary-700);

    --shadow-card: var(--shadow-sm);
    --shadow-dropdown: var(--shadow-lg);
    
    --table-header-bg: var(--gray-50);
    --table-header-text: var(--gray-600);
    --table-border: var(--gray-200);
    --table-row-hover: var(--gray-50);
}

/* ==========================================================================
   TEMA OSCURO (Dark Mode)
   ========================================================================== */
[data-theme="dark"] {
    --bg-app: #090e17;           /* Deep dark background */
    --bg-card: #131b2c;          /* Card background */
    --bg-elevated: #1e293b;      /* Modals, Dropdowns */
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.15);
    --border-focus: var(--primary-400);

    --btn-primary-bg: var(--primary-500);
    --btn-primary-hover: var(--primary-400);
    --btn-primary-text: #ffffff;

    --btn-secondary-bg: rgba(255, 255, 255, 0.05);
    --btn-secondary-hover: rgba(255, 255, 255, 0.1);
    --btn-secondary-text: var(--gray-100);

    --input-bg: rgba(0, 0, 0, 0.2);
    --input-border: rgba(255, 255, 255, 0.12);
    --input-text: #f8fafc;
    --input-placeholder: #94a3b8;
    
    --sidebar-bg: #090e17;
    --sidebar-border: rgba(255, 255, 255, 0.08);
    --sidebar-item-hover: rgba(255, 255, 255, 0.05);
    --sidebar-item-active: rgba(99, 102, 241, 0.15);
    --sidebar-text: var(--gray-300);
    --sidebar-text-active: var(--primary-300);

    --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.5);
    --shadow-dropdown: 0 10px 25px -5px rgba(0, 0, 0, 0.7);

    --table-header-bg: rgba(255, 255, 255, 0.02);
    --table-header-text: var(--gray-400);
    --table-border: rgba(255, 255, 255, 0.08);
    --table-row-hover: rgba(255, 255, 255, 0.03);
}

/* ==========================================================================
   Global Resets & Typographical Base
   ========================================================================== */
html {
    font-size: 16px;
    box-sizing: border-box;
    scroll-behavior: smooth;
}

*, *::before, *::after {
    box-sizing: inherit;
}

body {
    font-family: var(--font-family-base);
    background-color: var(--bg-app);
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
    margin: 0;
    padding: 0;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    font-weight: var(--font-semibold);
    margin-top: 0;
    margin-bottom: var(--space-4);
    line-height: 1.2;
}

h1 { font-size: var(--text-3xl); font-weight: var(--font-bold); letter-spacing: -0.02em; }
h2 { font-size: var(--text-2xl); letter-spacing: -0.01em; }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-base); }

p {
    color: var(--text-secondary);
    margin-top: 0;
    margin-bottom: var(--space-4);
}

a {
    color: var(--primary-600);
    text-decoration: none;
    transition: color 0.2s ease;
}

[data-theme="dark"] a {
    color: var(--primary-400);
}

a:hover {
    color: var(--primary-700);
    text-decoration: underline;
}

[data-theme="dark"] a:hover {
    color: var(--primary-300);
}

/* ==========================================================================
   SaaS Layout Architecture
   ========================================================================== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ── */
.app-sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
    z-index: 100;
}

.sidebar-header {
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 var(--space-6);
    border-bottom: 1px solid var(--sidebar-border);
}

.brand-link {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.brand-text {
    font-size: var(--text-lg);
    font-weight: var(--font-extrabold);
    background: linear-gradient(135deg, var(--primary-500), var(--primary-300));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4) 0;
}

.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background-color: var(--border-subtle);
    border-radius: var(--radius-full);
}

.nav-section-title {
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: var(--font-semibold);
    color: var(--text-tertiary);
    margin: var(--space-4) var(--space-6) var(--space-2);
}

.nav-item-link, .nav-group-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: var(--space-2) var(--space-6);
    color: var(--sidebar-text);
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    text-decoration: none;
    transition: background-color 0.2s, color 0.2s;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    outline: none;
}

.nav-item-link:hover, .nav-group-btn:hover {
    background-color: var(--sidebar-item-hover);
    color: var(--text-primary);
    text-decoration: none;
}

.nav-item-link:focus-visible,
.nav-group-btn:focus-visible {
    box-shadow: inset 0 0 0 2px var(--primary-500);
}

.nav-item-link.active {
    background-color: var(--sidebar-item-active);
    color: var(--sidebar-text-active);
    box-shadow: inset -3px 0 0 var(--primary-500);
}

.nav-icon {
    margin-right: var(--space-3);
    font-size: var(--text-base);
    opacity: 0.8;
}

.nav-group-btn .chevron {
    margin-left: auto;
    font-size: var(--text-xs);
    transition: transform 0.2s;
}

.nav-group-btn[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.nav-group-content .nav-item-link {
    padding-left: 3.5rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* Collapsible sections (Inventario, Facturación, etc.) */
.section-collapsible {
    margin-bottom: var(--space-1);
}

.section-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    padding: var(--space-2) var(--space-6);
    color: var(--sidebar-text);
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    text-decoration: none;
    background: transparent;
    border: none;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    outline: none;
}

.section-toggle:hover {
    background-color: var(--sidebar-item-hover);
    color: var(--text-primary);
}

.section-toggle:focus-visible {
    box-shadow: inset 0 0 0 2px var(--primary-500);
}

.section-toggle .chevron {
    margin-left: auto;
    font-size: var(--text-xs);
    transition: transform 0.2s;
}

.section-toggle[aria-expanded="true"] .chevron {
    transform: rotate(180deg);
}

.section-collapsible .collapse .nav-item-link {
    padding-left: 3.5rem;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.section-always-open {
    margin-bottom: var(--space-2);
}

.section-always-open .nav-item-link {
    padding-left: var(--space-6);
}

.section-always-open .nav-item-link:first-of-type {
    margin-top: 0;
}

.sidebar-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--sidebar-border);
}

.theme-toggle-btn {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    transition: all 0.2s;
}

.theme-toggle-btn:hover {
    border-color: var(--border-focus);
}

/* ── Main Wrapper ── */
.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

.app-header {
    height: 64px;
    background-color: var(--bg-app);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-8);
    position: sticky;
    top: 0;
    z-index: 50;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background-color: rgba(var(--bg-app-rgb), 0.8);
}

.page-context-title {
    font-size: var(--text-lg);
    font-weight: var(--font-semibold);
    margin: 0;
    color: var(--text-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    background: var(--primary-100);
    color: var(--primary-700);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-sm);
}

[data-theme="dark"] .avatar {
    background: var(--primary-900);
    color: var(--primary-300);
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-name {
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
}

.role-badge {
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: var(--radius-full);
    font-weight: var(--font-bold);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.role-badge.danger { background: var(--danger-50); color: var(--danger-700); }
.role-badge.warning { background: var(--warning-50); color: var(--warning-700); }
.role-badge.default { background: var(--gray-100); color: var(--gray-700); }

[data-theme="dark"] .role-badge.danger { background: rgba(244,63,94,0.1); color: var(--danger-500); }
[data-theme="dark"] .role-badge.warning { background: rgba(245,158,11,0.1); color: var(--warning-500); }
[data-theme="dark"] .role-badge.default { background: rgba(255,255,255,0.1); color: var(--gray-300); }

.btn-logout, .btn-login {
    font-size: var(--text-sm);
    font-weight: var(--font-medium);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
}

.btn-logout {
    color: var(--danger-500);
    background: var(--danger-50);
}
[data-theme="dark"] .btn-logout { background: rgba(244,63,94,0.1); }
.btn-logout:hover { background: var(--danger-500); color: #fff; text-decoration: none; }

.btn-login {
    background: var(--btn-primary-bg);
    color: var(--btn-primary-text);
}
.btn-login:hover {
    background: var(--btn-primary-hover);
    color: var(--btn-primary-text);
    text-decoration: none;
}

.app-content {
    flex: 1;
    padding: var(--space-8);
    overflow-y: auto;
}

.app-footer {
    padding: var(--space-4) var(--space-8);
    text-align: center;
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    border-top: 1px solid var(--border-subtle);
}

@media (max-width: 768px) {
    .app-layout { flex-direction: column; }
    .app-sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--sidebar-border); }
    .sidebar-nav { display: none; } /* Could be toggled with JS */
    .app-header { padding: 0 var(--space-4); }
    .app-content { padding: var(--space-4); }
}

/* ==========================================================================
   Common UI Patterns (consolidated from inline styles)
   ========================================================================== */

/* ── Glass Card (CRUD views: Usuarios, NCF, Empresa, Traslados, Ajustes) ── */
.glass-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 18px;
    padding: 28px;
}

/* ── Glass Panel with backdrop blur (Sucursales, Clientes, Productos, Admin) ── */
.glass-panel {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 18px;
    padding: 28px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
}

/* ── Stat Cards (Dashboard, Sucursales, Clientes, Productos, Admin) ── */
.stat-card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 14px;
    padding: 18px 22px;
}
.stat-value {
    font-size: 1.8rem;
    font-weight: 800;
    line-height: 1;
}
.stat-label {
    color: #64748b;
    font-size: 0.82rem;
    margin-top: 4px;
}

/* ── Status Badges ── */
.badge-status {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 700;
}
.status-active {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 1px solid rgba(16, 185, 129, 0.25);
}
.status-inactive {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.25);
}

/* ── Button Action ── */
.btn-action {
    border-radius: 8px;
}

/* ── Search Box (Clientes, Productos) ── */
.search-box {
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: white;
    border-radius: 10px;
    padding: 10px 16px;
}
.search-box:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
    outline: none;
}
.search-box::placeholder {
    color: #64748b;
}

/* ── Pill Tabs (Clientes, Productos) ── */
.pill-tab {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 7px 18px;
    color: #94a3b8;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.87rem;
}
.pill-tab.active,
.pill-tab:hover {
    background: linear-gradient(135deg, #6366f1, #0ea5e9);
    color: white;
    border-color: transparent;
}

/* ── Table Dark Custom (Usuarios, NCF Comprobantes, NCF Secuencias) ── */
.table-dark-custom {
    --bs-table-bg: transparent;
}
.table-dark-custom th {
    color: #64748b;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-color: rgba(255, 255, 255, 0.06) !important;
}
.table-dark-custom td {
    border-color: rgba(255, 255, 255, 0.05) !important;
    color: #e2e8f0;
    vertical-align: middle;
}
.table-dark-custom tbody tr:hover td {
    background: rgba(56, 189, 248, 0.04);
}

/* ── Badge Rol (Usuarios, NCF Secuencias, NCF Comprobantes) ── */
.badge-rol {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
/* Generic color-badge pattern */
.badge-danger-tint {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}
.badge-warning-tint {
    background: rgba(245, 158, 11, 0.2);
    color: #fcd34d;
    border: 1px solid rgba(245, 158, 11, 0.3);
}
.badge-info-tint {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
    border: 1px solid rgba(59, 130, 246, 0.3);
}
.badge-success-tint {
    background: rgba(16, 185, 129, 0.2);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.3);
}
.badge-default-tint {
    background: rgba(100, 116, 139, 0.2);
    color: #94a3b8;
    border: 1px solid rgba(100, 116, 139, 0.3);
}

/* ── Inactive Row ── */
.inactive-row td {
    opacity: 0.45;
}

/* ── Badge Tipo (NCF Secuencias) ── */
.badge-tipo {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-activo {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.25);
}
.badge-inactivo {
    background: rgba(100, 116, 139, 0.15);
    color: #94a3b8;
    border: 1px solid rgba(100, 116, 139, 0.25);
}
/* ── Empty State ── */
.empty-state {
    text-align: center;
    padding: 60px 0;
    color: #64748b;
}

@media (max-width: 768px) {
    .app-layout {
        display: block;
        height: auto;
        min-height: 100vh;
        overflow: visible;
    }

    .app-main {
        min-height: 100vh;
    }

    .app-header {
        min-height: 64px;
        height: auto;
        padding: 8px 12px 8px 56px;
        gap: 12px;
    }

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

    .page-context-title {
        max-width: 100%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: var(--text-base);
    }

    .header-right {
        flex: 0 0 auto;
        gap: 8px;
    }

    .user-profile {
        gap: 8px;
    }

    .avatar {
        width: 30px;
        height: 30px;
    }

    .user-name {
        max-width: 72px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .role-badge {
        font-size: 0.6rem;
        padding: 2px 5px;
        letter-spacing: 0.03em;
    }

    .btn-logout,
    .btn-login {
        padding: 8px 10px;
        white-space: nowrap;
    }
}
