/* ─── Variables ─── */
:root {
    --primary: #1e3a8a;
    --primary-dark: #1e2f6e;
    --primary-light: #3b5bd6;
    --accent: #d97706;
    --bg: #f6f8fb;
    --bg-card: #ffffff;
    --text: #111827;
    --text-muted: #6b7280;
    --border: #e5e7eb;
    --success: #059669;
    --error: #dc2626;
    --warning: #d97706;
    --shadow: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.08), 0 4px 10px rgba(0,0,0,0.04);
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

h1 { font-size: 26px; font-weight: 600; margin-bottom: 4px; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; color: var(--primary); margin-bottom: 12px; text-transform: uppercase; letter-spacing: 0.5px; }

.muted { color: var(--text-muted); font-size: 13px; }
.hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

/* ─── Topbar ─── */
.topbar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 60px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 100;
}
.brand a { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand .logo { font-size: 24px; }
.brand .brand-name { font-weight: 600; font-size: 16px; }
.nav-main { display: flex; gap: 4px; margin-left: 40px; flex: 1; }
.nav-item {
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 6px;
    font-weight: 500;
    transition: all 0.15s;
}
.nav-item:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--primary); color: white; }
.user-menu { display: flex; align-items: center; gap: 16px; color: var(--text-muted); }
.user-name { font-weight: 500; }

/* ─── Main ─── */
.main-container {
    max-width: 1280px;
    width: 100%;
    margin: 0 auto;
    padding: 28px 24px;
    flex: 1;
}

.footer {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}

/* ─── Page header ─── */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
    gap: 16px;
}

/* ─── Cards ─── */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.card-body { padding: 20px; }

/* ─── Stats ─── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    transition: all 0.15s;
    color: var(--text);
    text-decoration: none;
    display: block;
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); text-decoration: none; }
.stat-icon { font-size: 28px; margin-bottom: 8px; }
.stat-value { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

.dashboard-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
}
@media (max-width: 800px) { .dashboard-row { grid-template-columns: 1fr; } }

/* ─── Buttons ─── */
.btn {
    display: inline-block;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    text-align: center;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: white; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: var(--error); color: white; }
.btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { display: block; width: 100%; }
.btn-text { color: var(--text-muted); font-size: 13px; }
.btn-text:hover { color: var(--text); }

/* ─── Tables ─── */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.table th {
    background: var(--bg);
    font-size: 12px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.5px;
}
.table tbody tr:last-child td { border-bottom: none; }
.table-hover tbody tr.clickable { cursor: pointer; transition: background 0.15s; }
.table-hover tbody tr.clickable:hover { background: var(--bg); }

/* ─── Badges ─── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: var(--bg);
    color: var(--text-muted);
}
.badge-en-proceso { background: #dbeafe; color: #1e40af; }
.badge-listo-para-presentar { background: #fef3c7; color: #92400e; }
.badge-presentado { background: #e0e7ff; color: #3730a3; }
.badge-en-revisión, .badge-en-revision { background: #fce7f3; color: #9f1239; }
.badge-observado { background: #ffedd5; color: #9a3412; }
.badge-aprobado { background: #d1fae5; color: #065f46; }
.badge-rechazado { background: #fee2e2; color: #991b1b; }

/* ─── Forms ─── */
.form-grid { display: flex; flex-direction: column; gap: 16px; }
.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 12px;
}
.form-row:last-child { margin-bottom: 0; }
.form-group { display: flex; flex-direction: column; }
.form-group label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.form-group input, .form-group select, .form-group textarea {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
    background: white;
    transition: all 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30,58,138,0.1);
}
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 8px;
}

/* ─── Filter bar ─── */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
}
.filter-search {
    flex: 1;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
}
.filter-select {
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: white;
}

