@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --navy: #0f172a;
  --navy-soft: #1e293b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --accent: #3b5bdb;

  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --border-soft: #eef1f6;

  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --transit: #2563eb;
  --transit-bg: #dbeafe;
  --released-bg: #f1f5f9;
  --released: #475569;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 16px 40px rgba(15, 23, 42, 0.18);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); font-size: 14px; }
.spacer { flex: 1; }
svg.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ---------- Login ---------- */
.login-screen {
  position: relative;
  overflow: hidden;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle at 20% 15%, rgba(59, 91, 219, 0.32), transparent 42%),
    radial-gradient(circle at 82% 12%, rgba(37, 99, 235, 0.22), transparent 45%),
    radial-gradient(circle at 50% 100%, rgba(234, 141, 46, 0.12), transparent 55%),
    linear-gradient(160deg, #0b1626 0%, var(--navy) 45%, #142238 100%);
}
.login-stars {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}
.login-horizon {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 34vh;
  min-height: 220px;
  max-height: 420px;
  z-index: 0;
  pointer-events: none;
}
.login-card {
  position: relative;
  z-index: 1;
  background: var(--surface);
  padding: 40px 36px;
  border-radius: var(--radius-lg);
  width: 360px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(255, 255, 255, 0.06);
  animation: login-card-in 0.5s ease;
}
@keyframes login-card-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.login-brand { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 22px; }
.login-brand .brand-logo { height: 40px; width: auto; }
.login-card .subtitle { margin: 0; color: var(--text-muted); font-size: 13px; }
.login-card form { display: flex; flex-direction: column; gap: 16px; margin-top: 6px; }
.login-card label { font-size: 13px; font-weight: 600; color: var(--text-muted); display: flex; flex-direction: column; gap: 6px; }
.field-hint { font-size: 12px; color: var(--text-faint); margin-top: -8px; }

/* ---------- Form controls ---------- */
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 64px; font-family: inherit; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}
input::placeholder { color: var(--text-faint); }

