* {
    box-sizing: border-box;
}

:root {
    --primary: #2d7a37;
    --primary-dark: #1f5a28;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #d1d5db;
    --card: #fffdf6;
    --danger: #b42318;
    --wood: #8b5a2b;
    --wood-dark: #5c3a18;
    --gold: #f4c542;
    --sky-top: #6ec4ef;
    --sky-bottom: #d7f0ff;
}

html,
body {
    min-height: 100%;
}

body.farmville {
    font-family: "Trebuchet MS", "Segoe UI", Tahoma, Arial, sans-serif;
    margin: 0;
    color: var(--text);
    background: #143d1a;
}

.hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    background: linear-gradient(#f6d58b, #e0a84a);
    border-bottom: 4px solid var(--wood-dark);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.18);
    position: sticky;
    top: 0;
    z-index: 40;
}

.hud-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 800;
    color: var(--wood-dark);
    text-shadow: 0 1px 0 #fff3c4;
}

.hud-brand .logo {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: #ef8b2c;
    box-shadow: inset 0 -4px 0 #c96a14, 0 2px 0 #fff3c4;
}

.hud a {
    color: var(--wood-dark);
    text-decoration: none;
    margin-left: 10px;
    font-weight: 800;
}

.nav-links {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.farm-shell {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 16px 36px;
}

.ok,
.err {
    padding: 10px 12px;
    border-radius: 10px;
    margin-bottom: 12px;
    font-weight: 700;
}

.ok {
    background: #ecfdf3;
    border: 2px solid #75d19c;
    color: #13693b;
}

.err {
    background: #fef3f2;
    border: 2px solid #f7b4ae;
    color: var(--danger);
}

.world-card,
.empty-card {
    background: var(--card);
    border: 3px solid #c9a15b;
    border-radius: 16px;
    padding: 14px;
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.12);
    margin-bottom: 16px;
}

h2 {
    margin: 0 0 8px;
    color: var(--wood-dark);
}

.muted {
    color: var(--muted);
    font-size: 13px;
}

.actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
    align-items: center;
}

