/* ====================================================================
   LORA - DESIGN SYSTEM
   Sistema de tokens, colores, tipografía y componentes base
   ==================================================================== */

:root {
    /* === COLORES PRINCIPALES === */
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --accent: #7c3aed;
    --dark: #0f172a;

    /* === ESCALA DE GRISES === */
    --gray-900: #1e293b;
    --gray-700: #475569;
    --gray-500: #64748b;
    --gray-300: #cbd5e1;
    --gray-100: #f1f5f9;
    --gray-50: #f8fafc;
    --white: #ffffff;

    /* === ESTADOS === */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0ea5e9;

    /* === GRADIENTES === */
    --gradient-primary: linear-gradient(135deg, var(--primary), var(--accent));
    --gradient-dark: linear-gradient(135deg, var(--dark), #1e3a8a);

    /* === SOMBRAS === */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.06);
    --shadow-lg: 0 25px 50px -12px rgba(37, 99, 235, 0.25);

    /* === RADIOS === */
    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
    --radius-full: 999px;

    /* === TIPOGRAFIA === */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'Courier New', ui-monospace, monospace;

    /* === ESPACIADO === */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;

    /* === LAYOUT ADMIN === */
    --sidebar-width: 240px;
    --sidebar-width-collapsed: 64px;
    --topbar-height: 64px;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font-sans);
    color: var(--gray-900);
    background: var(--gray-50);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; transition: color .2s; }

/* ====================================================================
   BOTONES
   ==================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.4rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    transition: all .25s;
    white-space: nowrap;
    font-family: inherit;
}

.btn-sm { padding: 0.5rem 0.9rem; font-size: 0.82rem; }
.btn-lg { padding: 0.95rem 1.8rem; font-size: 1rem; }
.btn-block { width: 100%; }

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-md);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.btn-outline {
    background: white;
    color: var(--dark);
    border: 2px solid var(--gray-300);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

.btn-success { background: var(--success); color: white; }
.btn-danger  { background: var(--danger);  color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-ghost   { background: transparent; color: var(--gray-700); }
.btn-ghost:hover { background: var(--gray-100); }

/* ====================================================================
   CARDS
   ==================================================================== */
.card {
    background: white;
    border: 1px solid var(--gray-100);
    border-radius: var(--radius);
    padding: 1.5rem;
    transition: all .3s;
}

.card-hover:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: rgba(37, 99, 235, 0.2);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 1rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--gray-100);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--dark);
}

/* ====================================================================
   FORMULARIOS
   ==================================================================== */
.form-group { margin-bottom: 1rem; }

.form-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-control {
    width: 100%;
    padding: 0.7rem 0.9rem;
    border: 1.5px solid var(--gray-300);
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--dark);
    background: white;
    transition: all .2s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-control::placeholder { color: var(--gray-500); }

textarea.form-control { resize: vertical; min-height: 90px; }

.form-error { color: var(--danger); font-size: 0.8rem; margin-top: 0.25rem; }

/* ====================================================================
   TABLAS
   ==================================================================== */
.table-wrapper {
    background: white;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--gray-100);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th {
    text-align: left;
    padding: 0.85rem 1rem;
    background: var(--gray-50);
    color: var(--gray-500);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--gray-100);
}

.table td {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    color: var(--dark);
}

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

/* ====================================================================
   BADGES
   ==================================================================== */
.badge {
    display: inline-block;
    padding: 0.3rem 0.7rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-primary { background: rgba(37, 99, 235, 0.1);  color: var(--primary); }
.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.badge-danger  { background: rgba(239, 68, 68, 0.1);  color: var(--danger); }
.badge-info    { background: rgba(14, 165, 233, 0.1); color: var(--info); }

/* ====================================================================
   LAYOUT ADMIN (sidebar + topbar + main)
   ==================================================================== */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* --- SIDEBAR --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--dark);
    color: rgba(255,255,255,0.8);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    transition: width .3s;
    z-index: 100;
}

