/* Reset & Base */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* <fieldset> defaults to min-width: min-content, which refuses to shrink
 * below its widest unbreakable descendant. Any nowrap text (long user-agent
 * strings, etc.) inside a fieldset will stretch the whole fieldset past
 * the viewport on mobile. This reset makes fieldsets behave like normal
 * block elements. Well-known gotcha — see e.g. https://thatemil.com/blog/2015/01/03/reset-your-fieldset/
 */
fieldset {
  min-width: 0;
}

:root {
  /* Brand palette — see .ai/context/conventions.md#brand--colors.
     Primary is the vivid leaf-lime (rgb 132,189,0). It is light: NEVER put
     white text on it — pair lime backgrounds with --color-on-primary (dark).
     Forest is the readable dark green used for chrome (navbar), links, and
     any green text on white. Mint and gold are the secondary accents. */
  --color-primary: #84bd00; /* rgb(132,189,0) — brand lime; actions, progress, focus, active */
  --color-primary-hover: #6f9e00; /* darkened lime for hover on lime surfaces */
  --color-primary-light: #c6e5de; /* rgb(198,229,222) — mint; tints, badges, bubbles */
  --color-on-primary: #14250a; /* dark text/icons placed ON a lime background */
  --color-forest: #264e35; /* rgb(38,78,53) — dark green; chrome, links, readable green text */
  --color-forest-hover: #1a3826; /* darker forest for link/chrome hover */
  --color-accent: #e5c76d; /* rgb(229,199,109) — wheat gold; secondary accent */
  --color-accent-tint: rgba(229, 199, 109, 0.22); /* soft gold fill for badges/highlights */
  --color-accent-text: #7a5e12; /* readable dark gold for text on light/gold-tint */
  --color-bg: #f8f9fa;
  --color-surface: #ffffff;
  --color-text: #212529;
  --color-text-muted: #6c757d;
  --color-border: #dee2e6;
  --color-danger: #dc3545;
  --color-danger-hover: #bb2d3b;
  --color-success: #198754;
  --color-google: #4285f4;
  --color-linkedin: #0a66c2;
  --color-microsoft: #00a4ef;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
  --transition: 150ms ease;
}

html {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
}

a {
  color: var(--color-forest);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--color-forest-hover);
  text-decoration: underline;
}

/* Nav */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--color-forest);
  color: white;
  border-bottom: 3px solid var(--color-primary);
  box-shadow: var(--shadow-md);
}

.navbar-brand {
  font-weight: 700;
  font-size: 1.25rem;
  color: white;
  text-decoration: none;
  letter-spacing: -0.5px;
}

.navbar-brand:hover {
  color: white;
  text-decoration: none;
}

.navbar-links {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.navbar-links a {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.875rem;
  font-weight: 500;
}

.navbar-links a:hover {
  color: white;
  text-decoration: none;
}

.navbar-user {
  font-size: 0.8125rem;
  color: rgba(255, 255, 255, 0.7);
}

/* Role cue: which persona you're signed in as. Light pill + dark text reads
   clearly on the dark forest navbar. Gold = admin (staff), mint = grower. */
.navbar-role {
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  line-height: 1.4;
  white-space: nowrap;
}

.navbar-role-admin {
  background: var(--color-accent); /* wheat gold */
  color: #4a3a08;
}

.navbar-role-grower {
  background: var(--color-primary-light); /* mint */
  color: var(--color-forest);
}

.navbar-dropdown {
  position: relative;
}

.navbar-dropdown > summary {
  list-style: none;
  cursor: pointer;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.875rem;
  font-weight: 500;
  user-select: none;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  min-height: 44px;
}

.navbar-dropdown > summary::-webkit-details-marker {
  display: none;
}

.navbar-dropdown > summary::after {
  content: "▾";
  font-size: 0.75rem;
}

.navbar-dropdown > summary:hover {
  color: white;
}

.navbar-dropdown-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  min-width: 200px;
  display: flex;
  flex-direction: column;
  z-index: 100;
  padding: 0.25rem 0;
}

.navbar-dropdown-menu a {
  color: var(--color-text);
  padding: 0.5rem 0.875rem;
  font-size: 0.875rem;
  min-height: 44px;
  display: flex;
  align-items: center;
  text-decoration: none;
}

