:root {
    --brand-navy: #07466f;
    --brand-navy-dark: #04334f;
    --brand-navy-soft: #eaf1f6;
    --brand-red: #b42f38;
    --brand-red-dark: #92242c;
    --brand-red-soft: #f8ecee;
    --ink: #17344a;
    --muted: #71808d;
    --line: #dfe6ec;
    --surface: #ffffff;
    --page: #f4f7fa;
    --green: #159447;
    --green-soft: #e7f7ed;
    --gold: #f0b429;
    --shadow: 0 24px 65px rgba(7, 70, 111, .12);
    --shadow-soft: 0 12px 34px rgba(23, 52, 74, .07);
}

* { box-sizing: border-box; }
html { min-height: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background: var(--page);
    font-family: "Cairo", Tahoma, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button { cursor: pointer; }
input::placeholder { color: #9ba8b3; }

.eyebrow {
    margin: 0 0 8px;
    color: var(--brand-red);
    font-size: .78rem;
    font-weight: 800;
    letter-spacing: .04em;
}
.muted { color: var(--muted); }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    padding: 0 20px;
    border: 1px solid transparent;
    border-radius: 12px;
    font-weight: 800;
    transition: transform .2s ease, box-shadow .2s ease, background .2s ease, border-color .2s ease;
}
.button:hover { transform: translateY(-2px); }
.button.primary {
    color: #fff;
    background: linear-gradient(135deg, var(--brand-navy), var(--brand-navy-dark));
    box-shadow: 0 12px 26px rgba(7, 70, 111, .22);
}
.button.primary:hover { box-shadow: 0 16px 32px rgba(7, 70, 111, .28); }
.button.secondary {
    color: var(--brand-navy);
    background: var(--brand-navy-soft);
    border-color: #c9d9e5;
}
.button.secondary:hover { background: #dfeaf2; }
.button.wide { width: 100%; }

.alert {
    padding: 14px 17px;
    margin: 0 0 20px;
    border-radius: 12px;
    font-weight: 700;
}
.alert.success { color: #166534; background: #dcfce7; border: 1px solid #bbf7d0; }
.alert.error { color: #991b1b; background: #fee2e2; border: 1px solid #fecaca; }

/* Public page */
.public-page {
    position: relative;
    min-height: 100vh;
    overflow: hidden;
    background:
        linear-gradient(180deg, rgba(255,255,255,.72), rgba(244,247,250,.96)),
        var(--page);
}
.public-page::before {
    content: "";
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image:
        linear-gradient(rgba(7,70,111,.018) 1px, transparent 1px),
        linear-gradient(90deg, rgba(7,70,111,.018) 1px, transparent 1px);
    background-size: 42px 42px;
    mask-image: linear-gradient(to bottom, rgba(0,0,0,.5), transparent 70%);
}
.site-decoration {
    position: absolute;
    border-radius: 999px;
    pointer-events: none;
}
.decoration-pink {
    width: 190px;
    height: 190px;
    top: 44px;
    left: -78px;
    background: #f1e8ec;
}
.decoration-blue {
    width: 310px;
    height: 310px;
    right: -170px;
    bottom: -145px;
    border: 52px solid rgba(7, 70, 111, .055);
}
.decoration-red {
    width: 22px;
    height: 150px;
    left: 8%;
    bottom: 9%;
    border-radius: 20px;
    transform: rotate(34deg);
    background: rgba(180, 47, 56, .08);
}
.public-header {
    position: relative;
    z-index: 4;
    width: min(1120px, calc(100% - 40px));
    margin: 0 auto;
    padding: 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    border-bottom: 1px solid rgba(7, 70, 111, .08);
}
.public-brand {
    display: flex;
    align-items: center;
    gap: 13px;
}
.public-brand > span,
.brand-mark {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    flex: 0 0 48px;
    border-radius: 13px;
    color: #fff;
    background: var(--brand-navy);
    font-size: 1.35rem;
    font-weight: 900;
    box-shadow: 0 10px 24px rgba(7, 70, 111, .2);
    position: relative;
    overflow: hidden;
}
.public-brand > span::after,
.brand-mark::after {
    content: "";
    position: absolute;
    width: 17px;
    height: 60px;
    left: -7px;
    top: -8px;
    transform: rotate(24deg);
    background: var(--brand-red);
}
.public-brand > span,
.brand-mark { isolation: isolate; }
.public-brand > span::after,
.brand-mark::after { z-index: -1; }
.public-brand strong,
.public-brand small { display: block; }
.public-brand strong { font-size: .94rem; color: var(--brand-navy-dark); }
.public-brand small { margin-top: 2px; color: var(--muted); font-size: .76rem; }
.admin-login-link {
    padding: 10px 17px;
    border: 1px solid rgba(7, 70, 111, .23);
    border-radius: 999px;
    color: var(--brand-navy);
    background: rgba(255,255,255,.8);
    font-size: .82rem;
    font-weight: 800;
    box-shadow: 0 7px 20px rgba(7, 70, 111, .06);
    transition: background .2s ease, color .2s ease, transform .2s ease;
}
.admin-login-link:hover {
    color: #fff;
    background: var(--brand-navy);
    transform: translateY(-1px);
}

.hero {
    position: relative;
    z-index: 2;
    width: min(1035px, calc(100% - 40px));
    min-height: calc(100vh - 115px);
    margin: 0 auto;
    padding: 58px 0 105px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.hero-copy {
    max-width: 820px;
    margin: 0 auto 34px;
    text-align: center;
}
.section-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 25px;
    border-radius: 999px;
    color: #fff;
    background: var(--brand-navy);
    box-shadow: 0 10px 25px rgba(7, 70, 111, .16);
    font-size: .82rem;
    font-weight: 800;
}
.hero-copy h1 {
    margin: 24px 0 10px;
    color: var(--brand-navy);
    font-size: clamp(2.1rem, 4.6vw, 3.75rem);
    line-height: 1.25;
    letter-spacing: -.035em;
}
.hero-copy p {
    max-width: 760px;
    margin: 0 auto;
    color: var(--muted);
    font-size: 1rem;
    line-height: 2;
}
.search-card {
    position: relative;
    width: min(760px, 100%);
    padding: 34px 39px 38px;
    overflow: hidden;
    border: 1px solid #e1e7ec;
    border-radius: 24px;
    background: rgba(255,255,255,.96);
    box-shadow: var(--shadow);
    text-align: right;
}
.search-card::after {
    content: "";
    position: absolute;
    width: 110px;
    height: 110px;
    top: -58px;
    left: -48px;
    border-radius: 50%;
    background: var(--brand-red-soft);
}
.card-accent {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 7px;
}
.card-accent-right { right: 0; background: var(--brand-navy); }
.card-accent-left { left: 0; background: var(--brand-red); }
.search-icon {
    position: relative;
    z-index: 2;
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    border-radius: 14px;
    color: #fff;
    background: var(--brand-navy);
    box-shadow: 0 12px 25px rgba(7, 70, 111, .2);
}
.search-card h2 {
    margin: 20px 0 5px;
    color: var(--brand-navy);
    font-size: 1.55rem;
}
.search-card > p {
    margin: 0 0 25px;
    color: var(--muted);
    font-size: .88rem;
    line-height: 1.85;
}
.result-search-form label {
    display: block;
    margin-bottom: 8px;
    color: var(--ink);
    font-size: .86rem;
    font-weight: 800;
}
.input-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}
.input-row input {
    min-width: 0;
    height: 56px;
    padding: 0 17px;
    border: 1px solid #cfd9e1;
    border-radius: 12px;
    outline: 0;
    background: #fff;
    color: var(--ink);
    direction: ltr;
    text-align: right;
    transition: border-color .2s ease, box-shadow .2s ease;
}
.input-row input:focus {
    border-color: var(--brand-navy);
    box-shadow: 0 0 0 4px rgba(7, 70, 111, .11);
}
.input-row button {
    min-width: 145px;
    padding: 0 22px;
    border: 0;
    border-radius: 12px;
    color: #fff;
    background: linear-gradient(135deg, var(--brand-navy), var(--brand-navy-dark));
    font-weight: 800;
    box-shadow: 0 12px 25px rgba(7, 70, 111, .22);
    transition: transform .2s ease, box-shadow .2s ease;
}
.input-row button:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 30px rgba(7, 70, 111, .28);
}
.public-footer {
    position: absolute;
    z-index: 3;
    right: 0;
    left: 0;
    bottom: 19px;
    padding: 0 18px;
    color: #82909b;
    text-align: center;
    font-size: .76rem;
}

/* Success */
.public-page.celebrating {
    background:
        radial-gradient(circle at 15% 15%, rgba(180,47,56,.1), transparent 28%),
        radial-gradient(circle at 85% 80%, rgba(7,70,111,.1), transparent 30%),
        #f4f7fa;
}
#celebrationCanvas {
    position: fixed;
    z-index: 10;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.success-stage {
    position: relative;
    z-index: 5;
    min-height: calc(100vh - 105px);
    padding: 45px 20px 85px;
    display: grid;
    place-items: center;
}
.success-card {
    position: relative;
    width: min(610px, 100%);
    padding: 55px 44px 46px;
    overflow: hidden;
    border: 1px solid #dfe6ec;
    border-radius: 28px;
    background: rgba(255,255,255,.97);
    box-shadow: 0 30px 90px rgba(7,70,111,.17);
    text-align: center;
    animation: cardEntrance .95s cubic-bezier(.16,1,.3,1) both;
}
.success-card::before,
.success-card::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
}
.success-card::before { right: 0; background: var(--brand-navy); }
.success-card::after { left: 0; background: var(--brand-red); }
.success-top-line {
    position: absolute;
    top: 0;
    right: 8px;
    left: 8px;
    height: 6px;
    background: linear-gradient(90deg, var(--brand-red), var(--gold), var(--brand-navy));
}
.success-ring {
    position: relative;
    width: 112px;
    height: 112px;
    margin: 0 auto 25px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(145deg, #49c676, var(--green));
    box-shadow: 0 0 0 12px var(--green-soft), 0 18px 42px rgba(21,148,71,.25);
    animation: ringPulse 2s ease-in-out infinite;
}
.success-ring::before {
    content: "";
    position: absolute;
    inset: -18px;
    border: 1px solid rgba(21,148,71,.25);
    border-radius: 50%;
    animation: ripple 2.2s ease-out infinite;
}
.success-check {
    font-size: 4.35rem;
    line-height: 1;
    font-weight: 900;
    transform: rotate(-8deg);
    animation: checkPop .8s .4s cubic-bezier(.16,1.4,.3,1) both;
}
.success-kicker {
    margin: 0;
    color: var(--brand-red);
    font-size: .95rem;
    font-weight: 900;
    letter-spacing: .05em;
    animation: fadeUp .7s .45s both;
}
.success-word {
    display: inline-block;
    margin: 11px 0 28px;
    color: var(--brand-navy);
    font-size: clamp(3.2rem, 9vw, 5.8rem);
    line-height: 1.05;
    font-weight: 900;
    letter-spacing: .035em;
    text-shadow: 0 8px 24px rgba(7,70,111,.13);
    animation: successGlow 1.9s .8s ease-in-out infinite, fadeUp .8s .65s both;
}
.success-button {
    color: #fff;
    background: var(--brand-navy);
    box-shadow: 0 12px 30px rgba(7,70,111,.2);
    animation: fadeUp .8s .9s both;
}
.success-button:hover { background: var(--brand-navy-dark); }
.sparkle {
    position: absolute;
    color: var(--gold);
    text-shadow: 0 0 16px rgba(240,180,41,.5);
    animation: sparkle 1.5s ease-in-out infinite;
}
.sparkle-a { right: 13%; top: 18%; font-size: 1.5rem; }
.sparkle-b { left: 12%; top: 30%; font-size: 2.1rem; animation-delay: .35s; }
.sparkle-c { left: 19%; bottom: 22%; font-size: 1.2rem; animation-delay: .7s; }

@keyframes cardEntrance {
    from { opacity: 0; transform: translateY(55px) scale(.84); }
    to { opacity: 1; transform: none; }
}
@keyframes checkPop {
    from { opacity: 0; transform: scale(.2) rotate(-40deg); }
    to { opacity: 1; transform: scale(1) rotate(-8deg); }
}
@keyframes fadeUp {
    from { opacity: 0; transform: translateY(22px); }
    to { opacity: 1; transform: none; }
}
@keyframes ringPulse {
    0%,100% { transform: scale(1); box-shadow: 0 0 0 12px var(--green-soft), 0 18px 42px rgba(21,148,71,.25); }
    50% { transform: scale(1.045); box-shadow: 0 0 0 17px rgba(231,247,237,.7), 0 20px 55px rgba(21,148,71,.34); }
}
@keyframes ripple {
    from { transform: scale(.76); opacity: .9; }
    to { transform: scale(1.42); opacity: 0; }
}
@keyframes successGlow {
    0%,100% { transform: scale(1); filter: brightness(1); }
    50% { transform: scale(1.045); filter: brightness(1.12); }
}
@keyframes sparkle {
    0%,100% { opacity: .25; transform: scale(.65) rotate(0); }
    50% { opacity: 1; transform: scale(1.35) rotate(30deg); }
}

/* Login */
.login-page {
    position: relative;
    min-height: 100vh;
    padding: 35px 20px;
    display: grid;
    place-items: center;
    overflow: hidden;
    background:
        radial-gradient(circle at 8% 8%, #f1e8ec 0 115px, transparent 116px),
        radial-gradient(circle at 93% 92%, rgba(7,70,111,.075) 0 180px, transparent 181px),
        var(--page);
}
.login-card {
    position: relative;
    width: min(470px, 100%);
    padding: 40px;
    overflow: hidden;
    border: 1px solid #dfe6ec;
    border-radius: 24px;
    background: #fff;
    box-shadow: var(--shadow);
}
.login-card::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 6px;
    background: linear-gradient(90deg, var(--brand-red) 0 35%, var(--brand-navy) 35% 100%);
}
.login-brand span {
    display: grid;
    place-items: center;
    width: 62px;
    height: 62px;
    margin-bottom: 24px;
    border-radius: 15px;
    color: #fff;
    background: var(--brand-navy);
    box-shadow: 0 12px 26px rgba(7,70,111,.2);
    font-size: 1.8rem;
    font-weight: 900;
}
.login-card h1 {
    margin: 0 0 6px;
    color: var(--brand-navy);
    font-size: 1.7rem;
}
.back-link {
    display: inline-block;
    margin-bottom: 24px;
    color: var(--muted);
    font-size: .83rem;
    font-weight: 700;
}
.back-link:hover { color: var(--brand-red); }
.stack-form {
    display: grid;
    gap: 17px;
    margin-top: 28px;
}
.stack-form label {
    display: grid;
    gap: 7px;
    color: var(--ink);
    font-size: .85rem;
    font-weight: 800;
}
.stack-form input,
.password-grid input,
.admin-search input {
    height: 48px;
    padding: 0 14px;
    border: 1px solid #ccd7df;
    border-radius: 11px;
    outline: none;
    background: #fff;
    color: var(--ink);
    transition: border-color .2s ease, box-shadow .2s ease;
}
.stack-form input:focus,
.password-grid input:focus,
.admin-search input:focus {
    border-color: var(--brand-navy);
    box-shadow: 0 0 0 4px rgba(7,70,111,.1);
}

/* Admin */
.admin-body { background: #f4f7fa; }
.admin-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 250px 1fr;
}
.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 27px 18px;
    color: #e8f1f6;
    background: linear-gradient(180deg, var(--brand-navy), var(--brand-navy-dark));
    box-shadow: -8px 0 28px rgba(7,70,111,.08);
}
.sidebar::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 6px;
    background: var(--brand-red);
}
.brand-mini {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 5px 8px 25px;
    border-bottom: 1px solid rgba(255,255,255,.12);
}
.brand-mini .brand-mark {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    box-shadow: none;
    background: rgba(255,255,255,.14);
}
.brand-mini strong,
.brand-mini small { display: block; }
.brand-mini small { color: #b8cfdd; font-size: .74rem; }
.sidebar nav {
    display: grid;
    gap: 7px;
    margin-top: 25px;
}
.sidebar nav a {
    position: relative;
    padding: 12px 13px;
    border-radius: 10px;
    color: #d2e2ec;
    font-size: .86rem;
    font-weight: 700;
    transition: background .2s ease, color .2s ease;
}
.sidebar nav a:hover,
.sidebar nav a.active {
    color: #fff;
    background: rgba(255,255,255,.11);
}
.sidebar nav a.active::before {
    content: "";
    position: absolute;
    right: -18px;
    top: 9px;
    bottom: 9px;
    width: 4px;
    border-radius: 4px;
    background: var(--brand-red);
}
.sidebar nav a.danger-link {
    margin-top: 15px;
    color: #ffd8dc;
}
.admin-content {
    min-width: 0;
    padding: 33px;
}
.admin-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 25px;
}
.admin-topbar h1 {
    margin: 0;
    color: var(--brand-navy);
    font-size: 2rem;
}
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 17px;
    margin-bottom: 20px;
}
.stats-grid article {
    position: relative;
    padding: 22px;
    overflow: hidden;
    border: 1px solid #dde5eb;
    border-radius: 16px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}