/* ─── Alerts ─── */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
    border-left: 4px solid;
}
.alert-success { background: #d1fae5; color: #065f46; border-color: var(--success); }
.alert-error { background: #fee2e2; color: #991b1b; border-color: var(--error); }
.alert-warning { background: #fef3c7; color: #92400e; border-color: var(--warning); }

/* ─── Empty state ─── */
.empty-state {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
}
.empty-state-card {
    background: var(--bg-card);
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 60px 20px;
    text-align: center;
}
.empty-icon { font-size: 56px; margin-bottom: 16px; opacity: 0.5; }
.empty-state-card h2 { margin-bottom: 8px; }
.empty-state-card p { color: var(--text-muted); margin-bottom: 20px; }

/* ─── Status list ─── */
.status-list { list-style: none; }
.status-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.status-list li:last-child { border-bottom: none; }
.status-list .count { font-weight: 600; color: var(--text); }

/* ─── Botones especiales ─── */
.btn-cargar { background: #d97706; color: white; }
.btn-cargar:hover { background: #b45309; }
.btn-violet { background: #6a1b9a; color: white; }
.btn-violet:hover { background: #4a148c; }

.action-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.tab-secondary {
    margin-left: auto;
    color: var(--text-muted) !important;
    font-size: 13px;
}

/* ─── Documentos generables (Generar tab) ─── */
.docs-grid {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.docs-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}
.doc-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--bg-card);
}
.doc-item:hover {
    border-color: var(--primary);
    background: rgba(30, 58, 138, 0.02);
}
.doc-checkbox {
    margin-top: 2px;
    cursor: pointer;
    accent-color: var(--primary);
}
.doc-info { flex: 1; }
.doc-name { font-weight: 500; color: var(--text); font-size: 13px; }
.doc-desc { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.format-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 2px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
    background: white;
    font-weight: 500;
}
.format-option:hover { border-color: var(--primary); }
.format-option input[type="checkbox"] {
    accent-color: var(--primary);
    cursor: pointer;
    width: 16px;
    height: 16px;
}
.format-option input[type="checkbox"]:checked + span { color: var(--primary); }
.format-option:has(input:checked) {
    border-color: var(--primary);
    background: rgba(30, 58, 138, 0.05);
}

.btn-generar-grande {
    padding: 14px 32px;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: var(--error);
}
.btn-generar-grande:hover { background: #b91c1c; }

/* ─── Tabs ─── */
.tabs {
    display: flex;
    gap: 4px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.tab {
    padding: 10px 16px;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    white-space: nowrap;
    transition: all 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.tab:hover {
    color: var(--text);
    text-decoration: none;
    background: var(--bg);
}
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}
.tab-count {
    display: inline-block;
    background: var(--primary);
    color: white;
    font-size: 11px;
    padding: 1px 7px;
    border-radius: 10px;
    font-weight: 600;
    margin-left: 4px;
}
.tab-content { animation: fadeIn 0.2s; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

/* ─── Dropzone ─── */
.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    padding: 40px 20px;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
}
.dropzone:hover, .dropzone.dragover {
    border-color: var(--primary);
    background: rgba(30, 58, 138, 0.04);
}
.dropzone-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }
.dropzone-content h3 { margin-bottom: 8px; color: var(--text); }
.dropzone-content p { color: var(--text-muted); margin: 4px 0; }
.dropzone-content .btn { margin-top: 16px; }
.dropzone-files {
    margin-top: 16px;
    text-align: left;
    border-top: 1px solid var(--border);
    padding-top: 16px;
}
.dropzone-files:empty { display: none; }
.dropzone-file {
    padding: 8px 12px;
    background: var(--bg);
    border-radius: 4px;
    margin-bottom: 4px;
    display: flex;
    justify-content: space-between;
}
.file-icon { margin-right: 8px; }

/* ─── Modal ─── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: white;
    border-radius: 12px;
    padding: 32px;
    width: 90%;
    max-width: 540px;
    box-shadow: var(--shadow-lg);
}
.modal-content h2 { margin-bottom: 12px; }
.modal-content p { color: var(--text-muted); margin-bottom: 16px; }
.modal-content #modal-status { margin: 16px 0; }

/* ─── Drag overlay ─── */
.drag-overlay {
    position: fixed;
    inset: 0;
    background: rgba(30, 58, 138, 0.85);
    z-index: 300;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    backdrop-filter: blur(4px);
}
.drag-overlay.active { display: flex; }
.drag-overlay-content {
    background: white;
    border: 4px dashed var(--primary);
    border-radius: 16px;
    padding: 60px 80px;
    text-align: center;
    pointer-events: none;
}
.drag-icon { font-size: 80px; margin-bottom: 16px; }
.drag-overlay h2 { color: var(--primary); margin-bottom: 8px; }
.drag-overlay p { color: var(--text-muted); }

/* ─── Grid de tipos de documento ─── */
.tipo-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin: 16px 0;
}
@media (max-width: 540px) {
    .tipo-grid { grid-template-columns: repeat(2, 1fr); }
}
.tipo-card {
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 16px 8px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
    font-family: inherit;
}
.tipo-card:hover {
    border-color: var(--primary);
    background: rgba(30, 58, 138, 0.04);
    transform: translateY(-2px);
}
.tipo-icon { font-size: 32px; margin-bottom: 4px; }
.tipo-label { font-weight: 600; color: var(--text); font-size: 13px; }
.tipo-hint { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* ─── Login page ─── */
.login-page {
    min-height: calc(100vh - 80px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}
.login-header { text-align: center; margin-bottom: 32px; }
.login-logo { font-size: 56px; margin-bottom: 12px; }
.login-header h1 { font-size: 22px; margin-bottom: 4px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }

/* ─── Error page ─── */
.error-page {
    text-align: center;
    padding: 80px 20px;
}
.error-code {
    font-size: 96px;
    font-weight: 800;
    color: var(--primary);
    line-height: 1;
    opacity: 0.3;
}
.error-page h1 { margin: 16px 0 8px; }
.error-page p { margin-bottom: 24px; }

/* ─── Responsive ─── */
@media (max-width: 640px) {
    .topbar { padding: 0 12px; height: auto; flex-wrap: wrap; gap: 12px; padding: 12px; }
    .nav-main { margin-left: 0; width: 100%; overflow-x: auto; }
    .main-container { padding: 16px 12px; }
    .page-header { flex-direction: column; align-items: stretch; }
    .form-row { grid-template-columns: 1fr; }
}