.navbar-dropdown-menu a:hover {
  background: var(--color-bg);
  color: var(--color-text);
  text-decoration: none;
}

.navbar .btn-sm {
  padding: 0.25rem 0.75rem;
  font-size: 0.8125rem;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background var(--transition);
}

.navbar .btn-sm:hover {
  background: rgba(255, 255, 255, 0.25);
}

/* Flash messages */
.flash {
  padding: 0.75rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
}

.flash-alert {
  background: #f8d7da;
  color: #842029;
  border-bottom: 1px solid #f5c2c7;
}

.flash-notice {
  background: #d1e7dd;
  color: #0f5132;
  border-bottom: 1px solid #badbcc;
}

/* Layout */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

.container-narrow {
  max-width: 440px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Cards */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.card-header h1,
.card-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0;
}

.card-header p {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

/* Typography */
h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.25rem;
  color: var(--color-text);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 0.625rem 0.75rem;
  font-size: 0.9375rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(132, 189, 0, 0.3);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.625rem 1.25rem;
  font-size: 0.9375rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
  border-color: var(--color-primary);
  font-weight: 600;
}

.btn-primary:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
  color: var(--color-on-primary);
  text-decoration: none;
}

.btn-danger {
  background: var(--color-danger);
  color: white;
  border-color: var(--color-danger);
}

.btn-danger:hover {
  background: var(--color-danger-hover);
  border-color: var(--color-danger-hover);
  color: white;
}

.btn-outline {
  background: transparent;
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn-outline:hover {
  background: var(--color-bg);
  text-decoration: none;
}

.btn-block {
  display: flex;
  width: 100%;
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8125rem;
}

/* OAuth buttons */
.oauth-buttons {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

/* Provider sign-in buttons — themed to GrowerOne: white surface, forest text,
   brand logo on the left, mint hover. Uniform across providers so they read as
   "our" buttons; the colored logos carry the brand recognition. */
.btn-oauth {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  padding: 0.7rem 1rem;
  min-height: 44px;
  font-size: 0.9375rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-forest);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-oauth:hover {
  background: var(--color-primary-light);
  border-color: var(--color-forest);
  color: var(--color-forest);
}

.oauth-logo {
  width: 18px;
  height: 18px;
  flex: none;
  display: block;
}

/* Divider */
.divider {
  display: flex;
  align-items: center;
  margin: 1.5rem 0;
  color: var(--color-text-muted);
  font-size: 0.8125rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--color-border);
}

.divider::before {
  margin-right: 0.75rem;
}

.divider::after {
  margin-left: 0.75rem;
}

/* Tables */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead {
  background: var(--color-bg);
}

th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--color-border);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: rgba(132, 189, 0, 0.06);
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.2em 0.6em;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: capitalize;
}

.badge-owner {
  background: var(--color-accent-tint);
  color: var(--color-accent-text);
}

.badge-member {
  background: #e9ecef;
  color: var(--color-text-muted);
}

.badge-pending {
  background: #fff3cd;
  color: #664d03;
}

/* Action bar */
.action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Section spacing */
.section {
  margin-bottom: 2rem;
}

/* Turbo Frame defaults to display: inline, which collapses any block/grid
   layout we put inside it (e.g. .bpo-grid would stop spanning full width).
   Force block so children inherit the container's full width like they did
   before lazy-framing. */
turbo-frame {
  display: block;
}

/* Turbo Frame loading placeholder. Used as the in-frame default content for
   pages that lazy-load slow Fabric data — gives the user something to look at
   while the network round-trip resolves. Centered, compact, non-intrusive. */
.frame-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  padding: 3rem 1rem;
}

.frame-loading-label {
  color: var(--muted, #6b7280);
  font-size: 0.875rem;
  margin: 0;
}

.frame-loading-spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid #e5e7eb;
  border-top-color: var(--brand, #84bd00);
  border-radius: 50%;
  animation: frame-loading-spin 0.9s linear infinite;
}

@keyframes frame-loading-spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .frame-loading-spinner { animation: none; }
}

/* Errors */
.errors {
  background: #f8d7da;
  color: #842029;
  border: 1px solid #f5c2c7;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  font-size: 0.875rem;
}

.errors ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.errors li::before {
  content: "\2022";
  margin-right: 0.5rem;
}

