:root {
    --bg: #f4fbf6;
    --card: #ffffff;
    --accent: #216b31;
    --accent-strong: #174f25;
    --muted: #667085;
    --text: #0f1720;
    --danger: #b42318;
    --border: #dfeadf;
    --loss-low-border: #75bd8a;
    --loss-low-bg: #e7f5ec;
    --loss-low-text: #1e6337;
    --loss-medium-border: #e6a14a;
    --loss-medium-bg: #fff0dd;
    --loss-medium-text: #8a4600;
    --loss-high-border: #df8d98;
    --loss-high-bg: #fce8ea;
    --loss-high-text: #8f1d2c;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 24px;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, system-ui, "Segoe UI", Arial, sans-serif;
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 18px;
}

.title-banner {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 20px;
    font-weight: 700;
}

.subtitle {
    margin: 8px 0;
    color: var(--muted);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-actions a {
    color: var(--accent-strong);
    font-weight: 600;
    text-decoration: none;
}

.header-actions a:hover {
    text-decoration: underline;
}

.card {
    margin: 14px 0;
    padding: 20px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--card);
    box-shadow: 0 6px 18px rgba(34, 60, 80, 0.05);
}

h2 {
    margin: 0 0 14px;
    color: var(--text);
    font-size: 20px;
}

h3 {
    color: var(--accent-strong);
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.section-head p {
    margin: 4px 0 0;
    color: var(--muted);
}

button,
input[type="submit"] {
    padding: 10px 14px;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-weight: 650;
    cursor: pointer;
}

button:hover,
input[type="submit"]:hover {
    background: var(--accent-strong);
}

button:disabled,
input[type="submit"]:disabled {
    cursor: wait;
    opacity: 0.65;
}

.secondary {
    border: 1px solid var(--accent);
    background: #fff;
    color: var(--accent-strong);
}

.secondary:hover {
    background: #edf7ef;
    color: var(--accent-strong);
}

.language-toggle {
    min-width: 78px;
    white-space: nowrap;
}

.prev-step {
    background: #7a8288;
}

#delete-selected {
    border: 1px solid #f0c2bd;
    background: #fff;
    color: var(--danger);
}

.edit-calculation {
    padding: 7px 12px;
    font-size: 14px;
    white-space: nowrap;
}

.modal {
    box-sizing: border-box;
    padding: clamp(16px, 4vh, 40px) 16px;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: rgba(15, 23, 32, 0.52);
}

body.modal-open {
    overflow: hidden;
}

.modal-content {
    box-sizing: border-box;
    width: min(720px, 100%);
    min-width: 0;
    max-width: 100%;
    max-height: none;
    margin: 0 auto;
    padding: 26px;
    overflow: visible;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 18px 45px rgba(15, 23, 32, 0.2);
    transition: width 180ms ease;
}

.modal-content[data-active-step="1"] {
    width: min(960px, 100%);
}

.modal-content[data-active-step="2"] {
    width: min(800px, 100%);
}

.modal-content[data-active-step="3"],
.modal-content[data-active-step="4"] {
    width: min(680px, 100%);
}

.modal-content[data-active-step="5"] {
    width: min(880px, 100%);
}

.modal-content h2 {
    margin: 0 40px 20px 0;
    color: var(--accent-strong);
}

.close-modal {
    top: 12px;
    right: 14px;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #fff;
    color: var(--muted);
    font-size: 24px;
    line-height: 1;
}

.form-step {
    min-height: 0;
}

.form-group label {
    color: var(--text);
    font-weight: 600;
}

.form-group select,
.form-group input[type="number"],
.form-group input[type="text"] {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    font: inherit;
}

.form-group select:focus,
.form-group input:focus {
    border-color: var(--accent);
    outline: 2px solid rgba(43, 138, 62, 0.14);
    box-shadow: none;
}

.layer-group,
.fertilizers-list {
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #f6fbf7;
}

.dropdown-content {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 8px 20px rgba(15, 23, 32, 0.15);
}

.dropdown-item:hover {
    background: #edf7ef;
}

.fertilizer-search-select input {
    padding-right: 38px !important;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--muted) 50%),
        linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position:
        calc(100% - 18px) 50%,
        calc(100% - 13px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}

.fertilizer-picker-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: start;
}

#fertilizer-add-button {
    min-width: 92px;
}

#fertilizer-add-button:disabled {
    cursor: not-allowed;
}

.fertilizer-dropdown {
    max-height: 240px;
}

