:root {
    /* Brand palette */
    --cream: #fafbec;
    --yellow-green: #dde499;
    --light-green: #77b66b;
    --medium-green: #537043;
    --forest-green: #364c28;
    --terracota: #a95028;
    --dead-leaves: #b0a384;
    --brown: #3e1c00;
    --earth-brown: #351b04;

    /* Semantic roles */
    --bg: var(--cream);
    --result-bg: #eef1df;
    --surface: #ffffff;
    --border: #e3e0cf;
    --text: var(--earth-brown);
    --muted: #7a6f55;
    --accent: var(--medium-green);
    --accent-strong: var(--forest-green);
    --accent-soft: var(--yellow-green);
    --radius: 12px;
    --shadow: 0 1px 2px rgba(54, 76, 40, 0.05), 0 4px 16px rgba(54, 76, 40, 0.07);
    --navbar-height: 56px;
}

/* ---------- Navbar ---------- */
.navbar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: var(--navbar-height);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.navbar-brand {
    display: inline-flex;
    align-items: center;
    margin-right: auto;
}

.navbar-brand img {
    height: 32px;
    width: auto;
    display: block;
}

.navbar-link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}

.navbar-link + .navbar-link { margin-left: 1.5rem; }

.navbar-link:hover { text-decoration: underline; }

* {
    box-sizing: border-box;
}

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

main {
    max-width: 860px;
    margin: 0 auto;
    padding: 2.5rem 1.25rem 4rem;
}

h1 { font-size: 1.9rem; margin: 0; }
h2 { font-size: 1.15rem; margin: 0 0 1rem; }
h3 { font-size: 1.05rem; margin: 0; }
h4 { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 1.25rem 0 0.6rem; }

.muted { color: var(--muted); }

section { margin-bottom: 2.5rem; }

/* ---------- Form ---------- */
form p { margin-bottom: 1.25rem; }

.plan-form { max-width: 560px; }

/* ---------- Upload (index) ---------- */
.upload { max-width: 560px; }

.upload h1 { margin-bottom: 0.5rem; }

.upload-intro { margin: 0 0 1.75rem; }

.upload-form {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 1.5rem;
    padding: 1.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.upload-form .field { width: 100%; }

.upload-form input[type="file"] {
    padding: 0.85rem;
    border: 1px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    cursor: pointer;
}

.upload-form input[type="file"]:hover { border-color: var(--accent); }

/* AOI map preview on the "new" page, aligned above the plan form. */
.aoi-preview { max-width: 560px; }

.aoi-preview .map { height: 360px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.field { margin-bottom: 0; }

.span-2 { grid-column: 1 / -1; }

.input-unit { position: relative; }

.input-unit input { padding-right: 2.2rem; }

/* Hide native number spinners so they don't overlap the unit label. */
.input-unit input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.input-unit input[type="number"]::-webkit-outer-spin-button,
.input-unit input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.input-unit .unit {
    position: absolute;
    right: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    font-size: 0.85rem;
    pointer-events: none;
}

@media (max-width: 520px) {
    .form-grid { grid-template-columns: 1fr; }
}

/* Planting-line source: inline radio toggle + the angle input it reveals. */
.line-source-field .field-label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

.line-source-field > div {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.5rem;
}

.line-source-field > div > div { margin: 0; }

.line-source-field label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    font-weight: 400;
    cursor: pointer;
}

.line-source-field input[type="radio"] { width: auto; }

.line-angle-field[hidden] { display: none; }

/* Nota (disclaimer) editor. */
.nota-form { max-width: 720px; }

.nota-form .nota-text { width: 100%; }

.saved-msg {
    margin: 0 0 1rem;
    color: var(--accent-strong);
    font-weight: 600;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.4rem;
}

textarea,
input[type="text"],
input[type="number"],
input[type="file"],
select {
    width: 100%;
    font: inherit;
}

input[type="text"],
input[type="number"],
select {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

textarea {
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    resize: vertical;
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 0.85rem;
}

textarea:focus,
input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(119, 182, 107, 0.35);
}

button {
    padding: 0.65rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
}

button:hover { background: var(--accent-strong); }

.errorlist {
    color: #c5221f;
    list-style: none;
    padding: 0;
    margin: 0.35rem 0;
    font-size: 0.9rem;
}

/* ---------- Result ---------- */
:root { --sidebar-width: 360px; }

/* Results keep their normal centered width; the sidebar is pinned to the
   left viewport edge, and main is offset so the two never overlap. */
main.has-sidebar {
    max-width: none;
    margin: 0;
    padding-left: calc(var(--sidebar-width) + 2.5rem);
}

.result-main {
    max-width: 860px;
    margin: 0 auto;
    background: var(--result-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem 1.75rem;
}

.result-sidebar {
    position: fixed;
    left: 0;
    top: var(--navbar-height);
    bottom: 0;
    width: var(--sidebar-width);
    overflow-y: auto;
    background: var(--bg);
    border-right: 1px solid var(--border);
    padding: 1.5rem 1.5rem 2.5rem;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
}

.sidebar-head h2 { margin: 0; }

.result-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.result-actions .back { margin-bottom: 0; }

/* Drawer controls are mobile-only; hidden on desktop (persistent sidebar). */
.drawer-toggle,
.drawer-close,
.drawer-backdrop { display: none; }

.drawer-toggle {
    padding: 0.45rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-strong);
    background: var(--accent-soft);
    border: none;
    border-radius: 999px;
    cursor: pointer;
}

.drawer-close {
    font-size: 1.5rem;
    line-height: 1;
    padding: 0 0.25rem;
    color: var(--muted);
    background: none;
    border: none;
    cursor: pointer;
}

/* The form fills the sidebar; stack its fields in the narrow column. */
.result-sidebar .plan-form { max-width: none; }
.result-sidebar .form-grid,
.result-sidebar .tree-selects { grid-template-columns: 1fr; }

@media (max-width: 900px) {
    /* Results take the full width; the form becomes a side drawer. */
    main.has-sidebar { padding-left: 1.25rem; }
    .result-main {
        max-width: none;
        padding: 1.25rem 1rem;
    }

    .drawer-toggle { display: inline-flex; }

    .result-sidebar {
        top: var(--navbar-height);
        width: min(360px, 88vw);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 30;
        box-shadow: 4px 0 24px rgba(20, 30, 20, 0.25);
    }

    body.drawer-open .result-sidebar { transform: translateX(0); }

    .drawer-backdrop {
        display: block;
        position: fixed;
        inset: var(--navbar-height) 0 0 0;
        background: rgba(20, 30, 20, 0.45);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.25s ease;
        z-index: 20;
    }

    body.drawer-open .drawer-backdrop {
        opacity: 1;
        visibility: visible;
    }

    .drawer-close { display: inline-flex; }

    .map { height: 340px; }
}

.back {
    display: inline-block;
    margin-bottom: 1.5rem;
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.9rem;
}

.back:hover { text-decoration: underline; }

.page-header { margin-bottom: 2.5rem; }
.page-header .muted { margin: 0.25rem 0 0; }

.trees-table {
    width: 100%;
    max-width: 640px;
    border-collapse: collapse;
    font-size: 0.95rem;
}

.trees-table th,
.trees-table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border, #e2e2e2);
}

