:root {
  --green: #1f6f43;
  --green-dark: #164e30;
  --bg: #f5f7f6;
  --border: #e0e4e2;
  --text: #1c1f1e;
  --muted: #6b7570;
  --warn: #b8860b;
  --danger: #b3261e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.topbar {
  background: var(--green);
  color: white;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.topbar .brand { font-weight: 700; font-size: 1.1rem; }
.topbar-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; align-items: center; }

.content { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }

.flash { background: #fff3cd; border: 1px solid #ffe08a; padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; }

.auth-box {
  max-width: 360px; margin: 60px auto; background: white;
  padding: 28px; border-radius: 12px; border: 1px solid var(--border);
}
.auth-box h1 { font-size: 1.3rem; margin-top: 0; }

label { display: block; margin-bottom: 14px; font-size: 0.9rem; color: var(--muted); }
input, select, textarea {
  width: 100%; padding: 10px; margin-top: 4px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 1rem; font-family: inherit;
}

.btn {
  display: inline-block; padding: 10px 18px; border-radius: 8px; border: none;
  font-size: 0.95rem; cursor: pointer; text-decoration: none; text-align: center;
}
.btn-primary { background: var(--green); color: white; }
.btn-primary:hover { background: var(--green-dark); }
.btn-ghost { background: transparent; color: white; border: 1px solid rgba(255,255,255,0.5); }
.btn-small { padding: 4px 10px; font-size: 0.8rem; }
.btn-danger { background: white; color: var(--danger); border: 1px solid var(--danger); }

.muted { color: var(--muted); }
.warn { color: var(--warn); font-size: 0.85rem; }

.pill {
  background: rgba(255,255,255,0.15); padding: 6px 12px; border-radius: 20px; font-size: 0.85rem;
}

.content-wide { max-width: 1800px; }

/* Dashboard: map above the table on narrow screens; from 1280px the table
   takes ~60% and the (sticky) map ~40%. */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px; }
.map-panel { order: -1; }
#orders-list { overflow-x: auto; }
/* Compact inline fields so all columns fit in ~60% of a 1440px screen. */
#orders-list .order-table th, #orders-list .order-table td { padding: 8px 3px; }
#orders-list .inline-form input, #orders-list .inline-form select {
  font-size: 0.85rem; padding: 5px 6px; margin-top: 2px;
}
#orders-list .inline-form select { width: auto; min-width: 7.5em; max-width: 10em; }
#map { width: 100%; height: 450px; max-height: 65vh; border-radius: 8px; }
@media (min-width: 1280px) {
  .dash-grid { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; }
  .map-panel { order: 0; position: sticky; top: 16px; }
}

.panel { background: white; border: 1px solid var(--border); border-radius: 12px; padding: 18px; }
.panel.narrow { max-width: 480px; margin: 0 auto; }
.panel-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.panel-header h2 { margin: 0; font-size: 1.1rem; }

.order-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.order-table th, .order-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.inline-form { display: inline; }

