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

:root {
  --bg:         #f0f4f8;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #2d3748;
  --muted:      #718096;
  --primary:    #2b6cb0;
  --primary-dk: #2c5282;
  --danger:     #e53e3e;
  --warn:       #d69e2e;
  --orange:     #dd6b20;
  --success:    #38a169;
  --radius:     6px;
  --shadow:     0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

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

/* ─── Header / Nav ──────────────────────────────────────────────── */
.header {
  background: #1a3a5c;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 2.5rem;
  height: 54px;
}

.brand { display: flex; flex-direction: column; line-height: 1.2; white-space: nowrap; }
.brand-name { font-weight: 700; font-size: 15px; color: #fff; letter-spacing: .02em; }
.brand-sub  { font-size: 10.5px; color: rgba(255,255,255,.55); text-transform: uppercase; letter-spacing: .06em; }

.nav { display: flex; gap: .2rem; }

.nav-btn {
  background: transparent;
  border: none;
  color: rgba(255,255,255,.65);
  cursor: pointer;
  padding: .38rem .9rem;
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: inherit;
  transition: background .15s, color .15s;
}
.nav-btn:hover        { background: rgba(255,255,255,.12); color: #fff; }
.nav-btn.active       { background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }

/* ─── Layout ────────────────────────────────────────────────────── */
.main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* ─── Cards ─────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card.no-pad { padding: 0; }

.card h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: 1rem;
}

/* ─── View header ───────────────────────────────────────────────── */
.view-header {
  display: flex;
  align-items: center;
  gap: .85rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.view-header h2 { font-size: 1.25rem; font-weight: 700; flex: 1; }
.back-link { color: var(--muted); font-size: 13px; white-space: nowrap; }
.back-link:hover { color: var(--text); text-decoration: none; }

/* ─── Section divider ───────────────────────────────────────────── */
.section-divider {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin: 1.5rem 0 .85rem;
}
.section-divider h3 {
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
.section-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .4rem .85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  text-decoration: none !important;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover        { background: var(--bg); }
.btn-primary      { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dk); border-color: var(--primary-dk); }
.btn-sm           { padding: .22rem .6rem; font-size: 12px; }
.btn-active       { border-color: var(--primary); color: var(--primary); font-weight: 600; }
button.btn:disabled { opacity: .55; cursor: not-allowed; }

/* ─── Badges ────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .18rem .48rem;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  line-height: 1.5;
}
.badge-ok       { background: #c6f6d5; color: #276749; }
.badge-warn     { background: #fefcbf; color: #744210; }
.badge-orange   { background: #feebc8; color: #7b341e; }
.badge-alert    { background: #fed7d7; color: #742a2a; }
.badge-inactive { background: #e2e8f0; color: #4a5568; }
.badge-none     { background: #edf2f7; color: #718096; }

.text-ok   { color: var(--success); font-size: 12px; }
.text-muted { color: var(--muted); font-size: 12px; }

/* ─── Tables ────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table.table { width: 100%; border-collapse: collapse; font-size: 13px; }

table.table thead tr { background: #f7fafc; }
table.table th {
  padding: .55rem .9rem;
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.table td {
  padding: .6rem .9rem;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
table.table tr:last-child td { border-bottom: none; }
table.table tbody tr:hover   { background: #f7fafc; }

.machine-link { font-weight: 600; color: var(--text); }
.machine-link:hover { color: var(--primary); text-decoration: none; }
.row-inactive td     { opacity: .5; }
.row-discrepancy td  { background: #fff5f5; }
.flags-cell { display: flex; gap: .3rem; flex-wrap: wrap; align-items: center; }
.notes-cell { color: var(--muted); max-width: 200px; }
.table-empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}

/* ─── Forms ─────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: .8rem;
}
.form-row  { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; }
.form-group { display: flex; flex-direction: column; gap: .28rem; flex: 1; min-width: 140px; }

label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}

input[type="text"],
input[type="number"],
input[type="url"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: .42rem .7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(43,108,176,.12);
}
textarea { resize: vertical; min-height: 60px; }

.form-actions {
  display: flex;
  align-items: center;
  gap: .6rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.section-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin: .9rem 0 .5rem;
}

/* ─── Machine info grid ─────────────────────────────────────────── */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: .7rem 1.5rem;
}
.info-item  { display: flex; flex-direction: column; gap: .12rem; }
.info-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.info-value { font-size: 13.5px; color: var(--text); }

/* ─── Charts ────────────────────────────────────────────────────── */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}
.chart-empty { text-align: center; padding: 2.5rem 0; }

/* ─── Reconciliation stats ──────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem 1rem;
  box-shadow: var(--shadow);
}
.stat-card-warn      { border-color: #fbd38d; background: #fffbeb; }
.stat-card-highlight { border-color: #90cdf4; background: #ebf8ff; }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  margin-bottom: .3rem;
}
.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.1;
}
.stat-value.stat-money { font-size: 1.35rem; }
.stat-unit  { font-size: .9rem; font-weight: 400; color: var(--muted); margin-left: .15rem; }
.stat-sub   { font-size: 11.5px; color: var(--muted); margin-top: .25rem; }

/* ─── Revenue breakdown ─────────────────────────────────────────── */
.recon-breakdown { max-width: 320px; }
.breakdown-row {
  display: flex;
  justify-content: space-between;
  padding: .45rem 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}
.breakdown-row:last-child { border-bottom: none; }
.breakdown-total {
  font-weight: 700;
  color: var(--text);
  border-top: 2px solid var(--border);
  margin-top: .2rem;
  padding-top: .6rem;
}

/* ─── State indicators ──────────────────────────────────────────── */
.loading {
  text-align: center;
  color: var(--muted);
  padding: 4rem;
  font-size: 14px;
}
.error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  color: #c53030;
  padding: .9rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 13.5px;
}
.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 4rem;
  font-size: 14px;
}

