/* ============================================================
   DRIVI SaaS — Design System CSS
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;0,9..40,800&display=swap');

/* ---- TOKENS ---- */
:root {
    --yellow:      #FFDA1A;
    --yellow-dk:   #E6C300;
    --yellow-lt:   #FFFBE6;
    --black:       #0A0A0A;
    --white:       #FFFFFF;
    --gray-50:     #F8F8F7;
    --gray-100:    #F2F2F0;
    --gray-200:    #E8E8E5;
    --gray-300:    #D4D4CF;
    --gray-400:    #ABABAB;
    --gray-600:    #6B6B6B;
    --gray-800:    #2C2C2C;
    --green:       #16A34A;
    --green-lt:    #DCFCE7;
    --red:         #DC2626;
    --red-lt:      #FEE2E2;
    --orange:      #EA580C;
    --orange-lt:   #FFF7ED;
    --blue:        #2563EB;
    --blue-lt:     #EFF6FF;
    --sidebar-w:   240px;
    --topbar-h:    60px;
    --radius:      12px;
    --radius-sm:   8px;
    --radius-lg:   16px;
    --shadow-sm:   0 1px 3px rgba(0,0,0,.07), 0 1px 2px rgba(0,0,0,.05);
    --shadow:      0 4px 12px rgba(0,0,0,.08);
    --shadow-lg:   0 12px 32px rgba(0,0,0,.12);
    --transition:  0.18s ease;
}

/* ---- RESET ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-font-smoothing: antialiased; }
body {
    font-family: 'DM Sans', system-ui, sans-serif;
    background: var(--gray-50);
    color: var(--black);
    line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ============================================================
   LAYOUT — SIDEBAR + MAIN
   ============================================================ */
body:not(.auth-body) {
    display: flex;
    min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-w);
    min-height: 100vh;
    background: var(--black);
    color: var(--white);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 16px 16px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    min-height: var(--topbar-h);
}

.brand-icon {
    width: 34px; height: 34px;
    background: var(--yellow);
    border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    color: var(--black);
    flex-shrink: 0;
}
.brand-logo { width: 34px; height: 34px; object-fit: cover; border-radius: 8px; }
.brand-name {
    font-size: 15px; font-weight: 700;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    flex: 1;
}
.sidebar-close { display: none; background: none; border: none; color: var(--gray-400); padding: 4px; }

.sidebar-nav {
    flex: 1;
    padding: 12px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    color: rgba(255,255,255,.6);
    transition: all var(--transition);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.07); color: var(--white); }
.nav-item.active { background: var(--yellow); color: var(--black); }
.nav-divider { height: 1px; background: rgba(255,255,255,.08); margin: 8px 4px; }

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 12px;
    border-top: 1px solid rgba(255,255,255,.08);
    margin-top: auto;
}
.user-avatar-sm {
    width: 32px; height: 32px;
    background: var(--yellow);
    color: var(--black);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    flex-shrink: 0;
    overflow: hidden;
}
.user-avatar-sm img { width: 100%; height: 100%; object-fit: cover; }
.user-info { flex: 1; min-width: 0; }
.user-name { display: block; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; font-size: 11px; color: var(--gray-400); }
.logout-btn { color: var(--gray-400); padding: 4px; display: flex; }
.logout-btn:hover { color: var(--red); }