.fertilizer-dropdown-item.active,
.planned-crop-dropdown-item.active,
.fertilizer-dropdown-item:hover {
    background: #e5f3e8;
    color: var(--accent-strong);
}

.fertilizer-dropdown-item[hidden] {
    display: none;
}

.planned-crop-dropdown-item[hidden] {
    display: none !important;
}

.fertilizer-no-results {
    padding: 12px;
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}

.fertilizer-item {
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
}

.fertilizer-item input[type="checkbox"] {
    accent-color: var(--accent);
}

.history-section > p {
    color: var(--muted);
}

.history-section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 16px;
}

.history-section-head h2 {
    margin-bottom: 6px;
}

.history-section-head p {
    max-width: 760px;
    margin: 0;
    color: var(--muted);
}

.calculation-card-list {
    display: grid;
    gap: 14px;
}

.calculation-card {
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
}

.calculation-card-head {
    display: grid;
    grid-template-columns: auto minmax(180px, 1fr) minmax(190px, auto) auto;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    border-bottom: 1px solid #c9e3d2;
    background: #eef7f1;
}

.card-selector {
    display: flex;
    align-items: center;
    margin: 0;
}

.calculation-card-title span,
.calculation-card-result span,
.calculation-detail-label {
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.calculation-card-title h3 {
    margin: 0;
    color: var(--text);
    font-size: 17px;
}

.calculation-card-result {
    text-align: right;
}

.calculation-card-result strong {
    color: var(--accent-strong);
    font-size: 17px;
    white-space: nowrap;
}

.calculation-sections {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 16px;
    padding: 16px;
}

.calculation-data-section {
    min-width: 0;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.calculation-data-section h4 {
    margin: 0;
    padding: 11px 14px;
    border-bottom: 1px solid var(--border);
    background: #f4f7f5;
    color: var(--accent-strong);
    font-size: 16px;
}

.calculation-table-wrapper {
    width: 100%;
    overflow-x: auto;
}

.calculation-data-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.calculation-data-table th,
.calculation-data-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    overflow-wrap: anywhere;
    text-align: left;
}

.calculation-data-table tr:last-child th,
.calculation-data-table tr:last-child td {
    border-bottom: 0;
}

.calculation-data-table th {
    width: 48%;
    background: #fbfcfb;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.calculation-data-table td {
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
}

.calculation-table-multiline {
    white-space: pre-line;
}

.calculation-table-emphasis {
    color: var(--accent-strong) !important;
    font-size: 15px !important;
    font-weight: 700 !important;
}

.loss-recommendations {
    margin: 16px;
    padding: 18px 20px;
    border: 2px solid;
    border-radius: 8px;
}

.loss-recommendations--low {
    border-color: var(--loss-low-border);
    background: var(--loss-low-bg);
    color: var(--loss-low-text);
}

.loss-recommendations--medium {
    border-color: var(--loss-medium-border);
    background: var(--loss-medium-bg);
    color: var(--loss-medium-text);
}

.loss-recommendations--high {
    border-color: var(--loss-high-border);
    background: var(--loss-high-bg);
    color: var(--loss-high-text);
}

.loss-recommendations-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
}

.loss-recommendations h4,
.loss-recommendations h5,
.loss-recommendations p {
    color: inherit;
}

.loss-recommendations h4 {
    margin: 0;
    font-size: 18px;
}

.loss-recommendations h5 {
    margin: 16px 0 8px;
    font-size: 16px;
}

.loss-assessment-value {
    font-size: 16px;
    text-transform: capitalize;
}

.loss-range {
    margin: 5px 0 0;
    font-weight: 600;
}

.loss-recommendations-note {
    margin: 14px 0 0;
}

.loss-recommendations ul {
    margin: 0;
    padding-left: 22px;
}

.loss-recommendations li + li {
    margin-top: 8px;
}

.loss-recommendations--merged {
    grid-column: 1 / -1;
    margin: 0;
    padding: 13px 0 0;
    border: 0;
    border-top: 1px solid currentColor;
    border-radius: 0;
    background: transparent;
    color: inherit;
}

.loss-recommendations--merged h4 {
    font-size: 16px;
}

.loss-recommendations--merged h5 {
    margin-top: 12px;
    font-size: 14px;
}

.loss-recommendations--merged .loss-range,
.loss-recommendations--merged .loss-recommendations-note,
.loss-recommendations--merged li {
    font-size: 13px;
}

