/* ================================================
   GESTORFACTURAS — Design System
   Tipografía: Inter (body) + JetBrains Mono (datos)
   Paleta: Slate oscuro + Azul índigo + Blanco roto
   ================================================ */

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

:root {
    --bg:          #0F1117;
    --bg-card:     #171B26;
    --bg-hover:    #1E2336;
    --border:      #252A3A;
    --border-light:#2E3448;

    --text-primary:   #E8EAF0;
    --text-secondary: #8892AA;
    --text-muted:     #545E78;

    --indigo:      #4F6FFF;
    --indigo-dim:  #1E2B5E;
    --indigo-glow: rgba(79,111,255,0.15);

    --green:       #22C55E;
    --green-dim:   #052E16;
    --yellow:      #EAB308;
    --yellow-dim:  #1C1600;
    --red:         #EF4444;
    --red-dim:     #1A0000;
    --orange:      #F97316;
    --orange-dim:  #1A0A00;
    --purple:      #A855F7;

    --radius-sm:   6px;
    --radius:      10px;
    --radius-lg:   16px;

    --shadow:      0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-lg:   0 10px 40px rgba(0,0,0,0.5);

    --sidebar-w:   240px;
    --topbar-h:    60px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    font-family: 'Inter', sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

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

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand .brand-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

.sidebar-brand .brand-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    font-family: 'JetBrains Mono', monospace;
}

.sidebar-nav {
    padding: 12px 0;
    flex: 1;
}

.nav-section-label {
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 12px 20px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 20px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 450;
    border-left: 2px solid transparent;
    transition: all 0.15s ease;
    cursor: pointer;
}

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

.nav-item.active {
    color: var(--indigo);
    background: var(--indigo-glow);
    border-left-color: var(--indigo);
    font-weight: 500;
}

.nav-item svg { flex-shrink: 0; opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
}

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

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--indigo-dim);
    border: 1px solid var(--indigo);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--indigo);
    flex-shrink: 0;
}

.user-info .user-name {
    font-size: 12.5px;
    font-weight: 500;
    color: var(--text-primary);
}

.user-info .user-role {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: capitalize;
}

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

.topbar {
    height: var(--topbar-h);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    background: var(--bg-card);
    flex-shrink: 0;
}

.topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

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

.page-content {
    flex: 1;
    overflow-y: auto;
    padding: 28px;
}

/* ── Cards ── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

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

.card-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

/* ── Stat cards ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
}

.stat-card.blue::before  { background: var(--indigo); }
.stat-card.green::before { background: var(--green); }
.stat-card.yellow::before{ background: var(--yellow); }
.stat-card.red::before   { background: var(--red); }

.stat-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: -1px;
    line-height: 1;
}

.stat-value.money::before { content: '$'; font-size: 14px; color: var(--text-muted); vertical-align: super; margin-right: 2px; }

.stat-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.15s ease;
    font-family: 'Inter', sans-serif;
    white-space: nowrap;
}

.btn-primary {
    background: var(--indigo);
    color: #fff;
}
.btn-primary:hover { background: #3D5AE0; }

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
}
.btn-secondary:hover { color: var(--text-primary); border-color: var(--text-muted); }

.btn-danger {
    background: var(--red-dim);
    color: var(--red);
    border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-sm { padding: 5px 11px; font-size: 12px; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ── Tabla ── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

thead th {
    text-align: left;
    padding: 10px 14px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

tbody td {
    padding: 12px 14px;
    color: var(--text-primary);
    vertical-align: middle;
}

.td-mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-secondary);
}

.td-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ── Badge estatus ── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
}

.badge::before {
    content: '';
    width: 5px; height: 5px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.badge-green  { background: var(--green-dim);  color: var(--green); }
.badge-yellow { background: var(--yellow-dim); color: var(--yellow); }
.badge-red    { background: var(--red-dim);    color: var(--red); }
.badge-blue   { background: var(--indigo-dim); color: var(--indigo); }
.badge-orange { background: var(--orange-dim); color: var(--orange); }
.badge-gray   { background: var(--bg-hover);   color: var(--text-secondary); }
.badge-purple { background: #2D1052;           color: var(--purple); }

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

label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input, select, textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    padding: 9px 12px;
    color: var(--text-primary);
    font-size: 13.5px;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.15s;
    outline: none;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--indigo);
    box-shadow: 0 0 0 3px var(--indigo-glow);
}

input::placeholder { color: var(--text-muted); }
select option { background: var(--bg-card); }
textarea { resize: vertical; min-height: 80px; }

.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* ── Search bar ── */
.search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.search-input-wrap {
    position: relative;
    flex: 1;
    min-width: 240px;
}

.search-input-wrap svg {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.search-input-wrap input {
    padding-left: 38px;
}

.filter-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: center;
}

.filter-row select { width: auto; min-width: 140px; }

/* ── Modal ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 680px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.modal-title { font-size: 15px; font-weight: 600; }

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success { background: var(--green-dim); color: var(--green); border: 1px solid rgba(34,197,94,0.2); }
.alert-error   { background: var(--red-dim);   color: var(--red);   border: 1px solid rgba(239,68,68,0.2); }
.alert-warning { background: var(--yellow-dim);color: var(--yellow);border: 1px solid rgba(234,179,8,0.2); }
.alert-info    { background: var(--indigo-dim);color: var(--indigo);border: 1px solid rgba(79,111,255,0.2); }

/* ── Login page ── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    background-image: radial-gradient(ellipse at 30% 20%, rgba(79,111,255,0.06) 0%, transparent 60%);
}

.login-box {
    width: 100%;
    max-width: 380px;
    padding: 20px;
}

.login-brand {
    text-align: center;
    margin-bottom: 36px;
}

.login-brand-icon {
    width: 48px;
    height: 48px;
    background: var(--indigo-dim);
    border: 1px solid var(--indigo);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 14px;
}

.login-brand h1 { font-size: 20px; font-weight: 700; }
.login-brand p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    box-shadow: var(--shadow-lg);
}

/* ── Drop zone ── */
.dropzone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius);
    padding: 36px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-muted);
}

.dropzone:hover, .dropzone.drag-over {
    border-color: var(--indigo);
    background: var(--indigo-glow);
    color: var(--indigo);
}

.dropzone svg { margin-bottom: 10px; }
.dropzone p { font-size: 13px; margin-top: 6px; }
.dropzone span { font-size: 11px; opacity: 0.7; }

/* ── Tree de carpetas ── */
.folder-tree { font-size: 13px; }

.tree-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.1s;
    user-select: none;
}

.tree-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.tree-item.selected { background: var(--indigo-glow); color: var(--indigo); }

.tree-children { padding-left: 18px; border-left: 1px solid var(--border); margin-left: 14px; }

/* ── Divider ── */
.divider {
    border: none;
    border-top: 1px solid var(--border);
    margin: 20px 0;
}

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.empty-state svg { margin-bottom: 14px; opacity: 0.4; }
.empty-state h3 { font-size: 15px; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; }

/* ── Tabs ── */
.tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 24px;
}

.tab {
    padding: 10px 18px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s;
}

.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--indigo); border-bottom-color: var(--indigo); }

/* ── Conciliación ── */
.concil-row-ok     { background: rgba(34,197,94,0.04); }
.concil-row-falta  { background: rgba(239,68,68,0.04); }
.concil-row-extra  { background: rgba(234,179,8,0.04); }

/* ── Responsive ── */
@media (max-width: 1024px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar { display: none; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .page-content { padding: 16px; }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Toast ── */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 260px;
    animation: slideIn 0.2s ease;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0);    opacity: 1; }
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--indigo); }