/* MAIN CONTENT */
.main-content {
    margin-left: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* TOPBAR */
.topbar {
    height: var(--topbar-h);
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 14px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.menu-toggle {
    display: none;
    background: none; border: none;
    color: var(--gray-800); padding: 4px;
}
.topbar-title {
    font-size: 16px; font-weight: 700;
    flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* PAGE CONTENT */
.page-content {
    padding: 24px;
    flex: 1;
    max-width: 1400px;
    width: 100%;
}

/* ============================================================
   COMPONENTS
   ============================================================ */

/* CARDS */
.card {
    background: var(--white);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}
.card-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 16px; padding-bottom: 14px;
    border-bottom: 1px solid var(--gray-100);
}
.card-title { font-size: 15px; font-weight: 700; }

/* STAT CARDS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), transform var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-icon {
    width: 38px; height: 38px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 12px;
}
.stat-icon.yellow { background: var(--yellow-lt); color: var(--black); }
.stat-icon.green  { background: var(--green-lt); color: var(--green); }
.stat-icon.red    { background: var(--red-lt); color: var(--red); }
.stat-icon.blue   { background: var(--blue-lt); color: var(--blue); }
.stat-icon.orange { background: var(--orange-lt); color: var(--orange); }
.stat-num { font-size: 28px; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: 13px; color: var(--gray-600); }
.stat-delta { font-size: 12px; font-weight: 600; margin-top: 6px; }
.stat-delta.up   { color: var(--green); }
.stat-delta.down { color: var(--red); }

/* BUTTONS */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 0 18px; height: 40px;
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600;
    border: none;
    transition: all var(--transition);
    white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; flex-shrink: 0; }
.btn-primary   { background: var(--yellow); color: var(--black); box-shadow: 0 2px 8px rgba(255,218,26,.3); }
.btn-primary:hover { background: var(--yellow-dk); box-shadow: 0 4px 12px rgba(255,218,26,.4); }
.btn-secondary { background: var(--gray-100); color: var(--gray-800); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger    { background: var(--red-lt); color: var(--red); }
.btn-danger:hover { background: var(--red); color: var(--white); }
.btn-ghost     { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 48px; padding: 0 24px; font-size: 15px; }
.btn:active { transform: scale(0.97); }

/* ICON BUTTON */
.icon-btn {
    width: 36px; height: 36px;
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none;
    color: var(--gray-600);
    transition: all var(--transition);
    position: relative;
}
.icon-btn:hover { background: var(--gray-100); color: var(--black); }
.notif-dot {
    position: absolute; top: 5px; right: 5px;
    width: 8px; height: 8px;
    background: var(--red);
    border-radius: 50%;
    border: 2px solid var(--white);
}

/* TABLES */
.table-wrap { overflow-x: auto; }
.table {
    width: 100%; border-collapse: collapse;
    font-size: 14px;
}
.table th {
    text-align: left; padding: 10px 14px;
    font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .05em;
    color: var(--gray-600);
    border-bottom: 2px solid var(--gray-100);
    white-space: nowrap;
}
.table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--gray-50); }

/* BADGES */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 12px; font-weight: 600;
}
.badge-yellow  { background: var(--yellow-lt); color: #7A6000; }
.badge-green   { background: var(--green-lt); color: var(--green); }
.badge-red     { background: var(--red-lt); color: var(--red); }
.badge-blue    { background: var(--blue-lt); color: var(--blue); }
.badge-orange  { background: var(--orange-lt); color: var(--orange); }
.badge-gray    { background: var(--gray-100); color: var(--gray-600); }

/* FORMS */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--gray-800); }
.form-control {
    width: 100%; padding: 0 14px; height: 42px;
    border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    font-size: 14px; color: var(--black);
    background: var(--white);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}
.form-control:focus { border-color: var(--yellow); box-shadow: 0 0 0 3px rgba(255,218,26,.15); }
textarea.form-control { height: auto; padding: 12px 14px; resize: vertical; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B6B6B' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.form-hint { font-size: 12px; color: var(--gray-600); margin-top: 4px; }

/* AVATAR */
.avatar {
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700;
}
.avatar-md { width: 40px; height: 40px; font-size: 16px; }
.avatar-lg { width: 56px; height: 56px; font-size: 22px; }
.avatar-sm { width: 30px; height: 30px; font-size: 12px; }

/* PROGRESS BAR */
.progress-wrap { background: var(--gray-100); border-radius: 20px; height: 8px; overflow: hidden; }
.progress-bar  { height: 100%; border-radius: 20px; background: var(--yellow); transition: width .6s ease; }
.progress-bar.green  { background: var(--green); }
.progress-bar.red    { background: var(--red); }

/* FLASH */
.flash {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 20px;
    font-size: 14px; font-weight: 500;
    margin: 0 24px 0;
    border-radius: var(--radius-sm);
    margin-top: 12px;
}
.flash-ok  { background: var(--green-lt); color: var(--green); }
.flash-err { background: var(--red-lt); color: var(--red); }
.flash-close { margin-left: auto; background: none; border: none; font-size: 18px; cursor: pointer; opacity: .6; color: inherit; }
.flash-close:hover { opacity: 1; }

/* PAGE HEADER */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 24px; gap: 16px;
    flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; font-weight: 800; }