.btn,
.hud-select {
    padding: 9px 12px;
    border-radius: 999px;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    border: 2px solid var(--wood-dark);
    background: linear-gradient(#ffe48a, #f0b429);
    color: var(--wood-dark);
    font: inherit;
}

.btn-ghost {
    background: linear-gradient(#fff, #f3e6c4);
}

.farm-map {
    height: 320px;
    width: 100%;
    border-radius: 12px;
    border: 3px solid #c9a15b;
    margin-top: 10px;
    z-index: 1;
}

.leaflet-tooltip.farm-pin-tooltip {
    background: #fffdf6;
    color: var(--primary-dark);
    border: 2px solid #c9a15b;
    border-radius: 10px;
    padding: 8px 10px;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
    font-size: 13px;
    white-space: nowrap;
}

.leaflet-tooltip.farm-pin-tooltip::before {
    border-top-color: #c9a15b;
}

.farm-pin-label b {
    display: block;
    margin-bottom: 2px;
}

.farm-pin-label a {
    color: var(--primary-dark);
    font-weight: 700;
    text-decoration: none;
}

.farm-pin-open {
    display: block;
    margin-top: 2px;
    color: #c2410c;
    font-weight: 700;
    font-size: 12px;
}

.leaflet-tooltip.farm-pin-tooltip.is-open {
    border-color: #ef8b2c;
    box-shadow: 0 0 0 3px rgba(239, 139, 44, 0.25);
}

@keyframes papaya-blink {

    0%,
    100% {
        opacity: 1;
        filter: drop-shadow(0 0 0 rgba(239, 139, 44, 0));
    }

    50% {
        opacity: 0.4;
        filter: drop-shadow(0 0 12px rgba(239, 139, 44, 0.95));
    }
}

img.leaflet-marker-icon.papaya-pin-icon.is-open {
    animation: papaya-blink 1s ease-in-out infinite;
}

.orchard-wrap {
    border: 4px solid var(--wood-dark);
    border-radius: 22px;
    overflow: hidden;
    box-shadow: 0 12px 0 rgba(0, 0, 0, 0.2);
    margin-bottom: 16px;
    background: #4e9a3a;
}

.orchard-hud {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 14px;
    background: linear-gradient(#7a4a22, #5c3416);
    color: #fff8e4;
}

.orchard-hud h2 {
    color: #fff8e4;
    margin: 0;
    font-size: 20px;
}

.stats {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.stat {
    background: rgba(0, 0, 0, 0.25);
    border: 2px solid #c9a15b;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 12px;
    font-weight: 800;
}

.stat b {
    color: var(--gold);
}

.legend {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 14px;
    background: rgba(20, 61, 26, 0.35);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
}

.legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.swatch {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    border: 2px solid #fff;
    display: inline-block;
}

.swatch.none {
    background: #8dcf63;
}

.swatch.healthy {
    background: #2f9e44;
}

.swatch.disease {
    background: #dc3b3b;
}

.scene {
    position: relative;
    min-height: 680px;
    overflow: hidden;
}

.scene-land {
    background-color: #3f8c32;
    background-image:
        radial-gradient(circle at 18% 22%, rgba(255, 255, 255, 0.08) 0 2px, transparent 3px),
        radial-gradient(circle at 72% 48%, rgba(0, 0, 0, 0.08) 0 1px, transparent 2px),
        radial-gradient(circle at 40% 78%, rgba(255, 255, 255, 0.06) 0 2px, transparent 3px),
        linear-gradient(180deg, #5aaa3f 0%, #3f8c32 42%, #34782a 100%);
    background-size: 42px 42px, 28px 28px, 36px 36px, 100% 100%;
}

.cloud {
    position: absolute;
    background: #fff;
    border-radius: 40px;
    opacity: 0.85;
    animation: drift 40s linear infinite;
}

.cloud:before,
.cloud:after {
    content: "";
    position: absolute;
    background: #fff;
    border-radius: 50%;
}

.cloud.c1 {
    width: 90px;
    height: 28px;
    top: 28px;
    left: 8%;
}

.cloud.c1:before {
    width: 36px;
    height: 36px;
    top: -18px;
    left: 16px;
}

.cloud.c1:after {
    width: 48px;
    height: 48px;
    top: -24px;
    left: 38px;
}

.cloud.c2 {
    width: 120px;
    height: 32px;
    top: 70px;
    right: 12%;
    animation-duration: 55s;
}

.cloud.c2:before {
    width: 44px;
    height: 44px;
    top: -20px;
    left: 20px;
}

.cloud.c2:after {
    width: 56px;
    height: 56px;
    top: -28px;
    left: 50px;
}

@keyframes drift {
    from {
        transform: translateX(0);
    }

    to {
        transform: translateX(40px);
    }
}

.hill {
    position: absolute;
    left: -8%;
    right: -8%;
    top: 34%;
    height: 90px;
    background: #8ed56a;
    border-radius: 50% 50% 0 0;
    box-shadow: 0 -10px 0 #a6e07f inset;
}

.barn {
    position: absolute;
    left: 18px;
    top: 150px;
    width: 92px;
    height: 78px;
    z-index: 2;
    filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.15));
}

.fence {
    position: absolute;
    left: 0;
    right: 0;
    top: 41%;
    height: 18px;
    background: repeating-linear-gradient(90deg, #c48a48 0 10px, transparent 10px 22px);
    border-top: 4px solid #8b5a2b;
    border-bottom: 4px solid #8b5a2b;
    opacity: 0.7;
    z-index: 2;
}

.farm-zoom-bar {
    position: absolute;
    right: 12px;
    bottom: 12px;
    z-index: 8;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: calc(100% - 24px);
    gap: 6px;
    background: #fffdf6;
    border: 3px solid var(--wood-dark);
    border-radius: 14px;
    padding: 6px 8px;
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.16);
}

.farm-zoom-btn {
    width: 36px;
    height: 36px;
    margin: 0;
    padding: 0;
    font-size: 22px;
    font-weight: 900;
    line-height: 1;
}

.farm-zoom-reset {
    width: auto;
    padding: 0 10px;
    font-size: 12px;
}

#farmZoomLabel {
    min-width: 52px;
    text-align: center;
    font-weight: 800;
    color: var(--wood-dark);
}

.iso-viewport {
    position: relative;
    height: 720px;
    overflow: hidden;
    cursor: grab;
    z-index: 3;
    touch-action: none;
    overscroll-behavior: none;
    -webkit-overflow-scrolling: auto;
    scrollbar-width: none;
}

.iso-viewport::-webkit-scrollbar {
    display: none;
}

.iso-viewport.is-dragging {
    cursor: grabbing;
}

.iso-zoom-sizer {
    position: relative;
    transform-origin: 0 0;
    will-change: transform;
}

.iso-field {
    --tw: 400px;
    --th: 200px;
    --origin-x: calc(var(--rows) * var(--tw) / 2 + 180px);
    --origin-y: 90px;
    position: relative;
    width: calc((var(--cols) + var(--rows)) * var(--tw) / 2 + 480px);
    height: calc((var(--cols) + var(--rows)) * var(--th) / 2 + 520px);
    margin: 0 auto;
    transform-origin: 0 0;
}

.papaya-plot {
    position: absolute;
    width: 168px;
    height: 200px;
    left: calc((var(--c) - var(--r)) * (var(--tw) / 2) + var(--origin-x));
    top: calc((var(--c) + var(--r) - 2) * (var(--th) / 2) + var(--origin-y));
    z-index: calc(var(--r) * 40 + var(--c));
    text-decoration: none;
    color: inherit;
    transform-origin: 50% 90%;
}

.papaya-plot:hover,
.papaya-plot:focus-visible {
    transform: scale(1.12);
    z-index: 900;
}

.papaya-plot.is-selected {
    transform: scale(1.16);
    z-index: 850;
    animation: plot-highlight-pulse 1.1s ease-in-out infinite;
}

@keyframes plot-highlight-pulse {

    0%,
    100% {
        filter: drop-shadow(0 0 0 rgba(255, 224, 120, 0));
    }

    50% {
        filter: drop-shadow(0 0 18px rgba(255, 224, 120, 0.95));
    }
}

.papaya-plot.is-selected .soil {
    outline: 4px solid #fff4c4;
    box-shadow: 0 10px 0 rgba(70, 40, 10, 0.18), 0 0 0 6px rgba(255, 224, 120, 0.55);
}

.papaya-plot.is-selected .plot-tag {
    background: #ffe08a;
}

.soil {
    position: absolute;
    left: 50%;
    bottom: 14px;
    width: 132px;
    height: 76px;
    transform: translateX(-50%);
    background: #c49a63;
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
    box-shadow: 0 10px 0 rgba(70, 40, 10, 0.18);
    outline: 3px solid rgba(255, 244, 210, 0.35);
    pointer-events: none;
}

.soil::after {
    content: "";
    position: absolute;
    inset: 8px 16px;
    background: #a97840;
    clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
    opacity: 0.55;
}

.status-healthy .soil {
    background: #b8894a;
}

.status-disease .soil {
    background: #8a5a32;
}

.tree {
    position: absolute;
    left: 50%;
    bottom: 42px;
    width: 108px;
    height: 138px;
    transform: translateX(-50%);
    filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.18));
    pointer-events: none;
}