.stats-grid article::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    height: 4px;
    background: var(--brand-navy);
}
.stats-grid article:nth-child(2)::before { background: var(--green); }
.stats-grid article:nth-child(3)::before { background: var(--brand-red); }
.stats-grid span,
.stats-grid strong { display: block; }
.stats-grid span { color: var(--muted); font-size: .83rem; }
.stats-grid strong {
    margin-top: 7px;
    color: var(--brand-navy);
    font-size: 2rem;
}
.panel {
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid #dde5eb;
    border-radius: 17px;
    background: #fff;
    box-shadow: var(--shadow-soft);
}
.panel-heading {
    padding: 20px 22px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    border-bottom: 1px solid #edf1f4;
    background: linear-gradient(90deg, rgba(234,241,246,.5), #fff 35%);
}
.panel-heading h2 {
    margin: 0 0 3px;
    color: var(--brand-navy);
    font-size: 1.14rem;
}
.panel-heading p { margin: 0; color: var(--muted); font-size: .79rem; }
.import-form {
    padding: 22px;
    display: grid;
    grid-template-columns: minmax(250px, .85fr) 1fr auto;
    align-items: center;
    gap: 20px;
}
.file-drop {
    position: relative;
    min-height: 120px;
    display: grid;
    place-items: center;
    align-content: center;
    border: 2px dashed #b9cbd8;
    border-radius: 14px;
    background: #f8fbfd;
    text-align: center;
    cursor: pointer;
    transition: border-color .2s ease, background .2s ease;
}
.file-drop:hover {
    border-color: var(--brand-navy);
    background: var(--brand-navy-soft);
}
.file-drop input {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}
.file-drop strong,
.file-drop small { display: block; }
.file-drop small { color: var(--muted); }
.upload-icon {
    color: var(--brand-red);
    font-size: 2rem;
    line-height: 1;
}
.import-options {
    display: grid;
    gap: 10px;
    color: #40586a;
    font-size: .85rem;
}
.import-options label {
    display: flex;
    align-items: center;
    gap: 8px;
}
.import-options input { accent-color: var(--brand-navy); }
.admin-search { display: flex; gap: 8px; }
.admin-search input { width: 260px; }
.admin-search button {
    padding: 0 17px;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: var(--brand-navy);
    font-weight: 800;
}
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    padding: 14px 18px;
    border-bottom: 1px solid #edf1f4;
    text-align: right;
    white-space: nowrap;
    font-size: .85rem;
}
th {
    color: #526879;
    background: #f6f8fa;
    font-size: .77rem;
}
tbody tr:hover { background: #fbfcfd; }
.mono {
    direction: ltr;
    text-align: right;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.status {
    display: inline-flex;
    padding: 5px 10px;
    border-radius: 99px;
    font-size: .73rem;
    font-weight: 900;
}
.status.passed { color: #166534; background: #dcfce7; }
.status.failed { color: #991b1b; background: #fee2e2; }
.icon-button {
    width: 31px;
    height: 31px;
    border: 0;
    border-radius: 8px;
    color: var(--brand-red-dark);
    background: var(--brand-red-soft);
    font-size: 1.2rem;
}
.empty-cell { padding: 40px; color: var(--muted); text-align: center; }
.compact-panel { padding-bottom: 20px; }
.password-grid {
    padding: 20px 22px 0;
    display: grid;
    grid-template-columns: repeat(3, 1fr) auto;
    gap: 12px;
}

@media (max-width: 980px) {
    .admin-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; }
    .sidebar nav { grid-template-columns: repeat(4, 1fr); }
    .sidebar nav a.active::before { display: none; }
    .admin-content { padding: 22px; }
    .import-form { grid-template-columns: 1fr; }
    .password-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 680px) {
    .public-header {
        width: min(100% - 26px, 1120px);
        padding: 17px 0;
    }
    .public-brand strong { max-width: 190px; font-size: .74rem; line-height: 1.55; }
    .public-brand small { font-size: .68rem; }
    .public-brand > span { width: 40px; height: 40px; flex-basis: 40px; border-radius: 11px; }
    .admin-login-link { padding: 8px 11px; font-size: .7rem; }
    .hero {
        width: min(100% - 26px, 1035px);
        min-height: auto;
        padding: 53px 0 100px;
    }
    .hero-copy { margin-bottom: 26px; }
    .section-badge { min-height: 38px; padding: 0 20px; }
    .hero-copy h1 { margin-top: 20px; font-size: 2.15rem; }
    .hero-copy p { font-size: .88rem; line-height: 1.85; }
    .search-card { padding: 28px 23px 31px; border-radius: 20px; }
    .search-card h2 { font-size: 1.35rem; }
    .input-row { grid-template-columns: 1fr; }
    .input-row button { min-height: 52px; }
    .public-footer { position: absolute; font-size: .68rem; }
    .success-card { padding: 45px 22px 38px; border-radius: 23px; }
    .success-ring { width: 94px; height: 94px; }
    .success-check { font-size: 3.7rem; }
    .login-card { padding: 34px 24px; }
    .admin-topbar,
    .responsive-heading { align-items: stretch; flex-direction: column; }
    .stats-grid { grid-template-columns: 1fr; }
    .sidebar nav { grid-template-columns: 1fr 1fr; }
    .admin-content { padding: 15px; }
    .admin-search { width: 100%; }
    .admin-search input { min-width: 0; width: 100%; }
    .password-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}

/* Version 3: failed result, editable branding and stronger responsive behavior */
.admin-institution-name,
.login-institution {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: .86rem;
    line-height: 1.7;
}

.result-not-found {
    margin: -5px 0 20px;
    padding: 12px 14px;
    border: 1px solid #fecaca;
    border-radius: 11px;
    color: #991b1b;
    background: #fff1f2;
    font-size: .82rem;
    font-weight: 700;
    line-height: 1.75;
}

/* Failed result page */
.public-page.result-failed {
    background:
        radial-gradient(circle at 14% 15%, rgba(var(--brand-red-rgb), .10), transparent 27%),
        radial-gradient(circle at 86% 82%, rgba(var(--brand-navy-rgb), .10), transparent 30%),
        #f5f7f9;
}
#failureCanvas {
    position: fixed;
    z-index: 3;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.result-stage {
    position: relative;
    z-index: 5;
    min-height: calc(100vh - 105px);
    padding: 45px 20px 85px;
    display: grid;
    place-items: center;
}
.result-card {
    position: relative;
    width: min(630px, 100%);
    padding: 56px 48px 46px;
    overflow: hidden;
    border: 1px solid #e3e7eb;
    border-radius: 28px;
    background: rgba(255,255,255,.97);
    box-shadow: 0 30px 85px rgba(67, 42, 48, .14);
    text-align: center;
    animation: failureCardEntrance .85s cubic-bezier(.16,1,.3,1) both;
}
.result-card::before,
.result-card::after {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    width: 8px;
}
.result-card::before { right: 0; background: var(--brand-navy); }
.result-card::after { left: 0; background: var(--brand-red); }
.result-top-line {
    position: absolute;
    top: 0;
    right: 8px;
    left: 8px;
    height: 6px;
    background: linear-gradient(90deg, var(--brand-red), #9ca3af, var(--brand-navy));
}
.failure-ring {
    position: relative;
    z-index: 2;
    width: 112px;
    height: 112px;
    margin: 0 auto 25px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: linear-gradient(145deg, var(--brand-red), var(--brand-red-dark));
    box-shadow: 0 0 0 12px var(--brand-red-soft), 0 18px 42px rgba(var(--brand-red-rgb), .25);
    animation: failurePulse 2.4s ease-in-out infinite;
}
.failure-ring::before {
    content: "";
    position: absolute;
    inset: -18px;
    border: 1px solid rgba(var(--brand-red-rgb), .25);
    border-radius: 50%;
    animation: failureRipple 2.6s ease-out infinite;
}
.failure-symbol {
    font-size: 4.2rem;
    line-height: 1;
    font-weight: 900;
    animation: failureSymbol .75s .25s cubic-bezier(.16,1.35,.3,1) both;
}
.result-kicker {
    margin: 0;
    color: var(--muted);
    font-size: .94rem;
    font-weight: 900;
    animation: fadeUp .65s .38s both;
}
.failure-word {
    display: inline-block;
    margin: 10px 0 15px;
    color: var(--brand-red-dark);
    font-size: clamp(3rem, 9vw, 5.5rem);
    line-height: 1.1;
    font-weight: 900;
    letter-spacing: .035em;
    text-shadow: 0 8px 25px rgba(var(--brand-red-rgb), .14);
    animation: failureWord .85s .52s both;
}
.failure-message {
    max-width: 500px;
    margin: 0 auto 28px;
    color: var(--muted);
    font-size: .94rem;
    line-height: 2;
    animation: fadeUp .7s .65s both;
}
.failure-button {
    color: #fff;
    background: linear-gradient(135deg, var(--brand-navy), var(--brand-navy-dark));
    box-shadow: 0 12px 28px rgba(var(--brand-navy-rgb), .22);
    animation: fadeUp .7s .8s both;
}
.failure-orbit {
    position: absolute;
    border: 1px solid rgba(var(--brand-red-rgb), .16);
    border-radius: 50%;
    pointer-events: none;
}
.orbit-a {
    width: 170px;
    height: 170px;
    top: -88px;
    right: -70px;
    animation: orbitFloat 7s ease-in-out infinite;
}
.orbit-b {
    width: 105px;
    height: 105px;
    bottom: -45px;
    left: -38px;
    border-color: rgba(var(--brand-navy-rgb), .15);
    animation: orbitFloat 6s 1s ease-in-out infinite reverse;
}
@keyframes failureCardEntrance {
    from { opacity: 0; transform: translateY(45px) scale(.9); }
    to { opacity: 1; transform: none; }
}
@keyframes failureSymbol {
    from { opacity: 0; transform: scale(.25) rotate(18deg); }
    to { opacity: 1; transform: scale(1) rotate(0); }
}
@keyframes failureWord {
    from { opacity: 0; transform: translateY(24px); letter-spacing: .2em; }
    to { opacity: 1; transform: none; letter-spacing: .035em; }
}
@keyframes failurePulse {
    0%,100% { transform: scale(1); }
    50% { transform: scale(1.04); }
}
@keyframes failureRipple {
    from { transform: scale(.78); opacity: .8; }
    to { transform: scale(1.38); opacity: 0; }
}
@keyframes orbitFloat {
    0%,100% { transform: translate3d(0,0,0) rotate(0); }
    50% { transform: translate3d(12px,16px,0) rotate(30deg); }
}

/* Appearance settings */
#appearance-settings { scroll-margin-top: 18px; }
.settings-form {
    padding: 24px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
.settings-field {
    min-width: 0;
    display: grid;
    align-content: start;
    gap: 8px;
    color: var(--ink);
    font-size: .84rem;
    font-weight: 800;
}
.settings-field-wide { grid-column: 1 / -1; }
.settings-field > input {
    width: 100%;
    height: 49px;
    padding: 0 14px;
    border: 1px solid #ccd7df;
    border-radius: 11px;
    outline: none;
    color: var(--ink);
    background: #fff;
    transition: border-color .2s ease, box-shadow .2s ease;
}
.settings-field > input:focus {
    border-color: var(--brand-navy);
    box-shadow: 0 0 0 4px rgba(var(--brand-navy-rgb), .10);
}
.settings-field small {
    color: var(--muted);
    font-size: .72rem;
    font-weight: 500;
    line-height: 1.7;
}
.color-control {
    min-height: 49px;
    padding: 6px 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    border: 1px solid #ccd7df;
    border-radius: 11px;
    background: #fff;
}
.color-control input[type="color"] {
    width: 52px;
    height: 35px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
}
.color-control code {
    direction: ltr;
    color: var(--muted);
    font-size: .8rem;
}
.settings-preview {
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 13px;
    border: 1px solid #dbe4ea;
    border-radius: 14px;
    background: linear-gradient(135deg, var(--brand-navy-soft), #fff 68%);
}
.settings-preview strong,
.settings-preview small { display: block; }
.settings-preview strong {
    color: var(--brand-navy-dark);
    font-size: .9rem;
    line-height: 1.6;
}
.settings-preview small { color: var(--muted); font-size: .75rem; }
.settings-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
}

/* Layout hardening for long names and all screen sizes */
.public-brand { min-width: 0; }
.public-brand > div { min-width: 0; }
.public-brand strong {
    max-width: min(70vw, 670px);
    overflow-wrap: anywhere;
    line-height: 1.55;
}
.admin-topbar > div { min-width: 0; }
.admin-institution-name { overflow-wrap: anywhere; }
.public-page {
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
}
.public-header { flex: 0 0 auto; }
.hero {
    flex: 1 0 auto;
    min-height: auto;
    padding-bottom: 78px;
}
.success-stage,
.result-stage { flex: 1 0 auto; }
.public-footer {
    position: relative;
    bottom: auto;
    flex: 0 0 auto;
    margin-top: 0;
    padding: 20px 18px 24px;
    line-height: 1.7;
}

@media (max-width: 980px) {
    .sidebar nav { grid-template-columns: repeat(auto-fit, minmax(145px, 1fr)); }
    .settings-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 680px) {
    .public-header { align-items: flex-start; }
    .public-brand { align-items: flex-start; }
    .public-brand strong { max-width: 56vw; }
    .public-footer { padding-bottom: 22px; }
    .result-stage { min-height: auto; padding: 55px 13px 90px; }
    .result-card { padding: 45px 23px 38px; border-radius: 23px; }
    .failure-ring { width: 94px; height: 94px; }
    .failure-symbol { font-size: 3.55rem; }
    .failure-message { font-size: .86rem; }
    .settings-form { padding: 18px; grid-template-columns: 1fr; }
    .settings-field-wide { grid-column: auto; }
    .settings-actions { align-items: stretch; flex-direction: column; }
    .settings-actions .button { width: 100%; }
}

@media (max-width: 420px) {
    .public-header { width: calc(100% - 20px); gap: 9px; }
    .public-brand { gap: 9px; }
    .public-brand strong { max-width: 52vw; font-size: .69rem; }
    .public-brand small { font-size: .62rem; }
    .admin-login-link { flex: 0 0 auto; padding: 7px 9px; }
    .hero { width: calc(100% - 20px); padding-top: 40px; }
    .hero-copy h1 { font-size: 1.85rem; }
    .search-card { padding: 25px 18px 28px; }
    .result-card { padding-right: 18px; padding-left: 18px; }
    .failure-word { font-size: 3rem; }
    .admin-content { padding: 10px; }
    .panel-heading { padding: 17px; }
    .import-form { padding: 17px; }
    th, td { padding-right: 13px; padding-left: 13px; }
}