.page-header-sub { font-size: 14px; color: var(--gray-600); margin-top: 2px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* SEARCH BAR */
.search-bar {
    display: flex; align-items: center; gap: 10px;
    background: var(--white); border: 1.5px solid var(--gray-200);
    border-radius: var(--radius-sm);
    padding: 0 14px; height: 40px;
    flex: 1; max-width: 360px;
}
.search-bar svg { color: var(--gray-400); flex-shrink: 0; }
.search-bar input {
    border: none; background: none; outline: none;
    font-size: 14px; color: var(--black); flex: 1;
}
.search-bar input::placeholder { color: var(--gray-400); }

/* EMPTY STATE */
.empty-state {
    display: flex; flex-direction: column; align-items: center;
    justify-content: center; padding: 60px 20px;
    text-align: center; color: var(--gray-400);
}
.empty-state svg { width: 52px; height: 52px; margin-bottom: 14px; }
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--gray-600); margin-bottom: 8px; }
.empty-state p  { font-size: 14px; }

/* MODAL */
.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: 20px;
    opacity: 0; visibility: hidden;
    transition: all var(--transition);
}
.modal-backdrop.open { opacity: 1; visibility: visible; }
.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%; max-width: 520px;
    max-height: 90vh; overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: translateY(12px);
    transition: transform var(--transition);
}
.modal-backdrop.open .modal { transform: translateY(0); }
.modal-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--gray-100);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 17px; font-weight: 700; }
.modal-body { padding: 20px 24px; }
.modal-footer {
    padding: 14px 24px 20px;
    border-top: 1px solid var(--gray-100);
    display: flex; gap: 10px; justify-content: flex-end;
}

/* TABS */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--gray-100); margin-bottom: 20px; }
.tab-btn {
    padding: 8px 16px;
    font-size: 14px; font-weight: 600;
    background: none; border: none;
    color: var(--gray-600);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all var(--transition);
}
.tab-btn:hover { color: var(--black); }
.tab-btn.active { color: var(--black); border-bottom-color: var(--yellow); }

/* ============================================================
   AUTH PAGES
   ============================================================ */
.auth-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh;
    background: var(--gray-50);
    padding: 24px;
}
.auth-box {
    background: var(--white);
    border-radius: var(--radius-lg);
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%; max-width: 420px;
}
.auth-logo {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 28px;
}
.auth-logo-icon {
    width: 42px; height: 42px;
    background: var(--yellow);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
}
.auth-logo-name { font-size: 20px; font-weight: 800; }
.auth-title    { font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.auth-subtitle { font-size: 14px; color: var(--gray-600); margin-bottom: 28px; }
.auth-link     { color: var(--blue); font-size: 13px; }
.auth-link:hover { text-decoration: underline; }
.auth-footer   { text-align: center; margin-top: 20px; font-size: 13px; color: var(--gray-600); }

/* ============================================================
   CALENDARIO CUSTOM
   ============================================================ */
.cal-toolbar {
    display: flex; align-items: center; gap: 12px;
    margin-bottom: 16px; flex-wrap: wrap;
}
.cal-nav { display: flex; align-items: center; gap: 8px; }
.cal-nav-btn {
    width: 34px; height: 34px;
    border-radius: var(--radius-sm);
    background: var(--gray-100); border: none;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--transition);
}
.cal-nav-btn:hover { background: var(--gray-200); }
.cal-month-label { font-size: 16px; font-weight: 700; min-width: 180px; text-align: center; }
.cal-view-tabs { display: flex; gap: 2px; background: var(--gray-100); border-radius: var(--radius-sm); padding: 3px; }
.cal-view-btn {
    padding: 5px 12px; border-radius: 6px;
    font-size: 13px; font-weight: 600;
    background: none; border: none; color: var(--gray-600);
    transition: all var(--transition);
}
.cal-view-btn.active { background: var(--white); color: var(--black); box-shadow: var(--shadow-sm); }

