:root {
    --primary: #1e3a8a;
    --primary-600: #1d4ed8;
    --primary-50: #eff6ff;
    --text: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --green: #15803d;
    --green-bg: #dcfce7;
    --green-border: #86efac;
    --red: #b91c1c;
    --red-bg: #fee2e2;
    --red-border: #fca5a5;
    --amber: #92400e;
    --amber-bg: #fef3c7;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 16px rgba(15, 23, 42, .05);
}

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

body {
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.55;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .65rem 1.1rem; min-height: 44px;
    border: 1px solid transparent; border-radius: 10px;
    font: inherit; font-weight: 600; cursor: pointer;
    background: var(--primary); color: #fff; text-decoration: none;
    transition: background .15s, box-shadow .15s, transform .05s;
}
.btn:hover { background: #172e6e; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .slot:focus-visible {
    outline: 3px solid #93c5fd; outline-offset: 2px;
}
.btn-light { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-light:hover { background: #f8fafc; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #991b1b; }
.btn-outline-danger { background: var(--surface); color: var(--red); border-color: var(--red-border); }
.btn-outline-danger:hover { background: var(--red-bg); }
.btn-sm { padding: .35rem .7rem; min-height: 34px; font-size: .85rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--primary-600); padding: 0; min-height: 0; font-weight: 600; cursor: pointer; font: inherit; }
.btn-link:hover { background: none; text-decoration: underline; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.actions form { margin: 0; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.5rem; }
.card + .card { margin-top: 1rem; }
.card-header { display: flex; flex-wrap: wrap; gap: .75rem; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.card-header h2, .card-header h3 { margin: 0; }

/* Forms */
.field { margin-bottom: 1rem; }
label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: .92rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], select, textarea {
    width: 100%; padding: .65rem .8rem; min-height: 44px;
    border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--text); font: inherit;
}
textarea { min-height: 100px; resize: vertical; }
.is-invalid { border-color: var(--red) !important; }
.field-error { color: var(--red); font-size: .85rem; margin-top: .3rem; }
.hint { color: var(--muted); font-size: .85rem; margin-top: .3rem; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin: 0; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.grid-2 { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.grid-3 { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.code-input { font-size: 1.8rem !important; letter-spacing: .6rem; text-align: center; font-weight: 700; }
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: 1rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }

/* Alerts */
.alert { padding: .85rem 1rem; border-radius: 10px; margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: var(--green-bg); border-color: var(--green-border); color: #14532d; }
.alert-error { background: var(--red-bg); border-color: var(--red-border); color: #7f1d1d; }
.alert-warning { background: var(--amber-bg); border-color: #fcd34d; color: var(--amber); }
.alert-info { background: var(--primary-50); border-color: #bfdbfe; color: var(--primary); }

/* Badges */
.badge { display: inline-block; padding: .15rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: #e2e8f0; color: #334155; white-space: nowrap; }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-blue { background: var(--primary-50); color: var(--primary-600); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: .7rem .85rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #f8fafc; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafc; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* Stats */
.stats { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); margin-bottom: 1.5rem; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.stat-value { font-size: 1.75rem; font-weight: 800; margin-top: .2rem; font-variant-numeric: tabular-nums; }

/* Filters */
.filters { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); align-items: end; margin-bottom: 1rem; }
.filters .field { margin: 0; }
.filters label { font-size: .8rem; color: var(--muted); }

/* Slots */
.slot-grid { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
.slot {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: .8rem .5rem; min-height: 70px; border-radius: 10px; border: 2px solid; font: inherit; width: 100%;
}
.slot-time { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.slot-status { font-size: .78rem; font-weight: 600; }
.slot-available { background: var(--green-bg); border-color: var(--green-border); color: var(--green); cursor: pointer; transition: transform .1s, box-shadow .1s, background .1s; }
.slot-available:hover { background: #bbf7d0; box-shadow: 0 4px 12px rgba(21, 128, 61, .18); transform: translateY(-1px); }
.slot-booked { background: var(--red-bg); border-color: var(--red-border); color: var(--red); cursor: not-allowed; opacity: .85; }
.slot-booked .slot-time { text-decoration: line-through; }
.slot-current { background: var(--primary-50); border-color: #93c5fd; color: var(--primary); cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .85rem; color: var(--muted); margin-bottom: 1rem; }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; border: 2px solid; }
.legend .l-available::before { background: var(--green-bg); border-color: var(--green-border); }
.legend .l-booked::before { background: var(--red-bg); border-color: var(--red-border); }
.legend .l-current::before { background: var(--primary-50); border-color: #93c5fd; }

/* Key-value summary */
.summary { display: grid; grid-template-columns: minmax(110px, 35%) 1fr; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 1.25rem; }
.summary dt, .summary dd { margin: 0; padding: .7rem .9rem; border-bottom: 1px solid var(--border); }
.summary dt { color: var(--muted); background: #f8fafc; font-size: .9rem; }
.summary dd { font-weight: 600; }
.summary dt:last-of-type, .summary dd:last-of-type { border-bottom: 0; }

/* ---------- Public (responsible) layout ---------- */
.public-header { background: var(--surface); border-bottom: 1px solid var(--border); }
.public-header .inner { max-width: 760px; margin: 0 auto; padding: .8rem 1rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--text); font-weight: 800; }
.brand:hover { text-decoration: none; }
.brand img { width: 40px; height: 40px; }
.public-main { max-width: 760px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.public-main.narrow { max-width: 460px; padding-top: 3rem; }
.hero { text-align: center; margin-bottom: 1.5rem; }
.hero img { width: 72px; height: 72px; margin-bottom: .75rem; }
.public-footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 0 1rem 2rem; }

.steps { display: flex; gap: .35rem; margin-bottom: 1.25rem; }
.steps li { flex: 1; list-style: none; height: 6px; border-radius: 3px; background: #cbd5e1; }
.steps li.done { background: var(--primary); }
.steps { padding: 0; }
.step-label { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; margin-bottom: .25rem; }

.option-list { display: grid; gap: .75rem; }
.option {
    display: flex; justify-content: space-between; align-items: center; gap: 1rem;
    padding: 1rem 1.1rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
    color: var(--text); box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s;
}
.option:hover { border-color: #93c5fd; text-decoration: none; box-shadow: 0 4px 16px rgba(29, 78, 216, .12); }
.option-title { font-weight: 700; }
.option-arrow { color: var(--primary-600); font-size: 1.4rem; }

.appointment-card { border-left: 4px solid var(--primary); }
.appointment-card .summary { margin-bottom: 1rem; }
.calendar-buttons { display: flex; flex-direction: column; align-items: center; gap: .6rem; margin: .25rem 0 .5rem; }
.calendar-buttons .btn { width: 100%; max-width: 340px; }
.app-version { font-size: .75rem; color: #94a3b8; margin-top: .25rem; }
.sidebar-version { padding: 1rem .7rem .25rem; color: #7c8db5; }
.staff-link { text-align: center; margin: 3rem 0 0; font-size: .8rem; }
.staff-link a { color: #94a3b8; }
.staff-link a:hover { color: var(--muted); }
.discreet { text-align: center; margin-top: 1.5rem; padding: 1rem; border: 1px dashed #cbd5e1; border-radius: var(--radius); color: var(--muted); font-size: .92rem; }

/* ---------- Staff layout ---------- */
.staff { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: #0f1f4d; color: #cbd5e1; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sidebar .brand { color: #fff; padding: .25rem .5rem 1rem; font-size: .95rem; }
.nav-group { margin-bottom: .75rem; }
.nav-title { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: #7c8db5; padding: .5rem .6rem .25rem; font-weight: 700; }
.nav a { display: block; padding: .5rem .7rem; border-radius: 8px; color: #dbe4f5; font-size: .92rem; }
.nav a:hover { background: rgba(255, 255, 255, .08); text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .14); color: #fff; font-weight: 600; }
.nav .sub a { padding-left: 1.4rem; font-size: .87rem; }
.staff-main { min-width: 0; }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); padding: .7rem 1.5rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; position: sticky; top: 0; z-index: 5; }
.topbar .user { display: flex; align-items: center; gap: .75rem; font-size: .9rem; }
.content { padding: 1.5rem; max-width: 1280px; }
.page-header { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: center; margin-bottom: 1.25rem; }
.page-header h1 { margin: 0; }
.menu-toggle { display: none; background: none; border: 1px solid var(--border); border-radius: 8px; padding: .4rem .6rem; font-size: 1.2rem; cursor: pointer; }
.tabs { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: 1rem; }
.tabs a { padding: .45rem .9rem; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: .88rem; font-weight: 600; }
.tabs a.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.tabs a:hover { text-decoration: none; }
.class-checks { display: grid; gap: .4rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); margin-top: .5rem; padding-left: 1.6rem; }
.year-block { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.year-block:last-child { border-bottom: 0; }
.progress { height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; min-width: 80px; }
.progress span { display: block; height: 100%; background: var(--primary-600); }
.login-box { max-width: 400px; margin: 8vh auto; padding: 0 1rem; }

.pagination { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: 1rem; list-style: none; padding: 0; }
.pagination a, .pagination span { display: inline-block; padding: .4rem .75rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); font-size: .88rem; color: var(--text); }
.pagination .active span { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination .disabled span { color: #94a3b8; }

@media (max-width: 900px) {
    .staff { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: 270px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
    body.menu-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(15, 23, 42, .45); }
    .menu-toggle { display: inline-block; }
    .content { padding: 1rem; }
    .topbar { padding: .6rem 1rem; }
}

@media (max-width: 560px) {
    body { font-size: 15px; }
    h1 { font-size: 1.35rem; }
    .card { padding: 1.1rem; }
    .slot-grid { grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); }
    .actions .btn { flex: 1 1 auto; }
    .topbar .user .role { display: none; }
    .summary { grid-template-columns: 1fr; }
    .summary dt { border-bottom: 0; padding-bottom: .1rem; background: none; font-size: .8rem; }
    .summary dd { padding-top: 0; }
}

@media print {
    .sidebar, .topbar, .filters, .actions, .btn { display: none !important; }
    .staff { display: block; }
    body { background: #fff; }
}
