/* Variables de tema */
:root {
    --bg: #f4f5f7;
    --bg-card: #fff;
    --bg-input: #fff;
    --bg-hover: #f0f0f0;
    --color-primary: #185FA5;
    --color-danger: #A32D2D;
    --color-warning: #854F0B;
    --color-success: #3B6D11;
    --text: #1a1a1a;
    --text-muted: #777;
    --text-label: #444;
    --text-secondary: #555;
    --border: #e0e0e0;
    --border-input: #ddd;
    --border-table: #f0f0f0;
    --border-th: #eee;
    --navbar-bg: #fff;
    --footer-bg: #0a1628;
    --badge-gray-bg: #f0f0f0;
    --badge-gray-color: #555;
    --shadow: rgba(0,0,0,0.08);
    --drop-bg: #f0f6ff;
}

body.dark {
    --bg: #111827;
    --bg-card: #1f2937;
    --bg-input: #374151;
    --bg-hover: #374151;
    --color-primary: #5B9FD4;
    --color-danger: #E06060;
    --color-warning: #D48C3A;
    --color-success: #6AAF2E;
    --text: #f9fafb;
    --text-muted: #9ca3af;
    --text-label: #d1d5db;
    --text-secondary: #d1d5db;
    --border: #374151;
    --border-input: #4b5563;
    --border-table: #374151;
    --border-th: #374151;
    --navbar-bg: #1f2937;
    --footer-bg: #0a1628;
    --badge-gray-bg: #374151;
    --badge-gray-color: #d1d5db;
    --shadow: rgba(0,0,0,0.3);
    --drop-bg: #374151;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; min-height: 100vh; display: flex; flex-direction: column; transition: background 0.2s, color 0.2s; }

/* Login */
.login-page { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 8vh; flex: 1; }
.login-box { background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 2rem 2.5rem; width: 100%; max-width: 360px; }
.login-box h1 { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 1.5rem; }
button[type=submit] { width: 100%; padding: 9px; background: #185FA5; color: #fff; border: none; border-radius: 6px; font-size: 14px; cursor: pointer; margin-top: 0.5rem; }
button[type=submit]:hover { background: #0C447C; }
.alert { background: #FCEBEB; color: #A32D2D; border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 1rem; }

/* Navbar */
.navbar { background: var(--navbar-bg); border-bottom: 1px solid var(--border); padding: 0 2rem; height: 52px; display: flex; align-items: center; gap: 1rem; position: sticky; top: 0; z-index: 100; }
.nav-brand { text-decoration: none; white-space: nowrap; }
.nav-links { display: flex; gap: 4px; flex: 1; margin-left: 1.5rem; justify-content: center; }
.nav-link { font-size: 12px; color: var(--text-secondary); text-decoration: none; padding: 4px 7px; border-radius: 5px; text-align: center; align-content: center; }
.nav-link:hover { background: var(--bg-hover); color: var(--text); }
.nav-link.active { color: var(--color-primary); font-weight: 500; }
.nav-link-admin { color: var(--color-warning); }
.nav-user { font-size: 13px; color: var(--text-secondary); text-decoration: none; }
.nav-logout { font-size: 13px; color: var(--color-primary); text-decoration: none; }
.nav-logout:hover { text-decoration: underline; }

/* Botón modo oscuro */
.btn-dark-mode { background: none; border: none; cursor: pointer; font-size: 18px; padding: 4px 6px; border-radius: 5px; color: var(--text-secondary); flex-shrink: 0; }
.btn-dark-mode:hover { background: var(--bg-hover); }

/* Boton hamburguesa - oculto en PC */
.nav-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-secondary); padding: 4px 8px; }

/* Responsive navbar */
@media (max-width: 768px) {
    .navbar { height: auto; padding: 0 1rem; position: relative; z-index: 100; justify-content: space-between; }
    .nav-brand { padding: 12px 0; }
    .nav-toggle { display: block; padding: 12px 0; line-height: 1; }
    .nav-links {
        display: none !important;
        flex-direction: column;
        gap: 2px;
        padding: 8px 0 12px;
        border-top: 1px solid var(--border);
        background: var(--navbar-bg);
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        width: 100%;
        box-shadow: 0 4px 8px var(--shadow);
        z-index: 200;
    }
    .nav-links.open { display: flex !important; }
    .nav-link { padding: 8px 16px; border-radius: 0; white-space: nowrap; text-align: left !important; }
    .nav-user { display: none; }
    .nav-logout { padding: 8px 16px; }
    .btn-dark-mode { padding: 12px 4px; }
}

/* Tablas responsive */
@media (max-width: 768px) {
    .container { padding: 0 1rem; margin: 1rem auto; }
    .card { padding: 1rem; }
    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .modules-grid { grid-template-columns: 1fr; }
    .stats-row { grid-template-columns: 1fr 1fr; }
}

/* Contenido */
.container { max-width: 900px; margin: 2rem auto; padding: 0 1.5rem; flex: 1; width: 100%; }
.container-narrow { max-width: 680px; }
.container h2 { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.muted { color: var(--text-muted); font-size: 13px; }
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: 8px; padding: 1.25rem 1.5rem; }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-muted); padding: 6px 10px; border-bottom: 1px solid var(--border-th); }
td { padding: 8px 10px; border-bottom: 1px solid var(--border-table); }
tr:last-child td { border-bottom: none; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: 13px; color: var(--text-label); margin-bottom: 4px; }
.field input { width: 100%; padding: 8px 10px; border: 1px solid var(--border-input); border-radius: 6px; font-size: 14px; background: var(--bg-input); color: var(--text); }
.field input:focus { outline: none; border-color: #185FA5; }

/* Tabla Control Planillas */
.fila-encontrada { background: #EAF3DE; }
body.dark .fila-encontrada { background: #1a2e1a; }

/* Badges */
.badge { font-size: 11px; padding: 2px 8px; border-radius: 99px; font-weight: 500; white-space: nowrap; display: inline-block; }
.badge-blue { background: #E6F1FB; color: #185FA5; }
.badge-green { background: #EAF3DE; color: #3B6D11; }
.badge-red { background: #FCEBEB; color: #A32D2D; }
.badge-gray { background: var(--badge-gray-bg); color: var(--badge-gray-color); white-space: nowrap; }

/* Botones y links */
.btn-link { background: #185FA5; color: #fff; padding: 7px 14px; border-radius: 6px; text-decoration: none; font-size: 13px; }
.btn-link:hover { background: #0C447C; }
.btn-secondary { display: inline-block; padding: 8px 14px; border: 1px solid var(--border-input); border-radius: 6px; font-size: 14px; color: var(--text); text-decoration: none; background: var(--bg-card); }
.btn-secondary:hover { background: var(--bg-hover); }
.link-action { color: var(--color-primary); font-size: 13px; text-decoration: none; }
.link-action:hover { text-decoration: underline; }
.alert-ok { background: #EAF3DE; color: #3B6D11; border-radius: 6px; padding: 8px 12px; font-size: 13px; margin-bottom: 1rem; }

/* Formularios */
.field-check { display: flex; align-items: center; gap: 8px; margin-bottom: 1rem; }
.field-check input { width: auto; }
.field-check label { font-size: 14px; color: var(--text); margin: 0; }

/* Módulo PDF */
.drop-zone { border: 2px dashed var(--border-input); border-radius: 8px; padding: 2rem 1rem; text-align: center; cursor: pointer; transition: border-color 0.2s; }
.drop-zone:hover, .drop-zone.drag-over { border-color: #185FA5; background:var(--drop-bg); }
.drop-icon { font-size: 2rem; margin-bottom: .5rem; }
.drop-text { font-size: 14px; color: var(--text); margin-bottom: 4px; }
.drop-sub { font-size: 12px; color: var(--text-muted); }
.file-item { font-size: 13px; padding: 5px 0; color: var(--text); border-bottom: 1px solid var(--border-table); display: flex; justify-content: space-between; }
.file-size { color: var(--text-muted); }

/* Grilla de módulos */
.modules-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; }
.module-card { display: flex; align-items: center; gap: 14px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.25rem; text-decoration: none; color: var(--text); transition: border-color 0.15s, box-shadow 0.15s; }
.module-card:hover { border-color: #185FA5; box-shadow: 0 2px 8px var(--shadow); }
.module-card-admin { border-color: #FAC775; }
.module-card-admin:hover { border-color: #854F0B; }
.module-icon { font-size: 1.75rem; flex-shrink: 0; }
.module-info { flex: 1; }
.module-name { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.module-desc { font-size: 12px; color: var(--text-muted); }
.module-perms { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }

/* Footer */
footer.footer { margin-top: 4rem; }
.footer-skyline { width: 100%; display: block; max-height: 120px; object-fit: cover; object-position: bottom; }
.footer-bottom { background: var(--footer-bg); display: flex; align-items: center; justify-content: center; gap: 1.5rem; padding: 1rem 2rem; }
.footer-logo { height: 52px; width: auto; filter: brightness(0) invert(1); }
.footer-info { display: flex; flex-direction: column; gap: 2px; }
.footer-org { color: #fff; font-size: 13px; font-weight: 500; }
.footer-links a { color: #aac4e8; font-size: 12px; text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }

/* Corrección bordes login */
.login-page footer.footer { margin: 0; width: 100%; }
.login-page .footer-skyline { width: 100%; display: block; }
.login-page .footer-bottom { margin: 0; }
.login-page { margin-bottom: 0; padding-bottom: 0; }
html { margin: 0; padding: 0; }

/* Inputs y selects en modo oscuro */
body.dark input, body.dark select, body.dark textarea {
    background: var(--bg-input);
    color: var(--text);
    border-color: var(--border-input);
}
body.dark input::placeholder, body.dark textarea::placeholder {
    color: var(--text-muted);
}

.nav-mobile-only { display: none; }

@media (max-width: 768px) {
    .nav-desktop-only { display: none !important; }
    .nav-mobile-only { display: block; }
}

.tab-btn {
    padding: 8px 16px;
    border: none;
    border-bottom: 3px solid transparent;
    background: none;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: -2px;
    border-radius: 6px 6px 0 0;
    transition: color 0.15s;
    white-space: nowrap;
}
.tab-btn:hover { color: #185FA5; background: var(--bg-hover); }
.tab-btn.active { color: #185FA5; font-weight: 600; border-bottom: 3px solid #185FA5; background: var(--bg-card); }

@media (max-width: 768px) {
    .tab-label { display: none; }
    .tab-btn { padding: 8px 10px; font-size: 16px; }
}