:root {
    color-scheme: dark;
    --green-950: #071d14;
    --green-900: #0a2a1c;
    --green-800: #0f3a27;
    --green-700: #145137;
    --yellow-400: #f7c948;
    --red-500: #d4452f;
    --white: #fffaf0;
    --muted: #bdd2c4;
    --charcoal: #17211b;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--green-950);
    color: var(--white);
}

button,
input,
select {
    font: inherit;
}

.app-shell {
    width: min(100%, 760px);
    margin: 0 auto;
    padding: 20px 16px 32px;
}

.referral-gate {
    display: grid;
    gap: 12px;
    min-height: calc(100vh - 52px);
    align-content: center;
    padding: 28px 20px;
    border: 1px solid rgba(255, 250, 240, 0.12);
    border-radius: 8px;
    background: var(--green-900);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.referral-gate h1 {
    margin: 0;
    font-size: clamp(1.7rem, 8vw, 2.4rem);
    line-height: 1.05;
}

.referral-note,
.referral-error {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

.referral-error {
    color: #ffd0c8;
}

.eyebrow {
    margin: 0 0 8px;
    color: var(--yellow-400);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

h2,
p {
    margin-top: 0;
}

.camera-card,
.result-card {
    border: 1px solid rgba(255, 250, 240, 0.12);
    border-radius: 8px;
    background: var(--green-900);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.camera-card {
    overflow: hidden;
}

.camera-frame {
    position: relative;
    aspect-ratio: 4 / 5;
    min-height: 320px;
    background: var(--green-800);
}

video {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.snapshot-canvas {
    width: 100%;
    height: 100%;
    display: none;
    object-fit: cover;
}

.camera-frame.is-frozen video {
    display: none;
}

.camera-frame.is-frozen .snapshot-canvas {
    display: block;
}

.camera-fallback {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 24px;
    color: var(--muted);
    text-align: center;
    background: var(--green-800);
}

.camera-frame.has-stream .camera-fallback {
    display: none;
}

.camera-frame.has-result {
    aspect-ratio: auto;
    min-height: 0;
    overflow: visible;
}

.camera-frame.has-result video,
.camera-frame.has-result .snapshot-canvas,
.camera-frame.has-result .camera-fallback {
    display: none;
}

.loading-overlay {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    gap: 12px;
    padding: 24px;
    color: var(--white);
    text-align: center;
    background: rgba(7, 29, 20, 0.78);
    font-weight: 900;
    z-index: 4;
}

.loading-overlay[hidden] {
    display: none;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 4px solid rgba(255, 250, 240, 0.24);
    border-top-color: var(--yellow-400);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

.camera-result-panel {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    align-content: center;
    overflow-y: auto;
    padding: 56px 20px 24px;
    background: var(--green-900);
}

.camera-result-panel[hidden] {
    display: none;
}

.camera-result-content {
    width: 100%;
}

.camera-result-panel h2 {
    margin-bottom: 8px;
    font-size: 1.45rem;
}

.camera-frame.has-result .camera-result-panel {
    position: relative;
    inset: auto;
    min-height: 320px;
    overflow-y: visible;
}

.result-close-button {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 44px;
    min-height: 44px;
    border: 1px solid rgba(255, 250, 240, 0.2);
    border-radius: 50%;
    color: var(--white);
    background: rgba(7, 29, 20, 0.68);
    font-size: 1.5rem;
    line-height: 1;
}

.capture-form {
    display: grid;
    gap: 14px;
    padding: 16px;
}

.provider-field {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 800;
}

input[type="file"],
select {
    width: 100%;
    min-height: 48px;
    padding: 10px;
    border: 1px solid rgba(255, 250, 240, 0.22);
    border-radius: 8px;
    color: var(--white);
    background: var(--green-800);
}

select {
    appearance: none;
}

.provider-limit {
    display: grid;
    gap: 8px;
    padding: 12px;
    border: 1px solid rgba(247, 201, 72, 0.36);
    border-radius: 8px;
    background: rgba(15, 58, 39, 0.72);
}

.provider-limit[hidden] {
    display: none;
}

.provider-limit-title,
.provider-limit-status {
    margin: 0;
}

.provider-limit-title {
    color: var(--yellow-400);
    font-size: 0.88rem;
    font-weight: 900;
}

.provider-limit-status {
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.35;
}

.provider-limit-list {
    display: grid;
    gap: 8px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.provider-limit-list li {
    display: grid;
    grid-template-columns: minmax(76px, max-content) 1fr;
    gap: 8px;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

.provider-limit-key {
    color: var(--white);
    font-weight: 900;
}

.invite-row {
    display: grid;
    gap: 8px;
}

.invite-button {
    display: inline-flex;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 9px;
    min-height: 48px;
    border: 1px solid rgba(255, 250, 240, 0.26);
    color: var(--white);
    background: rgba(15, 58, 39, 0.78);
}

.invite-button:hover,
.invite-button:focus-visible {
    border-color: rgba(247, 201, 72, 0.75);
    background: rgba(20, 81, 55, 0.88);
    outline: none;
}

.invite-button:disabled {
    cursor: wait;
    opacity: 0.68;
}

.share-arrow-icon {
    width: 21px;
    height: 21px;
    fill: currentColor;
    flex: 0 0 auto;
}

.invite-status {
    margin: 0;
    color: var(--yellow-400);
    font-size: 0.84rem;
    font-weight: 800;
    text-align: center;
}

.invite-status[hidden] {
    display: none;
}

.actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

button {
    min-height: 50px;
    border: 0;
    border-radius: 8px;
    font-weight: 800;
    cursor: pointer;
}

.capture-form.is-submitting .primary-button,
.capture-form.is-submitting .secondary-button {
    opacity: 0.55;
    pointer-events: none;
}

.primary-button {
    background: var(--yellow-400);
    color: var(--charcoal);
}

.secondary-button {
    border: 1px solid rgba(255, 250, 240, 0.28);
    color: var(--white);
    background: transparent;
}

.result-card {
    margin-top: 16px;
    padding: 18px;
}

.result-card h2 {
    margin-bottom: 8px;
    font-size: 1.35rem;
}

.calories {
    margin-bottom: 12px;
    color: var(--yellow-400);
    font-size: 2rem;
    font-weight: 900;
}

.portion-weight {
    margin: -4px 0 14px;
    color: var(--white);
    font-size: 1rem;
    font-weight: 800;
}

.macros {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-bottom: 14px;
}

.macros div {
    min-width: 0;
    padding: 10px 8px;
    border: 1px solid rgba(255, 250, 240, 0.14);
    border-radius: 8px;
    background: rgba(7, 35, 24, 0.72);
}

.macros dd {
    color: var(--white);
    font-size: 1rem;
}

.macro-scope {
    margin: -4px 0 14px;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.35;
}

dl {
    margin: 0 0 12px;
}

dt {
    color: var(--muted);
    font-size: 0.8rem;
}

dd {
    margin: 2px 0 0;
    font-weight: 800;
}

.note {
    margin-bottom: 0;
    color: var(--muted);
    line-height: 1.45;
}

.correction-panel {
    display: grid;
    gap: 10px;
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid rgba(255, 250, 240, 0.14);
}

.correction-title {
    margin: 0;
    color: var(--yellow-400);
    font-size: 0.9rem;
    font-weight: 900;
}

.correction-actions {
    display: grid;
    gap: 8px;
}

.correction-button {
    min-height: 44px;
    padding: 9px 12px;
    border: 1px solid rgba(255, 250, 240, 0.24);
    color: var(--white);
    background: var(--green-800);
    font-size: 0.88rem;
    line-height: 1.25;
    white-space: normal;
}

.wrong-food-correction {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid rgba(247, 201, 72, 0.32);
    border-radius: 8px;
    background: rgba(7, 35, 24, 0.62);
}

.wrong-food-correction[hidden] {
    display: none;
}

.wrong-food-correction label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 800;
}

.wrong-food-correction input {
    width: 100%;
    min-height: 46px;
    padding: 10px 12px;
    border: 1px solid rgba(255, 250, 240, 0.22);
    border-radius: 8px;
    color: var(--white);
    background: var(--green-800);
}

.correction-submit-button {
    min-height: 44px;
    padding: 9px 12px;
    background: var(--yellow-400);
    color: var(--charcoal);
    font-size: 0.9rem;
}

.error-card {
    border-color: rgba(212, 69, 47, 0.55);
}

.admin-shell,
.admin-login-shell {
    width: min(100%, 1080px);
    margin: 0 auto;
    padding: 20px 16px 40px;
}

.admin-login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
}

.admin-login-panel,
.admin-section {
    border: 1px solid rgba(255, 250, 240, 0.12);
    border-radius: 8px;
    background: var(--green-900);
    box-shadow: 0 18px 50px rgba(0, 0, 0, 0.25);
}

.admin-login-panel {
    width: min(100%, 420px);
    padding: 20px;
}

.admin-login-panel h1,
.admin-header h1 {
    margin: 0;
    font-size: 1.6rem;
}

.admin-login-form,
.admin-token-form {
    display: grid;
    gap: 14px;
}

.admin-login-form label,
.admin-token-form label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 800;
}

.admin-login-form input,
.admin-token-form input {
    width: 100%;
    min-height: 48px;
    padding: 10px;
    border: 1px solid rgba(255, 250, 240, 0.22);
    border-radius: 8px;
    color: var(--white);
    background: var(--green-800);
}

.admin-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.admin-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    margin-bottom: 16px;
    padding-bottom: 4px;
}

.admin-tabs a,
.admin-download-link,
.admin-delete-button {
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border: 1px solid rgba(255, 250, 240, 0.18);
    border-radius: 8px;
    color: var(--white);
    background: var(--green-800);
    font-size: 0.9rem;
    font-weight: 800;
    text-decoration: none;
    white-space: nowrap;
}

.admin-delete-button {
    width: 44px;
    padding: 8px;
    color: #ffb0a3;
    background: rgba(212, 69, 47, 0.12);
}

.admin-section {
    margin-bottom: 16px;
    padding: 16px;
}

.admin-section h2 {
    margin: 0 0 14px;
    font-size: 1.2rem;
}

.admin-stat-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.admin-stat-grid div {
    min-width: 0;
    padding: 12px;
    border: 1px solid rgba(255, 250, 240, 0.12);
    border-radius: 8px;
    background: rgba(7, 35, 24, 0.72);
}

.admin-stat-grid span,
.admin-muted {
    color: var(--muted);
    font-size: 0.86rem;
    line-height: 1.4;
}

.admin-stat-grid strong {
    display: block;
    margin-top: 4px;
    color: var(--yellow-400);
    font-size: 1.5rem;
}

.admin-provider-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.admin-provider-stats span {
    padding: 6px 10px;
    border-radius: 999px;
    color: var(--green-950);
    background: var(--yellow-400);
    font-size: 0.78rem;
    font-weight: 900;
}

.admin-detections-list {
    max-height: 560px;
    overflow-y: auto;
    display: grid;
    gap: 10px;
    padding-right: 4px;
}

.admin-detection {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid rgba(255, 250, 240, 0.12);
    border-radius: 8px;
    background: rgba(7, 35, 24, 0.72);
}

.admin-detection-corrected {
    border-color: rgba(207, 169, 92, 0.42);
    border-left: 4px solid rgba(207, 169, 92, 0.76);
    background: linear-gradient(
            90deg,
            rgba(207, 169, 92, 0.16),
            rgba(7, 35, 24, 0.74) 42%
        ),
        rgba(7, 35, 24, 0.72);
}

.admin-detection > div {
    min-width: 0;
}

.admin-detection-title {
    margin-bottom: 4px;
    color: var(--white);
    font-weight: 900;
}

.admin-correction-badge {
    width: fit-content;
    margin: 8px 0;
    padding: 5px 9px;
    border: 1px solid rgba(207, 169, 92, 0.46);
    border-radius: 8px;
    color: #ead2a1;
    background: rgba(62, 50, 28, 0.42);
    font-size: 0.78rem;
    font-weight: 900;
    line-height: 1.25;
}

.admin-detection-thumb {
    width: 72px;
    height: 72px;
    border: 1px solid rgba(255, 250, 240, 0.18);
    border-radius: 8px;
    object-fit: cover;
    background: var(--green-800);
}

.admin-detection-thumb.is-placeholder {
    object-fit: contain;
    padding: 8px;
}

.admin-detection-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.admin-metadata {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 250, 240, 0.12);
}

.admin-metadata-title {
    margin: 0;
    color: var(--yellow-400);
    font-size: 0.82rem;
    font-weight: 900;
}

.admin-metadata-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 8px;
    margin: 0;
}

.admin-metadata-list div {
    min-width: 0;
}

.admin-metadata-list dd {
    overflow-wrap: anywhere;
    font-size: 0.82rem;
    line-height: 1.35;
}

.admin-exif {
    color: var(--muted);
    font-size: 0.82rem;
}

.admin-exif summary {
    cursor: pointer;
    color: var(--white);
    font-weight: 900;
}

.admin-exif pre {
    max-height: 220px;
    overflow: auto;
    margin: 8px 0 0;
    padding: 10px;
    border: 1px solid rgba(255, 250, 240, 0.12);
    border-radius: 8px;
    background: var(--green-950);
    color: var(--muted);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.admin-trash-icon {
    width: 20px;
    height: 20px;
    display: block;
    fill: currentColor;
}

.admin-error {
    margin-bottom: 0;
    color: #ffb0a3;
    line-height: 1.4;
}

@media (min-width: 640px) {
    .app-shell {
        padding-top: 36px;
    }

    .actions {
        grid-template-columns: 1fr 1fr;
    }

    .admin-stat-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .admin-detection {
        grid-template-columns: 1fr auto auto;
        align-items: center;
    }
}

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