/* Links row */
.text-center {
  text-align: center;
}

.text-muted {
  color: var(--color-text-muted);
  font-size: 0.875rem;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }

/* Responsive */
@media (max-width: 640px) {
  .container {
    padding: 1rem;
  }

  .container-narrow {
    padding: 1rem;
  }

  .navbar {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .navbar-links {
    flex-wrap: wrap;
    justify-content: center;
  }

  .action-bar {
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }

  table {
    font-size: 0.8125rem;
  }

  th, td {
    padding: 0.5rem 0.625rem;
  }
}

/* Vendor Search */
.vendor-search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.vendor-search-input-wrap input {
  flex: 1;
}

.vendor-search-input-wrap button {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: #666;
  cursor: pointer;
  padding: 0 0.25rem;
}

[data-vendor-search-target="dropdown"] {
  position: absolute;
  z-index: 100;
  background: #fff;
  border: 1px solid #ccc;
  border-radius: 4px;
  max-height: 240px;
  overflow-y: auto;
  width: 100%;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.vendor-search-item {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
}

.vendor-search-item:hover {
  background: #f0f4ff;
}

.vendor-search-no {
  font-weight: 600;
  color: #555;
  margin-right: 0.4rem;
}

.contract-preview-panel {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  padding: 2rem;
}

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

.contract-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  padding: 0.75rem 1rem;
  border-radius: 6px 6px 0 0;
  border-bottom: 1px solid #e5e7eb;
}

.contract-preview-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.contract-preview-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
  border-radius: 0 0 6px 6px;
}

.vendor-search-empty {
  padding: 0.5rem 0.75rem;
  color: #999;
  font-size: 0.9rem;
}

/* BPO Cards */
.bpo-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

.bpo-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Desktop: lay the card out horizontally as a single stretched row. */
@media (min-width: 960px) {
  .bpo-card {
    flex-direction: row;
    align-items: center;
    gap: 1.5rem;
    padding: 1.25rem 1.5rem;
  }

  .bpo-card-header {
    flex: 0 1 220px;
    min-width: 180px;
    flex-direction: column;
    align-items: flex-start;
  }

  .bpo-card-progress {
    flex: 1 1 200px;
    min-width: 160px;
  }

  .bpo-card-stats {
    flex: 2 1 320px;
    min-width: 280px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem 1rem;
  }

  .bpo-card-due {
    flex: 0 0 auto;
    min-width: 110px;
    border-top: none;
    padding-top: 0;
  }

  .bpo-card-actions {
    flex: 0 0 160px;
    flex-direction: column;
    margin-top: 0;
  }

  .bpo-card-actions .btn-tap {
    width: 100%;
  }
}

.bpo-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.bpo-card-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}

.bpo-card-pills {
  display: flex;
  gap: 0.375rem;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.quality-badge {
  display: inline-block;
  padding: 0.2em 0.7em;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  text-transform: capitalize;
  border: 1px solid transparent;
}

.quality-badge.green {
  background: #d1e7dd;
  color: #0f5132;
  border-color: #a3cfbb;
}

.quality-badge.yellow {
  background: #fff3cd;
  color: #664d03;
  border-color: #ffda6a;
}

.quality-badge.red {
  background: #f8d7da;
  color: #842029;
  border-color: #f1aeb5;
}

.bpo-card-progress {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.progress-bar {
  position: relative;
  width: 100%;
  height: 10px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill,
.progress-fill-pending {
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  transition: width var(--transition);
}

.progress-fill {
  background: var(--color-primary);
  z-index: 2;
}

.progress-fill-pending {
  background: var(--color-border);
  z-index: 1;
}

.progress-caption-pending {
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.progress-caption {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
}

.bpo-card-stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 520px) {
  .bpo-card-stats {
    grid-template-columns: repeat(2, 1fr);
  }
}

.bpo-stat {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.bpo-stat-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bpo-stat-value {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--color-text);
}

.bpo-stat-sub {
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  font-weight: 400;
  margin-left: 0.25rem;
}

.bpo-card-due {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--color-border);
}

.bpo-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: auto;
}

.btn-tap {
  min-height: 44px;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  flex: 1 1 auto;
}

/* Settlements page */
.settlement-summary-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}

