/* ---------- Base ---------- */
:root {
    --accent: #1b5bff;
    --accent-dark: #1346cc;
    --accent-soft: #e7efff;
    --text: #1f2933;
    --muted: #6b7785;
    --border: #e5e9ef;
    --bg: #f6f9fb;
    --card: #ffffff;
    --danger: #c0392b;
    --danger-soft: #fdecea;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 0 1.25rem;
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; }
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); }
h2 { font-size: 1.15rem; }

p { margin: 0 0 .75rem; }
.muted { color: var(--muted); font-size: .92rem; }

a { color: var(--accent-dark); }

/* Honeypot field — hidden from humans, visible to dumb bots. */
.hp-field {
    position: absolute !important;
    left: -10000px !important;
    width: 1px !important;
    height: 1px !important;
    opacity: 0 !important;
    overflow: hidden !important;
    pointer-events: none !important;
}

/* Keep ® and other superscripts from inflating line height. */
sup {
    font-size: .55em;
    vertical-align: baseline;
    position: relative;
    top: -0.5em;
    line-height: 0;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: .65rem 1.1rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus { outline: none; }
.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}
.btn--primary {
    background: var(--accent);
    color: #fff;
}
.btn--primary:disabled { background: #9ec9c4; cursor: progress; }
.btn--ghost {
    background: #fff;
    color: var(--text);
    border-color: var(--border);
}
.btn--danger {
    background: #fff;
    color: var(--danger);
    border-color: #f0c0bb;
}

/* Only apply hover styles on devices that actually have hover (mouse/trackpad).
   Prevents the "stuck active" look on iOS/Android after tapping. */
@media (hover: hover) {
    .btn--primary:hover { background: var(--accent-dark); }
    .btn--ghost:hover   { background: #f3f5f8; }
    .btn--danger:hover  { background: var(--danger-soft); }
}
.btn--large {
    padding: .9rem 1.5rem;
    font-size: 1.05rem;
    border-radius: 12px;
}

/* Button spinner — hidden by default, shown when .btn--loading is set. */
.btn__spinner {
    display: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid currentColor;
    border-right-color: transparent;
    animation: btn-spin .8s linear infinite;
    flex-shrink: 0;
}
.btn--loading .btn__spinner { display: inline-block; }
.btn--loading { cursor: progress; opacity: .92; }
.btn:disabled { cursor: progress; }
@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

.icon-btn {
    background: rgba(0,0,0,.55);
    color: #fff;
    border: 0;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
}

/* ---------- Forms ---------- */
label {
    display: block;
    font-weight: 600;
    font-size: .95rem;
    margin-bottom: 1rem;
}
input[type=text], input[type=email], input[type=password], input[type=search] {
    display: block;
    width: 100%;
    margin-top: .35rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .7rem .85rem;
    font: inherit;
    /* 16px minimum keeps iOS Safari from auto-zooming into the field on focus. */
    font-size: 16px;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 540px) { .form-row { grid-template-columns: 1fr; } }

.card {
    background: var(--card);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: var(--shadow);
    margin-bottom: 1.5rem;
}

/* ---------- Patient page ---------- */
.patient-page .hero {
    background: linear-gradient(180deg, #1b5bff 0%, #1346cc 100%);
    color: #fff;
    padding: 2rem 0 2.5rem;
}

/* ---------- Brand logo ---------- */
.brand-logo {
    display: block;
    height: 38px;
    width: auto;
    margin-bottom: 1.25rem;
}
.brand-logo--admin { height: 32px; margin-bottom: .35rem; }

.login-card__logo {
    display: block;
    height: 36px;
    width: auto;
    margin: 0 auto 1.25rem;
}

.thanks__logo {
    display: block;
    height: 40px;
    width: auto;
    margin: 0 auto 1.25rem;
}
.hero h1 { color: #fff; }
.hero .lede { font-size: 1.05rem; opacity: .95; margin: 0; max-width: 36rem; }

.patient-page main { padding-top: 1.5rem; padding-bottom: 3rem; }
.patient-page .container { max-width: 1180px; }

/* Pre-upload tip card */
.tip-card {
    display: flex;
    align-items: flex-start;
    gap: .9rem;
    background: var(--accent-soft);
    border-radius: 14px;
    padding: 1rem 1.1rem;
    margin-bottom: 1.5rem;
    position: relative;
    transition: opacity .25s ease, transform .25s ease, margin .25s ease, padding .25s ease, max-height .25s ease;
    max-height: 200px;
    overflow: hidden;
}
.tip-card--dismissed {
    opacity: 0;
    transform: translateY(-4px);
    padding-top: 0;
    padding-bottom: 0;
    margin-bottom: 0;
    max-height: 0;
}
.tip-card__icon {
    background: #fff;
    color: var(--accent);
    width: 38px; height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .05);
}
.tip-card__body { flex: 1; min-width: 0; }
.tip-card__body > strong { color: var(--accent-dark); display: block; margin-bottom: .15rem; font-weight: 700; }
.tip-card__body p strong { color: var(--accent-dark); font-weight: 700; }
.tip-card__body p {
    margin: 0;
    color: var(--text);
    font-size: .95rem;
    line-height: 1.5;
}
.tip-card__close {
    background: transparent;
    border: 0;
    color: var(--muted);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 .25rem;
    margin: -0.25rem -0.25rem 0 0;
    border-radius: 6px;
    flex-shrink: 0;
}
@media (hover: hover) {
    .tip-card__close:hover { color: var(--text); background: rgba(0,0,0,.05); }
}

/* 5 photo slots arranged as a 3-up row on top, 2-up row on bottom. */
.photo-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    margin-bottom: 1.5rem;
}
.photo-slot { grid-column: span 6; }
@media (min-width: 720px) {
    .photo-slot:nth-child(1),
    .photo-slot:nth-child(2),
    .photo-slot:nth-child(3) { grid-column: span 2; }
    .photo-slot:nth-child(4),
    .photo-slot:nth-child(5) { grid-column: span 3; }
}

.photo-slot {
    background: var(--card);
    border-radius: 16px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}
.photo-slot__header {
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    margin-bottom: 1rem;
}
.photo-slot__num {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--accent-soft);
    color: var(--accent-dark);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.photo-slot:nth-child(1) .photo-slot__num::before { content: "1"; }
.photo-slot:nth-child(2) .photo-slot__num::before { content: "2"; }
.photo-slot:nth-child(3) .photo-slot__num::before { content: "3"; }
.photo-slot:nth-child(4) .photo-slot__num::before { content: "4"; }
.photo-slot:nth-child(5) .photo-slot__num::before { content: "5"; }
.photo-slot__hint { font-size: .85rem; color: var(--muted); margin: .15rem 0 0; }

.photo-preview {
    position: relative;
    background: #f0f3f6;
    border: 1px dashed #c9d2dc;
    border-radius: 12px;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, border-color .15s;
}
/* Whole placeholder area is clickable when empty */
.photo-preview__placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: .35rem;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: rgba(27, 91, 255, .12);
}
/* Only show hover styles on devices that actually have hover (mouse/trackpad).
   Prevents the "stuck blue" state on iOS/Android after tapping. */
@media (hover: hover) {
    .photo-slot:not(.photo-slot--filled) .photo-preview:hover {
        background: #e8eef5;
        border-color: var(--accent);
    }
    .photo-slot:not(.photo-slot--filled) .photo-preview:hover .photo-preview__placeholder {
        color: var(--accent-dark);
    }
}
.photo-preview__placeholder:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
    border-radius: 12px;
}
.photo-slot--filled .photo-preview {
    border-style: solid;
    border-color: transparent;
}
.photo-preview__placeholder {
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .35rem;
    font-size: .9rem;
}
.photo-preview__img {
    display: none;
    width: 100%; height: 100%;
    object-fit: cover;
}
.photo-preview__remove {
    position: absolute;
    top: .5rem; right: .5rem;
    background: rgba(0,0,0,.6);
    color: #fff;
    border: 0;
    width: 30px; height: 30px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    line-height: 1;
}

