/* ═══════════════════════════════════════════════════════════════
   RESICO — Premium Design System v2
   ═══════════════════════════════════════════════════════════════ */

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

/* ── Design Tokens ── */
:root {
    --font:       'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --bg:         #f0f2f8;
    --bg-sidebar: #0f1629;
    --bg-card:    #ffffff;
    --text:       #1e293b;
    --text-muted: #64748b;
    --text-light: #94a3b8;
    --border:     #e2e8f0;
    --accent:     #6366f1;
    --accent-2:   #8b5cf6;
    --accent-glow: rgba(99, 102, 241, 0.25);
    --green:      #10b981;
    --green-bg:   #ecfdf5;
    --red:        #ef4444;
    --red-bg:     #fef2f2;
    --orange:     #f59e0b;
    --orange-bg:  #fffbeb;
    --blue:       #3b82f6;
    --blue-bg:    #eff6ff;
    --purple:     #8b5cf6;
    --purple-bg:  #f5f3ff;
    --radius:     14px;
    --radius-sm:  8px;
    --shadow:     0 1px 3px rgba(0,0,0,0.04), 0 4px 12px rgba(0,0,0,0.06);
    --shadow-lg:  0 4px 6px rgba(0,0,0,0.04), 0 10px 30px rgba(0,0,0,0.08);
    --shadow-xl:  0 10px 40px rgba(0,0,0,0.12);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ═══════════════════════════════════════════════════════════════
   LOGIN / REGISTRO
   ═══════════════════════════════════════════════════════════════ */

body.auth-page {
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 40%, #312e81 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    position: relative;
    overflow: hidden;
}

/* Animated background orbs */
body.auth-page::before,
body.auth-page::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 8s ease-in-out infinite;
}
body.auth-page::before {
    width: 400px; height: 400px;
    background: #6366f1;
    top: -100px; left: -100px;
}
body.auth-page::after {
    width: 350px; height: 350px;
    background: #8b5cf6;
    bottom: -80px; right: -80px;
    animation-delay: -4s;
    animation-direction: reverse;
}

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

.auth-container {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 24px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.35);
    width: 100%;
    max-width: 440px;
    padding: 48px 40px;
    position: relative;
    z-index: 1;
    border: 1px solid rgba(255, 255, 255, 0.2);
}
.auth-container.xl { max-width: 500px; }

.logo {
    text-align: center;
    margin-bottom: 32px;
}
.logo-icon {
    font-size: 56px;
    margin-bottom: 8px;
    display: block;
}
h1 {
    color: var(--text);
    font-size: 26px;
    font-weight: 800;
    text-align: center;
    margin-bottom: 6px;
    letter-spacing: -0.5px;
}
.subtitle {
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 36px;
    font-size: 14px;
    font-weight: 500;
}

/* ── Forms ── */
.form-group { margin-bottom: 22px; }

label {
    display: block;
    color: var(--text);
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 13px;
    letter-spacing: 0.02em;
}

input, select {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-family: var(--font);
    color: var(--text);
    background: #fff;
    transition: var(--transition);
}
input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

