:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-alt: #fbfcfd;
  --header: #eef3f8;
  --header-alt: #f4f7fa;
  --field: #ffffff;
  --border: #d9dee7;
  --text: #17202a;
  --muted: #667085;
  --accent: #0f766e;
  --negative: #b42318;
  --warning: #b45309;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #10151c;
  --surface: #151c25;
  --surface-alt: #121922;
  --header: #202b37;
  --header-alt: #1b2530;
  --field: #101821;
  --border: #2f3b49;
  --text: #e7edf4;
  --muted: #a5b2c2;
  --accent: #34d399;
  --negative: #fca5a5;
  --warning: #fbbf24;
}

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background: var(--bg);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding: 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

p {
  margin: 0;
  color: var(--muted);
}

.status {
  display: grid;
  gap: 6px;
  text-align: right;
  color: var(--muted);
  font-size: 13px;
  justify-items: end;
}

.toolbar,
.filterbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--surface);
}

.toolbar {
  padding: 16px 24px;
}

.filterbar {
  padding: 0 24px 16px;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 24px 0;
  background: var(--surface);
}

.tab {
  font-weight: 600;
}

.tab:hover:not(.active) {
  border-color: var(--accent);
  color: var(--accent);
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

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

.dispatcher-settings,
.account-settings {
  margin: 16px 24px 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.settings-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  margin-bottom: 12px;
}

.settings-header h2 {
  margin: 0 0 4px;
  font-size: 16px;
}

.settings-header p {
  font-size: 12px;
}

.dispatcher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 8px 12px;
}

.dispatcher-rate {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  align-items: center;
  gap: 8px;
}

.dispatcher-rate span {
  min-width: 0;
  font-size: 13px;
}

.dispatcher-rate small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 400;
  text-overflow: ellipsis;
}

.password-form {
  display: grid;
  gap: 12px;
  max-width: 420px;
}

