/* ── Reset & base ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #f5f5f3;
  --surface:   #ffffff;
  --border:    #e4e4e0;
  --border-md: #d0d0cc;
  --text:      #1a1a18;
  --text-2:    #6b6b67;
  --text-3:    #9b9b97;
  --accent:    #1a56db;
  --accent-bg: #eff4ff;
  --danger:    #c81e1e;
  --danger-bg: #fdf2f2;
  --warn:      #b45309;
  --warn-bg:   #fffbeb;
  --success:   #057a55;
  --success-bg:#f0fdf4;
  --sidebar-w: 200px;
  --topbar-h:  52px;
  --radius:    8px;
  --radius-sm: 5px;
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
}

html, body { height: 100%; font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; font-size: 13px; cursor: pointer; }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.shell { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto;
  padding-bottom: 1rem;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 14px; border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.brand-icon {
  width: 30px; height: 30px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 600; flex-shrink: 0;
}
.brand-icon--lg { width: 44px; height: 44px; border-radius: 10px; font-size: 20px; }
.brand-name { font-size: 13px; font-weight: 600; color: var(--text); }
.brand-sub  { font-size: 11px; color: var(--text-3); }

.nav-section {
  font-size: 10px; font-weight: 600; letter-spacing: .06em;
  color: var(--text-3); text-transform: uppercase;
  padding: 12px 16px 3px;
}

.nav-link {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 16px; color: var(--text-2);
  font-size: 13px; border-right: 2px solid transparent;
  transition: background 0.1s, color 0.1s;
}
.nav-link svg { flex-shrink: 0; opacity: 0.6; }
.nav-link:hover { background: var(--bg); color: var(--text); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-bg); border-right-color: var(--accent); font-weight: 500; }
.nav-link.active svg { opacity: 1; }

.sidebar-footer { margin-top: auto; padding: 12px 16px 0; }
.logout-btn {
  width: 100%; display: flex; align-items: center; gap: 6px;
  padding: 7px 0; background: none; border: none;
  color: var(--text-3); font-size: 12px;
}
.logout-btn:hover { color: var(--text); }

/* ── Main area ─────────────────────────────────────────────────────────── */
.main-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  height: var(--topbar-h); min-height: var(--topbar-h);
  background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 1.5rem; gap: 12px;
}
.page-title { font-size: 15px; font-weight: 600; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.page-content { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* ── Alerts ────────────────────────────────────────────────────────────── */
.alert {
  padding: 10px 1.5rem; font-size: 13px; border-bottom: 1px solid transparent;
}
.alert-success { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.alert-error   { background: var(--danger-bg);  color: var(--danger);  border-color: #fca5a5; }
.alert-info    { background: var(--accent-bg);  color: var(--accent);  border-color: #bfdbfe; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 7px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-md); background: var(--surface);
  color: var(--text); font-size: 13px; font-weight: 500;
  transition: background 0.1s; white-space: nowrap;
}
.btn:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.btn-primary  { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: #1648c0; color: #fff; }
.btn-danger   { background: var(--danger-bg); color: var(--danger); border-color: #fca5a5; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn--full { width: 100%; justify-content: center; }
.btn--outline-full { width: 100%; justify-content: flex-start; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font-size: 13px; }
.btn--outline-full:hover { background: var(--bg); }

/* ── Form inputs ───────────────────────────────────────────────────────── */
.input {
  display: block; width: 100%;
  padding: 7px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-md); background: var(--surface);
  font-size: 13px; font-family: inherit; color: var(--text);
  transition: border-color 0.1s;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-bg); }
select.input { cursor: pointer; }
.textarea { resize: vertical; min-height: 72px; }
.input-label { display: block; font-size: 12px; font-weight: 500; color: var(--text-2); margin-bottom: 4px; }

.filter-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 1rem; }
.filter-bar .input { width: auto; flex: 1; min-width: 150px; }
.select { width: auto; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 1rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 13px; font-weight: 600; }
.card-link  { font-size: 12px; color: var(--accent); }
.card-footer { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ── Stats grid ────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0,1fr));
  gap: 12px; margin-bottom: 1.5rem;
}
.stats-grid--sm { grid-template-columns: repeat(2, minmax(0,1fr)); max-width: 500px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.stat-card--warn { border-color: #fcd34d; background: var(--warn-bg); }
.stat-label { font-size: 11px; color: var(--text-2); margin-bottom: 4px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 600; line-height: 1; margin-bottom: 4px; }
.stat-sub   { font-size: 11px; color: var(--text-3); }

/* ── Layout helpers ────────────────────────────────────────────────────── */
.two-col-layout { display: grid; grid-template-columns: 1fr 340px; gap: 1rem; align-items: start; }
.detail-layout  { display: grid; grid-template-columns: 1fr 300px; gap: 1rem; align-items: start; }
.detail-main > .card, .detail-side > .card { margin-bottom: 1rem; }
.right-stack > .card { margin-bottom: 1rem; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  font-size: 11px; font-weight: 600; color: var(--text-2);
  text-align: left; padding: 8px 16px;
  border-bottom: 1px solid var(--border); white-space: nowrap;
  text-transform: uppercase; letter-spacing: .04em;
}
.data-table td { padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg); }
.empty-row { text-align: center; color: var(--text-3); padding: 2rem !important; }
.sub-text { font-size: 11px; color: var(--text-3); }
.fw-500 { font-weight: 500; }
.order-link { font-weight: 500; color: var(--accent); }

/* ── Badges ────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
}
.badge--pending    { background: #fef3c7; color: #92400e; }
.badge--pickedup   { background: #dbeafe; color: #1e40af; }
.badge--downloaded { background: #ede9fe; color: #5b21b6; }
.badge--processing { background: #e0f2fe; color: #075985; }
.badge--intransit  { background: #ecfdf5; color: #065f46; }
.badge--delivered  { background: #d1fae5; color: #065f46; }
.badge--done       { background: var(--bg); color: var(--text-3); border: 1px solid var(--border); }

.badge--pay-pending   { background: #fef3c7; color: #92400e; }
.badge--pay-processed { background: #d1fae5; color: #065f46; }
.badge--pay-failed    { background: #fee2e2; color: #991b1b; }
.badge--pay-rejected  { background: #fee2e2; color: #991b1b; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.action-form { display: flex; flex-direction: column; gap: 8px; padding: 14px 16px; }
.action-form--row { flex-direction: row; flex-wrap: wrap; align-items: flex-end; }
.action-form--row .input { min-width: 140px; }
.field { margin-bottom: 14px; }
.field--check { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ── Detail grid (dl) ──────────────────────────────────────────────────── */
.detail-grid {
  display: grid; grid-template-columns: 130px 1fr;
  gap: 1px; padding: 4px 0;
}
.detail-grid dt { font-size: 12px; color: var(--text-2); padding: 8px 16px; font-weight: 500; }
.detail-grid dd { font-size: 13px; padding: 8px 16px; }

/* ── Timeline ──────────────────────────────────────────────────────────── */
.timeline { padding: 12px 16px; }
.timeline-row { display: flex; gap: 10px; margin-bottom: 14px; }
.timeline-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-md); margin-top: 4px; flex-shrink: 0; }
.timeline-body { flex: 1; font-size: 13px; }
.timeline-meta { font-size: 11px; color: var(--text-3); margin-left: 6px; }
.timeline-note { font-size: 12px; color: var(--text-2); margin-top: 3px; font-style: italic; }

