/* Mobile-native layout — V9: primary Green (#006e1c) + secondary White */

@media (max-width: 767px) {
  :root {
    --mobile-nav-height: 3.5rem;
    --mobile-primary: #006e1c;
    --mobile-primary-soft: #e8f5e9;
    --mobile-primary-muted: #a0f399;
    --mobile-page-bg: #f8f9fa;
    --mobile-card-bg: #ffffff;
    --mobile-text: #191c1d;
    --mobile-text-muted: #3f4a3c;
    --mobile-border: #dbe3d6;
    color-scheme: light;
  }

  html {
    color-scheme: light;
    background-color: var(--mobile-page-bg);
  }

  body.has-mobile-nav {
    -webkit-tap-highlight-color: transparent;
    background-color: var(--mobile-page-bg) !important;
    color: var(--mobile-text);
  }

  body.has-mobile-nav .min-h-screen {
    background-color: var(--mobile-page-bg);
  }

  body.has-mobile-nav main {
    padding-left: 1rem;
    padding-right: 1rem;
    padding-bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 1rem);
    background-color: var(--mobile-page-bg);
  }

  /* Hide desktop sidebar — use bottom nav + More sheet */
  body.has-mobile-nav #sidebar-drawer,
  body.has-mobile-nav #sidebar-overlay {
    display: none !important;
  }

  .desktop-only {
    display: none !important;
  }

  .mobile-only {
    display: block !important;
  }

  .mobile-inline-only {
    display: inline-flex !important;
  }

  /* Header — white bar + green title */
  body.has-mobile-nav header {
    height: 3.25rem;
    padding-left: 1rem;
    padding-right: 1rem;
    background: var(--mobile-card-bg) !important;
    border-bottom: 1px solid var(--mobile-border);
    box-shadow: 0 1px 0 rgba(0, 110, 28, 0.05);
  }

  body.has-mobile-nav header h1 {
    font-size: 1rem;
    line-height: 1.25rem;
    max-width: 10rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--mobile-primary) !important;
  }

  /* Cards — white on light gray page */
  .custom-card {
    padding: 1rem;
    border-radius: 12px;
    background: var(--mobile-card-bg) !important;
    border: 1px solid rgba(0, 110, 28, 0.08);
    box-shadow: 0 2px 12px rgba(0, 110, 28, 0.05);
  }

  .custom-card--interactive:hover {
    transform: none;
    box-shadow: 0 4px 16px rgba(0, 110, 28, 0.08);
  }

  /* Form controls — force light (override OS dark mode) */
  body.has-mobile-nav input:not([type="file"]):not([type="checkbox"]):not([type="radio"]),
  body.has-mobile-nav select,
  body.has-mobile-nav textarea,
  body.has-mobile-nav .select-field-trigger {
    background-color: #ffffff !important;
    color: var(--mobile-text) !important;
    color-scheme: light;
    -webkit-text-fill-color: var(--mobile-text);
  }

  body.has-mobile-nav input::placeholder,
  body.has-mobile-nav textarea::placeholder {
    color: #727970;
    opacity: 1;
  }

  /* Bottom tab bar — white + green active */
  .mobile-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    min-height: var(--mobile-nav-height);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: var(--mobile-card-bg);
    border-top: 1px solid rgba(0, 110, 28, 0.12);
    box-shadow: 0 -2px 16px rgba(0, 110, 28, 0.06);
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    min-height: 48px;
    min-width: 48px;
    padding: 0.375rem 0.25rem;
    margin: 0.25rem 0.125rem;
    color: #5c5f5b;
    font-size: 0.625rem;
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    border: none;
    background: transparent;
    border-radius: 12px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .mobile-nav-item .material-symbols-outlined {
    font-size: 1.375rem;
  }

  .mobile-nav-item.is-active {
    color: var(--mobile-primary);
    background: var(--mobile-primary-soft);
  }

  .mobile-nav-item.is-active .material-symbols-outlined {
    font-variation-settings: 'FILL' 1;
  }

  .mobile-nav-item:active {
    transform: scale(0.96);
    background: var(--mobile-primary-soft);
  }

  /* More menu — bottom sheet */
  .mobile-more-sheet {
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    visibility: hidden;
  }

  .mobile-more-sheet.is-open {
    pointer-events: auto;
    visibility: visible;
  }

  .mobile-more-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 30, 8, 0.35);
    opacity: 0;
    transition: opacity 0.25s ease;
  }

  .mobile-more-sheet.is-open .mobile-more-backdrop {
    opacity: 1;
  }

  .mobile-more-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    max-height: 85vh;
    background: var(--mobile-card-bg);
    border-radius: 16px 16px 0 0;
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom, 0px));
    transform: translateY(100%);
    transition: transform 0.28s ease;
    overflow-y: auto;
    border-top: 3px solid var(--mobile-primary);
  }

  .mobile-more-sheet.is-open .mobile-more-panel {
    transform: translateY(0);
  }

  .mobile-more-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 48px;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    color: var(--mobile-text);
    text-decoration: none;
    font-weight: 500;
    transition: background-color 0.15s ease;
  }

  .mobile-more-link:active,
  .mobile-more-link:hover {
    background: var(--mobile-primary-soft);
  }

  /* Plot detail — right-side panel (bottom sheet was obscured by nav) */
  #plot-drawer {
    top: 0;
    right: 0;
    left: auto;
    bottom: 0;
    width: min(92vw, 22rem);
    max-width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 16px 0 0 16px;
    transform: translateX(100%);
    display: flex;
    flex-direction: column;
    background: var(--mobile-card-bg) !important;
    border-left: 3px solid var(--mobile-primary);
    border-top: none;
    z-index: 60;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.18);
  }

  #drawer-overlay {
    z-index: 55;
  }

  #plot-drawer > div:first-child {
    position: sticky;
    top: 0;
    z-index: 1;
    background: inherit;
    flex-shrink: 0;
  }

  #plot-drawer #drawer-body {
    flex: 1 1 auto;
    max-height: none;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 1.5rem;
  }

  #plot-drawer.plot-drawer-open {
    transform: translateX(0);
  }

  /* Full-screen forms on mobile */
  .modal-overlay .fixed.inset-0.flex.items-center {
    align-items: stretch;
    padding: 0;
  }

  .modal-overlay .modal-content {
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
    margin: 0;
    background: var(--mobile-card-bg) !important;
  }

  .modal-overlay .modal-content form > .p-6,
  .modal-overlay .modal-content form > div:first-of-type.p-6 {
    padding: 1rem;
  }

  .modal-overlay .modal-content form .grid {
    grid-template-columns: 1fr !important;
  }

  .modal-overlay .modal-content form > div:last-child {
    position: sticky;
    bottom: 0;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    background: var(--mobile-card-bg);
    box-shadow: 0 -4px 16px rgba(0, 110, 28, 0.06);
  }

  .modal-overlay .modal-content form button[type="submit"] {
    flex: 1;
    min-height: 48px;
    background: var(--mobile-primary) !important;
    color: #ffffff !important;
  }

  /* Data tables → card lists */
  .data-table-desktop {
    display: none !important;
  }

  .data-cards-mobile {
    display: block !important;
    background: var(--mobile-card-bg);
    border-radius: 12px;
    border: 1px solid rgba(0, 110, 28, 0.08);
    overflow: hidden;
  }

  .mobile-record-card {
    padding: 1rem;
    border-bottom: 1px solid rgba(0, 110, 28, 0.08);
    background: var(--mobile-card-bg);
  }

  .mobile-record-card:last-child {
    border-bottom: none;
  }

  .mobile-record-card:active {
    background: var(--mobile-primary-soft);
  }

  /* Farm map — show Plant/Seed/Harvest on readable tiles; swipe for full width */
  .farm-map-scroll-hint {
    display: block;
    margin: 0 0 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    background: var(--mobile-primary-soft);
    color: var(--mobile-text-muted);
    font-size: 0.75rem;
    line-height: 1.35;
  }

  .farm-map-wrapper {
    padding: 0.625rem !important;
    border-radius: 14px !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
    margin-inline: -0.25rem;
  }

  /* Wider canvas so north cells (~85px) can fit label + date */
  .farm-spatial-map {
    min-width: 1100px;
    gap: 8px;
  }

  .farm-north-zone {
    min-height: 520px !important;
    gap: 6px;
  }

  .farm-north-row {
    gap: 4px;
  }

  .farm-south-zone {
    min-height: 400px !important;
    gap: 5px;
    /* Widen strip columns slightly; E/B keep room for meta */
    grid-template-columns: 5.2fr 92px 84px 48px 4.2fr 92px !important;
  }

  .farm-road-band {
    min-height: 96px;
    padding: 8px 12px;
  }

  .farm-road-band-label {
    display: none;
  }

  .farm-f-row {
    grid-template-columns: repeat(4, minmax(72px, 100px));
    gap: 4px;
  }

  /* Keep hover tips off on touch; drawer still available on tap */
  .farm-plot-tip {
    display: none !important;
  }

  /* Show meta again (except ultra-thin A/C/D strips) */
  .farm-plot-meta {
    display: flex !important;
  }

  .farm-plot-tile--strip .farm-plot-meta {
    display: none !important;
  }

  .farm-plot-tile {
    justify-content: center !important;
    align-items: stretch !important;
    padding: 3px 2px 4px !important;
    gap: 2px !important;
    min-height: 88px !important;
    overflow: hidden;
    border-radius: 6px;
    border-width: 1.5px;
  }

  .farm-north-zone .farm-plot-tile {
    min-height: 0 !important;
    height: 100%;
  }

  .farm-plot-tile--lg {
    min-height: 88px !important;
  }

  .farm-plot-tile--strip {
    min-height: 18px !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 1px !important;
  }

  .farm-plot-id,
  .farm-plot-tile--north .farm-plot-id {
    font-size: 11px !important;
    line-height: 1.1;
  }

  .farm-plot-tile--strip .farm-plot-id {
    font-size: 7px !important;
  }

  .farm-plot-meta {
    gap: 2px;
    margin-top: 0;
  }

  .farm-plot-meta-line {
    flex-direction: row;
    justify-content: space-between;
    align-items: baseline;
    gap: 2px;
    padding: 0 1px;
    text-align: left;
  }

  .farm-plot-meta-k {
    font-size: 7px !important;
    opacity: 0.75;
  }

  .farm-plot-meta-v {
    font-size: 8px !important;
    text-align: right;
  }

  .farm-b-grid .farm-plot-tile,
  .farm-e-grid .farm-plot-tile {
    min-height: 110px !important;
  }

  .farm-zone-label {
    font-size: 9px;
    padding: 1px 4px;
    margin-bottom: 2px;
  }

  /* Farm map — larger touch cells (legacy grid class) */
  .farm-map-grid button {
    min-height: 52px !important;
  }

  .farm-map-legend {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  /* Dashboard KPI — hide 4-up on phone; show inventory hero layout */
  .dash-kpi-desktop {
    display: none !important;
  }

  .dash-kpi-mobile {
    display: block !important;
  }

  .dash-page .dash-page__title {
    font-size: 1.625rem;
    line-height: 1.2;
    letter-spacing: -0.01em;
  }

  .dash-page .dash-kpi-hero {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1rem 1.125rem;
    margin-bottom: 0.75rem;
  }

  .dash-page .dash-kpi-hero__icon {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.875rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .dash-page .dash-kpi-hero__body {
    min-width: 0;
  }

  .dash-page .dash-kpi-hero__label {
    font-size: 0.8125rem;
    font-weight: 600;
    line-height: 1.2;
  }

  .dash-page .dash-kpi-hero__value {
    font-variant-numeric: tabular-nums;
    font-size: 2.25rem;
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.02em;
  }

  .dash-page .dash-kpi-hero__value-unit {
    font-size: 1rem;
    font-weight: 600;
    margin-inline-start: 0.375rem;
  }

  .dash-page .dash-kpi-hero__sub {
    font-size: 0.8125rem;
    line-height: 1.25;
    margin-top: 0.125rem;
  }

  .dash-page .dash-kpi-mobile-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .dash-page .dash-kpi-mobile-row .dash-kpi-card {
    padding: 0.875rem !important;
    gap: 0.625rem;
  }

  .dash-page .dash-kpi-mobile-row .dash-kpi-card__label {
    font-size: 0.8125rem;
    line-height: 1.25;
    font-weight: 600;
  }

  .dash-page .dash-kpi-mobile-row .dash-kpi-card__value {
    font-size: 1.75rem !important;
    line-height: 1.1 !important;
    letter-spacing: -0.02em;
  }

  .dash-page .dash-kpi-mobile-row .dash-kpi-card__unit {
    font-size: 0.75rem;
    line-height: 1.25;
    white-space: normal;
  }

  .dash-page .dash-kpi-pin__mid {
    margin-bottom: 0.75rem;
  }

  .dash-page .dash-kpi-pin__bottom {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem !important;
  }

  .dash-page .dash-kpi-pin__bottom .dash-kpi-card__value {
    font-size: 1.75rem !important;
    line-height: 1.1 !important;
  }

  .dash-page .dash-kpi-pin__bottom .dash-kpi-card__label {
    font-size: 0.8125rem;
    font-weight: 600;
  }

  /* Farm map MVP: chip navigator + touch grid (hide aerial spatial map) */
  .farm-map-desktop {
    display: none !important;
  }

  .farm-map-mobile {
    display: block !important;
  }

  .farm-mobile-view-tabs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.375rem;
    padding: 0.25rem;
    margin-bottom: 0.75rem;
    border-radius: 0.875rem;
    background: var(--mobile-primary-soft);
  }

  .farm-mobile-view-tab {
    min-height: 40px;
    border: none;
    border-radius: 0.7rem;
    background: transparent;
    color: var(--mobile-text-muted);
    font-size: 0.875rem;
    font-weight: 700;
    cursor: pointer;
  }

  .farm-mobile-view-tab.is-active {
    background: var(--mobile-card-bg);
    color: var(--mobile-primary);
    box-shadow: 0 1px 3px rgba(0, 110, 28, 0.12);
  }

  .farm-map-mobile-hint {
    margin: 0 0 0.75rem;
    padding: 0.625rem 0.875rem;
    border-radius: 0.75rem;
    background: var(--mobile-primary-soft);
    color: var(--mobile-text-muted);
    font-size: 0.875rem;
    line-height: 1.4;
    font-weight: 500;
  }

  .farm-block-chips {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
    scrollbar-width: none;
  }

  .farm-block-chips::-webkit-scrollbar {
    display: none;
  }

  .farm-block-chip {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    min-height: 44px;
    padding: 0.5rem 0.875rem;
    border-radius: 9999px;
    border: 1px solid var(--mobile-border);
    background: var(--mobile-card-bg);
    color: var(--mobile-text-muted);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
  }

  .farm-block-chip.is-active {
    background: var(--mobile-primary);
    border-color: var(--mobile-primary);
    color: #ffffff;
  }

  .farm-block-chip__count {
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.35rem;
    border-radius: 9999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    background: rgba(0, 0, 0, 0.08);
  }

  .farm-block-chip.is-active .farm-block-chip__count {
    background: rgba(255, 255, 255, 0.22);
  }

  .farm-block-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .farm-block-cell {
    min-height: 52px;
    min-width: 0;
    border-radius: 0.75rem;
    border: 1px solid rgba(0, 110, 28, 0.14);
    font-size: 0.9375rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0.5rem;
    line-height: 1.1;
  }

  .farm-block-cell:active {
    transform: scale(0.97);
  }

  .farm-list-search-label {
    display: none;
  }

  .farm-list-filters {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    margin-bottom: 0.75rem;
    scrollbar-width: none;
  }

  .farm-list-filters::-webkit-scrollbar {
    display: none;
  }

  .farm-list-filter {
    flex: 0 0 auto;
    min-height: 36px;
    padding: 0.375rem 0.75rem;
    border-radius: 9999px;
    border: 1px solid var(--mobile-border);
    background: var(--mobile-card-bg);
    color: var(--mobile-text-muted);
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
  }

  .farm-list-filter.is-active {
    background: var(--mobile-primary);
    border-color: var(--mobile-primary);
    color: #ffffff;
  }

  .farm-plot-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }

  .farm-plot-list-row {
    display: grid;
    grid-template-columns: 0.75rem minmax(3rem, auto) 1fr 1.25rem;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    min-height: 52px;
    padding: 0.625rem 0.75rem;
    border-radius: 0.75rem;
    border: 1px solid rgba(0, 110, 28, 0.12);
    background: var(--mobile-card-bg);
    text-align: start;
    cursor: pointer;
  }

  /* display:grid above would otherwise override the HTML hidden attribute */
  .farm-plot-list-row[hidden],
  .farm-plot-list-empty[hidden],
  [data-farm-view-panel][hidden],
  .farm-block-panel[hidden] {
    display: none !important;
  }

  .farm-plot-list-row:active {
    background: var(--mobile-primary-soft);
  }

  .farm-plot-list-swatch {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 9999px;
    border: 1px solid rgba(0, 0, 0, 0.2);
  }

  .farm-plot-list-id {
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    font-size: 1rem;
    color: var(--mobile-text);
  }

  .farm-plot-list-meta {
    font-size: 0.8125rem;
    color: var(--mobile-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .farm-plot-list-chevron {
    color: var(--mobile-text-muted);
    font-size: 1.25rem;
    font-weight: 400;
    line-height: 1;
    text-align: center;
  }

  .farm-plot-list-empty {
    text-align: center;
    color: var(--mobile-text-muted);
    font-size: 0.875rem;
    padding: 1.5rem 0.5rem;
  }

  /* Thumbnail overview — simplified full-farm color map */
  .farm-overview {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.625rem;
    border-radius: 0.875rem;
    background: #edf2ea;
    border: 1px solid rgba(0, 110, 28, 0.12);
  }

  .farm-overview-band {
    display: grid;
    grid-template-columns: 1.75rem 1fr;
    gap: 0.375rem;
    align-items: center;
  }

  .farm-overview-block-label {
    min-height: 28px;
    min-width: 1.75rem;
    padding: 0;
    border: none;
    border-radius: 0.375rem;
    background: rgba(0, 110, 28, 0.12);
    color: var(--mobile-primary);
    font-size: 0.75rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: default;
  }

  .farm-overview-cells {
    display: grid;
    gap: 2px;
  }

  .farm-overview-cells--north {
    grid-template-columns: repeat(12, minmax(0, 1fr));
  }

  .farm-overview-cells--f {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-width: 55%;
    margin-inline: auto;
  }

  .farm-overview-band--road .farm-overview-cells--f {
    max-width: none;
  }

  .farm-overview-cell {
    aspect-ratio: 1;
    min-height: 14px;
    min-width: 0;
    padding: 0;
    border-radius: 2px;
    border: 1px solid rgba(0, 0, 0, 0.18);
    cursor: pointer;
  }

  .farm-overview-cell:active {
    transform: scale(0.92);
  }

  .farm-overview-south {
    display: grid;
    grid-template-columns: 2.2fr 0.7fr 0.7fr 1.6fr 0.7fr;
    gap: 0.375rem;
    align-items: stretch;
    min-height: 140px;
  }

  .farm-overview-south-col {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
  }

  .farm-overview-cells--e {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    flex: 1;
  }

  .farm-overview-cells--b {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    flex: 1;
  }

  .farm-overview-cells--strip {
    grid-template-columns: 1fr;
    flex: 1;
  }

  .farm-overview-south-col--strip .farm-overview-cell {
    min-height: 6px;
    aspect-ratio: auto;
  }

  /* FAB — primary green */
  .mobile-fab {
    position: fixed;
    right: 1rem;
    bottom: calc(var(--mobile-nav-height) + env(safe-area-inset-bottom, 0px) + 0.75rem);
    z-index: 44;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 9999px;
    background: var(--mobile-primary);
    color: #ffffff;
    box-shadow: 0 8px 24px rgba(0, 110, 28, 0.35);
    border: none;
    cursor: pointer;
  }

  .mobile-fab:active {
    transform: scale(0.94);
  }

  /* Page toolbars */
  .page-toolbar-mobile {
    flex-direction: column;
    align-items: stretch !important;
  }

  .page-toolbar-mobile .toolbar-search {
    max-width: none !important;
    width: 100%;
  }

  .page-toolbar-mobile .toolbar-actions {
    display: flex;
    gap: 0.5rem;
    width: 100%;
  }

  .page-toolbar-mobile .toolbar-actions > * {
    flex: 1;
    justify-content: center;
  }

  /* Tabs — green active indicator */
  .mobile-tab-bar {
    display: flex;
    gap: 0.25rem;
    background: #ffffff;
    border-radius: 9999px;
    padding: 0.25rem;
    border: 1px solid var(--mobile-border);
  }

  .mobile-tab-bar .tab-btn {
    flex: 1;
    text-align: center;
    min-height: 48px;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
    border-radius: 9999px;
    transition: background-color 0.15s ease, color 0.15s ease;
  }

  .mobile-tab-bar .tab-btn.border-primary,
  .mobile-tab-bar .tab-btn.text-primary {
    background: var(--mobile-primary-soft) !important;
    color: var(--mobile-primary) !important;
  }

  /* Season / admin action rows */
  .mobile-action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 0.75rem;
  }

  .mobile-action-row form,
  .mobile-action-row a,
  .mobile-action-row button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
  }

  .warehouse-add-btn {
    display: none !important;
  }

  .mobile-record-card .mobile-action-row {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid rgba(0, 110, 28, 0.08);
  }

  .admin-users-toolbar {
    display: none !important;
  }

  /* Touch-friendly form controls */
  .modal-content select,
  .modal-content input[type="text"],
  .modal-content input[type="number"],
  .modal-content input[type="date"],
  .modal-content textarea {
    min-height: 44px;
  }

  /* Primary buttons on mobile */
  body.has-mobile-nav .bg-primary,
  body.has-mobile-nav button.bg-primary,
  body.has-mobile-nav a.bg-primary {
    background-color: var(--mobile-primary) !important;
    color: #ffffff !important;
  }

  body.has-mobile-nav .text-primary {
    color: var(--mobile-primary) !important;
  }

  body.has-mobile-nav .bg-secondary-container {
    background-color: var(--mobile-primary-soft) !important;
  }

  body.has-mobile-nav .text-on-secondary-container {
    color: var(--mobile-primary) !important;
  }
}