.status { padding: 3px 10px; border-radius: 20px; font-size: 0.78rem; font-weight: 600; }
.status-waiting { background: #fdecd2; color: #a15c00; }
.status-picked_up { background: #d6e8ff; color: #1a5aa0; }
.status-delivered { background: #d9f2df; color: #1f6f43; }

.driver-list { list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.9rem; }
.driver-list li { padding: 4px 0; border-bottom: 1px solid var(--border); }

.stop-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 12px; }
.stop-card { background: white; border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.stop-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }

.stat-box {
  flex: 1; background: white; border: 1px solid var(--border); border-radius: 12px;
  padding: 20px; text-align: center;
}
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.stats-grid .stat-box { padding: 16px 10px; }
.stat-num { display: block; font-size: 2rem; font-weight: 700; color: var(--green); }

.price-box {
  background: #eaf5ee; border: 1px solid #cfe8d8; border-radius: 8px;
  padding: 12px 16px; margin-bottom: 14px; font-size: 1.1rem; font-weight: 600; color: var(--green-dark);
  text-align: center;
}

/* Driver PWA navigation: one <nav> in the top bar's markup. Phones get it
   fixed to the bottom of the screen; from 768px it sits inline in the green
   bar next to the brand. */
.driver-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: white; border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.driver-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px; font-size: 0.75rem; color: var(--muted); text-decoration: none;
}
.driver-nav a.active { color: var(--green); font-weight: 600; }
.driver-nav-icon { font-size: 1.3rem; line-height: 1; }
/* Keep the last bit of the page clear of the fixed bar. */
body:has(.driver-nav) .content { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }

@media (min-width: 768px) {
  .driver-nav {
    position: static; background: none; border: 0; padding: 0;
    margin: 0 auto 0 24px; gap: 4px;
  }
  .driver-nav a {
    flex: none; flex-direction: row; gap: 6px; padding: 6px 14px; border-radius: 20px;
    font-size: 0.9rem; color: rgba(255,255,255,0.85);
  }
  .driver-nav a:hover { background: rgba(255,255,255,0.1); color: white; }
  .driver-nav a.active { background: rgba(255,255,255,0.22); color: white; }
  .driver-nav-icon { font-size: 1rem; }
  body:has(.driver-nav) .content { padding-bottom: 60px; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* Dashboard map */
.map-legend { font-size: 0.85rem; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.legend-jump {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer;
  padding: 5px 12px 5px 6px; border-radius: 20px; font: inherit; color: var(--text);
  background: white; border: 1px solid var(--border);
}
.legend-jump:hover:not(:disabled) { border-color: var(--muted); }
.legend-jump:disabled { cursor: default; opacity: 0.4; filter: grayscale(1); background: var(--bg); }
.map-ctrl-btn {
  margin: 10px; height: 40px; padding: 0 14px; border: 0; border-radius: 2px; cursor: pointer;
  background: white; color: #333; font: 500 14px Roboto, Arial, sans-serif;
  box-shadow: rgba(0, 0, 0, 0.3) 0 1px 4px -1px;
}
.map-ctrl-btn:hover { background: #f1f1f1; }
.order-table tr.has-map { cursor: pointer; }
.order-table tr.has-map:hover td { background: #f7faf8; }
.order-link { color: var(--green); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
@keyframes row-flash { from { background: #fff1b8; } to { background: transparent; } }
.order-table tr.row-flash td { animation: row-flash 2s ease-out; }
.legend-dot {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; background: white; border: 3px solid; font-size: 0.7rem;
}
.legend-pickup { border-color: #d9822b; }
.legend-delivery { border-color: #1a5aa0; }
.legend-pin {
  display: inline-block; width: 12px; height: 12px; background: #ea4335;
  border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
}
.map-info { font-size: 0.85rem; line-height: 1.5; color: var(--text); }

/* Dispatcher statistics */
.period-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.period-link {
  padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-size: 0.9rem; background: white;
}
.period-link.active { background: var(--green); border-color: var(--green); color: white; }
.period-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-left: auto; }
.period-form input[type=date] { width: auto; margin: 0; padding: 6px 8px; font-size: 0.9rem; }
.stats-grid-3 { margin: 12px 0 8px; }
@media (min-width: 768px) { .stats-grid-3 { grid-template-columns: repeat(3, 1fr); } }
.stat-box small { display: block; margin-top: 2px; font-size: 0.75rem; }
.csv-bar { display: flex; flex-wrap: wrap; gap: 8px; }
.csv-bar .btn:not(.btn-primary) { background: white; color: var(--text); border: 1px solid var(--border); }
.stats-drivers td:not(:first-child), .stats-drivers th:not(:first-child) { text-align: right; width: 7em; }
.stats-drivers tr.selected td { background: #eaf5ee; font-weight: 600; }
.stats-drivers a { color: inherit; }
.driver-filter { width: auto; margin: 0; padding: 6px 8px; font-size: 0.9rem; }

/* Settings: driver management */
.notice { background: #eaf5ee; border: 1px solid #cfe8d8; border-radius: 8px; padding: 12px 14px; margin-bottom: 14px; }
.link-box { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; word-break: break-all; }
.small { font-size: 0.85rem; }
.add-driver { margin-bottom: 14px; }
.add-driver summary { list-style: none; }
.add-driver summary::-webkit-details-marker { display: none; }
.narrow-form { max-width: 420px; margin-top: 12px; }
.order-table tr.inactive td { color: var(--muted); }
.order-table td.actions { white-space: nowrap; }
.order-table td.actions .inline-form + .inline-form { margin-left: 4px; }
.panel h3 { font-size: 1rem; margin: 20px 0 4px; }

.forgot-link { margin: -6px 0 14px; font-size: 0.85rem; text-align: right; }