/* ─── Import view ───────────────────────────────────────────────── */
.import-intro {
  color: var(--muted);
  font-size: 13.5px;
  margin-bottom: 1.25rem;
  line-height: 1.55;
}

.import-toolbar {
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

/* Hide the native file input visually but keep it accessible */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}

.import-fname {
  font-size: 13px;
  color: var(--muted);
  font-style: italic;
}

.import-action-bar {
  display: flex;
  align-items: center;
  gap: .75rem;
  margin-top: .75rem;
}

.import-progress {
  font-size: 13px;
  color: var(--muted);
}

.import-meta {
  font-size: 13px;
  margin: .6rem 0 .5rem;
  color: var(--muted);
}

.import-ok  { color: var(--success); font-weight: 600; }
.import-err { color: var(--danger);  font-weight: 600; }

/* Preview table — compact, scrollable */
.import-table { font-size: 12px; }
.import-table th { font-size: 11px; }
.import-table td { padding: .4rem .7rem; }
.import-rownum   { color: var(--muted); text-align: right; width: 2rem; }
.row-import-skip td { opacity: .5; background: #fafafa; }

/* Summary box */
.import-summary {
  margin-top: .85rem;
  padding: .8rem 1rem;
  border-radius: var(--radius);
  font-size: 13.5px;
  border: 1px solid;
}
.import-summary-ok   { background: #f0fff4; border-color: #9ae6b4; }
.import-summary-warn { background: #fffbeb; border-color: #fbd38d; }

.import-summary-line { margin-bottom: .4rem; }

.import-error-detail {
  margin-top: .5rem;
  font-size: 12.5px;
}
.import-error-detail summary { cursor: pointer; color: var(--danger); }
.import-error-detail ul { margin: .4rem 0 0 1.2rem; line-height: 1.7; }

/* ─── Modal ─────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1.5rem;
}

.modal-dialog {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .3);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: .25rem .4rem;
  border-radius: var(--radius);
  transition: color .15s, background .15s;
}
.modal-close:hover { color: var(--text); background: var(--bg); }

.modal-body { padding: 1.25rem; }

/* Two-column field row inside a modal */
.modal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
  margin-bottom: .75rem;
}
.modal-row.hidden { display: none; }

.modal-body .form-group { margin-bottom: .75rem; }

/* Cleaning / Leak toggles side-by-side */
.modal-toggles {
  display: flex;
  gap: 2.5rem;
  margin-bottom: .75rem;
}

/* ─── Toggle switch ──────────────────────────────────────────────── */
.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  cursor: pointer;
  user-select: none;
}

.toggle-cb {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-track {
  position: relative;
  width: 38px;
  height: 22px;
  background: #e2e8f0;
  border-radius: 999px;
  flex-shrink: 0;
  transition: background .2s;
}
.toggle-cb:checked + .toggle-track { background: var(--success); }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
  transition: left .18s;
}
.toggle-cb:checked + .toggle-track > .toggle-thumb { left: 19px; }

.toggle-text { font-size: 13.5px; min-width: 2.2rem; color: var(--text); }

/* ─── Inline form error ──────────────────────────────────────────── */
.form-error {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  color: #c53030;
  padding: .55rem .85rem;
  border-radius: var(--radius);
  font-size: 13px;
  margin-top: .25rem;
}
.text-danger { color: var(--danger); }

/* ─── Collection confirmation box ───────────────────────────────── */
.confirm-box { text-align: center; }
.confirm-icon { font-size: 2.8rem; margin-bottom: .4rem; }
.confirm-box h4 { font-size: 1.05rem; font-weight: 700; margin-bottom: 1rem; }

.confirm-stats {
  background: var(--bg);
  border-radius: var(--radius);
  padding: .6rem 1rem;
  margin-bottom: .75rem;
  text-align: left;
}
.confirm-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .38rem 0;
  font-size: 13.5px;
  border-bottom: 1px solid var(--border);
}
.confirm-row:last-child { border-bottom: none; }
.confirm-row span { color: var(--muted); }

/* ─── Fleet table ───────────────────────────────────────────────── */
.fleet-table td {
  padding-top: .7rem;
  padding-bottom: .7rem;
  vertical-align: top;
}

/* Rows with active flags get a very subtle left accent */
.fleet-table tr.row-has-flags > td:first-child {
  border-left: 3px solid var(--orange);
}

.cell-primary   { font-weight: 600; font-size: 13.5px; }
.cell-secondary { font-size: 11.5px; color: var(--muted); }
.cell-unit      { font-size: 12px; color: var(--muted); font-weight: 400; }
.actions-cell   { white-space: nowrap; }

/* Days-since pill */
.day-pill {
  display: inline-block;
  margin-top: .25rem;
  padding: .15rem .5rem;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  white-space: nowrap;
}
.day-green { background: #c6f6d5; color: #276749; }
.day-amber { background: #fefcbf; color: #744210; }
.day-red   { background: #fed7d7; color: #742a2a; }

/* ─── Utility ───────────────────────────────────────────────────── */
.hidden { display: none !important; }