@media (min-width: 768px) {
  .mobile-only,
  .mobile-inline-only,
  .data-cards-mobile,
  .mobile-bottom-nav,
  .mobile-more-sheet,
  .mobile-fab {
    display: none !important;
  }

  .data-table-desktop {
    display: block;
  }

  #plot-drawer {
    top: 0;
    left: auto;
    right: 0;
    bottom: 0;
    width: 24rem;
    max-height: none;
    border-radius: 0;
    transform: translateX(100%);
    display: flex;
    flex-direction: column;
  }

  #plot-drawer > div:first-child {
    position: sticky;
    top: 0;
    z-index: 1;
    background: inherit;
  }

  #plot-drawer #drawer-body {
    max-height: calc(100vh - 4.5rem);
  }

  #plot-drawer.plot-drawer-open {
    transform: translateX(0);
  }
}

/* ── Dedicated H5 shell (not responsive adapt of PC pages) ─────────── */
.h5-shell {
  min-height: 100vh;
  background: var(--mobile-bg, #f6f8f5);
}
.h5-shell-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.625rem 0.875rem;
  background: #ffffff;
  border-bottom: 1px solid rgba(0, 110, 28, 0.12);
}
.h5-shell-brand {
  display: flex;
  align-items: center;
  min-width: 0;
  text-decoration: none;
}
.h5-shell-brand__logo {
  height: 28px;
  width: auto;
}
.h5-shell-brand__title {
  font-size: 0.9375rem;
  font-weight: 700;
  color: #006e1c;
  margin-inline-start: 0.5rem;
}
.h5-shell-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.h5-shell-lang {
  font-size: 0.8125rem;
  font-weight: 600;
  color: #006e1c;
  padding: 0.35rem 0.5rem;
}
.h5-shell-logout {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: #5c5f5a;
}
.h5-shell-main {
  padding: 0.875rem 0.75rem 1.5rem;
}
/* Always use mobile KPI + map surfaces inside H5 shell */
.h5-shell .dash-kpi-desktop,
.h5-shell .farm-map-desktop {
  display: none !important;
}
.h5-shell .dash-kpi-mobile,
.h5-shell .farm-map-mobile {
  display: block !important;
}