/* Small spinner overlay while a chosen photo is being processed locally. */
.photo-slot--processing .photo-preview::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, .7);
    backdrop-filter: blur(2px);
}
.photo-slot--processing .photo-preview::before {
    content: "";
    position: absolute;
    top: 50%; left: 50%;
    width: 28px; height: 28px;
    margin: -14px 0 0 -14px;
    border-radius: 50%;
    border: 3px solid var(--accent);
    border-right-color: transparent;
    animation: btn-spin .8s linear infinite;
    z-index: 1;
}

.photo-actions {
    display: flex;
    gap: .5rem;
}
.photo-actions .btn {
    flex: 1 1 0;
    min-width: 0;
    padding: .6rem .4rem;
    gap: .3rem;
    font-size: .88rem;
}
@media (max-width: 540px) {
    .photo-actions { flex-direction: column; }
}

.submit-row {
    display: flex;
    flex-direction: column;
    gap: .75rem;
    align-items: center;
    padding-top: 1rem;
}
.submit-row .btn--large { min-width: 14rem; }
.submit-row__status { font-size: .92rem; color: var(--muted); min-height: 1.4em; }
.submit-row__status--error { color: var(--danger); }

/* Upload progress card — shown while photos are being sent. */
.upload-progress {
    width: 100%;
    max-width: 24rem;
    background: var(--accent-soft);
    border-radius: 12px;
    padding: .85rem 1rem 1rem;
    border: 1px solid rgba(27, 91, 255, .12);
    text-align: center;
}
.upload-progress__bar {
    height: 8px;
    background: rgba(27, 91, 255, .15);
    border-radius: 999px;
    overflow: hidden;
    margin-bottom: .6rem;
}
.upload-progress__fill {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--accent), #4a7eff);
    border-radius: inherit;
    transition: width .25s ease-out;
    /* subtle moving stripe so the bar feels alive even when bytes pause */
    background-image:
        linear-gradient(90deg, var(--accent), #4a7eff),
        repeating-linear-gradient(135deg, rgba(255,255,255,.18) 0 8px, transparent 8px 16px);
    background-blend-mode: normal;
    animation: progress-stripes 1.2s linear infinite;
    background-size: 100% 100%, 32px 100%;
}
@keyframes progress-stripes {
    from { background-position: 0 0, 0 0; }
    to   { background-position: 0 0, 32px 0; }
}
.upload-progress__meta {
    display: flex;
    justify-content: space-between;
    font-size: .9rem;
    font-weight: 600;
    color: var(--accent-dark);
    margin-bottom: .35rem;
}
.upload-progress__note {
    font-size: .82rem;
    color: var(--muted);
    margin: 0;
    line-height: 1.4;
}

