:root {
  --bg: #f3f2ee;
  --panel: #ffffff;
  --ink: #17181a;
  --muted: #6b6e75;
  --line: #e2e0d9;
  --brand: #ffc51a;
  --brand-ink: #141414;
  --free: #16a34a;
  --offered: #f59e0b;
  --on_ride: #2563eb;
  --offline: #9ca3af;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 4px 14px rgba(0,0,0,.06);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); height: 100vh; overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; margin: 6px 0 0; }
h1, h2, h3 { margin: 0; }
h2 { font-size: 15px; }
h3 { font-size: 14px; margin: 18px 0 8px; }

input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
label > input, label > select, label > .search-row { margin-top: 3px; }
label.check { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
label.check input { width: auto; }

.btn {
  font: inherit; cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 7px 12px; border-radius: 8px; white-space: nowrap;
}
.btn:hover { background: #f7f6f2; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(.96); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn.wide { width: 100%; padding: 10px; }
.btn:disabled { opacity: .5; cursor: default; }

/* Login */
.login { height: 100vh; display: grid; place-items: center; background: #141414; }
.login-card { background: var(--panel); padding: 28px; border-radius: 16px; width: 320px; text-align: center; }
.login-card label { text-align: left; }
.login-logo { width: 64px; height: 64px; }
.login-card h1 { margin-top: 8px; }
.login-card p { margin: 2px 0 16px; }

/* Top bar */
.topbar {
  height: 54px; display: flex; align-items: center; gap: 18px; padding: 0 14px;
  background: #141414; color: #fff;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; }
.brand img { width: 30px; height: 30px; }
.tabs { display: flex; gap: 2px; }
.tabs button {
  font: inherit; background: none; border: 0; color: #c9c9c9; padding: 8px 12px; border-radius: 8px; cursor: pointer;
}
.tabs button:hover { color: #fff; }
.tabs button.active { background: #2a2a2a; color: var(--brand); }
.stats { margin-left: auto; display: flex; gap: 12px; font-size: 13px; }
.stats b { font-size: 15px; }
.stats .s { display: flex; align-items: center; gap: 5px; }
.who { display: flex; align-items: center; gap: 8px; color: #c9c9c9; }
.who .btn { color: #fff; border-color: #444; }

/* Dispatch layout */
.tab { height: calc(100vh - 54px); }
.dispatch { display: grid; grid-template-columns: 390px 1fr; }
.side { overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 10px; border-right: 1px solid var(--line); }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; align-items: end; }
.order .row2 + .row2 { margin-bottom: 8px; }

.search-row { display: flex; gap: 6px; }
.search-row input { flex: 1; }
.place { position: relative; }
.suggest {
  position: absolute; z-index: 1000; left: 0; right: 0; top: 52px; margin: 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); max-height: 220px; overflow: auto;
}
.suggest:empty { display: none; }
.suggest li { padding: 7px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.suggest li:hover { background: #f5f3ea; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.dot.pickup { background: var(--free); }
.dot.drop { background: var(--danger); }
.pick.on { background: var(--brand); border-color: var(--brand); }

.seg { display: flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; margin-bottom: 8px; }
.seg button { flex: 1; font: inherit; font-size: 12px; border: 0; background: #fff; padding: 7px 4px; cursor: pointer; color: var(--muted); }
.seg button.on { background: #141414; color: #fff; }
.quote { display: flex; flex-direction: column; font-size: 12px; margin-bottom: 8px; padding-left: 4px; }
.quote strong { font-size: 16px; }
.split { font-size: 12px; color: var(--muted); margin: -2px 0 8px; min-height: 1em; }
.split b { color: var(--ink); }

.pill { background: #141414; color: #fff; border-radius: 99px; padding: 1px 8px; font-size: 12px; }
.ride-list { display: flex; flex-direction: column; gap: 8px; }
.ride {
  border: 1px solid var(--line); border-left: 4px solid var(--offline); border-radius: 8px; padding: 8px 10px; cursor: pointer;
}
.ride:hover { background: #fbfaf6; }
.ride.pending { border-left-color: var(--danger); }
.ride.offered { border-left-color: var(--offered); }
.ride.accepted, .ride.arrived, .ride.in_progress { border-left-color: var(--on_ride); }
.ride .top { display: flex; justify-content: space-between; gap: 6px; }
.ride .route { font-size: 12px; color: var(--muted); margin: 4px 0; line-height: 1.4; }
.ride .actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.ride .actions select { width: auto; flex: 1; padding: 3px 6px; font-size: 12px; }

.badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 99px; background: #eee; white-space: nowrap; }
.badge.pending { background: #fde8e8; color: #b91c1c; }
.badge.offered { background: #fef3c7; color: #92400e; }
.badge.accepted, .badge.arrived, .badge.in_progress { background: #dbeafe; color: #1e40af; }
.badge.completed { background: #dcfce7; color: #166534; }
.badge.cancelled { background: #f3f4f6; color: #6b7280; }
.badge.free { background: #dcfce7; color: #166534; }
.badge.on_ride { background: #dbeafe; color: #1e40af; }
.badge.offline { background: #f3f4f6; color: #6b7280; }

/* Map */
.map-wrap { position: relative; }
#map { position: absolute; inset: 0; }
.legend {
  position: absolute; z-index: 500; left: 10px; bottom: 18px; background: #fff; border-radius: 8px; padding: 6px 10px;
  box-shadow: var(--shadow); display: flex; gap: 12px; font-size: 12px;
}
.lg { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: -1px; }
.lg.free { background: var(--free); } .lg.offered { background: var(--offered); }
.lg.on_ride { background: var(--on_ride); } .lg.offline { background: var(--offline); }
.driver-panel {
  position: absolute; z-index: 500; top: 10px; right: 10px; width: 290px; max-height: calc(100% - 20px); overflow: auto;
}
.drv { display: flex; gap: 8px; align-items: center; padding: 7px 4px; border-top: 1px solid var(--line); cursor: pointer; }
.drv:hover { background: #fbfaf6; }
.drv .info { flex: 1; min-width: 0; }
.drv .name { font-weight: 600; }
.drv .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.car-marker { background: none; border: 0; }
.car-marker .pin {
  width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 5px rgba(0,0,0,.4);
  display: grid; place-items: center; color: #fff; font-size: 11px; font-weight: 700;
}
.car-marker .label {
  position: absolute; top: 32px; left: 50%; transform: translateX(-50%); white-space: nowrap; background: #141414; color: #fff;
  font-size: 11px; padding: 1px 6px; border-radius: 6px;
}
.point-marker { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.5); }
.map-picking #map { cursor: crosshair; }

/* Pages */
.page { overflow: auto; padding: 16px 20px 40px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: end; margin-bottom: 12px; }
.toolbar label { margin: 0; }
.toolbar input, .toolbar select { width: auto; }
.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #faf9f5; position: sticky; top: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #fbfaf6; }
tfoot td { font-weight: 700; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.stat-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.stat-card .k { font-size: 12px; color: var(--muted); }
.stat-card .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-card .v.office { color: #a16207; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 8px; }
.inline-form { display: flex; gap: 6px; margin: 8px 0; flex-wrap: wrap; }
.inline-form > * { width: auto; flex: 1; min-width: 90px; }
.inline-form .btn { flex: 0; }

.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
fieldset { border: 0; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; margin: 0; }
legend { font-weight: 700; padding: 0; float: left; width: 100%; margin-bottom: 10px; }
.settings .actions { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; }
#tab-settings .two-col { margin-top: 16px; }
#tab-settings .card h2 { margin-bottom: 10px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 3000; }
.modal-box { background: #fff; border-radius: 14px; width: min(640px, 94vw); max-height: 90vh; overflow: auto; padding: 18px 20px; position: relative; }
.modal-x { position: absolute; right: 10px; top: 6px; font-size: 26px; background: none; border: 0; cursor: pointer; color: var(--muted); }
.modal-box h2 { font-size: 18px; margin-bottom: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.timeline { list-style: none; padding: 0; margin: 8px 0 0; font-size: 13px; }
.timeline li { padding: 5px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 10px; }
.timeline .t { color: var(--muted); width: 120px; flex-shrink: 0; }
.money-box { background: #fffbea; border: 1px solid #fde68a; border-radius: 8px; padding: 10px; margin: 6px 0 10px; display: flex; gap: 18px; }
.money-box div { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); }
.money-box b { font-size: 16px; color: var(--ink); }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; flex-wrap: wrap; }

#toasts { position: fixed; right: 14px; bottom: 14px; z-index: 4000; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #141414; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); max-width: 340px; animation: in .2s; }
.toast.warn { background: #b45309; }
.toast.good { background: #15803d; }
@keyframes in { from { transform: translateY(10px); opacity: 0; } }

@media (max-width: 1100px) {
  .dispatch { grid-template-columns: 340px 1fr; }
  .driver-panel { width: 240px; }
  .stats { display: none; }
  .two-col { grid-template-columns: 1fr; }
}

/* Customer app */
.badge.app { background: #ede9fe; color: #6d28d9; }
.toast.app { background: #6d28d9; font-weight: 600; }
.otp-card { border: 2px solid #7c3aed; }
.otp { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.otp > div { flex: 1; min-width: 0; }
.otp .code { font: 700 20px/1 ui-monospace, Consolas, monospace; letter-spacing: 2px; background: #f5f3ff; padding: 6px 8px; border-radius: 6px; }
.ride.app-src { box-shadow: inset 0 0 0 1px #c4b5fd; }

/* Developer portal */
body { overflow: auto; }
.badge.active { background: #dcfce7; color: #166534; }
.badge.grace { background: #fef3c7; color: #92400e; }
.badge.expired, .badge.unpaid { background: #fde8e8; color: #b91c1c; }
.badge.suspended { background: #1f2937; color: #fff; }
.keybox { font: 600 14px ui-monospace, Consolas, monospace; background: #f5f4f0; padding: 8px 10px; border-radius: 8px; word-break: break-all; user-select: all; }
pre.config { background: #141414; color: #e5e5e5; padding: 12px; border-radius: 8px; font-size: 12px; white-space: pre-wrap; word-break: break-all; user-select: all; }
.pay-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: end; }
.pay-row > * { width: auto; }
.warn-text { color: #b45309; }
.page h2 { margin: 6px 0 10px; }

/* Zoghby Tech portal brand */
:root { --brand: #016738; --brand-ink: #ffffff; }
.portal-logo { width: 170px; height: 170px; object-fit: contain; margin: -6px 0 2px; }
.brand img.tile { background: #fff; border-radius: 8px; padding: 2px; width: 32px; height: 32px; }
.tabs button.active { color: #6ee7a8; }