.table-wrap {
    width: 100%;
    margin: 14px 0;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.calculations-table {
    width: 100%;
    min-width: 1500px;
    margin: 0;
    border-collapse: collapse;
    background: #fff;
    box-shadow: none;
}

.calculations-table th {
    padding: 11px 10px;
    background: var(--accent);
    color: #fff;
    font-size: 14px;
    font-weight: 650;
    vertical-align: bottom;
}

.calculations-table td {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    vertical-align: middle;
}

.calculations-table tr:nth-child(even) td {
    background: #f6fbf7;
}

.calculations-table tr:hover td {
    background: #edf7ef;
}

.calculation-selector {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.summary-section-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px 20px;
}

.download-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.download-report-button {
    border: 1px solid #b8d8be;
    background: #fff;
    color: var(--accent-strong);
    font-size: 14px;
}

.download-report-button:hover {
    background: #eef8f0;
}

.summary-section-head h2,
.summary-fields h3 {
    margin: 0 0 16px;
    color: var(--accent-strong);
}

.summary-overview {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.summary-metric {
    min-width: 0;
    padding: 14px;
    border: 1px solid #c9e3d2;
    border-radius: 8px;
    background: #f7fbf8;
}

.summary-metric > span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.summary-metric strong {
    display: block;
    overflow-wrap: anywhere;
    color: var(--text);
    font-size: 17px;
}

.summary-metric--primary {
    border-color: #91c7a1;
    background: #eef7f1;
}

.calculation-card-head--low {
    border-bottom-color: var(--loss-low-border);
    background: var(--loss-low-bg);
    color: var(--loss-low-text);
}

.calculation-card-head--medium {
    border-bottom-color: var(--loss-medium-border);
    background: var(--loss-medium-bg);
    color: var(--loss-medium-text);
}

.calculation-card-head--high {
    border-bottom-color: var(--loss-high-border);
    background: var(--loss-high-bg);
    color: var(--loss-high-text);
}

.calculation-card-head--low .calculation-card-result strong,
.calculation-card-head--low .calculation-card-title h3 {
    color: var(--loss-low-text);
}

.calculation-card-head--medium .calculation-card-result strong,
.calculation-card-head--medium .calculation-card-title h3 {
    color: var(--loss-medium-text);
}

.calculation-card-head--high .calculation-card-result strong,
.calculation-card-head--high .calculation-card-title h3 {
    color: var(--loss-high-text);
}

.summary-metric--primary strong,
#summary-total {
    color: var(--accent-strong);
}

.summary-fields {
    margin-top: 22px;
}

.summary-fields-table-wrapper {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.summary-fields-table {
    width: 100%;
    min-width: 820px;
    margin: 0;
    border-collapse: collapse;
    background: #fff;
}

.summary-fields-table th,
.summary-fields-table td {
    padding: 10px 12px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
}

.summary-fields-table th:last-child,
.summary-fields-table td:last-child {
    border-right: 0;
}

.summary-fields-table tbody tr:last-child td {
    border-bottom: 0;
}

.summary-fields-table th {
    background: #eef7f1;
    color: var(--accent-strong);
    font-size: 12px;
    font-weight: 700;
}

.summary-fields-table td {
    color: var(--text);
    font-size: 13px;
}

.summary-fields-table tbody tr:nth-child(even) td {
    background: #fbfcfb;
}

.summary-assessment {
    font-weight: 700 !important;
}

.summary-assessment--low {
    color: var(--loss-low-text) !important;
}

.summary-assessment--medium {
    color: var(--loss-medium-text) !important;
}

.summary-assessment--high {
    color: var(--loss-high-text) !important;
}

.summary-metric .summary-assessment {
    display: inline-flex;
    width: fit-content;
    padding: 4px 9px;
    border-radius: 999px;
    background: #eef2f0;
}

.summary-metric .summary-assessment--low {
    background: var(--loss-low-bg);
}

.summary-metric .summary-assessment--medium {
    background: var(--loss-medium-bg);
}

.summary-metric .summary-assessment--high {
    background: var(--loss-high-bg);
}

.summary-chart {
    display: flex;
    justify-content: center;
    margin-top: 22px;
}

.chart-container {
    width: 400px !important;
    height: 320px !important;
}

.info-tooltip .info-icon {
    background: var(--accent);
}

.info-tooltip .info-icon:focus-visible {
    outline: 3px solid rgba(43, 138, 62, 0.25);
    outline-offset: 2px;
}

#tooltip-popup.tooltip-table {
    width: min(760px, calc(100vw - 24px));
    max-width: none;
    padding: 14px;
    line-height: 1.4;
    white-space: normal;
    pointer-events: auto;
    background: #216b31;
    box-shadow: 0 8px 28px rgba(22, 79, 37, 0.38);
}

.rainfall-norms-title {
    display: block;
    margin-bottom: 10px;
    font-size: 14px;
}

.rainfall-norms-table-scroll {
    max-height: min(58vh, 480px);
    overflow: auto;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
}

.rainfall-norms-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    background: transparent;
    color: #fff;
    box-shadow: none;
    font-size: 12px;
}