/* ── Route list (dashboard) ────────────────────────────────────────────── */
.route-list { padding: 4px 0; }
.route-row { display: flex; justify-content: space-between; align-items: center; padding: 9px 16px; border-bottom: 1px solid var(--border); }
.route-row:last-child { border-bottom: none; }
.route-name  { font-size: 13px; font-weight: 500; }
.route-count { font-size: 12px; color: var(--text-3); }
.route-count.has-pending { color: var(--warn); font-weight: 500; }
.empty-msg { padding: 16px; color: var(--text-3); font-size: 13px; text-align: center; }

/* ── SMS log ───────────────────────────────────────────────────────────── */
.sms-log { max-height: 520px; overflow-y: auto; }
.sms-row { padding: 10px 16px; border-bottom: 1px solid var(--border); }
.sms-row--failed { background: var(--danger-bg); }
.sms-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 3px; flex-wrap: wrap; }
.sms-time { font-size: 11px; color: var(--text-3); margin-left: auto; }
.sms-body { font-size: 12px; color: var(--text-2); }

/* ── Pagination ────────────────────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; margin-top: 1rem; }
.page-btn { padding: 5px 10px; border: 1px solid var(--border-md); border-radius: var(--radius-sm); font-size: 12px; color: var(--text); background: var(--surface); }
.page-btn:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.page-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Login page ────────────────────────────────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card { width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; }
.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-title { font-size: 18px; font-weight: 600; margin-top: 10px; }
.login-sub   { font-size: 13px; color: var(--text-3); }

/* ── Form layout helpers ────────────────────────────────────────────────── */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 140px; }
.form-row--3 .field:last-child { flex: 0 0 110px; }
.form-actions { display: flex; gap: 8px; padding-top: 4px; }
.section-label { font-size: 11px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .06em; margin: 4px 0 8px; }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .two-col-layout, .detail-layout { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .sidebar { display: none; }
  .stats-grid { grid-template-columns: 1fr; }
}