/* Calendario Mes */
.cal-grid-month { overflow: hidden; border-radius: var(--radius); border: 1px solid var(--gray-200); background: var(--white); }
.cal-weekdays {
    display: grid; grid-template-columns: repeat(7,1fr);
    border-bottom: 1px solid var(--gray-100);
}
.cal-weekday {
    padding: 10px 0; text-align: center;
    font-size: 12px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .05em; color: var(--gray-600);
}
.cal-days { display: grid; grid-template-columns: repeat(7,1fr); }
.cal-day {
    min-height: 96px; padding: 8px;
    border-right: 1px solid var(--gray-100);
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background var(--transition);
}
.cal-day:nth-child(7n) { border-right: none; }
.cal-day:hover { background: var(--gray-50); }
.cal-day.other-month { background: var(--gray-50); }
.cal-day.other-month .day-num { color: var(--gray-300); }
.cal-day.today .day-num {
    background: var(--yellow); color: var(--black);
    border-radius: 50%; width: 26px; height: 26px;
    display: flex; align-items: center; justify-content: center;
}
.day-num { font-size: 13px; font-weight: 600; margin-bottom: 4px; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; }
.day-events { display: flex; flex-direction: column; gap: 2px; }
.day-event {
    font-size: 11px; font-weight: 600;
    padding: 2px 6px; border-radius: 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    cursor: pointer;
}

/* Calendario Semana */
.cal-week-grid {
    display: grid; grid-template-columns: 56px repeat(7,1fr);
    border: 1px solid var(--gray-200); border-radius: var(--radius);
    background: var(--white); overflow: hidden;
}
.cal-week-header { grid-column: 2/-1; display: grid; grid-template-columns: repeat(7,1fr); border-bottom: 1px solid var(--gray-200); }
.cal-week-day-hdr {
    padding: 10px; text-align: center;
    font-size: 12px; font-weight: 600; color: var(--gray-600);
    border-right: 1px solid var(--gray-100);
}
.cal-week-day-hdr:last-child { border-right: none; }
.cal-week-day-hdr.today span { background: var(--yellow); border-radius: 50%; width: 24px; height: 24px; display: inline-flex; align-items: center; justify-content: center; }
.cal-week-body { grid-column: 1/-1; display: grid; grid-template-columns: 56px repeat(7,1fr); max-height: 600px; overflow-y: auto; }
.cal-time-col { border-right: 1px solid var(--gray-100); }
.cal-time-slot { height: 60px; display: flex; align-items: flex-start; padding-top: 4px; padding-right: 8px; justify-content: flex-end; font-size: 11px; color: var(--gray-400); border-bottom: 1px solid var(--gray-50); }
.cal-day-col { border-right: 1px solid var(--gray-100); position: relative; }
.cal-day-col:last-child { border-right: none; }
.cal-hour-cell { height: 60px; border-bottom: 1px solid var(--gray-100); position: relative; }
.cal-half-cell { position:absolute; top:50%; left:0; right:0; height:1px; background:var(--gray-50); pointer-events:none; }
.cal-event-block {
    position: absolute; left: 2px; right: 2px;
    border-radius: 6px; padding: 4px 6px;
    font-size: 11px; font-weight: 600;
    overflow: hidden; cursor: pointer;
    transition: opacity var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    min-height: 24px;
}
.cal-event-block:hover { opacity: .85; }

/* Agenda List */
.agenda-list { display: flex; flex-direction: column; gap: 10px; }
.agenda-item {
    display: flex; align-items: flex-start; gap: 14px;
    background: var(--white); border: 1px solid var(--gray-200);
    border-radius: var(--radius); padding: 14px 16px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition);
}
.agenda-item:hover { box-shadow: var(--shadow); }
.agenda-time {
    display: flex; flex-direction: column; align-items: center;
    min-width: 54px; gap: 2px;
    font-size: 13px; font-weight: 700;
}
.agenda-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; margin-top: 4px; }

/* ============================================================
   STUDENT PROFILE
   ============================================================ */