.plot-tag {
    position: absolute;
    left: 50%;
    bottom: 0;
    transform: translateX(-50%);
    background: #fffdf6;
    border: 2px solid var(--wood-dark);
    border-radius: 999px;
    padding: 4px 12px;
    font-size: 13px;
    font-weight: 800;
    color: var(--wood-dark);
    white-space: nowrap;
    pointer-events: none;
}

.plot-tip {
    display: none;
    position: absolute;
    left: 50%;
    top: -8px;
    transform: translate(-50%, -100%);
    background: #fffdf6;
    border: 2px solid var(--wood-dark);
    border-radius: 10px;
    padding: 8px 10px;
    min-width: 148px;
    text-align: center;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    box-shadow: 0 6px 0 rgba(0, 0, 0, 0.12);
    z-index: 5;
    pointer-events: none;
}

.papaya-plot:hover .plot-tip,
.papaya-plot:focus-visible .plot-tip,
.papaya-plot.is-selected .plot-tip {
    display: block;
}

.alert-dot {
    position: absolute;
    right: 18px;
    top: 12px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    font-size: 14px;
    font-weight: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 3px #fff;
    pointer-events: none;
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.12);
    }
}

.empty-field {
    position: relative;
    z-index: 3;
    padding: 80px 20px 80px;
    text-align: center;
    color: #143d1a;
}

.empty-field h2 {
    color: #143d1a;
}

.hud-subtitle {
    color: #5c3a18 !important;
    font-weight: 700;
}

.nav-links a.is-active {
    background: #fff3c4;
    border: 2px solid var(--wood-dark);
    border-radius: 999px;
    padding: 6px 10px;
    margin-left: 8px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 16px 16px 36px;
}

