:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e3e8ef;
  --accent: #0f766e;
  --accent-ink: #0b5d57;
  --accent-soft: #d7f2ee;
  --amber: #b45309;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px -18px rgba(15, 23, 42, .35);
  --font: "Segoe UI", system-ui, -apple-system, "Noto Sans", Tahoma, "Vazirmatn", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; font-weight: 650; }
h2 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }

.muted { color: var(--muted); font-size: .875rem; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: .7rem 1.5rem;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: .65rem; min-width: 0; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  flex: none;
}
.brand strong { display: block; font-size: .98rem; font-weight: 650; letter-spacing: -.01em; }
.brand small { display: block; font-size: .72rem; color: var(--muted); }

.tabs { display: flex; gap: .25rem; margin-inline-start: .5rem; }
.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: .9rem;
  padding: .45rem .8rem;
  border-radius: 8px;
  cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }

.topbar-end { display: flex; align-items: center; gap: .5rem; margin-inline-start: auto; }

.lang-switch {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.lang-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font: inherit;
  font-size: .8rem;
  padding: .3rem .6rem;
  cursor: pointer;
  color: var(--muted);
}
.lang-btn.active { background: var(--accent); color: #fff; }

/* ---------- layout ---------- */
.main { max-width: 1180px; margin: 0 auto; padding: 1.5rem; }
.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-head .muted { margin-top: .2rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
  margin-bottom: 1rem;
}
.card h2 { margin-bottom: .9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }

/* ---------- buttons & inputs ---------- */
.btn {
  appearance: none;
  font: inherit;
  font-size: .875rem;
  font-weight: 550;
  border-radius: 9px;
  border: 1px solid transparent;
  padding: .5rem .9rem;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn-danger { background: transparent; color: var(--danger); border-color: #f3d2d2; }
.btn-danger:hover { background: #fdf2f2; }
.btn-block { width: 100%; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }

input, select, textarea {
  font: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: .5rem .7rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 70px; }
label.field { display: block; }
label.field > span { display: block; font-size: .8rem; font-weight: 550; color: var(--muted); margin-bottom: .25rem; }

.form-error { color: var(--danger); font-size: .85rem; margin: .5rem 0; }
.toolbar { display: flex; gap: .6rem; margin-bottom: .9rem; flex-wrap: wrap; }
.toolbar input { flex: 1 1 260px; }
.toolbar select { flex: 0 1 190px; }

/* ---------- login ---------- */
#view-login.active { display: grid; place-items: center; min-height: calc(100vh - 6rem); }
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.3rem; }
.login-card .muted { margin: .35rem 0 1.4rem; }
.login-card .field { margin-bottom: .9rem; }

/* ---------- stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow);
}
.stat .label { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 650; margin-top: .3rem; letter-spacing: -.02em; }
.stat .hint { font-size: .78rem; color: var(--muted); margin-top: .15rem; }
.stat.accent .value { color: var(--accent); }

/* ---------- bars ---------- */
.bars { display: grid; gap: .6rem; }
.bar-row { display: grid; grid-template-columns: 7.5rem 1fr 2rem; align-items: center; gap: .6rem; font-size: .84rem; }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; background: var(--accent); }
.bar-num { text-align: end; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- feed ---------- */
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: .7rem; }
.feed li { display: grid; grid-template-columns: auto 1fr; gap: .6rem; align-items: start; font-size: .85rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-top: .45rem; }
.feed .meta { color: var(--muted); font-size: .78rem; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th {
  text-align: start;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  padding: .55rem .6rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
.table td { padding: .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table-hover tbody tr { cursor: pointer; }
.table-hover tbody tr:hover { background: var(--surface-2); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .82rem; letter-spacing: -.01em; }
.num { font-variant-numeric: tabular-nums; }
.empty { color: var(--muted); font-size: .875rem; padding: 1.2rem 0; text-align: center; }

/* status pills */
.pill {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .75rem;
  font-weight: 600;
  padding: .15rem .55rem;
  border-radius: 99px;
  white-space: nowrap;
  border: 1px solid transparent;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.s-booked    { color: #475569; background: #f1f5f9; border-color: #e2e8f0; }
.s-picked_up { color: #3730a3; background: #eef2ff; border-color: #e0e7ff; }
.s-in_transit{ color: #a16207; background: #fefce8; border-color: #fef08a; }
.s-customs   { color: #6b21a8; background: #faf5ff; border-color: #f0e0fd; }
.s-arrived   { color: #0f766e; background: #f0fdfa; border-color: #ccfbf1; }
.s-delivered { color: #15803d; background: #f0fdf4; border-color: #dcfce7; }
.s-cancelled { color: #b91c1c; background: #fef2f2; border-color: #fee2e2; }

/* ---------- tracking ---------- */
.track-form { display: flex; gap: .6rem; margin-bottom: 1rem; }
.track-form input { flex: 1; }
.track-head-actions { display: flex; align-items: center; gap: .5rem; }
.public-brand { display: flex; align-items: center; gap: .65rem; margin-bottom: 1.4rem; }
.public-brand strong { display: block; font-size: 1rem; }
.public-brand small { display: block; font-size: .75rem; color: var(--muted); }
body.public-track .main { max-width: 860px; }
.login-track { margin-top: .6rem; text-align: center; text-decoration: none; }
a.btn { display: inline-flex; align-items: center; justify-content: center; }

/* keep bars readable per status */
.bar-fill.s-booked { background: #94a3b8; }
.bar-fill.s-picked_up { background: #6366f1; }
.bar-fill.s-in_transit { background: #eab308; }
.bar-fill.s-customs { background: #a855f7; }
.bar-fill.s-arrived { background: #14b8a6; }
.bar-fill.s-delivered { background: #22c55e; }
.bar-fill.s-cancelled { background: #ef4444; }
.track-result { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: .5rem; }
.track-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.kv { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .85rem; margin: 1rem 0; }
.kv div span { display: block; font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kv div strong { font-size: .92rem; font-weight: 550; }

.timeline { list-style: none; margin: .5rem 0 0; padding: 0; }
.timeline li { position: relative; padding-inline-start: 1.35rem; padding-bottom: 1rem; }
.timeline li::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: .35rem;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.timeline li::after {
  content: "";
  position: absolute;
  inset-inline-start: 4px;
  top: 1.1rem;
  bottom: 0;
  width: 1px;
  background: var(--line);
}
.timeline li:last-child { padding-bottom: 0; }
.timeline li:last-child::after { display: none; }
.timeline .when { font-size: .76rem; color: var(--muted); }
.timeline .what { font-size: .88rem; }
.timeline .note { font-size: .84rem; color: var(--muted); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3rem 1rem;
  overflow-y: auto;
  z-index: 200;
}
.modal {
  background: var(--surface);
  border-radius: 16px;
  width: 100%;
  max-width: 720px;
  box-shadow: 0 24px 60px -20px rgba(15, 23, 42, .45);
  animation: pop .16s ease-out;
}
.modal.narrow { max-width: 480px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1.25rem; }
.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  padding: .9rem 1.25rem;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 16px 16px;
}
.icon-btn {
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: .2rem .4rem;
  border-radius: 6px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }

.detail-meta { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: .4rem; }
.detail-actions { display: flex; gap: .5rem; margin-top: 1rem; }
.section-title { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1.2rem 0 .3rem; }

/* ---------- toast ---------- */
.toast-root { position: fixed; inset-block-end: 1.2rem; inset-inline-end: 1.2rem; display: grid; gap: .5rem; z-index: 300; }
.toast {
  background: #0f172a;
  color: #f8fafc;
  font-size: .85rem;
  padding: .6rem .9rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  animation: pop .15s ease-out;
}
.toast.err { background: #7f1d1d; }

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: .6rem; padding: .6rem 1rem; }
  .tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; }
  .main { padding: 1rem; }
  .page-head { align-items: flex-start; }
  .table .col-optional { display: none; }
}

/* ---------- RTL touches ---------- */
[dir="rtl"] .mono { direction: ltr; unicode-bidi: embed; display: inline-block; }
[dir="rtl"] .brand strong,
[dir="rtl"] .brand small { letter-spacing: 0; }