.rainfall-norms-table th,
.rainfall-norms-table td {
    padding: 7px 9px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.16);
    text-align: left;
    white-space: nowrap;
}

.rainfall-norms-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: #174f25;
    font-weight: 700;
}

.rainfall-norms-table td {
    background: #216b31;
    color: #fff;
}

.rainfall-norms-table tbody tr:nth-child(even) td {
    background: #2b7a3b;
}

.rainfall-norms-table tbody tr:hover td {
    background: #358d47;
}

.rainfall-norms-table tbody tr:last-child td {
    border-bottom: 0;
}

.parcel-picker {
    margin-bottom: 20px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
}

.parcel-method-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border-bottom: 1px solid var(--border);
}

.parcel-method-tab {
    margin: 0;
    border-radius: 0;
    background: #f1f5f2;
    color: var(--muted);
    font-size: 14px;
    font-weight: 650;
}

.parcel-method-tab.active {
    background: var(--accent);
    color: #fff;
}

#parcel-map-method,
#parcel-identifier-method {
    padding: 14px;
}

.parcel-help {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 13px;
}

.leaching-parcel-map {
    width: 100%;
    height: 310px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #eaf1ec;
}

.leaching-parcel-map .ol-zoom button {
    width: 28px;
    height: 28px;
    margin: 1px;
    padding: 0;
}

.parcel-identifier-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    margin-top: 7px;
}

.parcel-identifier-row input,
.parcel-identifier-row button {
    min-width: 0;
    min-height: 44px;
    margin: 0;
}

.parcel-lookup-status {
    margin: 0 14px 14px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #edf3ef;
    color: var(--muted);
    font-size: 13px;
}

.parcel-lookup-status.loading {
    background: #eef5ff;
    color: #315f93;
}

.parcel-lookup-status.success {
    background: #e8f5eb;
    color: #176f2c;
}

.parcel-lookup-status.warning {
    background: #fff6dc;
    color: #795b00;
}

.parcel-lookup-status.error {
    background: #fdeaea;
    color: #b22424;
}

.selected-parcel-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1px;
    margin: 0 14px 14px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--border);
}

.selected-parcel-summary[hidden] {
    display: none;
}

.selected-parcel-summary > div {
    min-width: 0;
    padding: 9px 10px;
    background: #fff;
}

.selected-parcel-summary span,
.selected-parcel-summary strong {
    display: block;
}

.selected-parcel-summary span {
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 11px;
}

.selected-parcel-summary strong {
    overflow-wrap: anywhere;
    font-size: 13px;
}

.raster-layer-group {
    display: grid;
    grid-template-columns: minmax(150px, 0.8fr) minmax(220px, 1.2fr);
    gap: 8px 14px;
    align-items: center;
}

.raster-layer-group label {
    margin: 0;
}

.soil-override-button {
    grid-column: 2;
    justify-self: start;
    margin: 0 0 8px;
    font-size: 13px;
}

.soil-override-warning {
    grid-column: 1 / -1;
    margin: 0 0 10px;
    padding: 10px 12px;
    border-left: 4px solid #d89b00;
    border-radius: 6px;
    background: #fff6dc;
    color: #654d00;
    font-size: 13px;
}

.selected-fertilizers {
    display: grid;
    gap: 10px;
    margin: 12px 0 18px;
}

.selected-fertilizers-empty {
    margin: 0;
    padding: 13px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--muted);
    text-align: center;
}

.selected-fertilizer {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(130px, 0.45fr) auto;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: #f8fbf9;
}

.selected-fertilizer label {
    margin: 0;
    font-weight: 650;
}

.selected-fertilizer input,
.selected-fertilizer button {
    margin: 0;
}

.remove-selected-fertilizer {
    background: #fff;
    color: #b22424;
    border: 1px solid #efc5c5;
}

.custom-fertilizer-actions {
    display: flex;
    justify-content: flex-end;
    margin: -4px 0 12px;
}