.password-form input {
  width: 100%;
  box-sizing: border-box;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.form-status {
  color: var(--muted);
  font-size: 12px;
}

.auth-shell {
  display: grid;
  justify-items: center;
  margin: 48px 24px 0;
}

.auth-panel {
  width: min(460px, 100%);
  padding: 14px;
  border: 1px solid var(--border);
  background: var(--surface);
}

.auth-panel .settings-header {
  justify-content: center;
  text-align: center;
}

.auth-form {
  display: grid;
  gap: 12px;
}

.auth-form input,
.auth-form button {
  width: 100%;
  box-sizing: border-box;
}

.auth-error {
  padding: 10px 12px;
  border: 1px solid rgba(180, 35, 24, 0.3);
  background: rgba(180, 35, 24, 0.08);
  color: var(--negative);
  font-size: 13px;
}

.auth-error[hidden] {
  display: none;
}

label {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
}

input,
select,
button,
.file-button {
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 10px;
  background: var(--field);
  color: var(--text);
  font-size: 13px;
}

button,
.file-button,
.tab,
.toggle,
select,
input[type="file"],
input[type="checkbox"],
input[type="radio"],
input[type="number"] {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.file-button {
  display: inline-flex;
  align-items: center;
  font-weight: 400;
}

.file-button input {
  display: none;
}

.upload-flag {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 8px;
  background: var(--negative);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.upload-flag[hidden] {
  display: none;
}

#uploadStatus {
  color: var(--muted);
  font-size: 12px;
  align-self: center;
}

.error {
  margin: 16px 24px 0;
  padding: 10px 12px;
  border: 1px solid rgba(180, 35, 24, 0.3);
  background: rgba(180, 35, 24, 0.08);
  color: var(--negative);
}

.spinner {
  width: 26px;
  height: 26px;
  margin: 20px 24px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 0.8s linear infinite;
}

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

.totals {
  display: grid;
  grid-template-columns: repeat(9, minmax(120px, 1fr));
  gap: 1px;
  margin: 16px 24px;
  border: 1px solid var(--border);
  background: var(--border);
}

.totals div {
  display: grid;
  gap: 4px;
  padding: 12px;
  background: var(--surface);
}

.totals span {
  color: var(--muted);
  font-size: 12px;
}

.totals strong {
  font-size: 16px;
}

/* Action bar sitting directly above the table, so controls like "Collapse all"
   are next to the rows they affect rather than up in the top toolbar. */
.table-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin: 16px 24px 0;
}

.table-status {
  margin-left: auto;
  display: flex;
  gap: 16px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.status-key {
  font-weight: 600;
}

.table-wrap {
  margin: 16px 24px 32px;
  overflow-x: auto;
  border: 1px solid var(--border);
  background: var(--surface);
}

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

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 9px 10px;
  white-space: nowrap;
}

th {
  text-align: left;
  background: var(--header);
}

.sort-header {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  min-width: 100%;
  height: auto;
  border: none;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: right;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.toggle {
  width: 22px;
  height: 22px;
  padding: 0;
  margin-right: 6px;
  font-weight: 700;
  line-height: 20px;
}

.row-menu,
.icon-button {
  min-width: 28px;
  height: 28px;
  padding: 0;
  font-weight: 700;
  line-height: 1;
}

.row-menu {
  width: 36px;
}

.actions-col {
  width: 34px;
  text-align: center;
}

.warning-icon {
  display: inline-grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  border: 1px solid currentColor;
  border-radius: 999px;
  color: var(--warning);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  vertical-align: text-bottom;
}

.truck-row {
  background: var(--surface);
}

.load-detail-row > td {
  padding: 0;
  background: var(--surface-alt);
}

.load-panel {
  padding: 12px 12px 16px 38px;
}

.load-table {
  min-width: 1180px;
  background: var(--surface);
  border: 1px solid var(--border);
}

.load-table th {
  background: var(--header-alt);
  font-size: 12px;
}

.load-table td,
.load-table th {
  padding: 7px 8px;
}

.amount-positive {
  color: var(--accent);
  font-weight: 700;
}

.amount-negative {
  color: var(--negative);
  font-weight: 700;
}

tfoot th,
tfoot td {
  background: var(--header);
  font-weight: 700;
  border-top: 2px solid var(--border);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  display: grid;
  gap: 16px;
  width: min(420px, 100%);
  padding: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.22);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.modal h2 {
  margin: 0 0 4px;
  font-size: 18px;
}

.modal input:not([type="checkbox"]):not([type="radio"]),
.modal select {
  width: 100%;
  box-sizing: border-box;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.expense-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.expense-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 28px;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.expense-item-header {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.expense-item strong,
.expense-item span,
.expense-item small {
  display: block;
}

.expense-item strong {
  color: var(--negative);
}

.expense-item small,
.expense-empty {
  color: var(--muted);
  font-size: 12px;
}

.expense-recurring {
  color: var(--muted);
  font-size: 12px;
}

.checkbox-inline {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 400;
}

.checkbox-inline input {
  height: auto;
  padding: 0;
}

.recurring-field {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 10px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
}

.recurring-options {
  display: grid;
  gap: 8px;
  padding-left: 22px;
}

.recurring-options[hidden] {
  display: none;
}

.recurring-options p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.recurring-options label {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 400;
}

.recurring-options input {
  height: auto;
  padding: 0;
}

/* Filter controls share a fieldset/legend frame so each label sits on the box's
   top edge (the look the payment filter had). */
.filter-field {
  margin: 0;
  padding: 4px 10px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--field);
}

.filter-field legend {
  padding: 0 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

/* Inside the frame the control itself is borderless so it doesn't read as a
   box-in-a-box against the fieldset border. */
.filter-field > select,
.filter-field > input[type="search"] {
  border: none;
  background: transparent;
  padding: 0;
  height: 24px;
}

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: center;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 400;
}

.checkbox-group input {
  height: auto;
  padding: 0;
}

.checkbox-empty {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

/* Triumph data coverage grid. */
.triumph-coverage {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 0;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.coverage-upload {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.coverage-body {
  flex: 1;
}

.coverage-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 8px;
}

.coverage-header span {
  font-weight: 700;
  font-size: 13px;
}

.coverage-header small {
  color: var(--muted);
  font-size: 11px;
}

.coverage-grid {
  display: grid;
  gap: 6px;
}

.coverage-row {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.coverage-year {
  width: 48px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 12px;
  color: var(--muted);
}

.coverage-month {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  min-width: 40px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--field);
  font-size: 11px;
  color: var(--muted);
  cursor: default;
}

.coverage-month.present {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

@media (max-width: 900px) {
  .topbar {
    display: grid;
  }
  .status {
    text-align: left;
  }
  .totals {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}