/* H5 shell: farm overview map styles at any viewport width */
/* Thumbnail overview — simplified full-farm color map */
.h5-shell .farm-overview {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.625rem;
  border-radius: 0.875rem;
  background: #edf2ea;
  border: 1px solid rgba(0, 110, 28, 0.12);
}

.h5-shell .farm-overview-band {
  display: grid;
  grid-template-columns: 1.75rem 1fr;
  gap: 0.375rem;
  align-items: center;
}

.h5-shell .farm-overview-block-label {
  min-height: 28px;
  min-width: 1.75rem;
  padding: 0;
  border: none;
  border-radius: 0.375rem;
  background: rgba(0, 110, 28, 0.12);
  color: var(--mobile-primary);
  font-size: 0.75rem;
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.h5-shell .farm-overview-cells {
  display: grid;
  gap: 2px;
}

.h5-shell .farm-overview-cells--north {
  grid-template-columns: repeat(12, minmax(0, 1fr));
}

.h5-shell .farm-overview-cells--f {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  max-width: 55%;
  margin-inline: auto;
}

.h5-shell .farm-overview-band--road .farm-overview-cells--f {
  max-width: none;
}

.h5-shell .farm-overview-cell {
  aspect-ratio: 1;
  min-height: 14px;
  min-width: 0;
  padding: 0;
  border-radius: 2px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  cursor: pointer;
}

.h5-shell .farm-overview-cell:active {
  transform: scale(0.92);
}

.h5-shell .farm-overview-south {
  display: grid;
  grid-template-columns: 2.2fr 0.7fr 0.7fr 1.6fr 0.7fr;
  gap: 0.375rem;
  align-items: stretch;
  min-height: 140px;
}

.h5-shell .farm-overview-south-col {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
}

.h5-shell .farm-overview-cells--e {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  flex: 1;
}

.h5-shell .farm-overview-cells--b {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  flex: 1;
}

.h5-shell .farm-overview-cells--strip {
  grid-template-columns: 1fr;
  flex: 1;
}

.h5-shell .farm-overview-south-col--strip .farm-overview-cell {
  min-height: 6px;
  aspect-ratio: auto;
}

/* H5 KPI — 田 shape (strict 2×2) */
.h5-shell .dash-kpi-tian {
  display: grid !important;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.h5-shell .dash-kpi-tian__cell {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.5rem;
  min-height: 7.5rem;
  height: 100%;
  margin: 0 !important;
  padding: 0.875rem 0.875rem !important;
}
.h5-shell .dash-kpi-tian__cell .dash-kpi-card__label {
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.2;
}
.h5-shell .dash-kpi-tian__cell .dash-kpi-card__value {
  font-size: 1.625rem !important;
  line-height: 1.1 !important;
  font-variant-numeric: tabular-nums;
}
.h5-shell .dash-kpi-tian__cell .dash-kpi-card__unit {
  font-size: 0.6875rem;
  line-height: 1.25;
  white-space: normal;
}

/* H5 bottom nav — Dashboard trio only */
.h5-shell.has-h5-nav .h5-shell-main {
  padding-bottom: calc(4.75rem + env(safe-area-inset-bottom, 0px));
}
.h5-bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.25rem;
  padding: 0.375rem 0.5rem calc(0.375rem + env(safe-area-inset-bottom, 0px));
  background: #ffffff;
  border-top: 1px solid rgba(0, 110, 28, 0.14);
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.04);
}
.h5-bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.125rem;
  min-height: 3.25rem;
  padding: 0.35rem 0.25rem;
  border-radius: 0.75rem;
  text-decoration: none;
  color: #5c5f5a;
  font-size: 0.625rem;
  font-weight: 600;
  line-height: 1.15;
  text-align: center;
}
.h5-bottom-nav__item .material-symbols-outlined {
  font-size: 1.375rem;
  line-height: 1;
}
.h5-bottom-nav__label {
  max-width: 100%;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.h5-bottom-nav__item.is-active {
  color: #006e1c;
  background: rgba(0, 110, 28, 0.1);
}

/* H5 Historical by Data — cards only, no desktop tables/pagination */
.h5-shell .data-table-desktop,
.h5-shell .hist-pagination-desktop {
  display: none !important;
}
.h5-shell .data-cards-mobile {
  display: block !important;
}
.h5-shell .hist-filter-bar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.h5-shell .hist-filter-field,
.h5-shell .hist-filter-plot-group,
.h5-shell .hist-season-select {
  width: 100%;
  max-width: none;
}

/* H5 shell: keep plot drawer as mobile bottom sheet on desktop too */
@media (min-width: 768px) {
  .h5-shell #plot-drawer {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 85vh;
    border-radius: 1rem 1rem 0 0;
    transform: translateY(100%);
    display: flex;
    flex-direction: column;
  }
  .h5-shell #plot-drawer.plot-drawer-open {
    transform: translateY(0);
  }
  .h5-shell #plot-drawer #drawer-body {
    max-height: calc(85vh - 4.5rem);
  }
}