.card,
.world-card,
.empty-card,
.auth-card {
    background: var(--card);
    border: 3px solid #c9a15b;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 8px 0 rgba(0, 0, 0, 0.12);
    margin-bottom: 16px;
}

h1 {
    margin: 0 0 8px;
    color: var(--wood-dark);
}

h3,
.card-title {
    margin: 0 0 8px;
    color: var(--wood-dark);
}

label {
    display: block;
    margin: 10px 0 6px;
    font-size: 14px;
    font-weight: 700;
    color: var(--wood-dark);
}

input,
textarea,
select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 2px solid #c9a15b;
    background: #fffef8;
    color: var(--text);
    font: inherit;
}

textarea {
    min-height: 90px;
}

button,
.btn,
.hud-select {
    padding: 9px 12px;
    border-radius: 999px;
    font-weight: 800;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
    border: 2px solid var(--wood-dark);
    background: linear-gradient(#ffe48a, #f0b429);
    color: var(--wood-dark);
    font: inherit;
}

.btn-ghost {
    background: linear-gradient(#fff, #f3e6c4);
}

.btn-danger,
button.btn-danger {
    background: linear-gradient(#ef6b5a, #c0392b);
    color: #fff;
    border-color: #7a1f14;
}

.btn-small {
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 800;
    background: #fff3c4;
    color: var(--wood-dark);
    border: 2px solid var(--wood-dark);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-small.btn-danger {
    background: #fef3f2;
    color: var(--danger);
    border-color: #f7b4ae;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 10px 8px;
    border-bottom: 1px solid #ecd9a8;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
}

a.plot-jump {
    font-weight: 800;
    color: var(--primary-dark);
    text-decoration: none;
    border-bottom: 2px solid var(--gold);
}

a.plot-jump:hover {
    color: var(--primary);
}

img {
    border-radius: 10px;
}

.row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}

.facts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin: 12px 0;
}

.fact,
.kpi .box {
    background: #fff8e4;
    border: 2px solid #c9a15b;
    border-radius: 10px;
    padding: 10px 12px;
}

.fact b,
.kpi .num {
    display: block;
    font-size: 16px;
    color: var(--wood-dark);
}

.kpi {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.kpi .box {
    min-width: 140px;
}

.tag,
.pill,
.status-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    border: 2px solid #c9a15b;
    background: #fff3c4;
    color: var(--wood-dark);
}

.status-ok {
    color: #166534;
    background: #ecfdf3;
    border-color: #86efac;
}

.status-miss {
    color: #92400e;
    background: #fffbeb;
    border-color: #fcd34d;
}

.mono {
    font-family: Consolas, Menlo, monospace;
    font-size: 12px;
}

a {
    color: var(--wood-dark);
}

.camera-preview {
    width: 100%;
    max-width: 420px;
    border-radius: 10px;
    border: 2px solid #c9a15b;
    background: #000;
    object-fit: contain;
}

.camera-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.camera-actions button {
    background: linear-gradient(#fff, #f3e6c4);
}

img.thumb,
img.sample-thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border: 2px solid #c9a15b;
}

.table-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
}

.fixed-scrollbar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    height: 16px;
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(255, 253, 246, 0.95);
    border-top: 2px solid #c9a15b;
    z-index: 999;
    display: none;
}

.fixed-scrollbar-inner {
    height: 1px;
}

.search-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
    margin-top: 10px;
}

.search-wrap {
    position: relative;
}

.search-results {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 20;
    background: #fffdf6;
    border: 2px solid #c9a15b;
    border-radius: 10px;
    margin-top: 4px;
    max-height: 220px;
    overflow: auto;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
    display: none;
}

.search-results button {
    display: block;
    width: 100%;
    text-align: left;
    background: #fff;
    color: var(--text);
    border: 0;
    border-bottom: 1px solid #f3e6c4;
    border-radius: 0;
    font-weight: 500;
    padding: 10px 12px;
}

.search-results button:last-child {
    border-bottom: 0;
}

.search-results button:hover {
    background: #fff8e4;
}

.folder-tools {
    display: flex;
    gap: 8px;
    margin: 8px 0 10px;
}

.folder-browse {
    max-height: 280px;
    overflow: auto;
    border: 2px solid #c9a15b;
    border-radius: 10px;
    background: #fffef8;
}

.folder-item {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: #fff;
    color: var(--text);
    border: 0;
    border-bottom: 1px solid #f3e6c4;
    border-radius: 0;
    padding: 10px 12px;
    font-weight: 600;
    cursor: pointer;
}

