:root {
  --ag-type-caption: 12px;
  --ag-type-body: 14px;
  --ag-type-mobile-body: 15px;
  --ag-touch-target: 44px;
}

html {
  min-width: 320px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

body.admin-app,
body.dashboard-app,
body.harvest-app,
body.drying-app,
body.payroll-app {
  font-size: var(--ag-type-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.admin-app :where(button, input, select, textarea),
body.dashboard-app :where(button, input, select, textarea),
body.harvest-app :where(button, input, select, textarea),
body.drying-app :where(button, input, select, textarea),
body.payroll-app :where(button, input, select, textarea) {
  font-family: inherit;
}

body.admin-app :where(button, a, input, select, textarea, summary),
body.dashboard-app :where(button, a, input, select, textarea, summary),
body.harvest-app :where(button, a, input, select, textarea, summary),
body.drying-app :where(button, a, input, select, textarea, summary),
body.payroll-app :where(button, a, input, select, textarea, summary) {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body.admin-app :where(h1, h2, h3),
body.dashboard-app :where(h1, h2, h3),
body.harvest-app :where(h1, h2, h3),
body.drying-app :where(h1, h2, h3),
body.payroll-app :where(h1, h2, h3) {
  line-height: 1.2;
  text-wrap: balance;
}

body.admin-app :where(p, td, th, label, small, span),
body.dashboard-app :where(p, td, th, label, small, span),
body.harvest-app :where(p, td, th, label, small, span),
body.drying-app :where(p, td, th, label, small, span),
body.payroll-app :where(p, td, th, label, small, span) {
  overflow-wrap: break-word;
}

body.admin-app :where(
  .login-kicker,
  .login-security-note,
  .sidebar-brand-sub,
  .sidebar-section-label,
  .sidebar-user-role,
  .sidebar-footer-links a,
  .page-kicker,
  .stat-label,
  .admin-overview-updated,
  .admin-overview-count,
  .admin-attention-copy span,
  .admin-system-item-name,
  .admin-system-item small,
  .admin-module-state,
  .admin-module-metric span,
  .admin-quality-item span,
  .admin-important-copy strong,
  .admin-important-copy span,
  .admin-important-time,
  .section-kicker,
  .feed-pill,
  .badge,
  .field-hint,
  .mini-action,
  .cat-filter-badge,
  .cat-filter-hint,
  .field-error,
  thead th,
  .manager-count,
  .category-field-label,
  .mini-card-label,
  .season-value,
  .season-label,
  .modal-kicker,
  .form-help,
  .settings-card-pill,
  .branding-upload-card-head span,
  .branding-upload-empty,
  .branding-file-button,
  .branding-file-name,
  .fruit-colors-copy,
  .fruit-color-group-head h4,
  .fruit-color-count,
  .fruit-color-name,
  .weather-threshold-copy small,
  .weather-threshold-input b,
  .weather-thresholds-status,
  .nav-vis-desc,
  .nav-vis-badge,
  .user-account-username,
  .user-account-badge,
  .user-meta,
  .role-explainer-item,
  .users-overview-card span,
  .users-overview-card small,
  .user-create-summary-copy span,
  .user-create-summary-action,
  .user-directory-count,
  .user-summary-item span,
  .user-summary-item strong,
  .user-config-panel > summary,
  .user-config-section-head span,
  .user-access-option strong,
  .user-access-option span,
  .user-session-note,
  .user-create-permission,
  .user-create-permission small,
  .user-permission-row,
  .user-permission-row small,
  .users-feedback,
  .user-directory-identity span,
  .user-directory-meta,
  .user-editor-status,
  .user-editor-timestamps,
  .user-editor-section-title,
  .user-editor-section-title span,
  .user-editor-actions > span,
  .user-admin-stats,
  .user-create-section-head span,
  .user-active-copy small,
  .user-directory-username,
  .user-directory-access,
  .user-directory-status,
  .user-editor-mobile-back,
  .backup-status-pill,
  .backup-metric-label,
  .backup-metric small,
  .backup-detail-card > p,
  .backup-fact dt,
  .backup-fact dd,
  .backup-alert,
  .backup-boundary,
  .harvest-admin-completion small,
  .harvest-admin-report-head span,
  .drying-admin-tab-count,
  .drying-admin-metric span,
  .drying-admin-metric small,
  .drying-admin-stage-chip b,
  .drying-admin-record-section-head span,
  .drying-admin-record-item > span,
  .drying-admin-record-stage-value > span,
  .drying-admin-record-stage-title b,
  .drying-admin-record-stage-head time,
  .drying-status-pill
) {
  font-size: var(--ag-type-caption);
  line-height: 1.4;
}

body.dashboard-app :where(
  .sidebar-brand-sub,
  .sidebar-section-label,
  .kpi-card-label,
  .stat-card-label,
  .section-header,
  .filter-group > span,
  .ms-trigger .ms-badge,
  .ms-panel-btn,
  .stats-mini-label,
  .stats-mini-badge,
  .variety-badge,
  .variety-cell-label,
  .modal-badge,
  .modal-kpi-label,
  .modal-photo-slot .sub,
  .modal-issues-label,
  .modal-section-title,
  .add-form-badge,
  .fruit-group-count,
  .analytics-table th,
  .planning-group-table-title,
  .age-card-label,
  .calendar-table th,
  .calendar-group-row td,
  .calendar-nodata,
  .density-legend-item,
  .density-card-badge,
  .density-card-orchard,
  .d2-harvest-label,
  .d2-month-cell,
  .d2-drying-label,
  .d2-drying-status,
  .d2-drying-metric span,
  .d2-drying-aside-label,
  .d2-drying-aside-copy,
  .d2-drying-link,
  .d2-kpi-card-label,
  .d2-weather-title-refresh::after,
  .d2-weather-feels,
  .d2-weather-meta,
  .d2-weather-freshness,
  .d2-weather-day-name,
  .d2-weather-day-temps,
  .d2-weather-refresh,
  .export-card-header,
  .export-rate-ts,
  .export-rate-source,
  .export-price-note,
  .export-heatmap-table th,
  .export-heatmap-legend,
  .export-status-updated,
  .export-phyto-table th,
  .d2-issue-count,
  .ops-access-kicker,
  .ops-eyebrow,
  .ops-user-scope,
  .ops-tab-badge,
  .ops-period-date,
  .ops-panel-copy,
  .ops-kpi-label,
  .ops-kpi-unit,
  .ops-kpi-note,
  .ops-table th,
  .ops-status,
  .ops-bar-meta,
  .ops-orchard-location,
  .ops-orchard-date,
  .ops-orchard-stat span,
  .ops-alert-copy,
  .ops-scope-note,
  .ops-period-switch button,
  .ops-summary-metric > span,
  .ops-summary-metric strong small,
  .ops-summary-metric em,
  .ops-compact-list span,
  .dashboard-auth-kicker,
  .dashboard-auth-note,
  .incremental-list-sentinel-content
) {
  font-size: var(--ag-type-caption);
  line-height: 1.4;
}

body.harvest-app :where(
  .eyebrow,
  .title-block > p:last-child,
  .account-popover strong,
  .language-toggle,
  .workspace-kicker,
  .section-heading p,
  .section-number,
  .optional-number,
  .field-label,
  .unit,
  .currency,
  .calculation-copy > span,
  .formula > span,
  .money-icon,
  .metric-title,
  .sales-helper,
  .sales-card-total,
  .sent-item-side .sale-pending,
  .field-error,
  .nav-item,
  .nav-item b,
  .bottom-nav-label,
  .fridge-metric span,
  .fridge-weight span,
  .fridge-item span:not(.icon-tile),
  .fridge-item-side .fridge-age,
  .fridge-price-form label,
  .fridge-readonly-price span,
  .fridge-sale-form label,
  .fridge-input-with-unit small,
  .sent-item span:not(.icon-tile),
  .report-cancel,
  .duplicate-match-card > span,
  .duplicate-match-badge,
  .duplicate-reason-field small,
  .duplicate-reason-error,
  .collection-filter-count,
  .collection-variety-status-icon,
  .harvest-gate-card label,
  .harvest-report-meta,
  .harvest-report-owner,
  .harvest-report-state,
  .harvest-report-state b,
  .harvest-report-completion,
  .harvest-report-metric span,
  .harvest-report-sale,
  .harvest-report-readonly,
  .report-edit-eyebrow,
  .report-edit-group h3 small,
  .report-edit-group label,
  .report-edit-input-unit small,
  .report-edit-helper,
  .report-edit-summary small,
  .report-edit-error,
  .incremental-list-sentinel-content
) {
  font-size: var(--ag-type-caption);
  line-height: 1.4;
}

body.drying-app :where(
  .eyebrow,
  .title-block > p:last-child,
  .language-toggle,
  .workspace-kicker,
  .section-heading p,
  .section-number,
  .field-label,
  .field-label small,
  .inline-unit-input b,
  .drying-field > span,
  .drying-field small,
  .stage-delay-copy,
  .stage-delay-copy i,
  .stage-delay-control > b,
  .stage-index,
  .batch-stage-index,
  .mode-toggle small,
  .recipe-summary span,
  .form-message,
  .batch-subtitle,
  .batch-owner,
  .batch-owner strong,
  .batch-status,
  .batch-metric span,
  .batch-metric small,
  .active-stage-head time,
  .active-stage-head .stage-delay-copy,
  .active-stage-head .stage-delay-control > b,
  .active-stage-field > span,
  .active-stage-toggle strong,
  .active-stage-toggle small,
  .stage-edit-message,
  .batch-stage-copy small,
  .batch-stage-time,
  .batch-actions .button,
  .recipe-card-head p,
  .recipe-owner strong,
  .recipe-rating,
  .recipe-saved-at,
  .recipe-metric span,
  .recipe-stage-copy small,
  .recipe-stage-params span,
  .recipe-note > span,
  .recipe-note p,
  .recipe-actions .button,
  .optimizer-filter > span,
  .optimizer-highlight small,
  .optimizer-highlight div > span,
  .optimizer-selected-count,
  .optimizer-batch-copy small,
  .optimizer-batch-results small,
  .optimizer-table th:first-child,
  .optimizer-table td:first-child,
  .optimizer-table-batch > span,
  .optimizer-table-batch small,
  .optimizer-table-batch button,
  .optimizer-use-button,
  .batch-outcome span,
  .batch-quality small,
  .batch-quality strong,
  .empty-batches span,
  .drying-nav .nav-item,
  .active-stage-identity time,
  .inline-stage-cancel,
  .inline-stage-hint,
  .incremental-list-sentinel-content
) {
  font-size: var(--ag-type-caption);
  line-height: 1.4;
}

body.payroll-app :where(
  .eyebrow,
  .title-block > p:last-child,
  .account-popover strong,
  .language-toggle,
  .workspace-kicker,
  .section-heading p,
  .section-number,
  .payroll-section-kicker,
  .payroll-field-label,
  .field-hint,
  .summary-card span,
  .entry-summary small,
  .line-person small,
  .line-time small,
  .line-money small,
  .month-context-field > span,
  .month-autosave-state,
  .calculation-tab small,
  .status-badge,
  .incremental-list-sentinel-content
) {
  font-size: var(--ag-type-caption);
  line-height: 1.4;
}

body.drying-app :where(.button-compact, .active-stage-save) {
  font-size: 13px;
}

body.admin-app #view-activity tbody td {
  font-size: 13px;
  line-height: 1.4;
}

body.admin-app :where(
  .stat-value,
  .admin-module-metric strong,
  .user-account-name,
  .backup-metric strong,
  .drying-admin-metric strong
),
body.dashboard-app :where(
  .kpi-card-value,
  .stat-card-value,
  .d2-kpi-card-value,
  .ops-kpi-value,
  .ops-summary-metric strong
),
body.harvest-app :where(
  .metric-value,
  .harvest-report-metric strong,
  .fridge-metric strong
),
body.drying-app :where(
  .batch-metric strong,
  .recipe-metric strong,
  .optimizer-highlight strong
),
body.payroll-app :where(
  .summary-card strong,
  .entry-summary strong,
  .line-money strong,
  .payroll-total-value
) {
  font-variant-numeric: tabular-nums;
}

@media (max-width: 700px) {
  body.admin-app,
  body.dashboard-app,
  body.harvest-app,
  body.drying-app,
  body.payroll-app {
    font-size: var(--ag-type-mobile-body);
    line-height: 1.5;
    overscroll-behavior-y: contain;
    scroll-padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  }

  body.admin-app :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea),
  body.dashboard-app :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea),
  body.harvest-app :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea),
  body.drying-app :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea),
  body.payroll-app :where(input:not([type="checkbox"]):not([type="radio"]):not([type="hidden"]), select, textarea) {
    min-height: var(--ag-touch-target) !important;
    max-width: 100%;
    font-size: 16px !important;
  }

  body.admin-app :where(button, .btn, summary),
  body.dashboard-app :where(button, .btn, summary),
  body.harvest-app :where(button, .button, summary),
  body.drying-app :where(button, .button, summary),
  body.payroll-app :where(button, .button, summary) {
    min-height: var(--ag-touch-target) !important;
  }

  body.payroll-app :where(.month-context-number b, #new-run-button span) {
    font-size: var(--ag-type-caption);
  }

  body.admin-app .activity-context-toggle {
    position: relative;
    min-height: 20px !important;
  }

  body.admin-app .activity-context-toggle::before {
    position: absolute;
    content: "";
    inset: -12px -8px;
  }

  body.admin-app :where(.sidebar-nav button, .mobile-nav-toggle, .sidebar-mobile-close, .toggle-switch),
  body.dashboard-app :where(.sidebar-nav a, .sidebar-toggle, .ops-tab),
  body.harvest-app :where(.language-toggle, .account-menu summary, .bottom-nav .nav-item),
  body.drying-app :where(.language-toggle, .account-menu summary, .bottom-nav .nav-item, .mode-toggle),
  body.payroll-app :where(.language-toggle, .account-menu summary, .payroll-nav .nav-item, .calculation-tab) {
    min-height: var(--ag-touch-target);
  }

  body.admin-app :where(.user-access-option, .user-permission-row, .user-create-permission),
  body.harvest-app :where(.report-action, .fridge-price-form label, .fridge-sale-form label),
  body.drying-app :where(.active-stage-toggle, .mode-toggle),
  body.payroll-app :where(.payroll-choice, .payroll-check-option) {
    min-height: var(--ag-touch-target);
  }

  body.admin-app :where(.page-wrap, .content),
  body.dashboard-app .main-content {
    min-width: 0;
  }

  body.admin-app :where(.table-wrap, .activity-table-wrap),
  body.dashboard-app :where(.analytics-panel, .ops-table-wrap),
  body.harvest-app :where(.collection-table-wrap),
  body.drying-app :where(.optimizer-table-wrap),
  body.payroll-app :where(.payroll-table-wrap, .payroll-register) {
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  body.harvest-app .bottom-nav,
  body.drying-app .bottom-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  body.harvest-app .bottom-nav .nav-item,
  body.drying-app .bottom-nav .nav-item {
    min-height: 56px;
    font-size: var(--ag-type-caption);
  }

  body.harvest-app .collection-year-control {
    margin-bottom: 3px;
  }

  body.admin-app .admin-overview-hero-actions {
    align-items: center;
    flex-direction: row;
    justify-content: space-between;
  }

  body.admin-app .admin-overview-updated {
    white-space: nowrap;
  }

  body.admin-app :where(.login-card, .card, .settings-card),
  body.dashboard-app :where(.dashboard-auth-card),
  body.harvest-app :where(.form-section, .sent-panel, .fridge-panel, .collection-panel),
  body.drying-app :where(.drying-card, .batch-card, .recipe-card),
  body.payroll-app :where(.payroll-card, .calculation-surface, .payroll-dialog) {
    max-width: 100%;
  }

  body.admin-app :where(.modal, .dialog),
  body.dashboard-app :where(.modal, .add-modal-sheet),
  body.harvest-app dialog,
  body.drying-app dialog,
  body.payroll-app dialog {
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 20px);
  }
}

@media (prefers-reduced-motion: reduce) {
  body.admin-app *,
  body.dashboard-app *,
  body.harvest-app *,
  body.drying-app *,
  body.payroll-app * {
    scroll-behavior: auto !important;
  }
}