.footer {
    padding: 2rem 0;
    text-align: center;
    color: var(--muted);
    font-size: .9rem;
}

/* ---------- Camera modal ---------- */
.camera-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .85);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.camera-modal[hidden] { display: none; }
body.modal-open { overflow: hidden; }

.camera-modal__inner {
    background: #111;
    color: #fff;
    border-radius: 18px;
    width: min(900px, 100%);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.camera-modal__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: .75rem 1rem;
    background: #000;
}
.camera-modal__header h2 { color: #fff; margin: 0; font-size: 1rem; }
.camera-stage {
    flex: 1;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 50vh;
    max-height: 70vh;
    overflow: hidden;
}
.camera-stage video {
    width: 100%;
    height: 100%;
    max-height: 70vh;
    object-fit: contain;
    background: #000;
}
.camera-modal__footer {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    padding: 1rem;
    background: #0a0a0a;
}
.camera-modal__footer .btn--ghost {
    background: rgba(255,255,255,.08);
    color: #fff;
    border-color: rgba(255,255,255,.18);
}
@media (hover: hover) {
    .camera-modal__footer .btn--ghost:hover { background: rgba(255,255,255,.15); }
}
.camera-modal__footer .btn--primary { margin-left: auto; min-width: 8rem; }

/* ---------- Thanks page ---------- */
.thanks-page {
    background:
        radial-gradient(1100px 600px at 50% -15%, rgba(27, 91, 255, .18) 0%, transparent 60%),
        linear-gradient(180deg, #f6f9fb 0%, #eef2f8 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}
.thanks { width: 100%; max-width: 32rem; }
.thanks__card {
    background: #fff;
    border-radius: 24px;
    padding: 2.25rem 2rem 1.75rem;
    box-shadow:
        0 1px 2px rgba(15, 23, 42, .04),
        0 12px 40px rgba(27, 91, 255, .12);
    text-align: center;
    position: relative;
    overflow: hidden;
}
.thanks__head { margin-bottom: 1.5rem; }
.thanks__logo {
    display: block;
    height: 32px;
    width: auto;
    margin: 0 auto;
}

/* Animated checkmark in a soft circle, with a thin progress-ring that fills
 * in over the redirect delay. */
.thanks__icon { margin: 0 auto 1.25rem; width: 80px; height: 80px; }
.thanks__svg { display: block; }
.thanks__svg-bg {
    fill: var(--accent-soft);
    stroke: none;
}
.thanks__svg-ring {
    fill: none;
    stroke: var(--accent);
    stroke-width: 3;
    stroke-linecap: round;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
    stroke-dasharray: 226.2;       /* 2 * π * 36 */
    stroke-dashoffset: 226.2;
    animation: thanks-ring-fill 1.1s cubic-bezier(.2,.8,.2,1) .15s both;
}
.thanks__svg-check {
    fill: none;
    stroke: var(--accent);
    stroke-width: 5;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-dasharray: 60;
    stroke-dashoffset: 60;
    animation: thanks-check-draw .5s cubic-bezier(.2,.8,.2,1) .75s both;
}
@keyframes thanks-ring-fill {
    to { stroke-dashoffset: 0; }
}
@keyframes thanks-check-draw {
    to { stroke-dashoffset: 0; }
}

.thanks__title {
    font-size: clamp(1.5rem, 4vw, 1.9rem);
    letter-spacing: -0.015em;
    margin: 0 0 .35rem;
}
.thanks__lede {
    font-size: 1.05rem;
    color: var(--text);
    margin: 0 0 1.1rem;
}
.thanks__message {
    color: var(--muted);
    line-height: 1.6;
    margin: 0 auto 1.5rem;
    max-width: 26rem;
}
.thanks__message strong { color: var(--text); }

.thanks__cta {
    width: 100%;
    max-width: 18rem;
    margin: 0 auto .75rem;
}

.thanks__progress {
    height: 3px;
    background: rgba(27, 91, 255, .12);
    border-radius: 999px;
    overflow: hidden;
    margin: 1.25rem auto .5rem;
    max-width: 18rem;
}
.thanks__progress-bar {
    height: 100%;
    width: 0;
    background: var(--accent);
    border-radius: inherit;
    animation: thanks-progress linear forwards;
}
@keyframes thanks-progress {
    to { width: 100%; }
}
.thanks__redirect {
    font-size: .85rem;
    color: var(--muted);
    margin: 0;
    letter-spacing: .01em;
}

/* ---------- Admin ---------- */
.admin-page { background: #f4f6f8; min-height: 100vh; }

.admin-login { display: flex; align-items: center; min-height: 100vh; }
.login-card { max-width: 22rem; margin: 0 auto; }

.admin-header {
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
    margin-bottom: 1.5rem;
}
.admin-header__inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.admin-header h1 { font-size: 1.4rem; display: inline-flex; align-items: center; gap: .5rem; }
.admin-nav { display: flex; gap: .5rem; flex-wrap: wrap; }

.back-link { display: inline-block; margin-bottom: .25rem; font-size: .9rem; text-decoration: none; }
@media (hover: hover) {
    .back-link:hover { text-decoration: underline; }
}

.admin-main { padding-bottom: 3rem; }

.alert { padding: .75rem 1rem; border-radius: 10px; margin-bottom: 1rem; }
.alert--error { background: var(--danger-soft); color: var(--danger); }

.stats {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(3, 1fr);
    margin-bottom: 1.5rem;
}
@media (max-width: 600px) { .stats { grid-template-columns: 1fr; } }
.stat {
    background: #fff;
    border-radius: 12px;
    padding: 1rem 1.2rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: .15rem;
}
.stat__num { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat__label { color: var(--muted); font-size: .9rem; }
.stat--alert .stat__num { color: var(--accent-dark); }

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}
.toolbar__filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.chip {
    background: #fff;
    border: 1px solid var(--border);
    padding: .35rem .8rem;
    border-radius: 999px;
    text-decoration: none;
    color: var(--text);
    font-size: .9rem;
    font-weight: 500;
}
@media (hover: hover) {
    .chip:hover { border-color: var(--accent); }
}
.chip--active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.toolbar__search { display: flex; gap: .5rem; }
.toolbar__search input { min-width: 14rem; }

.empty { text-align: center; color: var(--muted); }

.submission-grid {
    display: grid;
    gap: 1.25rem;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}
.submission-card {
    background: #fff;
    border-radius: 14px;
    box-shadow: var(--shadow);
    text-decoration: none;
    color: inherit;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform .12s, box-shadow .12s;
}
@media (hover: hover) {
    .submission-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 2px 6px rgba(15, 23, 42, .06), 0 10px 24px rgba(15, 23, 42, .08);
    }
}
.submission-card__thumbs {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    background: #f0f3f6;
}
.submission-card__thumbs img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    display: block;
}
.submission-card__meta { padding: .85rem 1rem 1rem; }
.submission-card__name {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.submission-card__email { font-size: .9rem; }
.submission-card__date { font-size: .8rem; margin-top: .25rem; }
.submission-card--new { box-shadow: 0 0 0 2px var(--accent), var(--shadow); }

.badge {
    background: var(--accent);
    color: #fff;
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    padding: .15rem .5rem;
    border-radius: 999px;
}

.photo-review {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    margin-bottom: 1.5rem;
}

.photo-review__item {
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
    margin: 0;
}
.photo-review__item a { display: block; background: #000; }
.photo-review__item img {
    width: 100%;
    display: block;
    aspect-ratio: 4 / 3;
    object-fit: contain;
    background: #000;
}
.photo-review__item figcaption {
    padding: .75rem 1rem;
    font-weight: 600;
    text-align: center;
}

.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: .5rem 1.5rem;
    margin: 0;
}
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