.settlement-summary-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.settlement-summary-title {
  display: flex;
  flex-direction: column;
  gap: 0.125rem;
}

.settlement-summary-eyebrow {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.settlement-summary-doc {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
}

.settlement-status-pill,
.contract-status-pill {
  display: inline-block;
  padding: 0.25em 0.75em;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  background: var(--color-primary-light);
  color: var(--color-forest);
  text-transform: capitalize;
}

.settlement-summary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 520px) {
  .settlement-summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 820px) {
  .settlement-summary-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

.settlement-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.settlement-section-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  min-height: 44px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font-weight: 600;
}

.settlement-section-summary::-webkit-details-marker {
  display: none;
}

.settlement-section-title {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  font-size: 1.05rem;
  color: var(--color-text);
}

.settlement-section-count {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.settlement-section-chevron {
  font-size: 1.25rem;
  line-height: 1;
  color: var(--color-text-muted);
  transition: transform var(--transition);
  display: inline-block;
  transform: rotate(90deg);
}

.settlement-section[open] .settlement-section-chevron {
  transform: rotate(-90deg);
}

.settlement-section .table-wrapper,
.settlement-section .settlement-empty {
  margin: 0;
  border: none;
  border-top: 1px solid var(--color-border);
  border-radius: 0;
  padding: 0;
}

.settlement-section .settlement-empty {
  padding: 1rem 1.25rem;
}

.settlement-section .table-wrapper table {
  border-collapse: collapse;
}

.responsive-load-table td.num,
.responsive-load-table th.num {
  text-align: right;
  white-space: nowrap;
}

.responsive-load-table .totals-row td {
  font-weight: 700;
  border-top: 2px solid var(--color-border);
  background: var(--color-bg);
}

.grand-totals-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
}

.grand-totals-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.75rem;
}

.grand-totals-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

@media (min-width: 520px) {
  .grand-totals-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 760px) {
  .grand-totals-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Mobile: stack load tables as cards using data-label */
@media (max-width: 640px) {
  .responsive-load-table {
    display: block;
  }

  .responsive-load-table thead {
    display: none;
  }

  .responsive-load-table tbody,
  .responsive-load-table tr {
    display: block;
  }

  .responsive-load-table tr {
    border-bottom: 1px solid var(--color-border);
    padding: 0.75rem 1rem;
  }

  .responsive-load-table tbody tr:last-child {
    border-bottom: none;
  }

  .responsive-load-table td {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.25rem 0;
    border: none;
    text-align: right;
    white-space: normal;
  }

  .responsive-load-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    text-align: left;
  }

  .responsive-load-table .totals-row {
    background: var(--color-bg);
    border-top: 2px solid var(--color-border);
  }

  .responsive-load-table .totals-row td.totals-label {
    display: none;
  }

  .responsive-load-table tbody tr:hover {
    background: transparent;
  }
}

/* Organization financial summary card */
.financial-summary-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  padding: 0 1.5rem 1rem;
}

@media (min-width: 520px) {
  .financial-summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 820px) {
  .financial-summary-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.financial-stat {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.financial-stat-label {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.financial-stat-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--color-text);
}

.financial-stat-sub {
  font-size: 0.875rem;
  font-weight: 400;
  color: var(--color-text-muted);
  margin-left: 0.25rem;
}

.financial-summary-footer {
  padding: 0 1.5rem 1.5rem;
  font-size: 0.875rem;
}

/* Scale-ticket quality spec highlighting */
.spec-target {
  display: block;
  margin-top: 0.125rem;
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: none;
  letter-spacing: 0;
}

.spec-exceeded {
  background: #fff3cd;
  color: #664d03;
}

/* Scale Tickets page */
.container-wide {
  max-width: 1400px;
}

.scale-ticket-table {
  width: 100%;
  font-size: 0.8125rem;
  table-layout: auto;
}

.scale-ticket-table th,
.scale-ticket-table td {
  padding: 0.5rem 0.375rem;
}

.scale-ticket-table th {
  font-size: 0.6875rem;
  line-height: 1.2;
}

.scale-ticket-table .spec-target {
  display: block;
  margin-top: 0.125rem;
  font-size: 0.625rem;
}

.scale-ticket-table td.num,
.scale-ticket-table th.num {
  text-align: right;
  white-space: nowrap;
}

.scale-ticket-table .scale-ticket-toggle-cell {
  text-align: center;
  white-space: nowrap;
}

.scale-ticket-chevron {
  min-width: 44px;
  min-height: 44px;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--color-text);
  transition: background var(--transition), border-color var(--transition);
  padding: 0.25rem 0.5rem;
}

