/* Business dashboard. Brand colours live in the custom properties below. */
:root {
  --brand: #ff5a1f;
  --brand-dark: #d9440f;
  --ink: #0e1726;
  --ink-2: #3b4658;
  --muted: #6b7587;
  --line: #e3e7ee;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --ok: #138a4b;
  --ok-bg: #e3f6eb;
  --warn: #9a6100;
  --warn-bg: #fff3d6;
  --danger: #c22a2a;
  --danger-bg: #fde6e6;
  --info: #1d5fbf;
  --info-bg: #e5eefc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(14, 23, 38, .06), 0 4px 16px rgba(14, 23, 38, .06);
  --sidebar: 232px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; }
p { margin: 0 0 .75rem; }
a { color: var(--info); }
code { font: 600 .95em ui-monospace, SFMono-Regular, Consolas, monospace; background: #eef1f5; padding: .05em .35em; border-radius: 4px; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid rgba(255, 90, 31, .45); outline-offset: 2px; }

.small { font-size: .85rem; }
.muted { color: var(--muted); }
.grow { flex: 1 1 auto; min-width: 0; }
.center { text-align: center; }
.block { display: block; width: 100%; }
.hide { opacity: 0; transform: translateY(6px); }
.link { color: var(--info); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; font: inherit; }
.plain { background: none; border: 0; padding: 0; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .3rem 0; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }

/* ------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  min-height: 38px; padding: .45rem .9rem; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--ink); font: 600 .92rem var(--font); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: #f0f2f6; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(14, 23, 38, .06); }
.btn.small { min-height: 30px; padding: .25rem .6rem; font-size: .85rem; }
.btn.big { min-height: 48px; font-size: 1rem; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid currentColor; border-color: var(--muted) transparent var(--muted) transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.icon-btn {
  position: relative; display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
  border: 0; border-radius: 8px; background: transparent; cursor: pointer; font-size: 1.15rem; color: inherit; text-decoration: none;
}
.icon-btn:hover { background: rgba(14, 23, 38, .06); }
.actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.actions-cell { white-space: nowrap; text-align: right; }
.actions-cell .btn { margin-left: .25rem; }

/* ------------------------------------------------------------ badges */
.badge {
  display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
  background: #eef1f5; color: var(--ink-2); margin-right: .25rem; white-space: nowrap; vertical-align: middle;
}
.badge.ok, .badge.available { background: var(--ok-bg); color: var(--ok); }
.badge.warn, .badge.returning { background: var(--warn-bg); color: var(--warn); }
.badge.danger, .badge.delayed { background: var(--danger-bg); color: var(--danger); }
.badge.info, .badge.on_route, .badge.delivering { background: var(--info-bg); color: var(--info); }
.badge.muted, .badge.offline, .badge.ended { background: #eef1f5; color: var(--muted); }
.status-dot { width: 12px; height: 12px; border-radius: 50%; flex: 0 0 12px; margin-top: 5px; box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--line); }
.dot-count {
  position: absolute; top: 2px; right: 0; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 9px;
  background: var(--danger); color: #fff; font: 700 .7rem/18px var(--font); text-align: center;
}

/* ------------------------------------------------------------ layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: var(--sidebar); flex: 0 0 var(--sidebar);
  background: var(--ink); color: #cdd3dd; padding: 1rem .75rem; overflow-y: auto;
}
.logo { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 700; padding: .25rem .5rem 1.25rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: .65rem; padding: .6rem .75rem; border-radius: 8px; color: #cdd3dd; text-decoration: none; font-weight: 500; }
.nav a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav-icon { width: 1.2rem; text-align: center; }
.main-col { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  padding: .55rem 1.25rem; background: #fff; border-bottom: 1px solid var(--line);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: .6rem; min-width: 0; flex-wrap: wrap; }
.tenant-name { font-size: 1rem; }
.menu-toggle { display: none; }
.banner { padding: .6rem 1.25rem; font-weight: 500; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.main { padding: 1.25rem; outline: none; flex: 1 1 auto; }
.view { max-width: 1400px; margin: 0 auto; }
.view-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.panel.narrow { max-width: 560px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.center-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; padding: 1rem; }
.loading { color: var(--muted); padding: 2rem; text-align: center; }
.empty { padding: 1.5rem 1rem; text-align: center; color: var(--muted); }
.empty p { margin-bottom: .75rem; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a, .tabs button {
  padding: .6rem .9rem; border: 0; background: none; font: 600 .92rem var(--font); color: var(--muted);
  border-bottom: 2px solid transparent; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.tabs a.active, .tabs button.active, .tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--brand); }

.notice { padding: .65rem .85rem; border-radius: 8px; background: var(--info-bg); color: var(--info); margin: 0 0 1rem; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.danger, .notice.error { background: var(--danger-bg); color: var(--danger); }
.error { color: var(--danger); }

/* ------------------------------------------------------------ stats */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem .9rem; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.15; }
.stat-label { font-size: .82rem; color: var(--muted); }
.stat.ok .stat-value { color: var(--ok); }
.stat.warn .stat-value { color: var(--warn); }
.stat.danger .stat-value { color: var(--danger); }

