/* === Sistema de Cobranza Escolar === */

/* Tipografía institucional auto-alojada (funciona sin internet) */
@font-face {
    font-family: 'Source Sans 3';
    font-style: normal; font-weight: 400; font-display: swap;
    src: url("../fonts/source-sans-3-400.27ab01c4cb50.woff2") format('woff2');
}
@font-face {
    font-family: 'Source Sans 3';
    font-style: normal; font-weight: 600; font-display: swap;
    src: url("../fonts/source-sans-3-600.9a35cba76eda.woff2") format('woff2');
}
@font-face {
    font-family: 'Source Sans 3';
    font-style: normal; font-weight: 700; font-display: swap;
    src: url("../fonts/source-sans-3-700.9b13bd3653e3.woff2") format('woff2');
}

:root {
    --primary: #7B2433;          /* vinotinto institucional */
    --primary-light: #9E3144;    /* vinotinto claro */
    --primary-dark: #5A1822;     /* vinotinto oscuro */
    --secondary: #6C757D;        /* gris institucional */
    --secondary-dark: #4A5258;   /* gris oscuro */
    --danger: #C0392B;
    --warning: #E67E22;
    --success: #2E8B57;
    --gold: #C9A227;             /* dorado (reconocimientos) */
    --dark: #16243D;             /* azul marino (reemplaza el negro) */
    --light: #f0f2f5;
    --bg: #f4f5f7;
    --white: #ffffff;
    --text: #16243D;             /* azul marino intenso, NO negro */
    --text-light: #5a6678;       /* azul marino suave */
    --border: #d9dee5;
    --shadow: 0 2px 12px rgba(90,24,34,0.09);
    --radius: 12px;
}

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

html { font-size: 17px; }   /* base un poco más grande, mejor lectura */

