:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --text: #122033;
    --muted: #5f6b7a;
    --border: #dbe3ee;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --shadow: 0 8px 24px rgba(15, 23, 42, 0.07);
    --header-bg: rgba(244, 247, 251, 0.92);
    --header-border: rgba(219, 227, 238, 0.8);
    --surface-strong: #0f172a;
    --surface-soft: #f8fbff;
    --input-bg: #ffffff;
    --overlay: rgba(15, 23, 42, 0.45);
    --danger-border: rgba(220, 38, 38, 0.25);
    --danger-bg: rgba(220, 38, 38, 0.06);
    --danger-text: #991b1b;
    --radius: 18px;
    --floating-control-bg: rgba(10, 16, 30, 0.72);
    --floating-control-bg-hover: rgba(10, 16, 30, 0.9);
    --floating-control-border: rgba(255, 255, 255, 0.24);
    --floating-control-text: #f8fbff;
}

html[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #111b2e;
    --text: #e2e8f0;
    --muted: #9fb0c8;
    --border: #243650;
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --shadow: 0 12px 28px rgba(2, 6, 23, 0.42);
    --header-bg: rgba(11, 18, 32, 0.9);
    --header-border: rgba(36, 54, 80, 0.9);
    --surface-strong: #0b1325;
    --surface-soft: #16253a;
    --input-bg: #0f1a2f;
    --overlay: rgba(2, 6, 23, 0.6);
    --danger-border: rgba(252, 165, 165, 0.32);
    --danger-bg: rgba(239, 68, 68, 0.12);
    --danger-text: #fecaca;
    --floating-control-bg: rgba(241, 245, 249, 0.86);
    --floating-control-bg-hover: rgba(248, 250, 252, 0.95);
    --floating-control-border: rgba(15, 23, 42, 0.18);
    --floating-control-text: #0f172a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }

.shell {
    width: min(960px, calc(100% - 24px));
    margin: 0 auto;
}

/* ── Header ── */
.site-header {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--header-border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
}

.brand {
    font-weight: 800;
    color: var(--text);
}

.back-link {
    font-weight: 600;
    color: var(--text);
    padding: 8px 14px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--primary) 14%, transparent);
}

.back-link:hover { background: color-mix(in srgb, var(--primary) 22%, transparent); color: var(--text); }

.nav-form { margin: 0; }

.logout-btn {
    border: 1px solid rgba(220, 38, 38, 0.2);
    background: rgba(220, 38, 38, 0.07);
    color: #b91c1c;
    padding: 8px 14px;
    border-radius: 999px;
    font: inherit;
    cursor: pointer;
    box-shadow: none;
}

.logout-btn:hover { background: rgba(220, 38, 38, 0.14); }

/* ── Layout ── */
.page { padding: 20px 0 48px; }

.stack { display: grid; gap: 14px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.muted { color: var(--muted); }
.small { font-size: 0.9rem; }

/* ── Dashboard action buttons ── */
.action-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.button-card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100px;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font: inherit;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    border: 0;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.2);
    text-align: center;
    padding: 16px;
    transition: transform 0.1s, background 0.1s;
}

.button-card:hover { background: var(--primary-dark); transform: translateY(-1px); color: #fff; }
.button-card:disabled { background: #94a3b8; transform: none; cursor: wait; box-shadow: none; }

.admin-link { display: block; text-align: right; }

/* ── Generic button ── */
.button {
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 12px 22px;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.18);
}

.button:hover { background: var(--primary-dark); }

.button-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    box-shadow: none;
}

.button-secondary:hover {
    background: color-mix(in srgb, var(--primary) 14%, var(--surface));
    color: var(--text);
}

.button-secondary.is-disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* ── Alerts ── */
.msg-stack { display: grid; gap: 10px; margin-bottom: 14px; }

.alert {
    border-radius: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
}

.alert-error {
    border-color: var(--danger-border);
    background: var(--danger-bg);
    color: var(--danger-text);
}

/* ── Camera page ── */
.camera-page {
    display: grid;
    gap: 16px;
}

.camera-shell { position: relative; }

.camera-feed {
    width: 100%;
    max-height: 65vh;
    aspect-ratio: 4 / 3;
    border-radius: var(--radius);
    background: var(--surface-strong);
    border: 1px solid var(--border);
    object-fit: cover;
    display: block;
}

.camera-controls {
    display: flex;
    justify-content: center;
    padding: 8px 0;
}