/* ── Buttons ── */
.btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: var(--transition);
    margin-top: 8px;
    display: inline-block;
    text-align: center;
    position: relative;
    overflow: hidden;
}
.btn::after {
    content: '';
    position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.15) 0%, transparent 50%);
    opacity: 0;
    transition: opacity 0.3s;
}
.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}
.btn:hover::after { opacity: 1; }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-sm { padding: 6px 14px; font-size: 12px; border-radius: 6px; font-weight: 600; }
.btn-primary { background: var(--blue); color: white; }
.btn-success { background: var(--green); color: white; }
.btn-danger  { background: var(--red); color: white; }
.btn-warning { background: var(--orange); color: white; }

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 14px;
    font-weight: 500;
    display: none;
}
.alert.error   { background: var(--red-bg); border: 1px solid #fecaca; color: var(--red); }
.alert.success { background: var(--green-bg); border: 1px solid #a7f3d0; color: var(--green); }

.links { text-align: center; margin-top: 28px; }
.links a {
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: color var(--transition);
}
.links a:hover { color: var(--accent-2); text-decoration: underline; }

.help-text { font-size: 12px; color: var(--text-light); margin-top: 5px; }

/* ── Spinner ── */
.loading { display: none; text-align: center; margin-top: 20px; }
.spinner {
    border: 3px solid #e2e8f0;
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    width: 36px; height: 36px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}
@keyframes spin {
    0%   { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ═══════════════════════════════════════════════════════════════
   DASHBOARD / APP LAYOUT
   ═══════════════════════════════════════════════════════════════ */

/* ── Navbar ── */
.navbar {
    background: var(--bg-sidebar);
    color: white;
    padding: 0 28px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
.navbar.admin-nav {
    background: linear-gradient(135deg, #dc2626 0%, #991b1b 100%);
}
.navbar-brand {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.navbar-user {
    display: flex;
    align-items: center;
    gap: 16px;
}
.user-info { text-align: right; }
.user-name { font-weight: 600; font-size: 13px; }
.user-rfc  { font-size: 11px; opacity: 0.6; font-family: 'Courier New', monospace; letter-spacing: 0.5px; }

.btn-logout {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.12);
    color: white;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 600;
    font-size: 13px;
    font-family: var(--font);
    transition: var(--transition);
}
.btn-logout:hover {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.25);
}

/* ── Layout ── */
.app-container {
    display: flex;
    min-height: calc(100vh - 64px);
}
.admin-container {
    max-width: 1400px;
    margin: 30px auto;
    padding: 0 20px;
}

/* ── Sidebar ── */
.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    padding: 20px 0;
    border-right: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.menu-item {
    padding: 12px 24px;
    cursor: pointer;
    transition: var(--transition);
    color: rgba(255, 255, 255, 0.45);
    font-weight: 500;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    margin: 2px 8px;
    border-radius: var(--radius-sm);
}
.menu-item span {
    font-size: 18px;
}
.menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.85);
}
.menu-item.active {
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(139, 92, 246, 0.15) 100%);
    color: #a5b4fc;
    border-right: none;
    font-weight: 600;
}
.menu-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 2px 2px 0;
    background: var(--accent);
}

/* ── Main Content ── */
.main-content {
    flex: 1;
    padding: 28px;
    overflow-y: auto;
    background: var(--bg);
}
.content-section, .tab-content { display: none; }
.content-section.active, .tab-content.active { display: block; }

/* ── Tabs (Admin) ── */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 30px;
    border-bottom: 2px solid var(--border);
}
.tab {
    padding: 12px 24px;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 14px;
    font-family: var(--font);
    transition: var(--transition);
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab:hover  { color: var(--accent); }

/* ═══════════════════════════════════════════════════════════════
   STAT CARDS — Glass Style
   ═══════════════════════════════════════════════════════════════ */

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 18px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
    transition: var(--transition);
    border: 1px solid var(--border);
}
.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    border-radius: var(--radius) var(--radius) 0 0;
}