.scale-ticket-chevron:hover,
.scale-ticket-chevron:focus {
  background: var(--color-bg);
  border-color: var(--color-primary);
  outline: none;
}

.scale-ticket-detail[hidden] {
  display: none;
}

.scale-ticket-detail > td {
  background: var(--color-bg);
  padding: 1rem 1.25rem;
}

.scale-ticket-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.5rem;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  margin-bottom: 0.75rem;
}

.scale-ticket-meta-label {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-size: 0.75rem;
}

.scale-ticket-quality {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.quality-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 0.25rem;
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  font-size: 0.8125rem;
  line-height: 1.2;
}

.quality-chip-label {
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  font-size: 0.6875rem;
  letter-spacing: 0.04em;
}

.quality-chip-value {
  font-weight: 600;
  color: var(--color-text);
}

.quality-chip.spec-exceeded {
  border-color: #ffda6a;
}

.quality-chip.spec-exceeded .quality-chip-value,
.quality-chip.spec-exceeded .quality-chip-label {
  color: #664d03;
}

.scale-ticket-breakdown-wrap {
  overflow-x: auto;
}

.scale-ticket-breakdown {
  margin-top: 0.75rem;
  font-size: 0.8125rem;
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.scale-ticket-breakdown th,
.scale-ticket-breakdown td {
  padding: 0.5rem 0.75rem;
}

.scale-ticket-breakdown td.num,
.scale-ticket-breakdown th.num {
  text-align: right;
  white-space: nowrap;
}

.scale-ticket-breakdown .standard-line {
  background: rgba(132, 189, 0, 0.1);
  border-left: 3px solid var(--color-primary);
  font-weight: 600;
}

.scale-ticket-breakdown .discount-line {
  color: var(--color-text-muted);
}

.scale-ticket-breakdown .discount-line td:first-child {
  padding-left: 1.75rem;
}

.tiered-caption {
  display: block;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.125rem;
  font-weight: 400;
}

.scale-ticket-breakdown .truck-total td {
  font-weight: 700;
  border-top: 2px solid var(--color-border);
}

/* Charges / G-L adjustments — a financial section set apart below the load total. */
.scale-ticket-breakdown .charge-divider td {
  padding-top: 0.75rem;
}

.charge-section-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
  color: var(--color-text-muted);
}

.scale-ticket-breakdown .charge-line {
  color: var(--color-text-muted);
  font-style: italic;
}

.scale-ticket-breakdown .charge-line td:first-child {
  padding-left: 1.75rem;
}

.scale-ticket-breakdown .net-total td {
  font-weight: 700;
  border-top: 1px solid var(--color-border);
}

.scale-ticket-totals td {
  font-weight: 700;
  background: var(--color-bg);
  border-top: 2px solid var(--color-border);
}