.sidebar-logo {
    padding: 1.2rem 1.3rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    color: white;
    font-weight: 800;
    font-size: 1.2rem;
    letter-spacing: -0.02em;
}

.sidebar-logo .logo-mark {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.7rem;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.sidebar-section-title {
    color: rgba(255,255,255,0.4);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 1rem 0.8rem 0.5rem;
    font-weight: 700;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    color: rgba(255,255,255,0.75);
    font-size: 0.9rem;
    font-weight: 500;
    transition: background .2s, color .2s;
    cursor: pointer;
}

.sidebar-item:hover {
    background: rgba(255,255,255,0.06);
    color: white;
}

.sidebar-item.active {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-md);
}

.sidebar-item .icon { font-size: 1.1rem; width: 20px; text-align: center; }

/* Acordeón en sidebar */
.sidebar-group { display: flex; flex-direction: column; }
.sidebar-group-toggle {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    color: rgba(255,255,255,0.75);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .2s, color .2s;
    background: none;
    border: none;
    text-align: left;
    width: 100%;
    font-family: inherit;
}
.sidebar-group-toggle:hover { background: rgba(255,255,255,0.06); color: white; }
.sidebar-group-toggle .arrow { margin-left: auto; transition: transform .25s; font-size: .75rem; opacity: .6; }
.sidebar-group.open .sidebar-group-toggle .arrow { transform: rotate(90deg); }
.sidebar-group.open .sidebar-group-toggle { background: rgba(255,255,255,0.04); color: white; }
.sidebar-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-left: 1.5rem;
    border-left: 2px solid rgba(255,255,255,0.08);
    padding-left: 0.5rem;
}
.sidebar-group.open .sidebar-submenu { max-height: 400px; padding-top: 0.3rem; padding-bottom: 0.3rem; }
.sidebar-submenu .sidebar-item { font-size: 0.83rem; padding: 0.45rem 0.7rem; }

/* Grid compacto de formularios */
.form-grid {
    display: grid;
    gap: 0.75rem 1rem;
    grid-template-columns: repeat(12, 1fr);
}
.form-cell { display: flex; flex-direction: column; }
.form-cell .form-label { margin-bottom: 0.25rem; }
.form-cell.col-2  { grid-column: span 2; }
.form-cell.col-3  { grid-column: span 3; }
.form-cell.col-4  { grid-column: span 4; }
.form-cell.col-5  { grid-column: span 5; }
.form-cell.col-6  { grid-column: span 6; }
.form-cell.col-8  { grid-column: span 8; }
.form-cell.col-12 { grid-column: span 12; }
.form-grid .form-control { padding: 0.5rem 0.7rem; font-size: .88rem; }
@media (max-width: 968px) {
    .form-cell.col-2,.form-cell.col-3,.form-cell.col-4,
    .form-cell.col-5,.form-cell.col-6,.form-cell.col-8 { grid-column: span 12; }
}

/* Encabezado de sección dentro de un form */
.form-section {
    grid-column: span 12;
    border-bottom: 1px solid var(--gray-100);
    padding: 0.5rem 0 0.4rem;
    margin: 0.5rem 0 0;
    color: var(--gray-500);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 700;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 0.7rem;
    font-size: 0.85rem;
}

.sidebar-footer .avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 700;
}

/* --- MAIN CONTENT --- */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--gray-50);
}

/* --- TOPBAR --- */
.topbar {
    height: var(--topbar-height);
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.topbar-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--dark);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.empresa-selector {
    background: var(--gray-100);
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    color: var(--gray-700);
    cursor: pointer;
    border: none;
    font-family: inherit;
}

.user-chip {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--gray-100);
    padding: 0.35rem 0.7rem 0.35rem 0.35rem;
    border-radius: var(--radius-full);
    font-size: 0.85rem;
    color: var(--gray-700);
}

.user-chip .avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--gradient-primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
}