.custom-fertilizer-toggle,
.custom-fertilizer-cancel {
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--accent-strong);
}

.custom-fertilizer-toggle:hover,
.custom-fertilizer-cancel:hover {
    background: #eef8f0;
    color: var(--accent-strong);
}

.custom-fertilizer-panel {
    display: grid;
    gap: 14px;
    margin: 0 0 14px;
    padding: 16px;
    border: 1px solid #bfddc6;
    border-radius: 10px;
    background: #f4faf5;
}

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

.custom-fertilizer-heading {
    display: grid;
    gap: 4px;
}

.custom-fertilizer-heading strong {
    color: var(--accent-strong);
}

.custom-fertilizer-heading span,
.custom-fertilizer-note {
    color: var(--muted);
    font-size: 12px;
}

.custom-fertilizer-name,
.custom-fertilizer-fields label {
    display: grid;
    gap: 6px;
    margin: 0;
    color: var(--text);
    font-size: 12px;
    font-weight: 650;
}

.custom-fertilizer-name input,
.custom-fertilizer-fields input {
    width: 100%;
    min-height: 40px;
    margin: 0;
    padding: 8px 10px;
    box-sizing: border-box;
}

.custom-fertilizer-fields {
    display: grid;
    grid-template-columns: minmax(0, 260px) 110px;
    align-items: end;
    gap: 10px;
}

.custom-fertilizer-note {
    margin: -4px 0 0;
}

.custom-fertilizer-error {
    margin: 0;
    color: #b22424;
    font-size: 13px;
    font-weight: 600;
}

.custom-fertilizer-panel-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.custom-selected-fertilizer {
    border-color: #bfddc6;
    background: #f4faf5;
}

.custom-selected-fertilizer label strong,
.custom-selected-fertilizer label small {
    display: block;
}

.custom-selected-fertilizer label small {
    margin-top: 3px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 500;
}

@media (max-width: 800px) {
    body {
        padding: 12px;
    }

    .app-header,
    .section-head,
    .history-section-head {
        align-items: stretch;
        flex-direction: column;
    }

    .header-actions {
        align-items: stretch;
        flex-wrap: wrap;
        justify-content: flex-start;
    }

    .language-toggle {
        width: auto;
    }

    .calculation-start button {
        width: 100%;
    }

    .card {
        padding: 16px;
    }

    .modal {
        padding: 8px;
    }

    .modal-content,
    .modal-content[data-active-step] {
        width: 100%;
        min-height: auto;
        margin: 0;
        padding: 20px 14px 16px;
        border-radius: 12px;
        transition: none;
    }

    .modal-content h2 {
        margin-right: 44px;
        font-size: 21px;
        line-height: 1.25;
    }

    .form-step h3 {
        margin: 20px 0 16px;
        font-size: 18px;
        line-height: 1.3;
    }

    .form-group {
        margin-bottom: 20px;
    }

    .form-group label {
        margin-bottom: 8px;
        line-height: 1.4;
    }

    .form-group select,
    .form-group input[type="number"],
    .form-group input[type="text"],
    .searchable-select input[type="text"],
    .parcel-identifier-row input {
        min-height: 50px;
        padding: 12px 14px;
        font-size: 16px;
    }

    .dropdown-content {
        left: 0;
        right: 0;
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .dropdown-item {
        min-height: 44px;
        padding: 12px 14px;
        line-height: 1.35;
    }

    .parcel-method-tab {
        display: flex;
        align-items: center;
        justify-content: center;
        min-width: 0;
        min-height: 50px;
        padding: 10px 8px;
        line-height: 1.25;
        text-align: center;
    }

    #parcel-map-method,
    #parcel-identifier-method {
        padding: 12px;
    }

    .leaching-parcel-map {
        height: clamp(220px, 36dvh, 280px);
    }

    .parcel-lookup-status,
    .selected-parcel-summary {
        margin-right: 12px;
        margin-left: 12px;
    }

    .fertilizer-dropdown {
        position: static;
        max-height: min(38dvh, 240px);
        margin-top: 4px;
    }

    .fertilizer-picker-row {
        grid-template-columns: 1fr;
    }

    #fertilizer-add-button {
        width: 100%;
        min-height: 44px;
    }

    .form-step > button {
        min-height: 44px;
    }

    .form-step > .next-step,
    .form-step > .prev-step,
    #calculation-submit {
        min-height: 48px;
        padding: 12px 18px;
        font-size: 16px;
    }

    #step-5 > button {
        width: 100%;
        margin-top: 8px;
    }

    .fertilizer-item {
        align-items: stretch;
    }

    .calculation-card-head {
        grid-template-columns: auto 1fr;
    }

    .calculation-card-result {
        grid-column: 2;
        text-align: left;
    }

    .calculation-card-head .edit-calculation {
        grid-column: 2;
        justify-self: start;
    }

    .calculation-sections {
        grid-template-columns: 1fr;
    }

    .loss-recommendations {
        margin: 12px;
        padding: 16px;
    }

    .loss-recommendations-heading {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }

    .summary-overview {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .chart-container {
        width: 100% !important;
        height: 300px !important;
    }

    .selected-parcel-summary,
    .raster-layer-group,
    .selected-fertilizer {
        grid-template-columns: 1fr;
    }

    .selected-fertilizer input,
    .selected-fertilizer button {
        width: 100%;
        min-height: 44px;
        box-sizing: border-box;
    }

    .custom-fertilizer-fields {
        grid-template-columns: minmax(0, 1fr) 110px;
    }

    .soil-override-button,
    .soil-override-warning {
        grid-column: 1;
    }

    .parcel-identifier-row {
        grid-template-columns: 1fr;
    }

    .parcel-identifier-row button {
        width: 100%;
        min-height: 48px;
    }
}