.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, transform 0.05s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--primary-light); color: var(--primary-hover); }
.btn-secondary:hover:not(:disabled) { background: #dbe9ff; }
.btn-secondary.btn-active { background: var(--primary); color: #fff; }
.btn-secondary.btn-active:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }
.btn-danger:hover:not(:disabled) { background: #fdd; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; }
.btn-icon { padding: 8px; }

.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- Shell / sidebar layout ---------- */
.app { min-height: 100vh; display: flex; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--navy);
  color: #fff;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  background: #fff; border-radius: 10px; padding: 12px 14px; margin: 4px 4px 20px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 5px;
}
.sidebar-brand .brand-logo { height: 24px; width: auto; display: block; }
.sidebar-brand .tagline { font-size: 11px; color: var(--text-muted); font-weight: 600; letter-spacing: 0.02em; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 8px;
  color: #cbd5e1; font-size: 13.5px; font-weight: 500;
  cursor: pointer; border: none; background: transparent;
  text-align: left; width: 100%; font-family: inherit;
}
.nav-item svg { opacity: 0.85; }
.nav-item:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item.active svg { opacity: 1; }

.sidebar .spacer { flex: 1; }

.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.09); padding-top: 12px; margin-top: 8px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 12.5px; flex-shrink: 0;
}
.user-card .who { min-width: 0; flex: 1; }
.user-card .who .name { font-size: 13px; font-weight: 600; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-card .who .role { font-size: 11px; color: #94a3b8; text-transform: capitalize; }
.signout-btn {
  margin-top: 6px; width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 9px 10px; border-radius: 8px; border: none; background: transparent;
  color: #94a3b8; font-size: 13px; font-family: inherit; cursor: pointer; font-weight: 500;
}
.signout-btn:hover { background: rgba(255,255,255,0.07); color: #fff; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 18px 30px;
  display: flex; align-items: center; gap: 10px;
}
.page-title { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 1px; }

.content { padding: 26px 30px 60px; max-width: 1360px; width: 100%; margin: 0 auto; flex: 1; }

/* ---------- Stats ---------- */
.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat-card .top-row { display: flex; align-items: center; justify-content: space-between; }
.stat-card .num { font-size: 26px; font-weight: 800; color: var(--navy); letter-spacing: -0.02em; }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; font-weight: 500; }
.auto-hint { color: var(--text-faint); cursor: help; }
.stat-dot { width: 9px; height: 9px; border-radius: 50%; }
.stat-card-clickable { cursor: pointer; transition: border-color 0.12s, transform 0.05s; }
.stat-card-clickable:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.stat-card-clickable:active { transform: translateY(1px); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search-box { position: relative; flex: 1; min-width: 240px; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-faint); }
.search-box input { padding-left: 36px; }
#status-filter { max-width: 180px; }

/* ---------- Table ---------- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: auto;
  max-height: calc(100vh - 300px);
  min-height: 160px;
  position: relative;
}
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  position: sticky;
  top: 0;
  z-index: 5;
  text-align: left;
  padding: 11px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
thead th:hover { color: var(--text); }
thead th.sorted { color: var(--primary); }
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; color: var(--text); white-space: nowrap; }
tbody td.name-cell { font-weight: 600; }
tbody tr { cursor: pointer; transition: background 0.1s; }
tbody tr:nth-child(even):not(.row-overdue) { background: #fbfcfe; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.row-overdue { background: #fef7f6; }
tbody tr.row-overdue:hover { background: #fdeeec; }
tbody tr.row-overdue td.name-cell { box-shadow: inset 3px 0 0 var(--danger); padding-left: 11px; }
.overdue-tag { color: var(--danger); font-size: 11px; font-weight: 700; margin-top: 2px; }
.row-actions { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }
.track-icon-btn {
  background: transparent; border: none; cursor: pointer; padding: 6px;
  border-radius: 6px; color: var(--text-faint); display: flex; align-items: center;
}
.track-icon-btn:hover { background: var(--primary-light); color: var(--primary); }
.track-icon-btn:disabled { opacity: 0.35; cursor: default; }
.track-icon-btn:disabled:hover { background: transparent; color: var(--text-faint); }

.track-link {
  background: transparent; border: none; cursor: pointer; padding: 0;
  color: var(--primary); font-size: 11.5px; font-weight: 600; font-family: inherit;
  display: inline-flex; align-items: center; gap: 4px;
}
.track-link:hover { color: var(--primary-hover); text-decoration: underline; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; }
.badge-IN_TRANSIT { background: var(--transit-bg); color: #1d4ed8; }
.badge-IN_TRANSIT .dot { background: #2563eb; }
.badge-AQABA { background: var(--warning-bg); color: #92400e; }
.badge-AQABA .dot { background: #d97706; }
.badge-ASEZA { background: var(--success-bg); color: #15803d; }
.badge-ASEZA .dot { background: #16a34a; }

/* ---------- Empty state ---------- */
.empty-state { padding: 64px 24px; text-align: center; }
.empty-state .icon-wrap {
  width: 56px; height: 56px; border-radius: 14px; background: var(--primary-light);
  color: var(--primary); display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.empty-state .icon-wrap svg { width: 26px; height: 26px; }
.empty-state h3 { margin: 0 0 6px; font-size: 15.5px; color: var(--text); }
.empty-state p { margin: 0 0 18px; font-size: 13.5px; color: var(--text-muted); }
.empty-state .actions { display: flex; gap: 10px; justify-content: center; }

/* ---------- Loading ---------- */
.table-loading { padding: 48px; text-align: center; color: var(--text-muted); font-size: 13.5px; }
.spinner {
  width: 20px; height: 20px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--primary);
  animation: spin 0.7s linear infinite; display: inline-block; margin-right: 8px; vertical-align: -5px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.pagination { display: flex; gap: 10px; justify-content: center; margin-top: 16px; align-items: center; font-size: 13px; color: var(--text-muted); }

/* ---------- Cards / forms ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.card h3 { margin: 0 0 4px; font-size: 14.5px; }
.card > p.muted { margin-top: 0; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-top: 14px; }
.inline-form .field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 150px; }
.inline-form .field label { font-size: 12px; font-weight: 600; color: var(--text-muted); }
.stacked-form { display: flex; flex-direction: column; gap: 12px; max-width: 320px; }
.checkbox-row { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.checkbox-row input { width: auto; }

.notice { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-top: 10px; background: var(--success-bg); color: #15803d; display: flex; align-items: center; gap: 8px; }
.notice.error { background: var(--danger-bg); color: var(--danger); }

.section-header { margin-bottom: 18px; }
.section-header h2 { margin: 0 0 3px; font-size: 18px; }
.section-header p { margin: 0; }

/* ---------- Import wizard ---------- */
.steps { display: flex; align-items: center; gap: 8px; margin-bottom: 20px; }
.step { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-faint); font-weight: 600; }
.step .num { width: 22px; height: 22px; border-radius: 50%; background: var(--border); color: var(--text-muted); display: flex; align-items: center; justify-content: center; font-size: 11.5px; }
.step.active { color: var(--text); }
.step.active .num { background: var(--primary); color: #fff; }
.step.done .num { background: var(--success); color: #fff; }
.step-sep { width: 28px; height: 1px; background: var(--border); }

.dropzone {
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  background: #fbfcfe;
}
.dropzone .icon-wrap {
  width: 46px; height: 46px; border-radius: 12px; background: var(--primary-light);
  color: var(--primary); display: flex; align-items: center; justify-content: center; margin: 0 auto 12px;
}
.dropzone input[type=file] { max-width: 320px; margin: 12px auto 0; }
.dropzone-actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }

.sample-preview { margin-top: 12px; font-size: 12px; color: var(--text-muted); overflow: auto; border: 1px solid var(--border-soft); border-radius: var(--radius-sm); }
.sample-preview .label { padding: 8px 12px; font-weight: 600; color: var(--text); background: #f8fafc; border-bottom: 1px solid var(--border-soft); }
.sample-preview table { font-size: 12px; }
.sample-preview th, .sample-preview td { padding: 7px 12px; }
#mapping-table { width: 100%; }
#mapping-table td { padding: 7px 4px; }
#mapping-table th { padding: 7px 4px; font-size: 11.5px; text-transform: uppercase; color: var(--text-muted); text-align: left; }
#mapping-table td:first-child { font-weight: 600; }
.mapping-mapped { color: var(--success); font-size: 11px; font-weight: 600; margin-left: 6px; }

/* ---------- Autocomplete dropdown ---------- */
.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  z-index: 30;
  list-style: none;
  margin: 0;
  padding: 4px;
}
.autocomplete-list li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.autocomplete-list li:hover,
.autocomplete-list li.active { background: var(--primary-light); color: var(--primary-hover); }
.autocomplete-list li.no-match { color: var(--text-faint); cursor: default; font-style: italic; }
.autocomplete-list li.no-match:hover { background: none; color: var(--text-faint); }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5); backdrop-filter: blur(1px);
  display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px;
  animation: fade-in 0.12s ease;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: #fff; border-radius: var(--radius-lg); padding: 26px;
  width: 100%; max-width: 640px; max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-lg);
}
.modal.modal-sm { max-width: 400px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal h3 { margin: 0; color: var(--navy); font-size: 16.5px; }
.modal-close { background: transparent; border: none; color: var(--text-faint); cursor: pointer; padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.grid-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.grid-form .full { grid-column: 1 / -1; }
.modal-actions { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.confirm-body { font-size: 14px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.5; }

/* ---------- Toasts ---------- */
#toast-container { position: fixed; top: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 300; max-width: 340px; }
.toast {
  background: var(--navy); color: #fff; padding: 12px 14px; border-radius: 9px;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 9px;
  animation: toast-in 0.18s ease;
}
.toast.success { background: #14532d; }
.toast.error { background: #7f1d1d; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Users table ---------- */
#users-table select { width: auto; }

@media (max-width: 800px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 14px; gap: 10px; overflow-x: auto; }
  .sidebar-brand { padding: 6px 10px; margin: 0 8px 0 0; flex-shrink: 0; flex-direction: row; align-items: center; }
  .sidebar-brand .tagline { display: none; }
  .sidebar-brand .brand-logo { height: 20px; }
  .sidebar-nav { flex-direction: row; flex-shrink: 0; gap: 2px; }
  .nav-item { white-space: nowrap; flex-shrink: 0; padding: 8px 10px; }
  .sidebar .spacer { display: none; }
  .sidebar-footer { border-top: none; margin: 0; padding: 0; flex-shrink: 0; }
  .user-card .who { display: none; }
  .signout-btn { display: none; }
  .grid-form { grid-template-columns: 1fr; }
  .topbar { padding: 16px 18px; }
  .content { padding: 20px 18px 50px; }
}
