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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #f0f4f8;
    color: #1a202c;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card {
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,.1);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 460px;
}

h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: #2d3748;
}

.subtitle {
    font-size: 0.875rem;
    color: #718096;
    margin-bottom: 1.75rem;
}

label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: 0.35rem;
}

input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: 0.9375rem;
    transition: border-color .15s;
    margin-bottom: 1.1rem;
}

input:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66,153,225,.2);
}

.btn {
    display: inline-block;
    width: 100%;
    padding: 0.7rem 1rem;
    background: #3182ce;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
    transition: background .15s;
    margin-top: 0.25rem;
}
.btn:hover { background: #2b6cb0; }
.btn.btn-success { background: #38a169; }
.btn.btn-success:hover { background: #276749; }
.btn.btn-secondary {
    background: #e2e8f0;
    color: #2d3748;
}
.btn.btn-secondary:hover { background: #cbd5e0; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 1.25rem;
}
.alert-error   { background: #fff5f5; border: 1px solid #fed7d7; color: #c53030; }
.alert-success { background: #f0fff4; border: 1px solid #9ae6b4; color: #276749; }
.alert-info    { background: #ebf8ff; border: 1px solid #bee3f8; color: #2b6cb0; }

.divider {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 1.5rem 0;
}

.small-link {
    font-size: 0.8125rem;
    color: #4299e1;
    text-decoration: none;
}
.small-link:hover { text-decoration: underline; }

.success-icon {
    font-size: 4rem;
    text-align: center;
    margin-bottom: 1rem;
}

.meta-table {
    width: 100%;
    font-size: 0.8125rem;
    border-collapse: collapse;
    margin-top: 1rem;
}
.meta-table th, .meta-table td {
    padding: 0.4rem 0.6rem;
    border: 1px solid #e2e8f0;
    text-align: left;
}
.meta-table th {
    background: #f7fafc;
    font-weight: 600;
    width: 40%;
}

.step-list {
    counter-reset: steps;
    list-style: none;
    padding: 0;
    margin: 1rem 0;
}
.step-list li {
    counter-increment: steps;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
    font-size: 0.9rem;
    line-height: 1.4;
}
.step-list li::before {
    content: counter(steps);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 1.75rem;
    height: 1.75rem;
    background: #3182ce;
    color: #fff;
    border-radius: 50%;
    font-weight: 700;
    font-size: 0.8125rem;
    flex-shrink: 0;
}

.nav-links {
    display: flex;
    gap: 1rem;
    margin-top: 1.25rem;
    justify-content: center;
    font-size: 0.8125rem;
}

/* =============================================================================
   Application layout (dashboard, admin, profile pages)
   body.app overrides the login-page centered-card layout
   ============================================================================= */

body.app {
    display: block;
    background: #f0f4f8;
    align-items: unset;
    justify-content: unset;
    min-height: 100vh;
}

/* ---- Top header bar ------------------------------------------------------- */
.app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #1a202c;
    color: #e2e8f0;
    height: 52px;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    gap: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,.35);
}
.app-header .brand {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    white-space: nowrap;
}
.app-header .header-spacer { flex: 1; }
.app-header .header-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .82rem;
    color: #a0aec0;
}
.app-header .header-user strong { color: #e2e8f0; }
.app-header .header-user a {
    color: #63b3ed;
    text-decoration: none;
    font-size: .8rem;
}
.app-header .header-user a:hover { text-decoration: underline; }

.auth-badge {
    display: inline-flex;
    align-items: center;
    gap: .3rem;
    padding: .18rem .55rem;
    border-radius: 9999px;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}
.auth-badge.cert { background: #276749; color: #c6f6d5; }
.auth-badge.pass { background: #744210; color: #fefcbf; }

/* ---- Header school selector ------------------------------------------------ */
.school-selector {
    display: inline-flex;
    align-items: center;
    gap: .45rem;
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 9999px;
    padding: .18rem .3rem .18rem .7rem;
    transition: background .15s;
    white-space: nowrap;
}
.school-selector:hover { background: rgba(255,255,255,.16); }
.school-selector .sc-label {
    font-size: .7rem;
    font-weight: 600;
    color: #a0aec0;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.school-selector select {
    background: #2d3748;
    color: #e2e8f0;
    border: none;
    border-radius: 9999px;
    padding: .2rem .65rem;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
    max-width: 220px;
}
.school-selector select:focus {
    box-shadow: 0 0 0 2px rgba(99,179,237,.55);
}

/* ---- Shared page-level school switcher (e.g. inside report pages) ---------- */
.school-switcher {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 9999px;
    padding: .22rem .3rem .22rem .85rem;
    font-size: .8rem;
    color: #4a5568;
    margin-bottom: .9rem;
}
.school-switcher .sw-label {
    font-size: .72rem;
    font-weight: 700;
    color: #718096;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}
.school-switcher select {
    background: #fff;
    color: #2d3748;
    border: 1px solid #cbd5e0;
    border-radius: 9999px;
    padding: .22rem .75rem;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    outline: none;
}
.school-switcher select:focus {
    border-color: #63b3ed;
    box-shadow: 0 0 0 3px rgba(99,179,237,.25);
}

/* ---- Two-column body ------------------------------------------------------ */
.app-body {
    display: flex;
    min-height: calc(100vh - 52px);
}

/* ---- Sidebar -------------------------------------------------------------- */
.sidebar {
    width: 215px;
    flex-shrink: 0;
    background: #2d3748;
    padding: 1rem 0 2rem;
    display: flex;
    flex-direction: column;
}
.sidebar-section {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: #4a5568;
    padding: 1rem 1.25rem .3rem;
}
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem 1.25rem;
    color: #a0aec0;
    text-decoration: none;
    font-size: .875rem;
    border-left: 3px solid transparent;
    transition: background .12s, color .12s;
}
.sidebar-nav a:hover { background: #3a4a5e; color: #e2e8f0; }
.sidebar-nav a.active { background: #3a4a5e; color: #fff; border-left-color: #4299e1; }
.sidebar-nav .nav-icon { font-size: 1rem; }

/* ---- Main content area ---------------------------------------------------- */
.main {
    flex: 1;
    padding: 2rem 2.25rem;
    min-width: 0;
    overflow-x: clip;
}

.page-title {
    font-size: 1.45rem;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: .2rem;
}
.page-subtitle {
    font-size: .875rem;
    color: #718096;
    margin-bottom: 1.75rem;
}

/* ---- Certificate promotion banner ---------------------------------------- */
.cert-banner {
    background: linear-gradient(135deg, #276749 0%, #2f855a 100%);
    color: #fff;
    border-radius: 10px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.75rem;
    display: flex;
    align-items: center;
    gap: 1.25rem;
}
.cert-banner.cert-expired {
    background: linear-gradient(135deg, #c05621 0%, #dd6b20 100%);
}
.cert-banner.cert-ok {
    background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%);
}
.cert-banner .banner-icon { font-size: 2.75rem; flex-shrink: 0; }
.cert-banner .banner-body { flex: 1; }
.cert-banner h3 { font-size: 1rem; font-weight: 700; margin-bottom: .25rem; color: #fff; }
.cert-banner p  { font-size: .855rem; opacity: .9; margin-bottom: .65rem; line-height: 1.4; }
.cert-banner .btn-cert {
    display: inline-block;
    padding: .45rem 1.1rem;
    background: rgba(255,255,255,.2);
    color: #fff;
    border-radius: 6px;
    font-size: .855rem;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,.35);
    transition: background .15s;
}
.cert-banner .btn-cert:hover { background: rgba(255,255,255,.32); }

/* ---- Module grid ---------------------------------------------------------- */
.module-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: 1.1rem;
    margin-bottom: 2rem;
}
.module-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 6px rgba(0,0,0,.08);
    padding: 1.4rem 1.25rem;
    text-decoration: none;
    color: inherit;
    border-top: 3px solid #3182ce;
    display: flex;
    flex-direction: column;
    transition: box-shadow .15s, transform .15s;
}
.module-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,.13); transform: translateY(-2px); }
.module-card.green  { border-top-color: #38a169; }
.module-card.purple { border-top-color: #805ad5; }
.module-card.orange { border-top-color: #dd6b20; }
.module-card.teal   { border-top-color: #319795; }
.module-card .card-icon { font-size: 2rem; margin-bottom: .65rem; }
.module-card h3 { font-size: .975rem; font-weight: 700; color: #2d3748; margin-bottom: .3rem; }
.module-card p  { font-size: .8rem; color: #718096; line-height: 1.45; flex: 1; margin: 0; }

/* ---- Panels --------------------------------------------------------------- */
.panel {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 6px rgba(0,0,0,.08);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.panel-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #2d3748;
    margin-bottom: 1rem;
    padding-bottom: .65rem;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
}

/* ---- Data tables ---------------------------------------------------------- */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}
.data-table th {
    text-align: left;
    padding: .55rem .75rem;
    background: #f7fafc;
    border-bottom: 2px solid #e2e8f0;
    font-weight: 600;
    color: #4a5568;
    white-space: nowrap;
}
.data-table td {
    padding: .6rem .75rem;
    border-bottom: 1px solid #f0f4f8;
    color: #2d3748;
    vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f7fafc; }
.data-table .actions { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ---- Badges --------------------------------------------------------------- */
.badge {
    display: inline-block;
    padding: .18rem .55rem;
    border-radius: 9999px;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}
.badge-blue   { background: #ebf8ff; color: #2b6cb0; }
.badge-green  { background: #f0fff4; color: #276749; }
.badge-yellow { background: #fffff0; color: #744210; }
.badge-red    { background: #fff5f5; color: #c53030; }
.badge-gray   { background: #f7fafc; color: #4a5568; border: 1px solid #e2e8f0; }
.badge-purple { background: #faf5ff; color: #6b46c1; }
.badge-teal   { background: #e6fffa; color: #2c7a7b; }

/* ---- Small action buttons ------------------------------------------------- */
.btn-sm {
    display: inline-block;
    padding: .3rem .7rem;
    border-radius: 5px;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: background .15s;
    white-space: nowrap;
    line-height: 1.4;
}
.btn-sm.btn-primary   { background: #3182ce; color: #fff; }
.btn-sm.btn-primary:hover   { background: #2b6cb0; }
.btn-sm.btn-success   { background: #38a169; color: #fff; }
.btn-sm.btn-success:hover   { background: #276749; }
.btn-sm.btn-danger    { background: #e53e3e; color: #fff; }
.btn-sm.btn-danger:hover    { background: #c53030; }
.btn.btn-danger       { background: #e53e3e; color: #fff; }
.btn.btn-danger:hover { background: #c53030; }
.btn-sm.btn-secondary { background: #e2e8f0; color: #2d3748; }
.btn-sm.btn-secondary:hover { background: #cbd5e0; }

/* ---- Form helpers --------------------------------------------------------- */
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1.25rem;
}
.form-row .span2 { grid-column: 1 / -1; }
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: .8125rem;
    font-weight: 600;
    color: #4a5568;
    margin-bottom: .3rem;
}
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="tel"],
.form-group select,
.form-group textarea {
    width: 100%;
    padding: .55rem .8rem;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    font-size: .9rem;
    background: #fff;
    color: #2d3748;
    transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #4299e1;
    box-shadow: 0 0 0 3px rgba(66,153,225,.15);
}
.form-hint { font-size: .78rem; color: #718096; margin-top: .25rem; }

/* ---- Security status items ------------------------------------------------ */
.security-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .9rem 1rem;
    border-radius: 7px;
    margin-bottom: .75rem;
    border: 1px solid #e2e8f0;
    background: #f7fafc;
}
.security-item.ok      { border-color: #9ae6b4; background: #f0fff4; }
.security-item.warn    { border-color: #fbd38d; background: #fffff0; }
.security-item.missing { border-color: #feb2b2; background: #fff5f5; }
.security-item .si-icon  { font-size: 1.6rem; flex-shrink: 0; }
.security-item .si-body  { flex: 1; }
.security-item .si-label { font-weight: 700; font-size: .9rem; color: #2d3748; }
.security-item .si-desc  { font-size: .8rem; color: #718096; margin-top: .1rem; }
.security-item .si-action { flex-shrink: 0; }

/* ---- Tabs ----------------------------------------------------------------- */
.tabs {
    display: flex;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 1.5rem;
    gap: 0;
}
.tab-btn {
    padding: .6rem 1.25rem;
    border: none;
    background: none;
    font-size: .9rem;
    font-weight: 600;
    color: #718096;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
    text-decoration: none;
}
.tab-btn:hover { color: #2d3748; }
.tab-btn.active { color: #3182ce; border-bottom-color: #3182ce; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ---- TOTP QR code container ----------------------------------------------- */
.totp-setup-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 2rem;
    align-items: start;
}
#qrcode-container {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: .75rem;
    display: inline-block;
}
#qrcode-container canvas,
#qrcode-container img { display: block; }

.secret-display {
    font-family: 'Courier New', Courier, monospace;
    font-size: .95rem;
    letter-spacing: .1em;
    background: #f7fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    padding: .6rem .9rem;
    word-break: break-all;
    color: #2d3748;
}

/* ---- Utility -------------------------------------------------------------- */
.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: .5rem;
}
.text-muted { color: #718096; font-size: .85rem; }
.mt-1 { margin-top: .5rem !important; }
.mt-2 { margin-top: 1rem !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: .5rem !important; }
.mb-2 { margin-bottom: 1rem !important; }

/* ---- Additional button variants ------------------------------------------- */
.btn.btn-primary  { background: #3182ce; color: #fff; }
.btn.btn-primary:hover  { background: #2b6cb0; }
.btn.btn-warning  { background: #dd6b20; color: #fff; }
.btn.btn-warning:hover  { background: #c05621; }
.btn-sm.btn-warning { background: #dd6b20; color: #fff; }
.btn-sm.btn-warning:hover { background: #c05621; }

/* ---- tab-link (anchor-based tabs, alias of tab-btn) ----------------------- */
.tab-link {
    display: inline-block;
    padding: .6rem 1.25rem;
    font-size: .9rem;
    font-weight: 600;
    color: #718096;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color .15s, border-color .15s;
}
.tab-link:hover { color: #2d3748; }
.tab-link.active { color: #3182ce; border-bottom-color: #3182ce; }

/* ---- Responsive adjustments ----------------------------------------------- */
@media (max-width: 900px) {
    .sidebar { width: 180px; }
    .main { padding: 1.25rem; }
}
@media (max-width: 680px) {
    .sidebar { display: none; }
    .main { padding: 1rem; }
    .form-row { grid-template-columns: 1fr; }
    .module-grid { grid-template-columns: 1fr 1fr; }
    .totp-setup-grid { grid-template-columns: 1fr; }
}