body {
    font-family: 'Source Sans 3', 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Layout */
.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    background: linear-gradient(160deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-header h2 { font-size: 1.1rem; font-weight: 600; }
.sidebar-header small { color: rgba(255,255,255,0.5); font-size: 0.75rem; }

.sidebar-nav { padding: 10px 0; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 20px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
}
.sidebar-nav a:hover, .sidebar-nav a.active {
    background: rgba(255,255,255,0.1);
    color: var(--white);
}
.sidebar-nav a .icon { font-size: 1.2rem; width: 24px; text-align: center; }
.sidebar-divider {
    border-top: 1px solid rgba(255,255,255,0.1);
    margin: 8px 20px;
}

/* Submenús plegables */
.nav-group-toggle {
    display: flex; align-items: center; gap: 12px; width: 100%;
    padding: 12px 20px;
    background: none; border: none; cursor: pointer;
    color: rgba(255,255,255,0.7);
    font-size: 0.9rem; font-weight: 600; font-family: inherit;
    text-align: left; transition: all 0.2s;
}
.nav-group-toggle:hover { background: rgba(255,255,255,0.1); color: var(--white); }
.nav-group-toggle .icon { font-size: 1.2rem; width: 24px; text-align: center; }
.nav-group-toggle .chev { margin-left: auto; font-size: 0.68rem; transition: transform 0.25s; opacity: 0.75; }
.nav-group.open > .nav-group-toggle { color: var(--white); }
.nav-group.open > .nav-group-toggle .chev { transform: rotate(180deg); }
.nav-group-items {
    max-height: 0; overflow: hidden;
    transition: max-height 0.28s ease;
    background: rgba(0,0,0,0.13);
}
.nav-group.open > .nav-group-items { max-height: 440px; }
.nav-group-items a { padding-left: 46px; font-size: 0.86rem; }
.nav-group-items a.active { border-left: 3px solid var(--white); background: rgba(255,255,255,0.12); }

.main-content {
    flex: 1;
    margin-left: 260px;
    padding: 0;
}

/* Top bar */
.topbar {
    background: var(--white);
    padding: 15px 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 1.3rem; color: var(--dark); }
.topbar-right { display: flex; align-items: center; gap: 15px; }
.topbar-right .user-info { font-size: 0.85rem; color: var(--text-light); }

.page-content { padding: 25px 30px; }

/* Cards */
.card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid #edf0f3;
    padding: 22px 24px;
    margin-bottom: 22px;
}
.card-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 16px;
    padding-bottom: 13px;
    border-bottom: 2px solid var(--border);
}
.card-header h3 { font-size: 1.08rem; font-weight: 700; color: var(--dark); letter-spacing: -0.01em; }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 25px;
}
.stat-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 15px;
}
.stat-icon {
    width: 50px; height: 50px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem;
}
.stat-icon.blue { background: #e8f4fd; }
.stat-icon.green { background: #e8f8f0; }
.stat-icon.orange { background: #fef5e7; }
.stat-icon.red { background: #fdedec; }
.stat-info h4 { font-size: 1.4rem; color: var(--dark); font-weight: 700; }
.stat-info p { font-size: 0.8rem; color: var(--text-light); }

/* Tables */
.table-responsive { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.88rem;
}
th {
    background: var(--bg);
    font-weight: 600;
    color: var(--dark);
    white-space: nowrap;
}
tr:hover { background: #fafbfc; }

/* Status badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-success { background: #d4edda; color: #155724; }
.badge-warning { background: #fff3cd; color: #856404; }
.badge-danger { background: #f8d7da; color: #721c24; }
.badge-info { background: #d1ecf1; color: #0c5460; }
.badge-secondary { background: #e2e3e5; color: #383d41; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--dark);
}
.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(41,128,185,0.15);
}
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 80px; resize: vertical; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 18px;
    border: none; border-radius: 8px;
    font-size: 0.88rem; font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:hover { filter: brightness(1.06); box-shadow: 0 3px 8px rgba(0,0,0,0.14); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--white); }
.btn-success { background: var(--success); color: var(--white); }
.btn-danger  { background: var(--danger); color: var(--white); }
.btn-green   { background: #1c7a45; color: var(--white); }
.btn-gold    { background: var(--gold); color: var(--white); }
.btn-amber   { background: #8a6d00; color: var(--white); }
.btn-vino2   { background: var(--primary-dark); color: var(--white); }
.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg); filter: none; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; border-radius: 7px; }

/* Botón "Volver": bien visible (color y tamaño), no se pierde en la pantalla */
.btn-volver {
    background: var(--primary);
    color: var(--white);
    padding: 9px 20px;
    font-size: 0.9rem;
    box-shadow: 0 2px 5px rgba(0,0,0,0.18);
}
.btn-volver:hover { background: var(--primary-light); }

/* Alerts */
.alert {
    padding: 12px 18px;
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 0.88rem;
}
.alert-success { background: #d4edda; color: #155724; border-left: 4px solid var(--secondary); }
.alert-danger { background: #f8d7da; color: #721c24; border-left: 4px solid var(--danger); }
.alert-warning { background: #fff3cd; color: #856404; border-left: 4px solid var(--warning); }
.alert-info { background: #d1ecf1; color: #0c5460; border-left: 4px solid #17a2b8; }

/* Report cards */
.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 15px;
}
.report-card {
    background: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex; align-items: center; gap: 15px;
    text-decoration: none; color: var(--text);
    transition: transform 0.2s, box-shadow 0.2s;
}
.report-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.12);
}
.report-card .icon { font-size: 2rem; }
.report-card h4 { font-size: 0.95rem; margin-bottom: 2px; }
.report-card p { font-size: 0.78rem; color: var(--text-light); }

/* Morosidad preview */
.mora-preview {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 6px;
    padding: 12px 18px;
    margin-top: 10px;
    font-size: 0.88rem;
}
.mora-preview.no-mora {
    background: #d4edda;
    border-color: #c3e6cb;
}

/* Charts placeholder */
.chart-container {
    position: relative;
    height: 300px;
    margin-top: 10px;
}

/* Login page */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--dark) 100%);
}
.login-box {
    background: var(--white);
    border-radius: 12px;
    padding: 40px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-box h1 {
    text-align: center;
    color: var(--dark);
    margin-bottom: 5px;
    font-size: 1.3rem;
}
.login-box .subtitle {
    text-align: center;
    color: var(--text-light);
    margin-bottom: 25px;
    font-size: 0.85rem;
}

/* Mobile toggle */
.mobile-toggle {
    display: none;
    position: fixed;
    top: 12px; left: 12px;
    z-index: 200;
    background: var(--dark);
    color: var(--white);
    border: none; border-radius: 6px;
    padding: 8px 12px;
    font-size: 1.2rem;
    cursor: pointer;
}

/* Responsive */
@media (max-width: 768px) {
    .mobile-toggle { display: block; }
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    .topbar { padding: 15px 15px 15px 55px; }
    .page-content { padding: 15px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-row { grid-template-columns: 1fr; }
}

/* Print */
@media print {
    .sidebar, .topbar, .mobile-toggle, .btn, .no-print { display: none !important; }
    .main-content { margin-left: 0; }
    .card { box-shadow: none; border: 1px solid #ddd; }
}

/* ===== Toques finales: identidad institucional ===== */
.sidebar-logo {
    max-width: 90px; max-height: 90px;
    object-fit: contain;
    background: #fff; border-radius: 12px;
    padding: 6px; margin-bottom: 10px;
}
.sidebar-logo-placeholder { font-size: 2.4rem; margin-bottom: 6px; }
.sidebar-header h2 { color: #fff; }
.sidebar-header small { color: rgba(255,255,255,0.75); }

/* Título de dos líneas en la barra superior */
.topbar-titles { display: flex; flex-direction: column; line-height: 1.25; }
.topbar-titles .system-name {
    font-size: 0.78rem; font-weight: 600;
    color: var(--primary); letter-spacing: 0.3px; text-transform: uppercase;
}
.topbar-titles h1 {
    font-size: 1.35rem; color: var(--dark); margin: 0;
}

/* Botones primarios en vinotinto */
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }

/* Logo en la pantalla de inicio de sesión */
.login-logo {
    max-width: 110px; max-height: 110px; object-fit: contain;
    display: block; margin: 0 auto 16px; background:#fff;
    border-radius: 14px; padding: 8px;
}

/* ===== Alerta STOP (pago ya registrado) ===== */
.stop-alert {
    display: flex; align-items: center; gap: 18px;
    background: #fdecea; border: 3px solid var(--danger);
    border-left: 10px solid var(--danger);
    border-radius: 12px; padding: 18px 22px; margin-bottom: 20px;
    box-shadow: 0 4px 14px rgba(192,57,43,0.25);
    animation: stopPulse 1s ease-in-out 2;
}
.stop-icon { font-size: 2.8rem; line-height: 1; }
.stop-title { font-size: 1.3rem; font-weight: 800; color: var(--danger); letter-spacing: 0.5px; }
.stop-alert div { color: var(--dark); font-size: 1.02rem; }
@keyframes stopPulse {
    0%, 100% { box-shadow: 0 4px 14px rgba(192,57,43,0.25); }
    50% { box-shadow: 0 4px 24px rgba(192,57,43,0.55); }
}

/* ===== Autocompletado (buscadores) ===== */
.autocomplete-box {
    position: absolute; left: 0; right: 0; top: 100%; z-index: 100;
    background: #fff; border: 1px solid var(--border); border-top: none;
    border-radius: 0 0 8px 8px; max-height: 260px; overflow-y: auto;
    box-shadow: 0 6px 16px rgba(0,0,0,0.12); display: none;
}
.autocomplete-box .item { padding: 10px 12px; cursor: pointer; border-bottom: 1px solid #f0f0f0; }
.autocomplete-box .item:hover, .autocomplete-box .item.active { background: var(--primary); color: #fff; }
.autocomplete-box .item small { display: block; opacity: 0.8; font-size: 0.8rem; }
.autocomplete-box .vacio { padding: 10px 12px; color: var(--text-light); }


/* Cierre de sesión: Django 5 exige POST, así que es un formulario.
   Se le da la misma apariencia que a los demás enlaces del menú. */
.sidebar nav .form-salir { margin: 0; padding: 0; }
.sidebar nav .form-salir button {
    display: block; width: 100%; text-align: left;
    background: none; border: none; cursor: pointer;
    font: inherit; color: inherit;
    padding: 10px 18px;
}
.sidebar nav .form-salir button:hover { background: rgba(255,255,255,.08); }
