:root {
  color-scheme: light;
  --ink: #15231d;
  --muted: #64706a;
  --line: #d9e0dc;
  --surface: #ffffff;
  --soft: #f4f7f5;
  --accent: #0f7b63;
  --accent-strong: #0a604d;
  --warning: #9c5b08;
  --danger: #b83232;
  --ready: #0c6c4f;
  --shadow: 0 16px 40px rgba(21, 35, 29, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: #eef3f0;
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login-panel p {
  margin-top: 7px;
  color: var(--muted);
}

.form-message {
  min-height: 20px;
  color: var(--danger);
  font-size: 0.9rem;
}

.user-chip {
  align-items: center;
  min-height: 40px;
  color: var(--muted);
  font-size: 0.86rem;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 22px clamp(16px, 4vw, 42px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 2.5vw, 2rem);
  line-height: 1.15;
}

h2 {
  font-size: 1.1rem;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.role-header {
  font-weight: 700;
  color: var(--accent) !important;
}

.topbar-actions,
.toolbar-actions,
.dialog-actions,
.section-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

main {
  padding: 22px clamp(16px, 4vw, 42px) 42px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.report-section-heading {
  margin-top: 28px;
}

.metric {
  min-height: 92px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.84rem;
  margin-bottom: 9px;
}

.metric strong {
  display: block;
  font-size: 1.45rem;
  line-height: 1.15;
}

.metric strong.metric-money,
.metric #availableCash {
  font-size: clamp(0.92rem, 1.5vw, 1.15rem);
  overflow-wrap: anywhere;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin: 20px 0;
}

.tabs {
  display: inline-grid;
  grid-template-columns: repeat(8, minmax(82px, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.tab {
  min-height: 40px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 16px;
}

.tab.active {
  background: var(--accent);
  color: white;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.small-button,
.icon-button {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 0 14px;
}

.primary-button {
  background: var(--accent);
  color: white;
}

.primary-button:hover,
.tab.active:hover {
  background: var(--accent-strong);
}

.secondary-button,
.ghost-button,
.small-button,
.icon-button {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.danger-button {
  background: #fff;
  color: var(--danger);
  border-color: #e7bcbc;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.86rem;
}

.icon-button {
  width: 36px;
  min-height: 36px;
  padding: 0;
}

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

.file-button input {
  display: none;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 240px);
  gap: 12px;
  margin-bottom: 14px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 0.86rem;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

td {
  font-size: 0.94rem;
}

tr:last-child td {
  border-bottom: 0;
}

.overdue-order-row td {
  background: #fff0f0;
  border-bottom-color: #f4b8b8;
}

.customer-cell strong,
.status-text {
  display: block;
}

.subtext {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 4px;
  white-space: pre-wrap;
}

.actions-cell {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  min-width: 260px;
}

.status-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 0.82rem;
  font-weight: 700;
}

.status-ready {
  background: #e2f5ee;
  color: var(--ready);
}

.status-balance {
  background: #fff0d8;
  color: var(--warning);
}

.status-paused {
  background: #f0e8ff;
  color: #5b3a9a;
}

.status-overdue {
  background: #ffe0e0;
  color: var(--danger);
}

.status-cash {
  background: #fff7d6;
  color: #7a4a03;
}

.status-delivered {
  background: #e8eef8;
  color: #274b82;
}

.status-urgent {
  background: #ffe0e0;
  color: var(--danger);
  margin-left: 6px;
}

.status-transport {
  background: #e9e2ff;
  color: #4d3291;
  margin-left: 6px;
}

.empty-state {
  display: none;
  margin-top: 12px;
  padding: 22px;
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.section-heading {
  justify-content: space-between;
  margin-bottom: 14px;
}

.rate-chip {
  background: #e2f5ee;
  color: var(--ready);
  border-radius: 999px;
  padding: 8px 12px;
  font-weight: 700;
  font-size: 0.88rem;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.history-item dl {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin: 10px 0 0;
}

.history-item dt {
  color: var(--muted);
  font-size: 0.78rem;
}

.history-item dd {
  margin: 3px 0 0;
  font-weight: 700;
}

.balance-report-item {
  align-items: start;
}

.balance-detail {
  display: grid;
  gap: 7px;
  margin-top: 12px;
}

.balance-detail > div {
  display: grid;
  grid-template-columns: 110px 1fr minmax(120px, auto);
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.balance-detail span,
.balance-detail small {
  color: var(--muted);
}

dialog {
  width: min(620px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 0;
}

.wide-dialog {
  width: min(980px, calc(100vw - 24px));
}

dialog::backdrop {
  background: rgba(21, 35, 29, 0.32);
}

dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 12px;
}

.address-grid {
  grid-template-columns: 110px 1fr 220px;
}

.route-filters {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) minmax(180px, 240px);
}

.route-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.route-item {
  align-items: flex-start;
}

.route-item-selected {
  border-color: #0c6c4f;
  background: #eef9f5;
}

.route-picker {
  width: fit-content;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-weight: 700;
  color: var(--ready);
}

.route-picker input {
  width: auto;
}

.choice-list {
  min-height: 132px;
  max-height: 180px;
  overflow: auto;
  display: grid;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.choice-option {
  min-height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
}

.choice-option:hover {
  background: #f3f5f8;
}

.choice-option input {
  width: auto;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.checkbox-row input {
  width: auto;
}

.dialog-actions {
  justify-content: flex-end;
  padding-top: 4px;
}

.review-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.review-summary > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}

.review-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 5px;
}

.review-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.review-table {
  min-width: 780px;
}

.review-dl {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin: 0;
}

@media (max-width: 860px) {
  .summary-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .toolbar,
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions,
  .topbar-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 620px) {
  .summary-grid,
  .filters,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .tabs {
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .tab {
    padding: 0 8px;
  }

  .toolbar-actions > button,
  .topbar-actions > button,
  .file-button {
    flex: 1;
    justify-content: center;
  }

  .history-item {
    grid-template-columns: 1fr;
  }

  .review-summary {
    grid-template-columns: 1fr;
  }

  .balance-detail > div {
    grid-template-columns: 1fr;
  }
}