.profile-header {
    display: flex; align-items: center; gap: 20px;
    background: var(--white); border-radius: var(--radius);
    border: 1px solid var(--gray-200); padding: 24px;
    box-shadow: var(--shadow-sm); margin-bottom: 20px;
}
.profile-avatar {
    width: 72px; height: 72px; border-radius: 50%;
    background: var(--yellow);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; font-weight: 800; flex-shrink: 0;
}
.profile-name { font-size: 22px; font-weight: 800; }
.profile-meta { font-size: 14px; color: var(--gray-600); margin-top: 4px; }
.profile-tags { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ============================================================
   FACTURA PRINT
   ============================================================ */
.invoice-box {
    max-width: 720px; margin: 0 auto;
    background: var(--white); padding: 40px;
    border-radius: var(--radius); border: 1px solid var(--gray-200);
}
.invoice-header { display: flex; justify-content: space-between; margin-bottom: 32px; }
.invoice-logo { font-size: 24px; font-weight: 800; }
.invoice-num  { font-size: 14px; color: var(--gray-600); text-align: right; }
.invoice-num strong { font-size: 20px; color: var(--black); display: block; }
.invoice-parties { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 28px; }
.invoice-party-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--gray-400); margin-bottom: 8px; }
.invoice-party-name  { font-size: 16px; font-weight: 700; }
.invoice-items { border: 1px solid var(--gray-200); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 20px; }
.invoice-total-box { text-align: right; }
.invoice-total-row { display: flex; justify-content: flex-end; gap: 40px; font-size: 14px; padding: 4px 0; }
.invoice-total-final { font-size: 20px; font-weight: 800; }

/* ============================================================
   SUPERADMIN STYLES
   ============================================================ */
.is-superadmin .sidebar { background: #1A1A2E; }
.is-superadmin .nav-item.active { background: #4F46E5; color: var(--white); }
.is-superadmin .brand-icon { background: #4F46E5; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
.sidebar-overlay {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.4); z-index: 99;
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .sidebar-overlay.open { display: block; }
    .sidebar-close { display: flex; }
    .main-content { margin-left: 0; }
    .menu-toggle  { display: flex; }
    .topbar       { padding: 0 16px; }
    .page-content { padding: 16px; }
    .form-row, .form-row-3 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .modal { max-width: 100%; margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
    .modal-backdrop { align-items: flex-end; padding: 0; }
    .auth-box { padding: 28px 24px; }
    .invoice-parties { grid-template-columns: 1fr; }
}

@media print {
    .sidebar, .topbar, .btn, .flash { display: none !important; }
    .main-content { margin-left: 0; }
    .page-content { padding: 0; }
    .invoice-box  { border: none; padding: 0; }
}


/* ============================================================
   RESPONSIVE ADDITIONS — Mobile First Improvements
   ============================================================ */

/* ---- TABLES: stack on mobile ---- */
@media (max-width: 768px) {

    /* Tables scroll horizontally */
    .table-wrap, .card > table, .card > div > table {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        display: block;
        width: 100%;
    }

    /* Hide less important columns on mobile */
    .hide-mobile { display: none !important; }

    /* Stack page header vertically */
    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .page-actions {
        width: 100%;
        justify-content: flex-start;
    }

    /* Cards take full width */
    .card { padding: 14px; }

    /* Stats grid 2 columns on mobile */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
    .stat-num { font-size: 22px; }

    /* Buttons full width when stacked */
    .btn-block-mobile { width: 100%; justify-content: center; }

    /* Search bar full width */
    .search-bar { max-width: 100%; }

    /* Topbar adjustments */
    .topbar-title { font-size: 14px; }
    .topbar-actions .btn span { display: none; } /* hide text, show icon only */

    /* Grid layouts collapse */
    [style*="grid-template-columns: 280px"] {
        display: flex !important;
        flex-direction: column !important;
    }
    [style*="grid-template-columns: 1fr 1fr"] {
        display: flex !important;
        flex-direction: column !important;
    }

    /* Prevent horizontal overflow */
    .main-content, .page-content {
        overflow-x: hidden;
        max-width: 100vw;
    }

    /* Flash messages */
    .flash { margin: 8px 0; border-radius: var(--radius-sm); }

    /* Tabs scroll horizontally */
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap;
        padding-bottom: 2px;
    }
    .tab-btn { white-space: nowrap; }

    /* Modal full screen on mobile */
    .modal {
        max-width: 100%;
        width: 100%;
        margin: 0;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        max-height: 92vh;
    }
    .modal-backdrop { align-items: flex-end; padding: 0; }

    /* Calendar adjustments */
    .cal-day { min-height: 64px; padding: 4px; }
    .day-event { display: none; } /* hide event text on month view mobile */
    .day-events::after {
        content: attr(data-count);
        font-size: 10px;
        color: var(--gray-400);
    }

    /* Invoice */
    .invoice-box { padding: 16px; }
    .invoice-header { flex-direction: column; gap: 12px; }
    .invoice-num { text-align: left; }

    /* Filters row wraps */
    [style*="display:flex"][style*="gap"] {
        flex-wrap: wrap;
    }

    /* Form adjustments */
    .form-row, .form-row-3 { grid-template-columns: 1fr !important; }

    /* Estudiante ver.php left/right panel */
    .student-grid {
        grid-template-columns: 1fr !important;
    }

    /* Action buttons in tables */
    .table td:last-child {
        white-space: nowrap;
    }
}

/* ---- PORTAL SIDEBAR RESPONSIVE ---- */
@media (max-width: 768px) {
    :root { --portal-sidebar: 240px; }

    .portal-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 200;
    }
    .portal-sidebar.open {
        transform: translateX(0);
    }
    .portal-main {
        margin-left: 0 !important;
    }
    .portal-content {
        padding: 16px !important;
        overflow-x: hidden;
    }
    .portal-topbar {
        padding: 0 16px !important;
    }

    /* Portal overlay */
    .portal-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,.5);
        z-index: 199;
    }
    .portal-overlay.open { display: block; }

    /* Portal nav items on mobile */
    .portal-nav-item { padding: 12px 14px; font-size: 15px; }

    /* Wallet badge compact */
    .wallet-badge { font-size: 12px; padding: 4px 10px; }
    .wallet-badge span { display: none; }
}