.folder-item:last-child {
    border-bottom: 0;
}

.folder-item:hover,
.folder-item.is-selected {
    background: #ecfdf3;
}

.folder-item .count {
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
}

.sample-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.sample-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 8px;
    border: 2px solid #c9a15b;
    border-radius: 10px;
    background: #fff;
}

.sample-link {
    display: inline-flex;
}

.lightbox,
.img-lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.92);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.lightbox.show,
.img-lightbox.is-open {
    display: flex;
}

.lightbox img,
.img-lightbox img {
    max-width: 95vw;
    max-height: 78vh;
    object-fit: contain;
    border-radius: 8px;
    background: #111;
}

.lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 44px;
    border-radius: 999px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    background: rgba(17, 24, 39, 0.65);
    color: #fff;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.lightbox-prev {
    left: 18px;
}

.lightbox-next {
    right: 18px;
}

.img-lightbox-tools {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 2;
}

.img-lightbox-close {
    position: absolute;
    top: 12px;
    right: 16px;
    border-radius: 999px;
    width: 36px;
    height: 36px;
}

.img-lightbox-caption {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 12px;
    text-align: center;
    color: #e8f5e9;
}

.grid {
    display: grid;
    gap: 16px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.grid.detect {
    grid-template-columns: 2fr 1fr;
}

.farm-pick {
    display: grid;
    grid-template-columns: 1.4fr 1fr 1fr;
    gap: 10px;
    margin: 0 0 14px;
}

.result-area {
    margin: 16px 0;
    padding: 16px;
    background: #fff8e4;
    border-radius: 12px;
    border: 2px solid #c9a15b;
}

.result-box {
    margin: 10px 0 12px;
    padding: 12px;
    background: #fff;
    border-radius: 8px;
    border: 2px solid #ecd9a8;
}

.result-image {
    width: 100%;
    max-width: 280px;
    height: 200px;
    object-fit: cover;
    cursor: zoom-in;
    display: block;
    background: #f3f4f6;
}

.scan-latest,
.scan-result-split {
    display: grid;
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
    gap: 28px 36px;
    align-items: start;
    margin-top: 12px;
}

.scan-result-title {
    margin: 8px 0 10px;
    font-size: 1.45rem;
    color: var(--primary-dark);
}

.scan-result-photo img,
.scan-result-split .result-image {
    width: 100%;
    max-width: 300px;
    height: auto;
    max-height: 340px;
    object-fit: contain;
    object-position: top left;
    display: block;
    background: transparent;
    border-radius: 10px;
}

.scan-result-copy {
    margin: 0;
    padding: 0;
    background: none;
    border: none;
    color: var(--text);
}

.scan-result-copy strong {
    display: block;
    font-size: 1.28rem;
    color: var(--primary-dark);
    margin: 0 0 8px;
}

.scan-result-copy p,
.scan-result-copy .muted {
    margin: 0;
    font-size: 1.12rem;
    line-height: 1.65;
}

.scan-result-block + .scan-result-block {
    margin-top: 22px;
}

.confidence-calc {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 12px 14px;
}

.confidence-calc h3 {
    margin: 0 0 8px;
    font-size: 1rem;
}

.confidence-formula {
    margin: 8px 0 12px;
    padding: 8px 10px;
    background: #f8fafc;
    border-radius: 8px;
    font-size: 12px;
}

.confidence-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}

.confidence-kpis>div {
    background: #f8fafc;
    border-radius: 8px;
    padding: 8px 10px;
}

.confidence-kpis b {
    display: block;
    margin-top: 2px;
}

.confidence-row {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) 58px minmax(70px, 1fr);
    gap: 8px;
    align-items: center;
    margin-bottom: 6px;
    font-size: 13px;
}

.confidence-row.is-top .confidence-name {
    font-weight: 800;
    color: var(--primary-dark);
}

.confidence-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.confidence-pct {
    text-align: right;
}

.confidence-bar {
    height: 8px;
    background: #e5e7eb;
    border-radius: 99px;
    overflow: hidden;
}

.confidence-bar>span {
    display: block;
    height: 100%;
    background: #86efac;
}

.confidence-row.is-top .confidence-bar>span {
    background: #166534;
}

.scan-photo-wrap {
    position: relative;
    margin-top: 12px;
    max-width: 360px;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    background: #111;
}

.scan-photo-wrap img {
    display: block;
    width: 100%;
    max-height: 360px;
    object-fit: contain;
    background: #111;
}

