:root {
  --bg: #f5f7f5;
  --text: #17211b;
  --muted: #66736a;
  --line: #d9e1dc;
  --panel: #ffffff;
  --primary: #126a43;
  --primary-dark: #0c4f32;
  --danger: #b42318;
  --warn: #f4c542;
  --late: #e5484d;
  --done: #dff5e8;
  --info: #e8f1fb;
}

* {
  box-sizing: border-box;
}

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

a {
  color: var(--primary);
}

.page {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto;
  padding: 24px 0 64px;
}

.page.wide {
  width: min(1440px, calc(100% - 20px));
}

.topbar,
.driver-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.brand-head {
  display: flex;
  align-items: center;
  gap: 16px;
}

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

.driver-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.top-actions .small-btn {
  width: auto;
}

.brand-logo {
  width: min(260px, 42vw);
  max-height: 76px;
  object-fit: contain;
  background: white;
  border-radius: 8px;
  padding: 6px 10px;
  border: 1px solid var(--line);
}

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

h1 {
  font-size: 32px;
  margin-bottom: 4px;
}

h2 {
  font-size: 22px;
}

.panel,
.driver-card,
.next-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
}

.flat {
  background: transparent;
  border: 0;
  padding: 0;
}

.narrow {
  max-width: 420px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.grid,
.upload-grid,
.review-grid,
.manual-grid,
.config-grid {
  display: grid;
  gap: 12px;
}

.upload-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.manual-grid {
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  margin-top: 8px;
}

.config-grid {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.stats {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 16px;
}

.stats div {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.stats strong {
  display: block;
  font-size: 24px;
}

.stats span,
.muted,
.topbar p,
.driver-header p {
  color: var(--muted);
}

input,
select,
textarea,
button,
.link-btn,
.small-btn {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
}

button,
.link-btn,
.small-btn {
  background: #eef3ef;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

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

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

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

.danger {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

.big {
  font-size: 20px;
  min-height: 56px;
}

.huge {
  font-size: 22px;
  min-height: 66px;
  margin-top: 12px;
}

.small-btn,
.link-btn {
  width: auto;
  min-width: 120px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

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

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

.route-item {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdfb;
}

.route-item p {
  margin: 4px 0 0;
  color: var(--muted);
}

.notice {
  background: #eaf7ef;
  border: 1px solid #b8e2c7;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}

.notice.warn {
  background: #fff8dc;
  border-color: #f0d675;
}

.notice.error {
  background: #ffe8e6;
  border-color: #efb4ae;
  color: #6f120b;
}

.sql-ok {
  display: inline-flex;
  align-items: center;
  width: auto;
  min-height: 34px;
  border-radius: 999px;
  padding: 6px 12px;
  background: #e7f7ed;
  color: var(--primary-dark);
  font-weight: 700;
}

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

.nav-routes {
  display: grid;
  grid-template-columns: 140px 1fr 140px;
  align-items: center;
  text-align: center;
}

.disabled-link {
  opacity: 0.45;
  pointer-events: none;
}

.log-box {
  background: #101815;
  color: #eaf7ef;
  border-radius: 8px;
  padding: 14px;
  overflow: auto;
  min-height: 360px;
  max-height: 70vh;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
  line-height: 1.45;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th {
  color: var(--muted);
  font-weight: 700;
}

.review-head,
.summary-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.badges,
.summary-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 4px 10px;
  background: #eef3ef;
  font-size: 14px;
}

.badge.gasit {
  background: var(--done);
}

.badge.incert {
  background: #fff5cc;
}

.badge.negasit {
  background: #ffe8e6;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: rgba(245, 247, 245, 0.95);
  padding: 12px 0;
}

.driver-page {
  width: min(760px, calc(100% - 16px));
  margin: 0 auto;
  padding: 12px 0 48px;
}

.map-page {
  width: min(1200px, calc(100% - 16px));
  margin: 0 auto;
  padding: 12px 0;
}

.map-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.route-map {
  width: 100%;
  height: calc(100vh - 110px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #eef3ef;
}

.driver-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: 10px 0;
}

.status-pill {
  width: auto;
  min-height: 34px;
  border-radius: 999px;
  padding: 8px 12px;
  background: #e7f7ed;
  white-space: nowrap;
}

.status-pill.offline {
  background: #fff1c2;
}

.progress-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.next-card {
  border-color: #b7d8c5;
  box-shadow: 0 6px 24px rgba(18, 106, 67, 0.08);
}

.client-title {
  font-size: 26px;
  line-height: 1.18;
  margin-bottom: 8px;
}

.stop-meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

.stop-meta span {
  background: #f1f4f2;
  border-radius: 8px;
  padding: 8px;
}

.nav-grid,
.option-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

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

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

.row-actions {
  display: grid;
  gap: 8px;
  min-width: 150px;
}

.agent-dialog {
  width: min(520px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.agent-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.agent-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.agent-row strong {
  min-width: 0;
  font-size: clamp(14px, 3.6vw, 17px);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.agent-row .link-btn {
  min-width: 110px;
}

.stop-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.stop-row.livrat {
  background: var(--done);
}

.stop-row.sarit {
  background: var(--info);
}

.stop-row.geocodat_gresit {
  background: #fff2df;
  border-color: #f0b15f;
}

.stop-row.geocodat_gresit .order-pill {
  background: #f59e0b;
  color: white;
}

.stop-row.client_inchis,
.stop-row.refuzat {
  background: #ffe8e6;
  border-color: #efb4ae;
}

.stop-row.client_inchis .order-pill,
.stop-row.refuzat .order-pill {
  background: var(--danger);
  color: white;
}

.order-pill {
  width: 38px;
  height: 38px;
  border-radius: 999px;
  background: #eef3ef;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.details {
  display: grid;
  gap: 8px;
}

.details div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.details dt {
  color: var(--muted);
}

.details dd {
  margin: 0;
  text-align: right;
  font-weight: 700;
}

@media (max-width: 760px) {
  h1 {
    font-size: 26px;
  }

  .upload-grid,
  .review-grid,
  .manual-grid,
  .config-grid,
  .stop-meta,
  .nav-grid,
  .option-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .map-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .route-map {
    height: calc(100vh - 150px);
  }

  .stop-row {
    grid-template-columns: 42px 1fr;
  }

  .stop-row .small-btn,
  .row-actions {
    grid-column: 1 / -1;
    width: 100%;
  }
}