/* ── Boss View desktop responsiveness (≥768px) ──────────────────────
   Boss link pages stay mobile-first; at desktop widths the content
   column widens, the bottom nav is replaced by a top pill nav, and
   charts/KPIs reflow into multi-column grids. Mobile layout is
   untouched (all rules live inside this media query). */
@media (min-width: 768px) {
  .boss-main {
    max-width: 72rem;
    padding: 1.25rem 2rem 2.5rem;
  }

  /* Top pill nav (replaces .mobile-bottom-nav which is md:hidden) */
  .boss-top-nav {
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 1.25rem;
    padding-bottom: 0.625rem;
    border-bottom: 1px solid rgba(0, 110, 28, 0.12);
  }
  .boss-top-nav__item {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: 9999px;
    font-size: 0.875rem;
    font-weight: 600;
    color: #5c5f5a;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
  }
  .boss-top-nav__item .material-symbols-outlined {
    font-size: 1.125rem;
  }
  .boss-top-nav__item:hover {
    background: #edf2ea;
    color: #006e1c;
  }
  .boss-top-nav__item.is-active {
    background: #006e1c;
    color: #ffffff;
  }

  /* Stats page: charts side by side */
  .boss-chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
    align-items: start;
  }
  .boss-chart-grid > section {
    margin-bottom: 0;
  }

  /* KPI rows: 4 across */
  .boss-main .dash-kpi-tian {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: auto;
  }
  .boss-main .boss-kpi-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
