:root {
  --mow-green: #22c55e;
  --mow-green-dark: #15803d;
  --hold-red: #ef4444;
  --hold-red-dark: #b91c1c;
  --developer-blue: #3b82f6;
  --developer-blue-dark: #1d4ed8;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #1a6b5a;
  --primary-dark: #0f4a3e;
  --warn-bg: #fef3c7;
  --warn-border: #fcd34d;
}

* { box-sizing: border-box; }

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

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.app-header {
  background: var(--primary-dark);
  color: white;
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.app-header h1 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.app-header .muted { color: rgba(255, 255, 255, 0.7); margin: 0; font-size: 0.85rem; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

.card h2 { margin-top: 0; font-size: 1rem; font-weight: 600; color: var(--primary-dark); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

.pill {
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.pill-warn { background: var(--warn-bg); color: #92400e; }
.pill-ok { background: #dcfce7; color: #166534; }
.pill-error { background: #fee2e2; color: #991b1b; }

.legend { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.legend-pill {
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: white;
}
.legend-pill.green { background: var(--mow-green-dark); }
.legend-pill.red { background: var(--hold-red-dark); }
.legend-pill.blue { background: var(--developer-blue-dark); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  color: var(--text);
  text-decoration: none;
  font-family: inherit;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); color: white; border-color: var(--primary-dark); }
.btn-secondary { background: #f1f5f9; }
.btn-link { background: transparent; border-color: transparent; color: var(--muted); }
.btn-link:hover { color: var(--primary); border-color: transparent; }

.row { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }

textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #f8fafc;
  resize: vertical;
}

.csv-status { margin-top: 0.4rem; font-size: 0.85rem; min-height: 1.2em; }
.csv-status.ok { color: #166534; }
.csv-status.err { color: #991b1b; }

input[type="file"] { font-size: 0.9rem; }

.upload-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}
@media (min-width: 640px) {
  .upload-row { grid-template-columns: 1fr 1fr; }
}
.upload-cell {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding: 0.75rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: #f8fafc;
}
.upload-label { font-weight: 600; font-size: 0.85rem; color: var(--primary-dark); }

/* Pricing grid */
.pricing-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
@media (min-width: 640px) {
  .pricing-grid { grid-template-columns: 1fr 1fr; }
}
.price-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.4rem;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.price-row label { font-weight: 600; font-size: 0.85rem; }
.price-controls { display: flex; align-items: center; gap: 0.5rem; }
.price-controls input[type="range"] { flex: 1; }
.price-controls input[type="number"] {
  width: 5rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: inherit;
}

/* Summary cards */
.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
@media (min-width: 768px) {
  .summary { grid-template-columns: repeat(4, 1fr); }
}
.summary-card {
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  color: white;
}
.summary-green { background: var(--mow-green-dark); }
.summary-red { background: var(--hold-red-dark); }
.summary-blue { background: var(--developer-blue-dark); }
.summary-total { background: var(--primary-dark); }
.summary-label { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; opacity: 0.9; }
.summary-value { font-size: 1.75rem; font-weight: 700; margin-top: 0.25rem; }

/* Map */
.map-card { padding-bottom: 1rem; }
#map {
  height: 480px;
  border-radius: 6px;
  margin-top: 0.5rem;
  border: 1px solid var(--border);
}

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
.data-table th, .data-table td {
  padding: 0.5rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table th { font-weight: 600; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: #f8fafc; }

.action-tag {
  display: inline-block;
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  color: white;
  white-space: nowrap;
  letter-spacing: 0.03em;
}
.action-tag.green { background: var(--mow-green-dark); }
.action-tag.red { background: var(--hold-red-dark); }
.action-tag.blue { background: var(--developer-blue-dark); }

.actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.warnings { display: flex; flex-direction: column; gap: 0.5rem; }
.warning {
  background: var(--warn-bg);
  border-left: 4px solid var(--warn-border);
  padding: 0.6rem 0.8rem;
  border-radius: 4px;
  font-size: 0.85rem;
}
.warning.error { background: #fee2e2; border-left-color: #ef4444; color: #991b1b; }

/* Print-only elements */
.print-only { display: none; }
.print-header h1 { font-size: 1.5rem; margin: 0 0 0.25rem; color: var(--primary-dark); }
.print-header p { margin: 0; color: var(--muted); }

/* Print styles */
@media print {
  @page { size: letter landscape; margin: 0.5in; }
  body { background: white; font-size: 11pt; }
  .no-print { display: none !important; }
  .print-only { display: block; }
  main { padding: 0; gap: 0.75rem; max-width: 100%; }
  .card { border: none; padding: 0.5rem 0; }
  .card h2 { font-size: 0.95rem; margin-bottom: 0.4rem; }
  /* Cards that should never split mid-card */
  .summary, .invoice-card, .map-card {
    page-break-inside: avoid;
    break-inside: avoid;
  }
  /* Manifest table is long — let it flow across pages naturally */
  .data-table thead { display: table-header-group; }
  .data-table tr { page-break-inside: avoid; break-inside: avoid; }
  .summary { grid-template-columns: repeat(4, 1fr); }
  .summary-card { padding: 0.5rem; }
  .summary-value { font-size: 1.25rem; }
  .data-table { font-size: 9pt; }
  .data-table th, .data-table td { padding: 0.25rem 0.4rem; }
  footer { text-align: center; font-size: 9pt; color: var(--muted); margin-top: 1rem; }

  /* Move the map to its own page and let it fill the landscape page */
  .map-card {
    page-break-before: always;
    break-before: page;
    page-break-inside: avoid;
    break-inside: avoid;
  }
  .map-card .legend { margin-bottom: 0.4rem; }
  #map {
    height: 6.5in;
    page-break-inside: avoid;
    break-inside: avoid;
  }
}