.capture-button {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 7px solid rgba(255, 255, 255, 0.85);
    background: radial-gradient(circle at 34% 34%, #fff 0 18%, #ef4444 20%, #dc2626 100%);
    box-shadow: 0 10px 26px rgba(220, 38, 38, 0.3);
    cursor: pointer;
    transition: transform 0.1s;
}

.capture-button:hover:not(:disabled) { transform: scale(1.05); }

.capture-button:disabled {
    opacity: 0.45;
    background: radial-gradient(circle at 34% 34%, #fff 0 18%, #94a3b8 20%, #64748b 100%);
    box-shadow: none;
}

.camera-status { text-align: center; min-height: 1.4em; }

/* ── Processing overlay ── */
.processing-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    place-items: center;
    z-index: 1000;
    padding: 20px;
}

.processing-overlay.is-visible {
    display: grid;
}

.processing-window {
    width: min(320px, 100%);
    border-radius: 16px;
    border: 1px solid var(--border);
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 22px;
    display: grid;
    justify-items: center;
    gap: 12px;
    text-align: center;
}

.processing-spinner {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 4px solid #bfdbfe;
    border-top-color: var(--primary);
    animation: spin 0.85s linear infinite;
}

.processing-text {
    margin: 0;
    font-weight: 600;
    color: var(--text);
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ── History gallery ── */
.gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.history-search-card {
    margin-bottom: 16px;
    border-color: var(--border);
    background: linear-gradient(180deg, var(--surface) 0%, var(--surface-soft) 100%);
    overflow: hidden;
}

.history-search-form {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    align-items: stretch;
}

.history-search-form label {
    display: grid;
    gap: 7px;
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text);
    min-width: 0;
}

.history-search-form input {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 13px;
    font: inherit;
    background: var(--input-bg);
    min-height: 44px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.history-search-form input:focus {
    outline: 0;
    border-color: #7da7f7;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

.history-search-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    grid-column: 1 / -1;
    justify-content: flex-end;
    padding-top: 2px;
}

.history-search-actions .button,
.history-search-actions .button-secondary {
    min-width: 118px;
}

.record-card {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.record-delete-form {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    margin: 0;
}

.delete-corner {
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--floating-control-border);
    background: var(--floating-control-bg);
    color: var(--floating-control-text);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.delete-corner:hover { background: var(--floating-control-bg-hover); }

.record-image {
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    display: block;
}

.record-image-link {
    display: block;
}

.record-image-link .record-image {
    cursor: zoom-in;
}

.record-meta {
    display: grid;
    gap: 3px;
    padding: 12px 14px;
    font-size: 0.95rem;
}

.record-meta strong { color: var(--text); }

.recognition-card {
    position: relative;
}

.recognition-slider {
    position: relative;
}

.recognition-slide {
    display: none;
}

.recognition-slide.is-active {
    display: block;
}

.result-map-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    text-decoration: none;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    color: var(--text);
    background: color-mix(in srgb, var(--surface) 90%, #dbeafe 10%);
    margin-left: auto;
}

.result-map-link:hover {
    background: color-mix(in srgb, var(--surface) 78%, #bfdbfe 22%);
}

.result-map-emoji {
    font-size: 0.9rem;
    line-height: 1;
}

.record-meta-footer {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
}

.record-meta-footer time {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.carousel-btn {
    position: absolute;
    top: calc(50% - 36px);
    width: 36px;
    height: 36px;
    border: 1px solid var(--floating-control-border);
    border-radius: 50%;
    background: var(--floating-control-bg);
    color: var(--floating-control-text);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    z-index: 2;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
}

.carousel-btn:hover {
    background: var(--floating-control-bg-hover);
}

.carousel-btn.prev {
    left: 10px;
}

.carousel-btn.next {
    right: 10px;
}

.slide-indicator {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--floating-control-bg);
    border: 1px solid var(--floating-control-border);
    color: var(--floating-control-text);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    padding: 5px 8px;
    border-radius: 999px;
    z-index: 2;
    pointer-events: none;
    backdrop-filter: blur(2px);
}

/* ── Image modal ── */
.image-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1100;
    background: var(--overlay);
    place-items: center;
    padding: 20px;
    cursor: zoom-out;
}

.image-modal.is-open {
    display: grid;
}

.image-modal-content {
    position: relative;
    max-width: min(90vw, 960px);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: default;
}

.image-modal-img {
    display: block;
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
}

.image-modal-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--floating-control-border);
    background: var(--floating-control-bg);
    color: var(--floating-control-text);
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    font: inherit;
    z-index: 2;
}

.image-modal-close:hover {
    background: var(--floating-control-bg-hover);
}

.image-modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--floating-control-border);
    background: var(--floating-control-bg);
    color: var(--floating-control-text);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font: inherit;
    z-index: 2;
}