.stat-card-green::before  { background: linear-gradient(90deg, #10b981, #34d399); }
.stat-card-red::before    { background: linear-gradient(90deg, #ef4444, #f87171); }
.stat-card-orange::before { background: linear-gradient(90deg, #f59e0b, #fbbf24); }
.stat-card-purple::before { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }

.stat-card-green  { border-top: none; }
.stat-card-red    { border-top: none; }
.stat-card-orange { border-top: none; }
.stat-card-purple { border-top: none; }

.stat-label {
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
.stat-value {
    font-size: 30px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
}

/* ═══════════════════════════════════════════════════════════════
   CARDS
   ═══════════════════════════════════════════════════════════════ */

.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    margin-bottom: 20px;
    border: 1px solid var(--border);
    transition: box-shadow var(--transition);
}
.card:hover { box-shadow: var(--shadow-lg); }

.card-title, .card-header .card-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 18px;
    letter-spacing: -0.3px;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

/* ═══════════════════════════════════════════════════════════════
   UPLOAD AREA
   ═══════════════════════════════════════════════════════════════ */

.upload-area {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 56px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: #f8fafc;
}
.upload-area:hover {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.04);
    transform: translateY(-2px);
}
.upload-icon { font-size: 44px; margin-bottom: 12px; }

/* ═══════════════════════════════════════════════════════════════
   TABLAS
   ═══════════════════════════════════════════════════════════════ */

table {
    width: 100%;
    border-collapse: collapse;
}
th {
    background: #f8fafc;
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    border-bottom: 2px solid var(--border);
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 14px;
    color: var(--text);
}
tr {
    transition: background var(--transition);
}
tr:hover { background: #f8fafc; }

/* ═══════════════════════════════════════════════════════════════
   BADGES
   ═══════════════════════════════════════════════════════════════ */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
}
.badge-success { background: var(--green-bg); color: var(--green); }
.badge-danger  { background: var(--red-bg); color: var(--red); }
.badge-warning { background: var(--orange-bg); color: var(--orange); }
.badge-info    { background: var(--blue-bg); color: var(--blue); }

/* ═══════════════════════════════════════════════════════════════
   MODALES
   ═══════════════════════════════════════════════════════════════ */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 22, 41, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal.active { display: flex; }
.modal-content {
    background: white;
    border-radius: var(--radius);
    padding: 28px;
    max-width: 500px;
    width: 90%;
    box-shadow: var(--shadow-xl);
}
.modal-header {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 18px;
    color: var(--text);
}

.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 20px;
}
.form-actions .btn { width: auto; margin-top: 0; }

.search-box {
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    width: 300px;
    font-family: var(--font);
    transition: var(--transition);
}
.search-box:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

/* ═══════════════════════════════════════════════════════════════
   RADIO BUTTONS
   ═══════════════════════════════════════════════════════════════ */

.radio-group {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
}
.radio-label {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px 16px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}
.radio-label:has(input:checked) {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.06);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

/* ═══════════════════════════════════════════════════════════════
   LOADING STATES
   ═══════════════════════════════════════════════════════════════ */

.loading-placeholder {
    color: var(--text-light);
    text-align: center;
    padding: 24px;
    font-style: italic;
    font-size: 14px;
}
.empty-msg {
    color: var(--text-light);
    padding: 16px 0;
    font-size: 14px;
}
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════════════
   VISOR XML
   ═══════════════════════════════════════════════════════════════ */

.filter-select {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    background: white;
    font-family: var(--font);
}

.visor-resumen { margin-bottom: 20px; }

.visor-stats {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 5px;
}
.visor-stat {
    background: var(--bg-card);
    padding: 14px 22px;
    border-radius: var(--radius);
    text-align: center;
    min-width: 100px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.visor-stat-emitida { border-left: 4px solid var(--blue); }
.visor-stat-recibida { border-left: 4px solid var(--orange); }
.visor-stat-num {
    display: block;
    font-size: 26px;
    font-weight: 800;
    color: var(--text);
    letter-spacing: -0.5px;
}
.visor-stat-lbl {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 600;
    margin-top: 2px;
}

.visor-table th, .visor-table td { white-space: nowrap; }

/* ═══════════════════════════════════════════════════════════════
   CALCULADORA
   ═══════════════════════════════════════════════════════════════ */

.calc-form {
    display: flex;
    align-items: flex-end;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.calc-form .form-group { margin-bottom: 0; }

.btn-calc {
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
    color: white;
    border: none;
    padding: 12px 26px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.btn-calc:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(99, 102, 241, 0.35);
}
.btn-calc:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.calc-loading {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
}

/* ── Result Box ── */
.result-box {
    background: linear-gradient(135deg, #f0fdf4 0%, #ecfdf5 100%);
    border: 1px solid #bbf7d0;
    border-radius: var(--radius);
    padding: 24px;
    margin-top: 20px;
}
.result-box h3 {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
    color: var(--text);
    text-align: left;
}

.result-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.result-card {
    background: white;
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.result-card-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 6px;
    font-weight: 700;
}
.result-card-value {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.3px;
}

.result-detail {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 14px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.result-detail h4 {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
}

.detail-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.detail-table th {
    background: #f8fafc;
    padding: 10px 12px;
    text-align: left;
    font-size: 11px;
}
.detail-table td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
}
.detail-table td:last-child {
    text-align: right;
    font-weight: 600;
}
.detail-table .total-row td {
    border-top: 2px solid var(--border);
    font-weight: 800;
    font-size: 15px;
    color: var(--green);
}

.result-error {
    background: var(--red-bg);
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 20px;
    margin-top: 15px;
    color: var(--red);
    font-weight: 500;
}

/* ═══════════════════════════════════════════════════════════════
   SCROLLBAR
   ═══════════════════════════════════════════════════════════════ */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { padding: 16px; }
    .navbar { padding: 0 16px; height: 56px; }
    .navbar-brand { font-size: 16px; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .stat-value { font-size: 24px; }
    .card { padding: 20px; }
}