@media (max-width: 420px) {
    body {
        padding: 8px;
    }

    .container {
        width: 100%;
        min-width: 0;
    }

    .card {
        padding: 14px 12px;
    }

    .title-banner {
        max-width: 100%;
        font-size: 18px;
        line-height: 1.3;
    }

    .modal-content h2 {
        margin-bottom: 16px;
        font-size: 20px;
    }

    .form-step h3 {
        font-size: 17px;
    }

    .parcel-method-tab {
        font-size: 13px;
    }

    .parcel-help {
        line-height: 1.45;
    }

    .form-step > .next-step,
    .form-step > .prev-step,
    #calculation-submit {
        width: 100%;
        margin: 5px 0;
    }

    .custom-fertilizer-fields {
        grid-template-columns: minmax(0, 1fr) 90px;
    }

    .custom-fertilizer-panel-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .custom-fertilizer-actions,
    .custom-fertilizer-toggle,
    .custom-fertilizer-panel-actions button {
        width: 100%;
    }

    .modal {
        padding: 0;
    }

    .modal-content,
    .modal-content[data-active-step] {
        min-height: 100dvh;
        border-width: 0;
        border-radius: 0;
        padding: 16px 10px 20px;
    }

    .leaching-parcel-map {
        height: clamp(210px, 34dvh, 250px);
    }

    .calculation-sections {
        gap: 12px;
        padding: 12px;
    }

    .calculation-data-table,
    .calculation-data-table tbody,
    .calculation-data-table tr,
    .calculation-data-table th,
    .calculation-data-table td {
        display: block;
        width: 100%;
    }

    .calculation-data-table tr {
        padding: 9px 10px;
        border-bottom: 1px solid var(--border);
    }

    .calculation-data-table tr:last-child {
        border-bottom: 0;
    }

    .calculation-data-table th,
    .calculation-data-table td {
        padding: 0;
        border: 0;
        background: transparent;
    }

    .calculation-data-table td {
        margin-top: 3px;
    }

    .summary-overview {
        grid-template-columns: 1fr;
    }

    .summary-fields-table-wrapper {
        overflow: visible;
        border: 0;
    }

    .summary-fields-table,
    .summary-fields-table tbody,
    .summary-fields-table tr,
    .summary-fields-table td {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .summary-fields-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        clip-path: inset(50%);
        white-space: nowrap;
    }

    .summary-fields-table tr {
        margin-bottom: 12px;
        border: 1px solid var(--border);
        border-radius: 8px;
        background: #fff;
    }

    .summary-fields-table tr:last-child {
        margin-bottom: 0;
    }

    .summary-fields-table td,
    .summary-fields-table td:last-child,
    .summary-fields-table tbody tr:last-child td {
        display: grid;
        grid-template-columns: minmax(110px, 44%) minmax(0, 1fr);
        gap: 10px;
        padding: 9px 10px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        background: transparent;
        overflow-wrap: anywhere;
    }

    .summary-fields-table td:last-child {
        border-bottom: 0;
    }

    .summary-fields-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        font-weight: 600;
    }
}

@media (prefers-reduced-motion: reduce) {
    .modal-content {
        transition: none;
    }
}
