:root {
  --ground: #F4EFE6;
  --card: #FFFFFF;
  --ink: #1D1C1A;
  --muted: #5E5A52;
  --line: #E3DCCF;
  --field: #D6CEBF;
  --teal: #0E5F58;
  --teal-dark: #0A4540;
  --teal-tint: #E7F0EE;
  --amber: #7A4608;
  --amber-tint: #FBEBD3;
  --red: #A33A2A;
  --red-tint: #F9E3DF;
  --radius: 14px;
  font-family: 'IBM Plex Sans Arabic', Tahoma, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--ground); color: var(--ink); font-size: 15px; line-height: 1.6; }
a { color: var(--teal); }
a:hover { color: var(--teal-dark); }
h1, h2, h3 { margin: 0; line-height: 1.3; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
button, input, select, textarea { font: inherit; color: inherit; }

.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--ink); color: #EDE7DC;
  padding: 20px 12px; display: flex; flex-direction: column; gap: 4px;
}
.brand { font-size: 22px; font-weight: 700; padding: 4px 12px 16px; color: #fff; }
.brand small { display: block; font-size: 12px; font-weight: 400; color: #B5AC9C; }
.nav a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px; border-radius: 10px; color: #EDE7DC; text-decoration: none;
}
.nav a:hover { background: #2E2C29; color: #fff; }
.nav a.active { background: var(--teal); color: #fff; }
.nav .badge { background: var(--amber-tint); color: var(--amber); }
.sidebar .who { margin-top: auto; padding: 12px; font-size: 13px; color: #B5AC9C; }
.sidebar .who button { margin-top: 8px; }

main { flex: 1; min-width: 0; padding: 28px 32px 48px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat .n { font-size: 26px; font-weight: 700; }
.stat .l { font-size: 13px; color: var(--muted); }
.stat.warn { background: var(--amber-tint); border-color: transparent; }
.stat.warn .l { color: var(--amber); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--teal);
  background: var(--teal); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--teal-dark); color: #fff; }
.btn.ghost { background: #fff; color: var(--teal); }
.btn.ghost:hover { background: var(--teal-tint); }
.btn.danger { background: var(--red); border-color: var(--red); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.sidebar .btn.ghost { background: transparent; color: #EDE7DC; border-color: #57534C; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--field);
  border-radius: 10px; background: #fff;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--teal); outline-offset: 2px;
}
.field { display: flex; flex-direction: column; }

table { width: 100%; border-collapse: collapse; background: var(--card); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
th, td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 13px; color: var(--muted); font-weight: 600; background: #FBF9F5; white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #FBF9F5; }
.mono { font-family: ui-monospace, Menlo, monospace; direction: ltr; unicode-bidi: embed; }

.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--ground); white-space: nowrap; }
.pill.open { background: #EEE9DF; }
.pill.matched, .pill.at_point { background: var(--amber-tint); color: var(--amber); }
.pill.picked_up { background: var(--teal-tint); color: var(--teal); }
.pill.delivered, .pill.approved, .pill.resolved { background: #E3EFE0; color: #2F5D24; }
.pill.cancelled, .pill.rejected { background: #EEE; color: #555; }
.pill.dispute, .pill.pending { background: var(--red-tint); color: var(--red); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--field); background: #fff; border-radius: 999px; padding: 6px 14px; cursor: pointer; }
.tabs button.active { background: var(--teal); border-color: var(--teal); color: #fff; }

.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.timeline li { display: flex; gap: 10px; align-items: center; }
.timeline .dot { width: 12px; height: 12px; border-radius: 6px; border: 2px solid var(--field); flex-shrink: 0; }
.timeline .done .dot { background: var(--teal); border-color: var(--teal); }

.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.media-grid figure { margin: 0; }
.media-grid img, .media-grid video { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; background: #000; }
.media-grid figcaption { font-size: 12px; color: var(--muted); margin-top: 4px; }

.map { height: 360px; border-radius: var(--radius); border: 1px solid var(--line); }
.map.tall { height: calc(100vh - 160px); min-height: 420px; }

.notice { padding: 12px 14px; border-radius: 12px; background: var(--amber-tint); color: var(--amber); }
.notice.ok { background: var(--teal-tint); color: var(--teal); }
.notice.err { background: var(--red-tint); color: var(--red); }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 2000;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; max-width: 90vw;
}
.toast.err { background: var(--red); }

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; height: 100%; }
.bars .bar span { width: 100%; background: var(--teal); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .bar small { font-size: 10px; color: var(--muted); }

.empty { padding: 32px; text-align: center; color: var(--muted); }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 4px 8px; font-size: 18px; }
  .brand small { display: none; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav a { padding: 6px 10px; font-size: 14px; }
  .sidebar .who { margin: 0; padding: 4px 8px; }
  main { padding: 16px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
}