.image-modal-nav:hover {
    background: var(--floating-control-bg-hover);
}

.image-modal-prev { left: 10px; }
.image-modal-next { right: 10px; }

.image-modal-nav[hidden],
.image-modal-counter[hidden] {
    display: none;
}

.image-modal-counter {
    position: absolute;
    top: 10px;
    left: 10px;
    background: var(--floating-control-bg);
    border: 1px solid var(--floating-control-border);
    color: var(--floating-control-text);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.01em;
    padding: 5px 8px;
    border-radius: 999px;
    pointer-events: none;
    backdrop-filter: blur(2px);
    white-space: nowrap;
    z-index: 2;
}

.image-modal-datetime {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--floating-control-bg);
    border: 1px solid var(--floating-control-border);
    color: var(--floating-control-text);
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1;
    padding: 5px 10px;
    border-radius: 999px;
    pointer-events: none;
    backdrop-filter: blur(2px);
    white-space: nowrap;
    z-index: 2;
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--muted);
}

.history-pagination {
    margin-top: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.pagination-status {
    min-width: 120px;
    text-align: center;
}

/* ── Auth ── */
.auth-card { max-width: 420px; margin: 0 auto; }

.form-grid { display: grid; gap: 14px; }
.form-grid label { display: block; margin-bottom: 5px; font-weight: 600; }
.form-grid input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 13px;
    font: inherit;
    background: var(--input-bg);
}

/* ── Utility ── */
.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .action-grid { grid-template-columns: 1fr; }
    .button-card { min-height: 64px; }
    .gallery { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
    .history-search-form {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    .history-search-actions {
        display: grid;
        grid-template-columns: 1fr 1fr;
        grid-column: auto;
        justify-content: stretch;
        padding-top: 0;
    }
    .history-pagination {
        display: grid;
        grid-template-columns: 1fr;
    }
}

/* ── Language switcher ── */
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.theme-toggle {
    position: relative;
    width: 48px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--primary) 10%, var(--input-bg));
    cursor: pointer;
    padding: 0;
    box-shadow: none;
}

.theme-toggle-track {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    border: 1px solid color-mix(in srgb, var(--border) 70%, #ffffff);
    transition: transform 0.18s ease;
}

html[data-theme="dark"] .theme-toggle-track {
    transform: translateX(20px);
    background: #dbeafe;
    border-color: color-mix(in srgb, var(--primary) 40%, var(--border));
}

.theme-toggle:hover {
    background: color-mix(in srgb, var(--primary) 20%, var(--input-bg));
}

.theme-toggle:focus {
    outline: 0;
    border-color: color-mix(in srgb, var(--primary) 60%, var(--border));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 26%, transparent);
}

.lang-form {
    display: flex;
    align-items: center;
    margin: 0;
}

.lang-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 999px;
    padding: 6px 30px 6px 12px;
    font: inherit;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: none;
    letter-spacing: 0.03em;
    line-height: 1.2;
    background:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%) calc(100% - 14px) calc(50% - 1px) / 6px 6px no-repeat,
        linear-gradient(135deg, var(--muted) 50%, transparent 50%) calc(100% - 10px) calc(50% - 1px) / 6px 6px no-repeat,
        var(--input-bg);
}

.lang-select:hover {
    background:
        linear-gradient(45deg, transparent 50%, var(--text) 50%) calc(100% - 14px) calc(50% - 1px) / 6px 6px no-repeat,
        linear-gradient(135deg, var(--text) 50%, transparent 50%) calc(100% - 10px) calc(50% - 1px) / 6px 6px no-repeat,
        color-mix(in srgb, var(--primary) 16%, var(--input-bg));
}

.lang-select:focus {
    outline: 0;
    border-color: #7da7f7;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.16);
}

/* ── Dashboard intro ── */
.dashboard-intro {
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.intro-text {
    color: var(--muted);
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.5;
    max-width: 520px;
}
.intro-highlight {
    color: var(--text);
    font-weight: 800;
    font-size: 1.08rem;
}

.brand-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-chip {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--text) 7%, var(--surface));
    color: var(--muted);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.92rem;
    font-weight: 600;
}


.dashboard-logout {
    display: flex;
    justify-content: center;
    margin-top: 10px;
}