/* ---- TABLET (768px - 1024px) ---- */
@media (min-width: 769px) and (max-width: 1024px) {
    :root { --sidebar-w: 200px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .page-content { padding: 16px 20px; }
    .stat-num { font-size: 24px; }
}

/* ---- SMALL PHONES (max 480px) ---- */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px 14px; }
    .stat-num { font-size: 20px; }
    .stat-label { font-size: 11px; }
    .btn { height: 38px; padding: 0 14px; font-size: 13px; }
    .btn-sm { height: 30px; padding: 0 10px; font-size: 12px; }
    .auth-box { padding: 20px 16px; border-radius: var(--radius); }
    .auth-title { font-size: 20px; }
    .card { border-radius: var(--radius-sm); }
    .page-content { padding: 12px; }
    .topbar { padding: 0 12px; }

    /* Stack all flex rows */
    .topbar-actions { gap: 4px; }

    /* Calendar month view smaller */
    .cal-day { min-height: 48px; }
    .cal-weekday { font-size: 10px; padding: 6px 0; }
}

/* ---- UTILITY CLASSES ---- */
.d-mobile-none { }
.d-mobile-block { display: none; }

@media (max-width: 768px) {
    .d-mobile-none  { display: none !important; }
    .d-mobile-block { display: block !important; }
    .d-mobile-flex  { display: flex !important; }
    .text-mobile-sm { font-size: 12px !important; }
    .w-mobile-full  { width: 100% !important; }
}

/* ---- FIX OVERFLOW GLOBAL ---- */
body { overflow-x: hidden; }
* { max-width: 100%; }
img { max-width: 100%; height: auto; }
table { table-layout: auto; }

/* ---- TOUCH IMPROVEMENTS ---- */
@media (hover: none) {
    .btn:hover { transform: none; }
    .stat-card:hover { transform: none; box-shadow: var(--shadow-sm); }
    .nav-item, .portal-nav-item { padding: 13px 12px; } /* bigger touch targets */
}

/* ---- SAFE AREA (iPhone notch) ---- */
@supports (padding: env(safe-area-inset-bottom)) {
    .sidebar, .portal-sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Sidebar fix */
.sidebar { transform:translateX(0); transition: transform 0.3s ease !important; }
@media(max-width:768px){.sidebar{transform:translateX(-100%)}.sidebar.open{transform:translateX(0) !important}}
/* Portal menu toggle - same as admin */
#menuTogglePortal { display:none; }
@media(max-width:768px) { #menuTogglePortal { display:flex !important; } }

#portalOverlay { z-index:200 !important; }
#portalSidebar { z-index:201 !important; }

@media(max-width:768px) { .mobile-full { max-width:100% !important; width:100% !important; } }