.trees-table th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

a.button {
    display: inline-block;
    text-decoration: none;
    padding: 0.6rem 1.1rem;
    background: var(--accent);
    color: #fff;
    border-radius: 6px;
    font-weight: 600;
    font-size: 0.9rem;
}

a.button:hover { background: var(--accent-strong); }

/* Prominent primary call-to-action */
a.button--primary {
    padding: 0.9rem 2.1rem;
    font-size: 1.05rem;
    font-weight: 700;
    box-shadow: 0 4px 14px rgba(54, 76, 40, 0.28);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

a.button--primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 7px 20px rgba(54, 76, 40, 0.34);
}

/* Quieter, outlined companion action */
a.button--secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

a.button--secondary:hover {
    background: var(--accent);
    color: #fff;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 0.75rem;
}

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

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.3rem;
}

.stat-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-unit {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--muted);
    margin-left: 0.15rem;
}

/* Module cards mirror the selva PDF report's "Módulos" section: a white card
   with a top color bar, a planting line of numbered dots, and one gradient tree
   box per dot (each with its own accent bar) hanging below the line. */
.module-card {
    --module-color: #3182ce;
    --module-text-color: #fff;
    background: var(--surface);
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-top: 6px solid var(--module-color);
    border-radius: 16px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.module-blue { --module-color: #3182ce; --module-text-color: #fff; }
.module-yellow { --module-color: #ecc94b; --module-text-color: #2d3748; }
.module-orange { --module-color: #ed8936; --module-text-color: #fff; }

.module-card-head {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 2px solid rgba(226, 232, 240, 0.4);
}

.module-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--module-color);
    color: var(--module-text-color);
    font-weight: 700;
    font-size: 0.85rem;
}

.module-card-total { display: block; font-size: 1.05rem; font-weight: 700; color: #2d3748; }
.module-card-carbon { display: block; margin-top: 0.2rem; font-size: 0.8rem; color: var(--muted); }

.module-line { position: relative; margin-bottom: 6px; }

/* horizontal line joining the dots: it has to stop at the first and last dot,
   so it is inset by half a column — which depends on how many tree slots the
   module has. */
.module-track {
    position: absolute;
    top: 11px;
    left: calc(50% / var(--module-slots, 4));
    right: calc(50% / var(--module-slots, 4));
    height: 2px;
    background: var(--module-color);
    opacity: 0.5;
}

/* One column per tree slot in the module, however many that is. */
.module-dots,
.module-items {
    display: grid;
    grid-template-columns: repeat(var(--module-slots, 4), 1fr);
    gap: 0.75rem;
}

.module-dot-node {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 24px;
}

/* connector dropping from the dot into the tree box below */
.module-dot-node::after {
    content: "";
    position: absolute;
    top: 22px;
    left: 50%;
    margin-left: -1px;
    width: 2px;
    height: 10px;
    background: var(--module-color);
    opacity: 0.5;
}

.module-dot {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--module-color);
    color: var(--module-text-color);
    font-size: 0.72rem;
    font-weight: 700;
    z-index: 1;
}

.module-item {
    text-align: center;
    padding: 0.9rem;
    border: 1px solid rgba(226, 232, 240, 0.8);
    border-top: 3px solid var(--module-color);
    border-radius: 8px;
    background: linear-gradient(135deg, #f7fafc 0%, #edf2f7 100%);
}

.module-tree-name,
.module-tree-strata,
.module-tree-carbon,
.module-tree-count { display: block; }

.module-tree-name { font-weight: 700; font-size: 0.9rem; color: #2d3748; }
.module-tree-strata {
    margin-top: 0.25rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
}
.module-tree-carbon { margin-top: 0.25rem; font-size: 0.75rem; color: var(--accent-strong); }
.module-tree-count {
    margin-top: 0.35rem;
    font-size: 1.05rem;
    font-weight: 700;
    color: #2d3748;
    font-variant-numeric: tabular-nums;
}

.species {
    list-style: none;
    margin: 0;
    padding: 0;
    font-size: 0.9rem;
}

.species li {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
}

.species li + li { border-top: 1px dashed var(--border); }

.species .count {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.map {
    width: 100%;
    height: 480px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

/* Name badge drawn at each boundary polygon's centroid, so plots in a
   multi-polygon KML can be told apart. Display-only for now — clicks fall
   through to the map. */
.plot-label {
    padding: 0.1rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: var(--forest-green);
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
    pointer-events: none;
    user-select: none;
}

/* Per-plot planting breakdown in the result. */
.plot-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.plot-table th,
.plot-table td {
    padding: 0.45rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.plot-table th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.plot-table td:first-child { font-weight: 600; }

/* ---------- Per-plot tabs ---------- */
.plot-notice { margin: 0 0 1rem; font-size: 0.85rem; }

.plot-notice[hidden] { display: none; }

/* Shown only when the KML has more than one plot; a single plot renders its
   panel bare, as if the tabs did not exist. */
.plot-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
}

.plot-tabs[hidden] { display: none; }

.plot-tab {
    padding: 0.4rem 0.9rem;
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
    background: transparent;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.plot-tab:hover { background: var(--surface); color: var(--accent-strong); }

.plot-tab.is-active {
    background: var(--surface);
    border-color: var(--border);
    color: var(--accent-strong);
    /* Sit on top of the tab strip's border so the panel reads as continuous. */
    margin-bottom: -1px;
    padding-bottom: calc(0.4rem + 1px);
}

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

/* ---------- Config subgroups (Linhas de Plantio / Bordadura) ---------- */
.config-subgroup { margin-bottom: 1.75rem; }

.config-subgroup h3 { margin-bottom: 1rem; }

/* A subgroup disabled by "Somente bordadura" — dimmed and non-interactive. */
.config-subgroup.is-disabled { opacity: 0.5; }

.checkbox-field { margin-bottom: 0.6rem; }

.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }

.checkbox-label input[type="checkbox"] { width: auto; margin: 0; }

.checkbox-label input:disabled + span,
.checkbox-label input:disabled { cursor: not-allowed; }

/* ---------- Árvores (tree selects) ---------- */
.trees-section { margin: 2rem 0 1.5rem; }

.trees-section h2 { margin-bottom: 1rem; }

.tree-module {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem 1.25rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

.tree-module h3 {
    margin: 0 0 0.9rem;
    color: var(--accent-strong);
}

.tree-selects {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.tree-selects label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--muted);
}

/* ---------- Carbono ---------- */
.income-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.income-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    border-top: 4px solid var(--accent);
}

.income-card.euro { border-top-color: var(--light-green); }
.income-card.real { border-top-color: var(--medium-green); }

.income-card h3 {
    text-align: center;
    color: var(--accent-strong);
    margin-bottom: 1rem;
}

.income-rows {
    list-style: none;
    margin: 0;
    padding: 0;
}

.income-rows li {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.45rem 0;
    font-size: 0.92rem;
}

.income-rows li + li { border-top: 1px solid var(--border); }

.income-rows .amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.footnote {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.5rem;
}

/* ---------- Report download ---------- */
.report-download {
    display: flex;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* ---------- Footer ---------- */
.site-footer {
    margin-top: 3rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.85rem;
    color: var(--muted);
}

.site-footer a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.site-footer a:hover { text-decoration: underline; }

.tree-carbon {
    display: block;
    margin-top: 0.3rem;
    font-size: 0.8rem;
    color: var(--accent-strong);
}

.aoi-file {
    margin: 0 0 0.6rem;
    font-size: 0.9rem;
    color: var(--muted);
}
