/* Mambanda Market — Manage panel.
   Light, high-contrast operations UI: this is a desk tool used all day, often
   on a cheap screen, and a driver uses it one-handed on a phone. Density and
   legibility beat decoration. */

:root {
  --brand: #3f51b5;
  --brand-dark: #32408f;
  --brand-soft: #eef0fb;

  --bg: #f4f6fa;
  --surface: #ffffff;
  --line: #e2e6ee;
  --line-strong: #cbd2e0;

  --text: #131824;
  --muted: #616b80;
  --faint: #8b94a7;

  --ok: #12805c;
  --ok-soft: #e3f5ee;
  --warn: #9a6100;
  --warn-soft: #fdf2dd;
  --danger: #bb2d2d;
  --danger-soft: #fdeaea;
  --info: #1f5fa8;
  --info-soft: #e7f0fb;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .06), 0 8px 24px rgba(17, 24, 39, .06);
}

* { box-sizing: border-box; }

/* The UA stylesheet's [hidden] rule is display:none, which ANY author `display`
   declaration outranks — and .modal/.auth-wrap/.layout all set one. Without
   this, every "hidden" view paints on top of the app. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
a { color: var(--brand); }

/* ---------- Auth ---------- */
.auth-wrap {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}
.brand-mark {
  width: 52px; height: 52px;
  margin: 0 auto 16px;
  border-radius: 14px;
  background: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  font-size: 24px; font-weight: 700;
}
.brand-mark.sm { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; margin: 0; }
.brand-mark.danger { background: var(--danger); }
.auth-title { font-size: 21px; }
.auth-sub { margin: 6px 0 22px; color: var(--muted); font-size: 14px; }
.auth-note { margin: 18px 0 0; color: var(--faint); font-size: 12.5px; line-height: 1.5; }
.auth-form { display: grid; gap: 14px; text-align: left; }
.auth-error {
  margin: 4px 0 0; padding: 9px 11px;
  background: var(--danger-soft); color: var(--danger);
  border-radius: var(--radius-sm); font-size: 13px;
}

/* ---------- Form primitives ---------- */
.field { display: grid; gap: 6px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field.compact > span { font-size: 11.5px; }
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 14px;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}
textarea { resize: vertical; min-height: 84px; }
label.inline { display: flex; align-items: center; gap: 8px; font-size: 14px; }
label.inline input { width: auto; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f7f8fc; }
.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-danger:hover { filter: brightness(.94); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.icon-btn {
  appearance: none; border: 0; background: transparent;
  font-size: 18px; line-height: 1; cursor: pointer; color: var(--muted);
  padding: 6px 8px; border-radius: var(--radius-sm);
}
.icon-btn:hover { background: #eef1f6; }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100dvh; }
.sidebar {
  width: 232px; flex: 0 0 232px;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100dvh;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px;
  font-size: 15px;
  border-bottom: 1px solid var(--line);
}
.sidebar-brand strong { color: var(--brand); }
.nav { flex: 1; overflow-y: auto; padding: 10px 8px; display: grid; gap: 2px; align-content: start; }
.nav button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  padding: 9px 11px;
  border: 0; background: transparent; color: var(--muted);
  border-radius: var(--radius-sm);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.nav button:hover { background: #f4f6fb; color: var(--text); }
.nav button.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav .nav-ico { width: 18px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--warn-soft); color: var(--warn);
  border-radius: 999px; padding: 1px 7px; font-size: 11.5px; font-weight: 700;
}
.sidebar-foot { border-top: 1px solid var(--line); padding: 12px; display: grid; gap: 10px; }
.who-email { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.who-role { font-size: 12px; color: var(--faint); text-transform: capitalize; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-right { margin-left: auto; }
.chip {
  background: var(--brand-soft); color: var(--brand);
  padding: 4px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
}
#menu-toggle { display: none; }
.content { padding: 20px; display: grid; gap: 18px; align-content: start; }

/* ---------- Cards / KPIs ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.card-head h2 { font-size: 15px; }
.card-tools { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.card-body { padding: 16px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr)); gap: 12px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.kpi-label { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.02em; }
.kpi-sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.kpi.attn { border-color: #f0d59b; background: var(--warn-soft); }
.kpi.attn .kpi-value { color: var(--warn); }
.kpi-link { cursor: pointer; text-align: left; width: 100%; font: inherit; }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th {
  font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--faint); font-weight: 700; white-space: nowrap;
}
tbody tr:hover { background: #fafbfe; }
tbody tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; display: flex; gap: 6px; flex-wrap: wrap; }
.mono { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.truncate { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 34px 16px; text-align: center; color: var(--faint); font-size: 14px; }
.sub { font-size: 12px; color: var(--faint); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 700; white-space: nowrap;
  background: #eef1f6; color: var(--muted);
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.info { background: var(--info-soft); color: var(--info); }

/* ---------- Pager ---------- */
.pager {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-top: 1px solid var(--line);
  font-size: 13px; color: var(--muted);
}
.pager .spacer { margin-left: auto; }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(15, 20, 32, .45);
  display: grid; place-items: center; padding: 20px;
}
.modal-card {
  width: 100%; max-width: 520px;
  max-height: 88dvh; overflow-y: auto;
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
}
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--surface);
}
.modal-head h2 { font-size: 16px; }
.modal-head .icon-btn { margin-left: auto; }
.modal-body { padding: 18px; display: grid; gap: 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 80;
  background: #131824; color: #fff;
  padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 500;
  box-shadow: var(--shadow);
  max-width: min(92vw, 520px);
}
.toast.ok { background: var(--ok); }
.toast.err { background: var(--danger); }

/* ---------- Chat ---------- */
.chat-wrap { display: grid; grid-template-columns: 280px 1fr; min-height: 460px; }
.chat-list { border-right: 1px solid var(--line); overflow-y: auto; max-height: 62dvh; }
.chat-item {
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
  cursor: pointer; font: inherit; display: grid; gap: 3px;
}
.chat-item:hover { background: #f7f8fc; }
.chat-item.active { background: var(--brand-soft); }
.chat-item .who { font-weight: 600; font-size: 13.5px; }
.chat-pane { display: flex; flex-direction: column; max-height: 62dvh; }
.chat-msgs { flex: 1; overflow-y: auto; padding: 16px; display: grid; gap: 10px; align-content: start; }
.msg { max-width: 74%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.45; }
.msg.them { background: #eef1f6; justify-self: start; border-bottom-left-radius: 4px; }
.msg.us { background: var(--brand); color: #fff; justify-self: end; border-bottom-right-radius: 4px; }
.msg-time { display: block; font-size: 10.5px; opacity: .65; margin-top: 3px; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-form input { flex: 1; }

/* ---------- Driver view ---------- */
.drop {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; display: grid; gap: 10px;
}
.drop-addr { font-size: 16px; font-weight: 600; line-height: 1.35; }
.drop-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); }
.drop-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.drop-actions .btn { flex: 1; min-width: 120px; padding: 12px; }

/* ---------- Invoice print ---------- */
.inv-head { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.inv-total { font-size: 20px; font-weight: 700; }
@media print {
  .sidebar, .topbar, .card-head, .pager, .no-print { display: none !important; }
  .content { padding: 0; }
  .card { border: 0; box-shadow: none; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .chat-wrap { grid-template-columns: 1fr; }
  .chat-list { max-height: 220px; border-right: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 760px) {
  #menu-toggle { display: block; }
  .sidebar {
    position: fixed; z-index: 40; left: 0; top: 0;
    transform: translateX(-100%);
    transition: transform .18s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .content { padding: 14px; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
}