.scan-photo-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    background: linear-gradient(transparent, rgba(0, 0, 0, .72));
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
}

.scan-chip {
    background: rgba(255, 255, 255, .92);
    color: #111827;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 700;
}

.scan-chip.is-top {
    background: #166534;
    color: #fff;
}

.confidence-table-wrap {
    overflow: auto;
}

.confidence-table {
    width: 100%;
    font-size: 12px;
}

.confidence-table th,
.confidence-table td {
    padding: 6px 4px;
    vertical-align: middle;
}

.confidence-table tr.is-top td {
    font-weight: 800;
}

.formula-open {
    background: #fff;
    border: 1px solid #c9a15b;
    color: var(--wood-dark);
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.formula-modal {
    position: fixed;
    inset: 0;
    z-index: 80;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 28px 12px;
    overflow: auto;
    background: rgba(17, 24, 39, .55);
}

.formula-modal[hidden] {
    display: none !important;
}

.formula-dialog {
    width: min(760px, 100%);
    background: #fffef8;
    border: 2px solid #c9a15b;
    border-radius: 14px;
    padding: 18px 20px 22px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, .25);
}

.formula-block {
    margin: 8px 0 14px;
    padding: 10px 12px;
    background: #f8fafc;
    border-radius: 8px;
    line-height: 1.55;
    overflow-x: auto;
}

.formula-close {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #fff;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.formula-lesson {
    font-size: 16px;
    line-height: 1.65;
    color: #111827;
}

.formula-lesson p {
    margin: 10px 0;
}

.formula-lesson .tex {
    margin: 14px 0;
    overflow-x: auto;
}

.formula-prob-table {
    max-width: 420px;
}

.formula-prob-table th,
.formula-prob-table td {
    text-align: left;
}

.formula-result-cards {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin: 12px 0 16px;
    max-width: 420px;
}

.formula-result-cards>div {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 10px 12px;
}

.formula-result-cards b {
    display: block;
    font-size: 1.15rem;
    margin-top: 4px;
}

.image-panels {
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 14px;
    margin-top: 12px;
}

.image-panel {
    background: #fff;
    border: 2px solid #c9a15b;
    border-radius: 10px;
    padding: 12px;
}

.samples-panel {
    grid-column: 1 / -1;
}

.sample-grid,
.leaf-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.info-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 10px;
}

.info-list li {
    padding: 10px 12px;
    border: 2px solid #c9a15b;
    border-radius: 10px;
    background: #fff;
}

.hint {
    margin-top: 12px;
    color: var(--muted);
    font-size: 13px;
}

body.auth-page {
    min-height: 100vh;
    background: linear-gradient(var(--sky-top) 0%, var(--sky-bottom) 38%, #7bc45a 38%, #3f8a32 100%);
}

.auth-hero {
    text-align: center;
    padding: 36px 16px 8px;
    color: var(--wood-dark);
    text-shadow: 0 1px 0 #fff3c4;
}

.auth-hero h1 {
    font-size: clamp(1.3rem, 3vw, 1.9rem);
}

.auth-card {
    max-width: 460px;
    margin: 16px auto 36px;
}

.auth-card button {
    width: 100%;
    margin-top: 16px;
}

.scene-strip {
    position: relative;
    overflow: hidden;
    border: 4px solid var(--wood-dark);
    border-radius: 22px;
    margin-bottom: 16px;
    min-height: 140px;
    background: linear-gradient(var(--sky-top) 0%, var(--sky-bottom) 55%, #7bc45a 55%, #4e9a3a 100%);
    color: var(--wood-dark);
    padding: 28px 20px;
}

.scene-strip h1,
.scene-strip p {
    position: relative;
    z-index: 2;
    max-width: 780px;
}

@media (max-width: 920px) {

    .grid,
    .grid.detect {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 800px) {
    .nav-links {
        width: 100%;
        justify-content: flex-start;
        gap: 8px;
    }

    .nav-links a {
        margin-left: 0;
        padding: 6px 10px;
        border: 2px solid var(--wood-dark);
        border-radius: 999px;
        background: #fff3c4;
    }

    .iso-viewport {
        height: 580px;
    }

    .farm-map {
        height: 280px;
    }

    .row,
    .search-row,
    .farm-pick,
    .image-panels,
    .scan-latest,
    .scan-result-split {
        grid-template-columns: 1fr;
    }

    .camera-actions button {
        width: 100%;
    }
}