:root {
  --bg: #f3f4f0;
  --panel: #ffffff;
  --panel-soft: #eef3ff;
  --line: #d8deed;
  --text: #111827;
  --muted: #626977;
  --blue: #e66b2c;
  --blue-2: #1a56db;
  --green: #0a9f45;
  --red: #c81e1e;
  --amber: #b7791f;
  --shadow: 0 14px 40px rgba(24, 39, 75, .07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: linear-gradient(135deg, #f8fbff 0%, #eef3ff 100%);
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 32px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 8px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }

.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 20px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark, .icon-box {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--panel-soft);
  color: var(--blue);
  font-weight: 800;
}
.brand-title { font-size: 20px; font-weight: 800; color: var(--blue); }
.brand-sub { color: var(--muted); font-size: 13px; }
.nav { display: grid; gap: 8px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: 8px;
  color: var(--muted);
}
.nav a.active {
  color: var(--blue);
  background: #e8efff;
  box-shadow: inset -4px 0 0 var(--blue);
}
.sidebar-footer { margin-top: auto; display: grid; gap: 10px; }
.logout {
  display: flex;
  gap: 12px;
  align-items: center;
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--red);
  padding: 12px;
  cursor: pointer;
}

.main { min-width: 0; }
.topbar {
  min-height: 78px;
  padding: 18px 32px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(247, 248, 254, .86);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 3;
}
.content { padding: 32px; max-width: 1280px; }
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 24px;
}
h1, h2, h3 { margin: 0; letter-spacing: 0; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 20px; }
.muted { color: var(--muted); }
.tiny { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }

.grid { display: grid; gap: 20px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 4px 16px rgba(17, 24, 39, .03);
}
.metric { display: grid; gap: 12px; min-height: 140px; }
.metric-value { font-size: 36px; font-weight: 750; line-height: 1.1; }
.metric-value small { font-size: 16px; color: var(--muted); font-weight: 500; }
.progress {
  height: 8px;
  background: #eff1f6;
  border-radius: 999px;
  overflow: hidden;
}
.progress > span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  background: var(--blue);
}
.status {
  display: inline-flex;
  align-items: center;
  width: max-content;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.status.paid, .status.active { color: var(--green); background: #e7f8ee; }
.status.pending { color: #4b5563; background: #eef1f6; }
.status.partial { color: var(--amber); background: #fff3d6; }
.status.overdue { color: var(--red); background: #fde8e8; }

.btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 16px;
  background: var(--panel);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 650;
  cursor: pointer;
}
.btn.primary { background: var(--blue); color: white; border-color: var(--blue); }
.btn.soft { background: #e8efff; color: var(--blue); border-color: #e8efff; }
.btn.danger { color: var(--red); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: end; }
.field { display: grid; gap: 6px; }
.field label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.field input, .field select, .field textarea {
  min-height: 42px;
  border: 1px solid #bdc5d8;
  border-radius: 8px;
  background: #fbfcff;
  padding: 10px 12px;
  color: var(--text);
}
.field textarea { min-height: 76px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(6, 71, 199, .14);
  border-color: var(--blue);
}

.table-card { padding: 0; overflow: hidden; }
.table-head {
  padding: 20px 24px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .05em;
  background: #f1f4fb;
}
tr:last-child td { border-bottom: 0; }
.row-actions { display: flex; justify-content: flex-end; gap: 8px; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--blue);
  font-weight: 650;
  cursor: pointer;
  padding: 0;
}

.chart-bars {
  height: 260px;
  display: flex;
  align-items: end;
  gap: 12px;
  padding-top: 24px;
}
.bar-wrap { flex: 1; display: grid; gap: 8px; align-items: end; text-align: center; color: var(--muted); font-size: 12px; }
.bar {
  min-height: 4px;
  height: calc(var(--h, 0) * 1%);
  background: #cbd8ef;
  border-radius: 6px 6px 0 0;
}
.bar.active { background: var(--blue); }
.category-row { display: grid; gap: 8px; margin-top: 18px; }
.category-line { display: flex; justify-content: space-between; gap: 10px; }
.flash {
  margin-bottom: 20px;
  padding: 12px 14px;
  border-radius: 8px;
  color: var(--blue);
  background: #e8efff;
  border: 1px solid #cbd8ef;
}
.warning {
  margin-bottom: 20px;
  padding: 12px 14px;
  border-radius: 8px;
  color: #8a4d00;
  background: #fff7df;
  border: 1px solid #f4d28a;
}

.compact-head { margin-bottom: 18px; }
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}
.dashboard-summary-row {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(260px, .85fr) minmax(260px, .85fr);
  gap: 16px;
  align-items: stretch;
}
.dashboard-buyout {
  grid-column: span 3;
  padding: 20px;
}
.dashboard-buyout-tight {
  grid-column: span 2;
}
.dashboard-buyout-card {
  grid-column: auto;
}
.dashboard-primary-card {
  min-height: 154px;
}
.dashboard-meta {
  justify-content: space-between;
  margin-top: 12px;
}
.compact-metric {
  min-height: 124px;
  padding: 18px;
  gap: 8px;
}
.compact-metric .metric-value { font-size: 30px; }
.compact-metric .muted { font-size: 13px; line-height: 1.35; }
.compact-payments { margin-top: 16px; }
.compact-table-head { padding: 14px 18px; }
.compact-table-head h2 { font-size: 18px; }
.compact-payments th,
.compact-payments td {
  padding: 10px 18px;
}
.payments-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, .9fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}
.inline-form {
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: #f8fbff;
}
.row-edit-form {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
}
.payment-inline-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
}
.compact-data-table th,
.compact-data-table td {
  padding: 10px 14px;
}
.table-actions-cell {
  text-align: right;
  width: 1%;
  white-space: nowrap;
}
.table-action-btn {
  min-height: 30px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--blue);
  padding: 5px 8px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
}
.table-action-btn:hover {
  background: #e8efff;
  border-color: #d6e1fb;
}
.file-input {
  min-height: 34px;
  max-width: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 5px 8px;
  font-size: 13px;
  color: var(--muted);
}