/* --- CONTENT AREA --- */
.content {
    padding: 1.5rem;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--dark);
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--gray-500);
    font-size: 0.9rem;
    margin-top: 0.25rem;
}

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

.kpi-card {
    background: white;
    border: 1px solid var(--gray-100);
    border-radius: var(--radius);
    padding: 1.2rem;
    position: relative;
    overflow: hidden;
}

.kpi-card::before {
    content: "";
    position: absolute;
    top: 0; left: 0;
    width: 4px; height: 100%;
    background: var(--gradient-primary);
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.kpi-value {
    font-size: 1.7rem;
    font-weight: 800;
    color: var(--dark);
    letter-spacing: -0.02em;
}

.kpi-change {
    font-size: 0.8rem;
    margin-top: 0.4rem;
}
.kpi-change.up   { color: var(--success); }
.kpi-change.down { color: var(--danger); }

/* ====================================================================
   LOGIN
   ==================================================================== */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(circle at 20% 20%, rgba(124,58,237,0.08), transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(37,99,235,0.10), transparent 50%),
        var(--gray-50);
    padding: 2rem 1rem;
}

.login-card {
    background: white;
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: min(420px, 100%);
}

.login-logo {
    font-weight: 800;
    font-size: 1.6rem;
    text-align: center;
    margin-bottom: 0.3rem;
    letter-spacing: -0.02em;
}

.login-sub {
    color: var(--gray-500);
    font-size: 0.9rem;
    text-align: center;
    margin-bottom: 1.8rem;
}

/* ====================================================================
   UTILIDADES
   ==================================================================== */
.text-primary { color: var(--primary); }
.text-muted   { color: var(--gray-500); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-dark    { color: var(--dark); }

.text-center  { text-align: center; }
.text-right   { text-align: right; }

.gradient-text {
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

.flex   { display: flex; }
.flex-1 { flex: 1; }
.gap-1  { gap: 0.5rem; }
.gap-2  { gap: 1rem; }
.items-center  { align-items: center; }
.justify-between { justify-content: space-between; }

/* ====================================================================
   MODALES
   ==================================================================== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.55);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}
.modal-overlay.show { display: flex; }

.modal {
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.modal-header {
    padding: 1rem 1.2rem;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 700; color: var(--dark); }
.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--gray-500);
    line-height: 1;
    padding: 0 .3rem;
}
.modal-close:hover { color: var(--dark); }
.modal-body {
    padding: 1rem 1.2rem;
    overflow-y: auto;
    flex: 1;
}
.modal-input {
    width: 100%;
    padding: 0.7rem 1rem;
    border: 2px solid var(--gray-300);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    margin-bottom: 1rem;
}
.modal-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* Toggle Switch (iOS style) */
.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    cursor: pointer;
    user-select: none;
}
.toggle-switch input { display: none; }
.toggle-switch .toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--gray-300);
    border-radius: 999px;
    transition: background .25s;
    flex-shrink: 0;
}
.toggle-switch .toggle-slider::before {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 20px; height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform .25s, box-shadow .25s;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked ~ .toggle-slider {
    background: var(--gradient-primary);
}
.toggle-switch input:checked ~ .toggle-slider::before {
    transform: translateX(20px);
}
.toggle-switch .toggle-label {
    font-weight: 600;
    color: var(--gray-700);
    font-size: .9rem;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--dark);
    color: white;
    padding: 0.9rem 1.4rem;
    border-radius: 10px;
    box-shadow: var(--shadow-lg);
    font-weight: 500;
    z-index: 2000;
    transform: translateY(20px);
    opacity: 0;
    transition: transform .3s, opacity .3s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }

/* ====================================================================
   RESPONSIVE
   ==================================================================== */
@media (max-width: 968px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .3s;
    }
    .sidebar.open { transform: translateX(0); }
    .main-wrapper { margin-left: 0; }
    .topbar { padding: 0 1rem; }
    .content { padding: 1rem; }
}