/* ------------------------------------------------------------ forms */
.form { display: flex; flex-direction: column; gap: .2rem; }
.field { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .6rem; }
.field label { font-weight: 600; font-size: .88rem; }
input, select, textarea {
  font: inherit; color: inherit; padding: .5rem .65rem; border: 1px solid #cfd5df; border-radius: 8px; background: #fff; min-height: 38px; width: 100%;
}
input[type="checkbox"], input[type="radio"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--brand); flex: 0 0 auto; }
textarea { min-height: 80px; resize: vertical; }
input:disabled, select:disabled, textarea:disabled { background: #f2f4f7; color: var(--muted); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--danger); }
.hint { color: var(--muted); font-size: .8rem; }
.field-error { color: var(--danger); font-size: .8rem; min-height: 0; }
.field-error:empty { display: none; }
.check { display: flex; align-items: center; gap: .5rem; font-weight: 500; margin: .3rem 0 .6rem; }
.choices { display: flex; flex-direction: column; gap: .35rem; margin: .5rem 0; }
.address-block { margin-bottom: .6rem; }
.address-block .grid-3, .address-block .grid-2 { gap: 0 .6rem; }
.address-block .grid-3 { grid-template-columns: 1.3fr 1fr .8fr; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 160px; }
.advanced { border: 1px dashed var(--line); border-radius: 8px; padding: .5rem .75rem; margin: .4rem 0 .8rem; }
.advanced summary { cursor: pointer; font-weight: 600; font-size: .9rem; }
.sticky-actions { position: sticky; bottom: 0; background: linear-gradient(transparent, #fff 30%); padding-top: 1rem; display: flex; gap: .5rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0 0 1rem; }
.details dt { color: var(--muted); }
.details dd { margin: 0; }

/* ------------------------------------------------------------ tables & lists */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); padding: .5rem .6rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #fafbfc; }
.list { display: flex; flex-direction: column; gap: .4rem; }
.list-item {
  display: flex; gap: .65rem; align-items: flex-start; width: 100%; padding: .65rem .7rem; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; text-align: left; font: inherit; color: inherit;
}
button.list-item { cursor: pointer; }
button.list-item:hover, .order-item:hover { border-color: #c7cfdb; }
.order-item.selected { border-color: var(--brand); background: #fff7f3; }
.order-item input[type="checkbox"] { margin-top: 3px; }
.eta-line { display: flex; flex-wrap: wrap; gap: .25rem .9rem; margin-top: .25rem; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 1rem; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 0 0 .7rem .5rem; }
.timeline li::before { content: ""; position: absolute; left: -1.38rem; top: .45rem; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); }

/* ------------------------------------------------------------ live */
.live-grid { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 1rem; align-items: start; }
.live-side { max-height: calc(100vh - 230px); overflow-y: auto; }
.live-side h2:not(:first-child) { margin-top: 1.25rem; }
.map-panel { padding: 0; overflow: hidden; position: sticky; top: 70px; }
.map { width: 100%; height: calc(100vh - 230px); min-height: 420px; background: #e9edf2; }
.small-map { height: 360px; min-height: 0; border-radius: 8px; margin-top: .75rem; }
.map-placeholder { height: 100%; min-height: 300px; display: flex; align-items: center; justify-content: center; padding: 2rem; text-align: center; color: var(--muted); }
.assign-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .6rem; margin-bottom: .6rem;
  background: #fff7f3; border: 1px solid #ffd2bf; border-radius: 8px; position: sticky; top: 0; z-index: 2;
}
.assign-bar select { width: auto; flex: 1 1 160px; }
.stops { list-style: none; margin: .5rem 0 0; padding: 0; counter-reset: stop; }
.stop { display: flex; gap: .6rem; align-items: flex-start; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.stop::before {
  counter-increment: stop; content: counter(stop); flex: 0 0 26px; height: 26px; border-radius: 50%;
  background: var(--info-bg); color: var(--info); font: 700 .8rem/26px var(--font); text-align: center;
}
.stop-completed::before { background: var(--ok-bg); color: var(--ok); }
.stop-failed::before { background: var(--danger-bg); color: var(--danger); }
.stop-removed { opacity: .5; }
.stop-arrived::before { background: var(--warn-bg); color: var(--warn); }
.reorder { display: flex; flex-direction: column; gap: 2px; }
.reorder .btn { min-height: 24px; padding: 0 .45rem; }

/* ------------------------------------------------------------ kitchen */
.kitchen-board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) 280px; gap: 1rem; align-items: start; }
.k-col { background: #eef1f5; border-radius: var(--radius); padding: .75rem; min-height: 50vh; }
.k-col h2 { display: flex; justify-content: space-between; }
.k-pending { border-top: 4px solid #8a94a6; }
.k-preparing { border-top: 4px solid #e0a100; }
.k-ready { border-top: 4px solid var(--ok); }
.k-col-body { display: flex; flex-direction: column; gap: .6rem; }
.k-card { background: #fff; border-radius: 8px; padding: .75rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .45rem; }
.k-card.late { box-shadow: 0 0 0 2px var(--danger); }
.k-ref { font-size: 1.25rem; }
.k-items { font-size: .95rem; white-space: pre-wrap; }
.k-card .btn { min-height: 44px; font-size: 1rem; }
.k-drivers { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
.k-driver { padding: .55rem 0; border-bottom: 1px solid var(--line); }
.k-driver:last-child { border-bottom: 0; }
.k-eta { font-weight: 700; }
.k-clock { font: 700 1.4rem var(--font); font-variant-numeric: tabular-nums; }
:fullscreen .view, .kitchen-full .view { max-width: none; }
:fullscreen { background: var(--bg); overflow: auto; padding: 1rem; }

/* ------------------------------------------------------------ reports & billing */
.bars { display: flex; flex-direction: column; gap: .35rem; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 60px; gap: .6rem; align-items: center; font-size: .88rem; }
.bar-label { color: var(--muted); }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 10px; background: #eef1f5; border-radius: 5px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--brand); border-radius: 5px; }
.bar-fill.full { background: var(--danger); }
.usage-list { display: flex; flex-direction: column; gap: .7rem; margin-top: 1rem; }
.usage .bar { margin-top: .25rem; }
.feature-list { list-style: none; padding: 0; margin: .75rem 0; display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; }
.feature-list li::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.feature-list li.no { color: var(--muted); }
.feature-list li.no::before { content: "– "; color: var(--muted); }
.plan-name { font-size: 1.1rem; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; }
.plan { display: flex; flex-direction: column; gap: .5rem; margin: 0; }
.plan.current { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.price-row { display: flex; align-items: baseline; gap: .35rem; }
.price { font-size: 1.6rem; font-weight: 800; }

/* ------------------------------------------------------------ credentials (shown once, printable) */
.credentials { border: 2px solid var(--ink); border-radius: var(--radius); padding: 1rem; }
.cred-list { display: grid; grid-template-columns: max-content 1fr max-content; gap: .6rem 1rem; align-items: center; margin: 0; }
.cred-list dt { color: var(--muted); }
.cred-list dd { margin: 0; }
.big-code { font: 700 1.5rem ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .06em; background: none; padding: 0; }

/* ------------------------------------------------------------ notifications */
.notification-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
.notification { display: flex; align-items: flex-start; gap: .75rem; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .75rem; }
.notification.unread { border-left: 4px solid var(--brand); }
.notification.read { opacity: .75; }

/* ------------------------------------------------------------ auth pages */
.auth-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 1.5rem; background: linear-gradient(160deg, #0e1726 0, #1d2a40 100%); }
.auth-brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-size: 1.2rem; font-weight: 700; margin-bottom: 1.25rem; }
.auth-card .auth-brand { color: var(--ink); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border-radius: 14px; padding: 1.6rem; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.auth-card h1 { margin-bottom: 1rem; }
.auth-card .btn.primary { width: 100%; min-height: 44px; margin-top: .4rem; }
.auth-foot { margin-top: 1rem; display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-size: .9rem; }
.tenant-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.tenant-choice { width: 100%; justify-content: space-between; min-height: 48px; }

/* ------------------------------------------------------------ modal & toasts */
.backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(14, 23, 38, .45); display: flex; align-items: flex-start; justify-content: center; padding: 5vh 1rem; overflow-y: auto; }
.modal { width: 100%; max-width: 560px; background: #fff; border-radius: 14px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.modal-wide { max-width: 920px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.2rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1rem 1.2rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1.2rem; border-top: 1px solid var(--line); }
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 200; display: flex; flex-direction: column; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.toast { background: var(--ink); color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--shadow); transition: opacity .4s, transform .4s; }
.toast-success { background: var(--ok); }
.toast-error { background: var(--danger); }
.toast-warn { background: #b07000; }

/* ------------------------------------------------------------ responsive */
@media (max-width: 1100px) {
  .live-grid { grid-template-columns: 1fr; }
  .live-side { max-height: none; }
  .map-panel { position: static; }
  .map { height: 55vh; }
  .kitchen-board { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kitchen-board .k-drivers { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(14, 23, 38, .45); }
  .menu-toggle { display: inline-flex; }
  .grid-2, .grid-3, .kitchen-board { grid-template-columns: 1fr; }
  .address-block .grid-3 { grid-template-columns: 1.3fr 1fr .8fr; }
  .address-block .grid-2 { grid-template-columns: 1fr 1fr; }
  .main { padding: .9rem; }
  .topbar { padding: .5rem .75rem; }
  .cred-list { grid-template-columns: 1fr; }
}

@media print {
  body * { visibility: hidden; }
  .credentials, .credentials * { visibility: visible; }
  .credentials { position: absolute; left: 0; top: 0; width: 100%; border: 2px solid #000; }
  .credentials .btn { display: none; }
}
