:root {
  --bg: #f5f6f3;
  --surface: #ffffff;
  --ink: #1c2522;
  --muted: #66716b;
  --line: #dce2dc;
  --accent: #0f766e;
  --accent-dark: #0a5f59;
  --amber: #b7791f;
  --green-soft: #e7f4ef;
  --yellow-soft: #fff5d6;
  --red-soft: #fae8e6;
  --shadow: 0 14px 38px rgba(28, 37, 34, 0.08);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", "YuGothic", "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

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

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

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 4px;
  font-size: 21px;
}

h3 {
  margin-bottom: 12px;
  font-size: 16px;
}

.topbar-actions,
.toolbar,
.panel-head,
.panel-actions,
.form-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.date-field,
.search-box,
.inline-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--ink);
}

.icon-button,
.primary-button,
.secondary-button,
.nav-item,
.segmented button {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 14px;
  font-weight: 700;
}

.icon-button {
  width: 42px;
  padding: 0;
  background: #edf2ef;
  color: var(--ink);
}

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

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button {
  background: #edf2ef;
  color: var(--ink);
  border-color: var(--line);
}

.sync-status {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 2px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.help-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

.help-link:hover {
  text-decoration: underline;
}

main {
  padding: 18px 28px 34px;
}

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

.segmented {
  display: grid;
  grid-template-columns: repeat(7, minmax(58px, 1fr));
  gap: 4px;
  width: min(680px, 100%);
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #e8ede8;
}

.segmented button {
  min-height: 36px;
  padding: 6px 8px;
  background: transparent;
  color: var(--muted);
}

.segmented button.active {
  background: var(--surface);
  color: var(--accent-dark);
  box-shadow: 0 1px 4px rgba(28, 37, 34, 0.08);
}

.search-box {
  width: min(280px, 100%);
}

.compact-field {
  width: 150px;
}

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

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

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.workspace {
  display: grid;
  grid-template-columns: 156px minmax(0, 1fr);
  gap: 16px;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 6px;
}

.nav-item {
  text-align: left;
  background: transparent;
  color: var(--muted);
}

.nav-item.active {
  background: var(--ink);
  color: #fff;
}

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

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.panel-head {
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.panel-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.panel-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 13px;
}

.route-layout {
  display: grid;
  grid-template-columns: minmax(360px, 1.2fr) minmax(280px, 0.8fr);
  gap: 16px;
  padding-top: 16px;
}

.route-list {
  display: grid;
  gap: 8px;
}

.delivery-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  min-height: 58px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.delivery-row.active {
  border-color: var(--accent);
  background: var(--green-soft);
}

.sequence {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.delivery-title {
  min-width: 0;
}

.delivery-title strong,
.delivery-title span {
  display: block;
}

.delivery-title strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #edf2ef;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.badge.warn {
  background: var(--yellow-soft);
  color: var(--amber);
}

.status-select {
  min-height: 34px;
  padding: 4px 8px;
  background: var(--surface);
}

.detail-pane {
  align-self: start;
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfb;
}

.detail-pane dl {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 10px 12px;
  margin: 16px 0;
}

.detail-pane dt {
  color: var(--muted);
  font-weight: 700;
}

.detail-pane dd {
  margin: 0;
}

.detail-actions {
  display: flex;
  gap: 8px;
}

.table-wrap {
  overflow-x: auto;
  padding-top: 16px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

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

th {
  color: var(--muted);
  font-size: 12px;
}

.payment-grid,
.billing-grid,
.monthly-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  padding-top: 16px;
}

.receipt,
.billing-grid article,
.mini-metric {
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fbfcfb;
}

.mini-metric {
  min-height: 92px;
}

.mini-metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mini-metric strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
}

.receipt-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.receipt h3 {
  margin-bottom: 0;
}

.receipt .amount {
  font-size: 24px;
  font-weight: 800;
}

.receipt-print-button {
  margin-top: 8px;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf8;
}

.inline-form .form-actions {
  grid-column: 1 / -1;
  justify-content: flex-end;
}

.empty-state {
  display: grid;
  place-items: center;
  min-height: 240px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 980px) {
  .topbar,
  .toolbar,
  .panel-head,
  .panel-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid,
  .workspace,
  .route-layout {
    grid-template-columns: 1fr;
  }

  .side-nav {
    grid-template-columns: repeat(5, 1fr);
  }

  .nav-item {
    text-align: center;
  }
}

@media (max-width: 680px) {
  .topbar,
  main {
    padding-left: 14px;
    padding-right: 14px;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .segmented {
    grid-template-columns: repeat(4, 1fr);
  }

  .summary-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .delivery-row {
    grid-template-columns: 36px minmax(0, 1fr);
  }

  .delivery-row .badge,
  .delivery-row .status-select {
    grid-column: 2;
    justify-self: start;
  }

  .inline-form {
    grid-template-columns: 1fr;
  }
}

@media print {
  @page {
    margin: 12mm;
  }

  body {
    background: #fff;
  }

  .topbar-actions,
  .toolbar,
  .summary-grid,
  .side-nav,
  .secondary-button,
  .primary-button,
  .status-select {
    display: none !important;
  }

  main,
  .topbar {
    padding: 0;
  }

  .workspace,
  .route-layout {
    display: block;
  }

  .panel {
    border: 0;
    box-shadow: none;
    padding: 0;
  }

  .view-panel:not(.active),
  .detail-pane {
    display: none;
  }

  .receipt-printing .topbar,
  .receipt-printing .toolbar,
  .receipt-printing .summary-grid,
  .receipt-printing .side-nav,
  .receipt-printing #view-payments .panel-head,
  .receipt-printing .receipt-print-button {
    display: none !important;
  }

  .receipt-printing .workspace,
  .receipt-printing .payment-grid {
    display: block;
  }

  .receipt-printing #view-payments {
    display: block !important;
  }

  .receipt-printing .receipt {
    display: block;
    min-height: 0;
    margin: 0 0 12mm;
    border: 1px solid #111;
    box-shadow: none;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .receipt-print-single .receipt:not(.print-target) {
    display: none;
  }
}

.manual-body {
  background: var(--bg);
}

.manual-page {
  width: min(920px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 56px;
}

.manual-header,
.manual-page section {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 22px;
}

.manual-header h1 {
  margin-bottom: 10px;
}

.manual-header p {
  color: var(--muted);
}

.manual-back {
  display: inline-flex;
  text-decoration: none;
}

.manual-page section h2 {
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.manual-page ol,
.manual-page ul {
  padding-left: 22px;
}

.manual-page li {
  margin: 6px 0;
}
