:root {
    --navy: #1c2d5b;
    --navy-soft: #2d4376;
    --blue: #ebf4ff;
    --blue-strong: #4c8bf5;
    --white: #ffffff;
    --bg: #eef4fb;
    --panel: #f8fbff;
    --text: #1e2c44;
    --muted: #5b6d88;
    --border: #dfeaf8;
    --green: #3bbd8a;
    --warning:#f2a957;
    --danger:#e66161;
    --shadow: 0 14px 32px rgba(31, 61, 112, 0.08);
}

* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a { text-decoration: none; }
body { min-height: 100vh; overflow-x: hidden; }
.auth-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    min-height: 100vh;
    padding: 32px;
    background: linear-gradient(135deg, #f4f8ff, #eaf1fd);
}
.login-shell {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(390px, 0.85fr);
    width: min(1120px, 100%);
    min-height: 640px;
    overflow: hidden;
    background: var(--white);
    border: 1px solid rgba(223, 234, 248, 0.9);
    border-radius: 28px;
    box-shadow: 0 24px 64px rgba(31, 61, 112, 0.14);
    margin: auto 0;
}
.auth-body .powered-by-footer,
.app-shell > .powered-by-footer {
    width: min(1120px, calc(100% - 30px));
    justify-self: center;
}
.app-shell > .powered-by-footer { grid-area: footer; }
.login-illustration {
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: linear-gradient(145deg, #e7f1ff, #f4f8ff 58%, #dceaff);
}
.login-illustration img {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 25% center;
    -webkit-mask-image: radial-gradient(ellipse 120% 120% at center, #000 62%, rgba(0, 0, 0, 0.8) 82%, transparent 100%);
    mask-image: radial-gradient(ellipse 120% 120% at center, #000 62%, rgba(0, 0, 0, 0.8) 82%, transparent 100%);
}
.login-card {
    align-self: center;
    width: 100%;
    max-width: 500px;
    justify-self: center;
    background: var(--white);
    padding: 56px 48px;
}
.brand-block {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 42px;
}
.brand-mark {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    border-radius: 15px;
    background: linear-gradient(135deg, var(--navy), #3d71d6);
    color: var(--white);
    font-size: 32px;
    font-weight: 700;
}
.brand-logo {
    width: 52px;
    height: 52px;
    flex: 0 0 auto;
    object-fit: contain;
}
.brand-block h1 { margin: 0; font-size: 1.55rem; color: var(--navy); }
.brand-block p { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.login-welcome { margin-bottom: 28px; }
.login-welcome h2 { margin: 0; color: var(--text); font-size: 1.8rem; }
.login-welcome p { margin: 8px 0 0; color: var(--muted); line-height: 1.6; }
.auth-form { display: grid; gap: 16px; }
.auth-form label, .student-form label { display: grid; gap: 8px; color: var(--text); font-weight: 600; }
.auth-form input, .student-form input, .student-form select, .student-form textarea, .toolbar-form input, .toolbar-form select, .search-inline input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    font-size: 0.95rem;
    background: #fdfefe;
    color: var(--text);
}
.auth-form input { min-height: 48px; background: #f8fbff; }
.password-field {
    position: relative;
    width: 100%;
}
.password-field input { width: 100%; padding-right: 48px; }
.password-toggle {
    position: absolute;
    top: 50%;
    right: 8px;
    display: grid;
    width: 34px;
    height: 34px;
    padding: 0;
    place-items: center;
    transform: translateY(-50%);
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
}
.password-toggle:hover { background: var(--blue); color: var(--navy); }
.password-toggle:focus-visible { outline: 2px solid var(--blue-strong); outline-offset: 2px; }
.password-icon { width: 20px; height: 20px; fill: currentColor; }
.password-icon-pupil { fill: #f8fbff; }
.password-icon-slash-back, .password-icon-slash-front { fill: none; stroke-linecap: round; }
.password-icon-slash-back { stroke: #f8fbff; stroke-width: 5; }
.password-icon-slash-front { stroke: currentColor; stroke-width: 2.2; }
.password-icon-hide { display: none; }
.password-toggle[aria-pressed="true"] .password-icon-show { display: none; }
.password-toggle[aria-pressed="true"] .password-icon-hide { display: block; }
.auth-form input:focus, .student-form input:focus, .student-form textarea:focus, .student-form select:focus { outline: 2px solid rgba(76, 139, 245, 0.15); border-color: var(--blue-strong); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    padding: 11px 18px;
}
.btn.primary { background: var(--blue-strong); color: var(--white); }
.btn.secondary { background: var(--blue); color: var(--navy); }
.btn.logout-btn { background: rgba(255,255,255,0.08); color: var(--white); width: 100%; }
.full { width: 100%; }
.small { padding: 8px 12px; font-size: 0.8rem; }

.app-shell {
    display: grid;
    grid-template-areas: "sidebar content" "sidebar footer";
    grid-template-columns: 260px minmax(0, 1fr);
    grid-template-rows: minmax(auto, 1fr) auto;
    min-height: 100vh;
}
.app-shell > * { min-width: 0; }
.app-shell > .main-content { grid-area: content; }
.sidebar {
    grid-area: sidebar;
    background: var(--navy);
    color: var(--white);
    display: flex;
    flex-direction: column;
    padding: 24px 18px;
}
.sidebar-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sidebar-panel { display: flex; flex: 1; min-height: 0; flex-direction: column; gap: 14px; }
.sidebar-toggle {
    min-height: 44px;
    padding: 0 12px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--white);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.sidebar-toggle:focus-visible { outline: 2px solid #b5d1ff; outline-offset: 3px; }
.sidebar-toggle[aria-expanded="true"] { background: rgba(255, 255, 255, 0.2); }
.sidebar :is(.sidebar-panel, .sidebar-toggle)[hidden] { display: none; }
.brand-box {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 32px;
}
.brand-box .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    font-size: 24px;
}
.brand-box .brand-logo {
    width: 42px;
    height: 42px;
}
.brand-box h1 { margin: 0; font-size: 1.25rem; }
.brand-box small { color: rgba(255,255,255,0.75); }
.nav-menu { display: grid; gap: 10px; }
.nav-item {
    display: block;
    padding: 12px 14px;
    border-radius: 12px;
    color: rgba(255,255,255,0.82);
    background: transparent;
}
.nav-item.active, .nav-item:hover {
    background: rgba(255,255,255,0.09);
    color: var(--white);
}
.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 12px;
}
.user-card {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 12px 14px;
    display: grid;
    gap: 2px;
}
.user-card small { color: rgba(255,255,255,0.7); }

.main-content {
    min-width: 0;
    padding: 28px;
}
.powered-by-footer {
    display: grid;
    align-items: center;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    gap: 20px 32px;
    margin: 0 15px 15px;
    padding: 14px 28px;
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    color: var(--muted);
    font-size: 0.8125rem;
    font-weight: 700;
    letter-spacing: 0.08em;
}
.footer-copyright {
    justify-self: start;
    color: var(--muted);
    font-size: 0.8125rem;
    letter-spacing: 0.04em;
}
.powered-by-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    justify-self: center;
    gap: 8px;
}
.powered-by-brand img {
    display: block;
    width: auto;
    max-width: 120px;
    height: 32px;
    object-fit: contain;
}
.footer-registration {
    display: flex;
    align-items: center;
    justify-self: end;
    gap: 10px;
    letter-spacing: normal;
}
.footer-registration img {
    display: block;
    width: auto;
    height: 68px;
    object-fit: contain;
}
.footer-registration p {
    display: grid;
    gap: 3px;
    margin: 0;
    color: var(--text);
    font-size: 0.8125rem;
    line-height: 1.25;
}
.footer-registration strong { color: var(--navy); }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 28px;
}
.topbar h2 { margin: 0; font-size: 2rem; }
.topbar p { margin: 5px 0 0; color: var(--muted); }
.topbar-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.user-pill {
    background: var(--white);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 10px 16px;
    font-weight: 600; 
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
    margin-bottom: 24px;
}
.stat-card {
    display: flex;
    align-items: center;
    background: var(--white);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 20px;
    gap: 16px;
}
.stat-card h3 { margin: 0; font-size: 2.1rem; }
.stat-card p { margin: 6px 0 0; color: var(--muted); }
.icon {
    width: 52px;
    height: 52px;
    display: grid;
    place-items: center;
    color: var(--blue-strong);
}
.icon svg {
    width: 30px;
    height: 30px;
}
.icon.blue {
    border-radius: 16px;
    background: var(--blue-strong);
    color: var(--white);
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1.2fr 1fr;
    gap: 20px;
}
.panel {
    min-width: 0;
    background: var(--white);
    border-radius: 24px;
    padding: 22px;
    box-shadow: var(--shadow);
}
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
}
.panel-header h3 { margin: 0; }
.panel-header.split { align-items: end; }
.quick-links { display: flex; gap: 12px; margin-top: 20px; }
.search-inline, .toolbar-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
.search-inline input, .toolbar-form input, .toolbar-form select {
    flex: 1 1 180px;
    min-width: 0;
}
.visit-list { display: grid; gap: 12px; }
.visit-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.visit-item strong { display: block; }
.visit-item small, .muted { color: var(--muted); }

.table-wrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}
th, td {
    padding: 14px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.empty-cell { text-align: center; color: var(--muted); padding: 24px; }
.tiny-link { color: var(--blue-strong); font-weight: 600; }

.form-panel { margin-top: 20px; }
.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
.form-grid > * { min-width: 0; }
.form-grid .wide { grid-column: 1 / -1; }
.student-form textarea { min-height: 110px; resize: vertical; }
.student-search-field { align-content: start; }
.field-hint { color: var(--muted); font-size: 0.82rem; font-weight: 400; }
.tooth-chart {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 14px;
}
.dental-workspace { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(280px, 0.75fr); align-items: start; gap: 18px; }
.dental-chart-panel, .dental-details-panel { min-width: 0; border-radius: 16px; }
.dental-chart-panel { background: #f7faff; }
.dental-details-panel { display: grid; gap: 16px; padding: 18px; border: 1px solid var(--border); background: var(--white); }
.dental-section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.dental-section-heading h4 { margin: 0; font-size: 1.05rem; }
.dental-section-heading p { margin: 5px 0 0; font-size: 0.88rem; }
.tooth-count { flex: 0 0 auto; padding: 6px 10px; border-radius: 999px; background: var(--blue); color: var(--navy); font-size: 0.8rem; font-weight: 700; }
.dental-chart-scroll { width: 100%; overflow-x: auto; padding: 8px 0; }
.dental-chart-svg { display: block; width: 100%; min-width: 340px; max-height: 390px; margin: 0 auto; }
.dental-arch { fill: none; stroke: #d8e4f2; stroke-width: 2; stroke-dasharray: 4 5; }
.dental-tooth { cursor: pointer; outline: none; }
.dental-tooth rect { fill: var(--white); stroke: #9badc4; stroke-width: 1.5; transition: fill 0.15s ease, stroke 0.15s ease, transform 0.15s ease; }
.dental-tooth text { fill: var(--text); font-size: 8px; font-weight: 700; pointer-events: none; }
.dental-tooth:hover rect, .dental-tooth:focus rect { stroke: var(--blue-strong); stroke-width: 2.5; }
.dental-tooth.is-selected rect { fill: var(--blue-strong); stroke: #2c68ce; }
.dental-tooth.is-selected text { fill: var(--white); }
.dental-legend { display: flex; flex-wrap: wrap; gap: 14px; margin: 0 0 14px; color: var(--muted); font-size: 0.8rem; }
.dental-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-tooth { width: 13px; height: 13px; border: 1px solid #9badc4; border-radius: 5px; background: var(--white); }
.legend-tooth.selected { border-color: #2c68ce; background: var(--blue-strong); }
.dental-findings { display: grid; gap: 10px; }
.dental-empty-state { margin: 0; padding: 14px; border: 1px dashed var(--border); border-radius: 12px; color: var(--muted); text-align: center; font-size: 0.9rem; }
.dental-finding-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--white); }
.dental-finding-label { min-width: 0; }
.dental-finding-label input { min-width: 0; }
.dental-student-summary { display: grid; gap: 8px; padding: 12px; border-radius: 12px; background: var(--panel); }
.dental-student-summary div { display: grid; gap: 3px; min-width: 0; }
.dental-student-summary span { color: var(--muted); font-size: 0.78rem; }
.dental-student-summary strong { overflow-wrap: anywhere; font-size: 0.9rem; }
.dental-details-panel > label { min-width: 0; }
.dental-hidden-input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; }
.address-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
}
.address-grid > * { min-width: 0; }
.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 22px;
}
.filters { width: 100%; }

.profile-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 20px;
}
.profile-details, .summary-block {
    display: grid;
    gap: 14px;
}
.profile-details div, .summary-block div {
    display: grid;
    gap: 6px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}
.profile-details strong, .summary-block strong { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; }

.section-group {
    margin-top: 28px;
    background: var(--panel);
    border-radius: 16px;
    padding: 18px;
    border: 1px solid var(--border);
}
.section-group h4 { margin-top: 0; }
.entry-list { display: grid; gap: 12px; margin-top: 14px; }
.entry-row {
    display: grid;
    grid-template-columns: 1.3fr 1.3fr 0.9fr 1.5fr;
    gap: 10px;
}
.add-row { margin-top: 12px; }

.pagination {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 18px;
}
.page-link {
    display: inline-flex;
    width: 34px;
    height: 34px;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    background: var(--blue);
    color: var(--navy);
    font-weight: 600;
}
.page-link.active {
    background: var(--blue-strong);
    color: var(--white);
}

.flash {
    margin-bottom: 20px;
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 600;
}
.flash.success { background: rgba(59,189,138,0.12); color: #0e8a5f; }
.flash.error { background: rgba(230,97,97,0.12); color: #b33232; }

.inventory-stock-tools {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 16px;
}
.inventory-fields, .medication-lines { display: grid; gap: 12px; }
.inventory-nav { min-width: max-content; }
.inventory-nav summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    list-style: none;
    cursor: pointer;
}
.inventory-nav summary::-webkit-details-marker { display: none; }
.inventory-nav summary::after {
    content: "";
    flex: none;
    width: 7px;
    height: 7px;
    border: solid currentColor;
    border-width: 0 1.5px 1.5px 0;
    transform: rotate(45deg);
    transition: transform var(--motion, 180ms ease);
}
.inventory-nav[open] summary::after { transform: rotate(225deg); }
.inventory-nav-links {
    display: grid;
    gap: 4px;
    margin: 6px 0 0 10px;
    padding-left: 6px;
    border-left: 1px solid rgba(255, 255, 255, 0.24);
}
.inventory-nav-links .nav-item { font-size: 0.9rem; }
.inventory-page .toolbar-form { margin-bottom: 12px; }
.stock-receipt-lines { display: grid; gap: 14px; margin-top: 18px; }
.stock-receipt-line { min-width: 0; margin: 0; }
.stock-receipt-line legend { padding: 0 6px; font-weight: 700; }
.stock-receipt-details {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 165px), 1fr));
    gap: 12px;
    margin-top: 12px;
}
.stock-receipt-line [data-remove-stock-receipt-line] { margin-top: 12px; }
:is([data-stock-receipt], [data-inventory-create]) [hidden] { display: none; }
[data-inventory-create] .inventory-name-matches {
    margin-top: 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--white);
}
.inventory-name-matches p { margin: 0; padding: 9px 12px; }
.inventory-name-matches ul { margin: 0; padding: 0; list-style: none; }
.inventory-name-matches ul:not(:empty) { max-height: 230px; overflow-y: auto; }
.inventory-name-matches a {
    display: grid;
    gap: 3px;
    padding: 9px 12px;
    border-top: 1px solid var(--border);
    color: var(--navy);
    text-decoration: none;
    overflow-wrap: anywhere;
}
.inventory-name-matches a:is(:hover, :focus-visible) { background: var(--blue); }
.inventory-name-matches a:focus-visible { outline-offset: -3px; }
.inventory-name-matches small { color: var(--muted); }
[data-add-stock-receipt-line]:disabled { opacity: .6; cursor: default; }
.stock-status {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.8125rem;
    font-weight: 600;
    white-space: nowrap;
}
.stock-available { color: #176044; background: #e0f2ea; }
.stock-low { color: #785017; background: #fff0d6; }
.stock-out { color: #932e36; background: #fce6e8; }
.stock-urgent { color: #863a14; background: #ffe4d3; }
.stock-neutral { color: #52627a; background: #eaf0f8; }
.stock-expire-button { color: #932e36; background: #fce6e8; }
.stock-expire-button:hover { background: #f7d4d8; }
.student-form .medication-toggle {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
}
.student-form .medication-toggle input {
    width: 18px;
    height: 18px;
    margin: 0;
    accent-color: var(--accent, var(--navy));
}
.medication-fields {
    min-inline-size: 0;
    margin: 10px 0 0;
    padding: 0;
    border: 0;
}
.medication-fields legend { padding: 0; margin-bottom: 12px; }
.medication-line { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
.medication-line label:first-child { min-width: 0; flex: 1 1 270px; }
.medication-line label:nth-child(2) { flex: 0 1 145px; }
.medication-fields > .btn { margin-top: 12px; }
.medication-stock-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}
.medication-fields button[hidden] { display: none; }
.medication-fields .btn:disabled, .medication-stock-actions .btn:disabled { opacity: 0.6; cursor: default; }

@media screen {
    :root {
        --glass: rgba(255, 255, 255, 0.78);
        --glass-edge: rgba(255, 255, 255, 0.92);
        --glass-shadow: 0 12px 36px rgba(28, 45, 91, 0.1), inset 0 1px 0 rgba(255, 255, 255, 0.75);
        --accent: #285fbe;
        --accent-hover: #204d9e;
        --hover-tint: #e6efff;
        --motion: 180ms cubic-bezier(0.2, 0.7, 0.25, 1);
        --page-background: radial-gradient(ellipse at 12% 4%, #dceafa, transparent 52%),
            radial-gradient(ellipse at 100% 20%, #d9e6fb, transparent 60%),
            linear-gradient(150deg, #f6f9fd, #eaf1fb);
    }

    .auth-body, .app-shell {
        background: var(--page-background);
    }
    .sidebar {
        background: linear-gradient(155deg, #2a4379, var(--navy) 58%, #162449);
    }
    .nav-item.active {
        background: rgba(255, 255, 255, 0.16);
        box-shadow: inset 3px 0 0 #a3c5ff;
    }
    .user-card {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.18);
    }

    .auth-body > .login-shell,
    .auth-body > .powered-by-footer,
    .app-shell > .powered-by-footer,
    .app-shell :is(.panel, .stat-card, .user-pill) {
        background: var(--glass);
        border: 1px solid var(--glass-edge);
        box-shadow: var(--glass-shadow);
        -webkit-backdrop-filter: blur(12px);
        backdrop-filter: blur(12px);
    }
    .login-card { background: transparent; }
    .app-shell :is(.section-group, .dental-details-panel, .dental-student-summary) {
        background: rgba(239, 246, 255, 0.78);
    }

    :is(.auth-body, .app-shell) :is(.btn, .nav-item, .page-link, .password-toggle, .tiny-link) {
        transition: background-color var(--motion), color var(--motion),
            box-shadow var(--motion), transform var(--motion);
    }
    :is(.auth-body, .app-shell) .btn.primary,
    .app-shell .page-link.active {
        background: var(--accent);
    }
    .app-shell .tiny-link { color: var(--accent); }

    :is(.auth-body, .app-shell) :is(.btn, .nav-item, .page-link, .password-toggle, .tiny-link):focus-visible {
        outline: 2px solid var(--accent);
        outline-offset: 3px;
    }
    .sidebar :is(.nav-item, .logout-btn):focus-visible { outline-color: #b5d1ff; }

    :is(.auth-form, .student-form, .toolbar-form, .search-inline) :is(input, select, textarea) {
        transition: background-color var(--motion), border-color var(--motion), box-shadow var(--motion);
    }
    :is(.auth-form, .student-form, .toolbar-form, .search-inline) :is(input, select, textarea):focus {
        background-color: var(--white);
        border-color: var(--accent);
        outline: 2px solid transparent;
        box-shadow: 0 0 0 3px rgba(40, 95, 190, 0.18);
    }

    .app-shell :is(tbody td, .visit-item, .stat-card) {
        transition: background-color var(--motion), box-shadow var(--motion), transform var(--motion);
    }
    .app-shell tbody tr:focus-within > td { background-color: var(--hover-tint); }
}

@media screen and (hover: hover) and (pointer: fine) {
    :is(.auth-body, .app-shell) .btn.primary:not(:disabled):hover { background: var(--accent-hover); }
    .app-shell :is(.btn.secondary, .page-link:not(.active)):hover { background: #d9e7fc; }
    .sidebar .btn.logout-btn:hover,
    .sidebar .nav-item:hover { background: rgba(255, 255, 255, 0.19); }
    .app-shell .tiny-link:hover {
        color: var(--accent-hover);
        text-decoration: underline;
        text-underline-offset: 3px;
    }
    .app-shell tbody tr:hover > td,
    .app-shell .visit-item:hover { background-color: var(--hover-tint); }
    :is(.auth-body, .app-shell) .btn:enabled:hover,
    .app-shell a.btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 5px 13px rgba(28, 45, 91, 0.2);
    }
    :is(.auth-body, .app-shell) .btn:active { transform: translateY(0); }
    .app-shell .stat-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 15px 38px rgba(28, 45, 91, 0.15);
    }
}

@media screen and (prefers-reduced-motion: no-preference) {
    .auth-body > .login-shell, .app-shell .topbar {
        animation: enter-view 360ms cubic-bezier(0.2, 0.7, 0.25, 1);
    }
    @keyframes enter-view {
        from { opacity: 0; transform: translateY(6px); }
        to { opacity: 1; transform: translateY(0); }
    }
}

@media screen and (prefers-reduced-motion: reduce) {
    :root { --motion: 0ms; }
    :is(.auth-body, .app-shell) .btn:hover,
    .app-shell .stat-card:hover { transform: none; }
    .app-shell .dental-tooth rect { transition: none; }
}

@media screen and (min-width: 981px) and (max-height: 780px) {
    .sidebar {
        align-self: start;
        position: sticky;
        top: 0;
        height: 100vh;
        height: 100dvh;
        padding: 14px;
    }
    .sidebar .brand-box { margin-bottom: 14px; gap: 10px; }
    .sidebar .brand-logo { width: 36px; height: 36px; }
    .sidebar .nav-menu { gap: 3px; overflow-y: auto; padding: 4px; margin: -4px; }
    .sidebar .nav-item { padding: 8px 12px; }
    .sidebar-footer { gap: 6px; }
    .sidebar .user-card { padding: 8px 12px; }
}

@media (max-width: 980px) {
    .app-shell {
        grid-template-areas: "sidebar" "content" "footer";
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto 1fr auto;
    }
    .sidebar { padding: 8px 16px; gap: 10px; }
    .brand-box { margin-bottom: 0; }
    .sidebar-panel { gap: 8px; }
    .nav-menu {
        grid-template-columns: repeat(auto-fit, minmax(min(100%, 145px), 1fr));
        align-items: start;
        gap: 4px;
    }
    .sidebar .nav-item { display: flex; align-items: center; min-height: 44px; padding: 6px 10px; }
    .inventory-nav { min-width: 0; }
    .inventory-nav-links { margin-left: 6px; }
    .sidebar-footer { display: flex; align-items: center; gap: 8px; margin: 0 0 4px; }
    .user-card { flex: 1; min-width: 0; padding: 8px 10px; }
    .user-card strong, .user-card small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .sidebar-footer .logout-btn { width: auto; min-height: 44px; padding: 8px 12px; }
    .main-content { padding: 22px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dashboard-grid, .profile-grid { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .entry-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .address-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .login-shell { grid-template-columns: minmax(0, 1fr) minmax(360px, 0.9fr); min-height: 580px; }
    .login-card { padding: 44px 36px; }
}

@media (max-width: 760px) {
    .powered-by-footer { grid-template-columns: 1fr; justify-items: center; margin: 0 10px 10px; padding: 16px; }
    .footer-copyright, .powered-by-brand, .footer-registration { justify-self: center; }
    .footer-copyright { text-align: center; }
    .main-content { padding: 18px; }
    .topbar { align-items: flex-start; flex-direction: column; gap: 14px; margin-bottom: 20px; }
    .topbar h2 { font-size: 1.7rem; }
    .topbar-actions { width: 100%; }
    .topbar-actions .btn { flex: 1 1 auto; }
    .panel { padding: 18px; border-radius: 18px; }
    .panel-header, .panel-header.split { align-items: flex-start; flex-direction: column; gap: 12px; }
    .filters, .toolbar-form { width: 100%; }
    .toolbar-form > * { flex: 1 1 100%; }
    .quick-links { flex-wrap: wrap; }
    .quick-links .btn { flex: 1 1 180px; }
    .form-grid { grid-template-columns: 1fr; gap: 14px; }
    .form-grid .wide { grid-column: auto; }
    .section-group { padding: 14px; }
    .entry-row { grid-template-columns: 1fr; }
    .dental-workspace { grid-template-columns: 1fr; }
    .dental-details-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .dental-details-panel .dental-section-heading, .dental-details-panel .dental-student-summary,
    .dental-details-panel > label:last-child { grid-column: 1 / -1; }
    .visit-item { align-items: flex-start; flex-wrap: wrap; }
    .visit-item > * { min-width: 40%; }
    .form-actions { flex-wrap: wrap; }
    .form-actions .btn { flex: 1 1 140px; }
    .login-shell { grid-template-columns: 1fr; min-height: 0; }
    .login-illustration { min-height: 220px; }
    .login-card { max-width: 560px; }
}

@media (max-width: 580px) {
    .address-grid { grid-template-columns: 1fr; }
    .sidebar { padding-inline: 12px; }
    .brand-box { gap: 10px; }
    .brand-box h1 { font-size: 1.05rem; }
    .brand-box small { font-size: 0.75rem; }
    .brand-box .brand-logo { width: 36px; height: 36px; }
    .sidebar .nav-menu { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .sidebar .nav-item { font-size: 0.9rem; }
    .main-content { padding: 14px; }
    .topbar h2 { font-size: 1.5rem; }
    .topbar-actions { gap: 8px; }
    .topbar-actions .btn { flex-basis: 100%; }
    .stats-grid { grid-template-columns: 1fr; gap: 12px; }
    .stat-card { padding: 16px; border-radius: 16px; }
    .stat-card h3 { font-size: 1.8rem; }
    .panel { padding: 15px; border-radius: 16px; }
    .search-inline, .toolbar-form { align-items: stretch; flex-direction: column; }
    .search-inline > *, .toolbar-form > * { width: 100%; flex-basis: auto; }
    .form-actions .btn { flex-basis: 100%; }
    .pagination { flex-wrap: wrap; }
    th, td { padding: 11px 10px; }
    .table-wrap table { min-width: 680px; }
    .dental-details-panel { grid-template-columns: 1fr; }
    .dental-details-panel .dental-section-heading, .dental-details-panel .dental-student-summary,
    .dental-details-panel > label:last-child { grid-column: auto; }
    .dental-finding-row { grid-template-columns: 1fr; }
    .dental-chart-svg { min-width: 310px; }
    .auth-form input, .student-form input, .student-form select, .student-form textarea,
    .toolbar-form input, .toolbar-form select, .search-inline input { font-size: 16px; }
    .auth-body { padding: 16px; }
    .login-shell { grid-template-columns: 1fr; min-height: 0; border-radius: 22px; }
    .login-illustration { min-height: 190px; }
    .login-card { max-width: none; padding: 30px 24px; }
    .brand-block { margin-bottom: 30px; }
    .login-welcome h2 { font-size: 1.55rem; }
}