@media (max-width: 640px) {
  .hide-on-mobile {
    display: none;
  }

  /* Scale-ticket main row collapses to a stacked card per truck — no horizontal scroll. */
  .scale-ticket-table {
    display: block;
    border: none;
  }

  .scale-ticket-table thead {
    display: none;
  }

  .scale-ticket-table tbody {
    display: block;
    margin-bottom: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    overflow: hidden;
  }

  .scale-ticket-table tr.scale-ticket-main {
    display: block;
    padding: 0.5rem 0.75rem;
  }

  .scale-ticket-table tr.scale-ticket-main > td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.375rem 0;
    border: none;
    text-align: right;
  }

  .scale-ticket-table tr.scale-ticket-main > td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    margin-right: 1rem;
  }

  .scale-ticket-table tr.scale-ticket-main > td.scale-ticket-toggle-cell {
    justify-content: flex-end;
    padding-top: 0.5rem;
    border-top: 1px solid var(--color-border);
    margin-top: 0.25rem;
  }

  .scale-ticket-table tr.scale-ticket-main > td.scale-ticket-toggle-cell::before {
    content: "";
  }

  .scale-ticket-table tr.scale-ticket-detail:not([hidden]) {
    display: block;
  }

  .scale-ticket-table tr.scale-ticket-detail > td {
    display: block;
    padding: 0.75rem;
    border-top: 1px solid var(--color-border);
  }

  /* Breakdown table (inside the detail panel) also stacks on mobile. */
  .scale-ticket-breakdown {
    display: block;
    border: none;
  }

  .scale-ticket-breakdown thead {
    display: none;
  }

  .scale-ticket-breakdown tbody {
    display: block;
    border: none;
  }

  .scale-ticket-breakdown tbody tr {
    display: block;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    background: var(--color-surface);
  }

  .scale-ticket-breakdown tbody tr > td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0;
    border: none;
    text-align: right;
  }

  .scale-ticket-breakdown tbody tr > td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    margin-right: 1rem;
  }

  /* First cell in each breakdown row is the Category label — render as a heading, no data-label prefix, left-aligned. */
  .scale-ticket-breakdown tbody tr > td:first-child {
    justify-content: flex-start;
    font-weight: 600;
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
    border-bottom: 1px solid var(--color-border);
    text-align: left;
  }

  .scale-ticket-breakdown tbody tr > td:first-child::before {
    content: "";
  }

  .scale-ticket-breakdown tbody tr.truck-total > td:first-child {
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }
}

/* ============================================================
   Org ↔ admin messaging (conversations index + show + composer)
   ============================================================ */

/* Conversation index list */
.conversation-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.conversation-row {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.conversation-row-unread {
  border-color: var(--color-primary);
}

.conversation-link {
  display: block;
  padding: 0.875rem 1rem;
  min-height: 44px;
  color: var(--color-text);
  text-decoration: none;
}

.conversation-link:hover,
.conversation-link:focus {
  background: var(--color-bg);
  color: var(--color-text);
}

.conversation-link-start {
  width: 100%;
  text-align: left;
  background: var(--color-surface);
  border: none;
  font: inherit;
  cursor: pointer;
  color: var(--color-forest);
  font-weight: 500;
}

.conversation-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.conversation-row-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
}

