:root {
  --primary: #1DA1F2;
  --secondary: #FFA500;
  --bg: #f2f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --danger: #dc2626;
  --green: #10b981;
  --amber: #f59e0b;
}

* { box-sizing: border-box; }

/* Make the hidden attribute always win over any display rule. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Tajawal", "Inter", system-ui, sans-serif;
}

/* English: prefer Inter for Latin text. */
html:lang(en) body { font-family: "Inter", "Tajawal", system-ui, sans-serif; }

/* Top bar */
.topbar {
  background: linear-gradient(135deg, var(--primary), #0e7cc4);
  color: #fff;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
}
.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 800; }
.topbar h1 span { color: var(--secondary); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.who { font-size: 14px; opacity: 0.9; }

/* Buttons */
.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.primary { background: var(--primary); color: #fff; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.ghost { background: rgba(255,255,255,0.15); color: #fff; }
.btn.ghost.sm { background: #eef2f7; color: var(--muted); }

/* Login */
.center {
  min-height: calc(100vh - 60px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.05);
}
.login-card {
  padding: 36px 40px;
  text-align: center;
  max-width: 380px;
  width: 100%;
}
.login-card h2 { margin: 0 0 6px; font-size: 22px; }
.muted { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
#login-widget { display: flex; justify-content: center; }

/* Layout */
.wrap { max-width: 1000px; margin: 0 auto; padding: 20px; }

.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 20px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Vendor table */
.table { display: flex; flex-direction: column; gap: 10px; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }

.vendor-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: grid;
  grid-template-columns: 2fr 1.2fr 0.8fr auto auto;
  gap: 14px;
  align-items: center;
}
.vendor-name { font-weight: 800; font-size: 15px; }
.vendor-meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.vendor-sectors { color: var(--text); font-size: 13px; }
.vendor-comm { color: var(--secondary); font-weight: 700; font-size: 13px; }

.status {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.status.pending { background: #fef3c7; color: #92400e; }
.status.active { background: #d1fae5; color: #065f46; }
.status.suspended { background: #fee2e2; color: #991b1b; }

.vendor-actions { display: flex; gap: 6px; justify-content: flex-end; }

@media (max-width: 720px) {
  .vendor-row {
    grid-template-columns: 1fr;
    gap: 8px;
  }
  .vendor-actions { justify-content: flex-start; }
}

/* Vendor row — commission sub-lines */
.comm-rates { color: var(--muted); font-size: 11.5px; font-weight: 400; margin-top: 2px; }

/* Commission modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
  animation: backdrop-in 0.15s ease;
}
.modal {
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  width: 100%;
  max-width: 480px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  animation: modal-in 0.18s ease;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close {
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px 22px; }

.cm-section { margin-bottom: 24px; }
.cm-section:last-child { margin-bottom: 0; }
.cm-section h4 { margin: 0 0 12px; font-size: 13px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; }

.cm-type { display: flex; gap: 18px; margin-bottom: 12px; flex-wrap: wrap; }
.cm-type label { display: flex; align-items: center; gap: 6px; font-size: 14px; cursor: pointer; }

.cm-value-row { display: flex; align-items: center; gap: 8px; }
.cm-value-row input[type="number"] {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}
.cm-unit { color: var(--muted); font-size: 13px; min-width: 78px; }

.cm-rates-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.cm-empty { color: var(--muted); font-size: 13px; margin: 0; }
.cm-rate-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.cm-rate-info { display: flex; flex-direction: column; gap: 2px; }
.cm-rate-name { font-weight: 700; font-size: 14px; }
.cm-rate-value { color: var(--secondary); font-weight: 700; font-size: 12.5px; }
.cm-rate-actions { display: flex; gap: 6px; }

.cm-add-rate { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cm-add-rate input[type="text"] { flex: 1 1 140px; min-width: 120px; }
.cm-add-rate input[type="number"] { width: 90px; }
.cm-add-rate input,
.cm-add-rate select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
}

@keyframes backdrop-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Admin nav tabs */
.admin-nav {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.nav-tab {
  border: none;
  background: transparent;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-family: inherit;
}
.nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Deals ledger — stats */
.deals-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-card {
  flex: 1 1 160px;
  min-width: 140px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.stat-value { font-size: 18px; font-weight: 800; color: var(--text); margin-bottom: 4px; }
.stat-card.blue .stat-value { color: var(--primary); }
.stat-card.orange .stat-value { color: var(--secondary); }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; }

/* Deals ledger — rows */
.deal-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}
.deal-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.deal-vendor { font-weight: 800; font-size: 15px; }
.deal-source { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; }
.deal-source.request { background: #dbeafe; color: #1d4ed8; }
.deal-source.manual { background: #fef3c7; color: #92400e; }
.deal-date { margin-inline-start: auto; color: var(--muted); font-size: 12px; }
.deal-customer { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.deal-nums { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 6px; }
.deal-num { font-size: 13px; color: var(--text); }
.deal-comm { font-size: 13.5px; font-weight: 700; color: var(--secondary); margin-bottom: 4px; }
.deal-extra { font-size: 12px; color: var(--muted); }

/* Deals filters */
.deals-filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.deals-filters select,
.deals-filters input[type="date"] {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
.df-label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.df-label input[type="date"] { max-width: 150px; }

/* Add-vendor (invite) */
.status.invited { background: #dbeafe; color: #1d4ed8; }
.vendors-head { display: flex; margin-bottom: 14px; }

.av-field { margin-bottom: 14px; }
.av-field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.av-field input[type="text"],
.av-field input[type="number"],
.av-field select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}
.av-field input:focus,
.av-field select:focus { outline: none; border-color: var(--primary); }

.av-sectors { display: flex; flex-direction: column; gap: 6px; }
.av-sector { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); }
.av-sector input { width: 17px; height: 17px; }

.av-commission { display: flex; align-items: center; gap: 8px; }
.av-commission select { flex: 1; }
.av-commission input[type="number"] { width: 90px; }

.av-result {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 14px;
}
.av-result-title { font-weight: 800; font-size: 14px; color: #065f46; margin-bottom: 4px; }
.av-result-hint { font-size: 12.5px; color: #047857; margin-bottom: 10px; }
.av-result-link { display: flex; gap: 8px; }
.av-result-link input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 12.5px;
  font-family: inherit;
  color: var(--text);
  background: #fff;
}
#av-create { width: 100%; }