/* 2026 visual refresh */
:root {
  --panel-soft: #f4f0e8;
  --line: #dedfd8;
  --text: #18201d;
  --muted: #6d756f;
  --blue-2: #f37b3e;
  --shadow: 0 18px 50px rgba(27,36,32,.08);
}
body { background: radial-gradient(circle at 80% -10%,#fff3e4 0,transparent 32%),var(--bg); }
.auth-page { background: radial-gradient(circle at 20% 10%,#f7a66e 0,transparent 28%),linear-gradient(135deg,#17231f 0%,#263932 100%); }
.login-card { border-radius: 24px; padding: 38px; }
.app { grid-template-columns: 260px 1fr; }
.sidebar { padding: 28px 18px; background: #17231f; color: #fff; border-right: 0; }
.brand-mark,.icon-box { background: #e66b2c; color: #fff; }
.brand-title { color: #fff; }
.brand-sub { color: #9db0a8; }
.nav a { border-radius: 12px; color: #aebbb5; }
.nav a.active { color: #fff; background: rgba(230,107,44,.22); box-shadow: inset 3px 0 0 #f1854c; }
.topbar { background: rgba(243,244,240,.84); }
.content { padding: 34px clamp(20px,4vw,54px); max-width: 1480px; }
h1 { font-size: clamp(28px,3vw,42px); line-height: 1.08; letter-spacing: -.035em; }
.card { border-radius: 20px; box-shadow: var(--shadow); }
.metric-value { font-size: 38px; font-weight: 800; line-height: 1.05; letter-spacing: -.04em; }
.progress > span { background: linear-gradient(90deg,#df6224,#f39a61); }
.btn { border-radius: 12px; transition: transform .15s ease,box-shadow .15s ease; }
.btn.primary { background: #e66b2c; border-color: #e66b2c; box-shadow: 0 8px 18px rgba(230,107,44,.22); }
.btn.soft { background: #fff1e7; color: #bb4d17; border-color: #f3d2bf; }
.btn:hover { transform: translateY(-1px); }
.field input,.field select,.field textarea { border-radius: 11px; background: #fff; }
th { background: #f7f5f0; }
.status.paid,.status.active { background: #e5f4ea; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { background: #17231f; border-top: 0; box-shadow: 0 -10px 30px rgba(23,35,31,.18); }
  .nav a.active { box-shadow: inset 0 3px 0 #f1854c; }
}
.page-head > .actions {
  gap: 8px;
}
.page-head > .actions > .btn.soft,
.page-head > .actions form.actions .btn.primary {
  min-height: 34px;
  padding: 7px 10px;
  font-size: 13px;
}
.report-source {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: -8px 0 18px;
  color: var(--muted);
}
.report-source strong {
  color: var(--text);
}
.report-source span {
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f1f4fb;
  font-size: 12px;
}
.period-filter {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  padding: 10px 12px;
}
.period-filter-row {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 8px;
  align-items: start;
}
.period-filter-row > span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: .05em;
  line-height: 24px;
  text-transform: uppercase;
}
.period-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.period-chip {
  min-height: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcff;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.period-chip.active {
  background: #e8efff;
  border-color: var(--blue);
  color: var(--blue);
}
.period-chip.muted-chip:not(.active) {
  color: #a6adbb;
  background: #fbfcff;
}
.month-chip {
  min-width: 66px;
}
.report-empty-state {
  margin-bottom: 18px;
}
.report-speed-grid,
.report-tables,
.report-imports,
.route-card {
  margin-top: 20px;
}
.route-card {
  padding: 0;
  overflow: hidden;
}
.map-canvas {
  height: 460px;
  width: 100%;
  background: #eef3ff;
}
.map-bounds {
  padding: 14px 24px 20px;
  font-size: 13px;
}
.route-svg-wrap {
  padding: 16px 24px 0;
}
.route-svg-wrap svg {
  width: 100%;
  height: auto;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2f6ff;
}
.empty-state {
  padding: 32px 24px;
  color: var(--muted);
}
.dense-report-table th,
.dense-report-table td {
  padding: 12px 16px;
}
.load-cell {
  display: grid;
  grid-template-columns: 48px minmax(80px, 1fr);
  gap: 10px;
  align-items: center;
  min-width: 150px;
}
.wide-load-cell {
  grid-template-columns: 42px minmax(120px, 1fr);
  min-width: 180px;
}
.mini-progress {
  height: 6px;
}
.full-report-table {
  min-width: 980px;
}
.mobile-sort-bar {
  display: none;
}
.sort-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: .05em;
  cursor: pointer;
}
.sort-button span::before {
  content: "↕";
  font-size: 11px;
  color: #9aa3b5;
}
.sort-button.active {
  color: var(--blue);
}
.sort-button.active.asc span::before {
  content: "↑";
  color: var(--blue);
}
.sort-button.active.desc span::before {
  content: "↓";
  color: var(--blue);
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; padding-bottom: 74px; }
  .sidebar {
    position: fixed;
    inset: auto 0 0;
    height: 74px;
    z-index: 8;
    padding: 8px 10px;
    border-right: 0;
    border-top: 1px solid var(--line);
    display: block;
  }
  .brand, .sidebar-footer { display: none; }
  .nav { grid-template-columns: repeat(4, 1fr); gap: 4px; }
  .nav a { padding: 8px 4px; justify-content: center; font-size: 11px; flex-direction: column; gap: 3px; }
  .nav a span:first-child { font-size: 22px; line-height: 1; }
  .nav a.active { box-shadow: inset 0 3px 0 var(--blue); }
  .topbar { padding: 14px 16px; }
  .content { padding: 20px 16px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .form-grid { grid-template-columns: 1fr; }
  .page-head { display: grid; }
  .period-filter { padding: 10px; }
  .period-filter-row { grid-template-columns: 1fr; gap: 5px; }
  .period-filter-row > span { line-height: 1.2; }
  .month-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .month-chip { min-width: 0; padding: 5px 4px; font-size: 10px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .dashboard-summary-row { grid-template-columns: 1fr; }
  .dashboard-buyout { grid-column: auto; }
  .dashboard-meta { align-items: flex-start; }
  .payments-columns { grid-template-columns: 1fr; }
  .payment-inline-grid { grid-template-columns: 1fr; }
  .map-canvas { height: 360px; }
  .full-report-table { min-width: 0; }
  .table-card table, .table-card thead, .table-card tbody, .table-card th, .table-card td, .table-card tr { display: block; }
  .table-card [hidden] { display: none !important; }
  .table-card thead { display: none; }
  .table-card tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .table-card td { border: 0; padding: 6px 0; display: flex; justify-content: space-between; gap: 16px; }
  .table-card td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
  .report-tables { overflow: visible; }
  .report-tables .table-head { display: block; }
  .mobile-sort-bar {
    display: grid;
    grid-template-columns: 1.15fr .9fr .75fr .95fr;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    background: #f1f4fb;
  }
  .mobile-sort-bar .sort-button {
    font-size: 9px;
    line-height: 1.1;
    white-space: normal;
    text-align: left;
  }
  .page-head .actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    width: 100%;
    align-items: center;
  }
  .page-head .actions > .btn.soft {
    grid-column: 1 / -1;
    min-height: 34px;
    width: max-content;
    padding: 7px 10px;
    font-size: 13px;
  }
  .page-head .actions form.actions {
    display: contents;
  }
  .page-head .file-input {
    min-height: 34px;
    max-width: none;
    width: 100%;
    padding: 5px 8px;
    font-size: 12px;
  }
  .page-head .actions form.actions .btn.primary {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 13px;
    white-space: nowrap;
  }
  .report-tables .dense-report-table tbody tr[data-date] {
    display: grid !important;
    grid-template-columns: 1.15fr .9fr .75fr .95fr;
    gap: 8px;
    padding: 12px 14px;
    align-items: center;
  }
  .report-tables .dense-report-table td {
    display: grid !important;
    grid-template-columns: 1fr;
    justify-content: start;
    gap: 2px;
    padding: 0;
    min-width: 0;
    font-size: 13px;
    line-height: 1.2;
  }
  .report-tables .dense-report-table td::before {
    display: block;
    line-height: 1;
    font-size: 9px;
    white-space: nowrap;
  }
  .report-tables .dense-report-table td:nth-child(2),
  .report-tables .dense-report-table td:nth-child(5),
  .report-tables .dense-report-table td:nth-child(6),
  .report-tables .dense-report-table td:nth-child(8),
  .report-tables .dense-report-table td:nth-child(9) {
    display: none !important;
  }
  .report-tables .dense-report-table td strong {
    display: inline;
  }
  .row-actions { justify-content: flex-start; }
}

/* Final visual layer: keep below legacy responsive rules. */
body { background: radial-gradient(circle at 80% -10%,#fff3e4 0,transparent 32%),var(--bg); }
.auth-page { background: radial-gradient(circle at 20% 10%,#f7a66e 0,transparent 28%),linear-gradient(135deg,#17231f 0%,#263932 100%); }
.login-card { border-radius:24px; padding:38px; }
.app { grid-template-columns:260px 1fr; }
.sidebar { padding:28px 18px; background:#17231f; color:#fff; border-right:0; }
.brand-mark,.icon-box { background:#e66b2c; color:#fff; }
.brand-title { color:#fff; }
.brand-sub { color:#9db0a8; }
.nav a { border-radius:12px; color:#aebbb5; }
.nav a.active { color:#fff; background:rgba(230,107,44,.22); box-shadow:inset 3px 0 0 #f1854c; }
.topbar { background:rgba(243,244,240,.84); }
.content { padding:34px clamp(20px,4vw,54px); max-width:1480px; }
h1 { font-size:clamp(28px,3vw,42px); line-height:1.08; letter-spacing:-.035em; }
.card { border-radius:20px; box-shadow:0 18px 50px rgba(27,36,32,.08); }
.metric-value { font-size:38px; font-weight:800; line-height:1.05; letter-spacing:-.04em; }
.progress>span { background:linear-gradient(90deg,#df6224,#f39a61); }
.btn { border-radius:12px; transition:transform .15s ease,box-shadow .15s ease; }
.btn.primary { background:#e66b2c; border-color:#e66b2c; box-shadow:0 8px 18px rgba(230,107,44,.22); }
.btn.soft { background:#fff1e7; color:#bb4d17; border-color:#f3d2bf; }
.btn:hover { transform:translateY(-1px); }
.field input,.field select,.field textarea { border-radius:11px; background:#fff; }
th { background:#f7f5f0; }
@media (max-width:980px) {
  .app { grid-template-columns:1fr; }
  .sidebar { background:#17231f; border-top:0; box-shadow:0 -10px 30px rgba(23,35,31,.18); }
  .nav a.active { box-shadow:inset 0 3px 0 #f1854c; }
}