.conversation-org {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-row-meta {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.badge-unread {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

/* Conversation show: thread + composer */
.conversation-show {
  display: flex;
  flex-direction: column;
}

.conversation-show-title {
  font-size: 1.25rem;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-thread {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.conversation-messages {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 200px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 0.5rem;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}

.conversation-empty {
  padding: 1rem;
  text-align: center;
}

/* Message bubble — default ("theirs"): left, grey */
.message {
  background: #e9ecef;
  border: 1px solid #e9ecef;
  border-radius: var(--radius);
  padding: 0.625rem 0.75rem;
  max-width: 85%;
  align-self: flex-start;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

/* "Mine": right, brand tint. Hide redundant sender label since it's me. */
.message-mine {
  align-self: flex-end;
  background: var(--color-primary-light);
  border-color: var(--color-primary-light);
}

.message-mine .message-sender {
  display: none;
}

.message-meta {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  flex-wrap: wrap;
}

.message-sender {
  font-weight: 600;
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
}

.message-sender-badge {
  font-size: 0.65rem;
}

.message-time {
  margin-left: auto;
}

.message-body {
  white-space: pre-wrap;
  line-height: 1.4;
}

/* Conversation header */
.conversation-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--color-border);
}

.conversation-back {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--color-text-muted);
  text-decoration: none;
  font-size: 0.9rem;
  min-height: 44px;
  padding: 0.5rem;
  margin: -0.5rem 0;
}

.conversation-back:hover {
  color: var(--color-forest);
}

.conversation-back-arrow {
  font-size: 1.25rem;
  line-height: 1;
}

.conversation-header-main {
  flex: 1 1 auto;
  min-width: 0;
}

.conversation-header-title {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-header-subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  line-height: 1.3;
}

@media (max-width: 480px) {
  .conversation-back-text {
    display: none;
  }
  .conversation-header-title {
    font-size: 1.1rem;
  }
}

/* Composer */
.conversation-composer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.conversation-composer-error {
  font-size: 0.85rem;
  color: var(--color-danger);
  padding: 0.25rem 0;
}

.conversation-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.conversation-composer-input {
  flex: 1 1 auto;
  min-height: 44px;
  max-height: 200px;
  resize: none;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font: inherit;
  line-height: 1.4;
}

.conversation-composer-submit {
  flex: 0 0 auto;
  min-height: 44px;
}

.conversation-composer-submit:disabled,
.conversation-composer-submit[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

@media (max-width: 480px) {
  .conversation-messages {
    max-height: 55vh;
  }
  .message {
    max-width: 95%;
  }
}

/* Account settings page (/account)
 *
 * Density-focused: the page has the user's contact info plus three notification
 * channels (email/SMS/push) plus per-device push subscriptions plus an
 * SMS-terms disclosure. We tighten vertical spacing aggressively on phones
 * and collapse the SMS-terms behind a <details> so the page fits in roughly
 * one mobile viewport instead of requiring scroll. The SMS-terms element
 * stays one tap from the consent checkbox, which keeps it CTIA-compliant
 * (readily accessible at the point of opt-in).
 */
.account-form-group {
  margin-bottom: 0.875rem;
}

.account-help-text {
  font-size: 0.8125rem;
  margin-top: 0.25rem;
}

/* Phone input group: +1 prefix joined to a flex-1 input. */
.phone-input-group {
  display: flex;
  align-items: stretch;
}

.phone-prefix {
  display: inline-flex;
  align-items: center;
  padding: 0.625rem 0.75rem;
  background: var(--color-bg);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  font-size: 0.9375rem;
  min-height: 44px;
  user-select: none;
}

.phone-input-group input[type="tel"] {
  border-radius: 0 var(--radius) var(--radius) 0;
  flex: 1;
  min-height: 44px;
}

.account-notifications-fieldset {
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.875rem 1rem;
  margin-bottom: 0.875rem;
}

.account-notifications-legend {
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0 0.5rem;
}

.account-checkbox-row {
  margin-bottom: 0.5rem;
}

.account-checkbox-row:last-child {
  margin-bottom: 0;
}

.account-checkbox-label {
  display: flex;
  align-items: center;
  min-height: 44px;
}

/* Explicit margin on the checkbox itself (more robust than flex `gap`,
 * which some browsers handle inconsistently when the label contains a
 * hidden Rails-generated input). */
.account-checkbox-label input[type="checkbox"] {
  margin-right: 0.625rem;
  flex-shrink: 0;
}

.sms-disclosure {
  margin-top: 0.375rem;
  padding: 0.625rem 0.75rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  line-height: 1.45;
  background: var(--color-bg);
}

.sms-disclosure-heading {
  margin: 0 0 0.375rem;
  font-weight: 600;
  color: var(--color-text);
}

.sms-disclosure-body {
  margin: 0;
}

.sms-disclosure-links {
  margin: 0.4rem 0 0;
}

/* Push subscription section inside the notifications fieldset. */
.push-device-section {
  margin-top: 0.625rem;
  padding-top: 0.625rem;
  border-top: 1px solid var(--color-border);
}

.push-device-heading {
  font-size: 0.9375rem;
  margin: 0 0 0.375rem;
}

.push-device-actions {
  gap: 0.5rem;
  flex-wrap: wrap;
}

.push-devices-heading {
  font-size: 0.875rem;
  margin: 0.75rem 0 0.375rem;
}

.push-devices-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.push-device-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--color-border);
  flex-wrap: wrap;
}

.push-device-row .device-info {
  flex: 1 1 200px;
  min-width: 0;
}

.push-device-row .device-ua {
  font-size: 0.875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.push-device-row .text-muted {
  font-size: 0.75rem;
}

@media (max-width: 640px) {
  /* Card has 2rem padding by default; combined with container + fieldset
   * that's >100px lost. Tighten everything for phone viewports. */
  .card {
    padding: 1.25rem;
  }

  .account-notifications-fieldset {
    padding: 0.625rem 0.75rem;
  }

  .account-form-group {
    margin-bottom: 0.625rem;
  }

  /* Full-width Save button — obvious tap target instead of a small chip. */
  .account-save-row .btn {
    display: block;
    width: 100%;
  }

  /* Stack the Enable / Disable buttons on phones so each is a wide tap target. */
  .push-device-actions {
    flex-direction: column;
  }
  .push-device-actions .btn {
    width: 100%;
  }
}
