:root {
  /* Brand palette */
  --brand-charcoal: #262626;
  --brand-gold: #e5bd7c;
  --brand-stone: #a4aeb5;
  --brand-emerald: #1e3f2e;

  /* Surface & background (derived only from brand colors) */
  --bg: color-mix(in srgb, var(--brand-gold) 12%, white);
  --bg-soft: color-mix(in srgb, var(--brand-stone) 16%, white);
  --surface: white;
  --surface-soft: color-mix(in srgb, var(--brand-gold) 7%, white);

  /* Text */
  --text: var(--brand-charcoal);
  --text-soft: color-mix(in srgb, var(--brand-charcoal) 86%, var(--brand-stone));
  --muted: color-mix(in srgb, var(--brand-charcoal) 58%, var(--brand-stone));

  /* Roles */
  --primary: var(--brand-emerald);
  --primary-hover: color-mix(in srgb, var(--brand-emerald) 84%, var(--brand-charcoal));
  --on-primary: white;
  --accent: var(--brand-gold);
  --accent-soft: color-mix(in srgb, var(--brand-gold) 34%, white);
  --accent-strong: color-mix(in srgb, var(--brand-gold) 76%, var(--brand-charcoal));
  --success: var(--brand-emerald);
  --success-soft: color-mix(in srgb, var(--brand-emerald) 16%, white);
  --danger: var(--brand-charcoal);
  --danger-soft: color-mix(in srgb, var(--brand-charcoal) 12%, white);

  /* Borders & shadows */
  --border: rgba(38, 38, 38, 0.12);
  --border-soft: rgba(38, 38, 38, 0.06);
  --shadow-sm: 0 1px 2px rgba(38, 38, 38, 0.06);
  --shadow-md: 0 8px 24px rgba(38, 38, 38, 0.08);
  --shadow-lg: 0 24px 48px rgba(38, 38, 38, 0.14);

  /* Radii */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
  font-family: "Yekan Bakh", "Vazirmatn", Tahoma, sans-serif;
}

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(229, 189, 124, 0.08) 0%, transparent 42%),
    radial-gradient(circle at 88% 92%, rgba(30, 63, 46, 0.05) 0%, transparent 46%),
    var(--bg);
  color: var(--text);
  position: relative;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 1040px;
  margin: 0 auto;
  padding: 24px 18px 32px;
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  gap: 12px;
}

h1 {
  font-size: 24px;
  margin: 0;
  letter-spacing: -0.2px;
  color: var(--brand-charcoal);
  font-weight: 700;
  position: relative;
  padding-bottom: 6px;
}

h1::after {
  content: "";
  position: absolute;
  bottom: 0;
  right: 0;
  width: 38px;
  height: 3px;
  border-radius: 999px;
  background: var(--accent);
}

h2, h3 {
  color: var(--brand-charcoal);
  font-weight: 700;
}

h3 {
  font-size: 17px;
  margin: 0 0 10px;
}

/* ---------- Card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}

/* ---------- Form controls ---------- */
form {
  display: grid;
  gap: 12px;
}

input,
select,
button {
  font-size: 16px;
  border-radius: var(--radius-md);
  padding: 12px 14px;
  border: 1px solid var(--border);
  font-family: inherit;
}

input,
select {
  background: var(--surface);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  min-height: 44px;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent-strong);
  box-shadow: 0 0 0 3px rgba(229, 189, 124, 0.22);
}

input::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

/* ---------- Buttons ---------- */
button {
  border: 1px solid transparent;
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease, color 0.15s ease;
  min-height: 44px;
}

button:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

button:active:not(:disabled) {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  box-shadow: none;
}

button.ghost {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
}

button.ghost:hover:not(:disabled) {
  background: rgba(38, 38, 38, 0.04);
  border-color: rgba(38, 38, 38, 0.2);
}

button.danger {
  background: var(--danger);
  color: white;
}

button.danger:hover:not(:disabled) {
  background: color-mix(in srgb, var(--brand-charcoal) 88%, var(--brand-emerald));
}

/* ---------- Top tabs (auth-switch reuses .tab) ---------- */
.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

nav.tabs {
  background: var(--surface);
  padding: 10px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

nav.tabs .tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: transparent;
  border: none;
  box-shadow: none;
  width: 100%;
  height: 64px;
  padding: 0;
  margin: 0;
  color: var(--muted);
  border-radius: var(--radius-md);
  min-height: 0;
}

nav.tabs .tab:hover:not(.active) {
  background: rgba(38, 38, 38, 0.04);
  color: var(--text);
}

.tab-icon {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  font-size: 18px;
  line-height: 1;
  border-radius: 10px;
  background: var(--bg-soft);
  border: 1px solid var(--border-soft);
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

nav.tabs .tab-label {
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}

nav.tabs .tab.active {
  background: var(--success-soft);
  color: var(--brand-emerald);
}

nav.tabs .tab.active .tab-icon {
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* Auth switch tabs (login/register) */
.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.auth-switch .tab {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: none;
  height: auto;
  padding: 10px;
  border-radius: var(--radius-md);
  font-weight: 600;
}

.auth-switch .tab.active {
  background: var(--brand-emerald);
  color: white;
  border-color: var(--brand-emerald);
}

.tabpanel {
  display: none;
}

.tabpanel.active {
  display: block;
}

/* ---------- Lead card ---------- */
.lead-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.lead-card:hover {
  box-shadow: var(--shadow-md);
}

.lead-title {
  font-weight: 700;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
  color: var(--brand-charcoal);
  letter-spacing: 0.2px;
}

.lead-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 0.95fr;
  gap: 12px;
  align-items: start;
}

.lead-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-soft);
}

.lead-table th,
.lead-table td {
  text-align: right;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 14px;
}

.lead-table tr:last-child th,
.lead-table tr:last-child td {
  border-bottom: none;
}

.lead-table th {
  width: 40%;
  color: var(--text-soft);
  background: rgba(38, 38, 38, 0.04);
  font-weight: 600;
}

.lead-table td {
  color: var(--text);
  background: transparent;
}

.lead-actions {
  display: grid;
  gap: 10px;
}

.lead-actions select,
.lead-actions button {
  width: 100%;
}

.meta {
  font-size: 13px;
  color: var(--muted);
  margin: 4px 0;
  line-height: 1.6;
}

/* ---------- Badge ---------- */
.badge {
  display: inline-block;
  font-size: 12px;
  background: var(--accent-soft);
  color: var(--brand-charcoal);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  margin-bottom: 0;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.badge.badge-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ---------- Status text ---------- */
.error {
  color: var(--danger);
  font-size: 14px;
}

.ok {
  color: var(--success);
  font-size: 14px;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.hidden {
  display: none !important;
}

/* ---------- Filters ---------- */
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 14px;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.field-full {
  grid-column: 1 / -1;
}

/* ---------- Admin ---------- */
.lookup-card {
  margin-bottom: 14px;
}

.admin-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.admin-actions button {
  font-weight: 600;
}

.active-admin-action {
  background: var(--brand-emerald) !important;
  color: white !important;
  border-color: var(--brand-emerald) !important;
}

.wallet-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.wallet-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.wallet-edit input {
  max-width: 110px;
}

.lookup-form {
  display: grid;
  grid-template-columns: 1fr 120px 120px;
  gap: 10px;
  margin-bottom: 12px;
}

.lookup-form.single-row {
  grid-template-columns: 1fr 180px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.lookup-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 480px;
}

.lookup-table th,
.lookup-table td {
  text-align: right;
  border-top: 1px solid var(--border-soft);
  padding: 10px 8px;
  font-size: 14px;
  vertical-align: middle;
}

.lookup-table th {
  color: var(--text-soft);
  font-weight: 700;
  background: rgba(38, 38, 38, 0.03);
}

.lookup-table tr:hover td {
  background: rgba(229, 189, 124, 0.06);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(38, 38, 38, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
  animation: modalFadeIn 0.18s ease-out;
}

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px 22px 20px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: modalPopIn 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  position: relative;
}

.modal.modal-large {
  max-width: 640px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 14px;
  left: 14px;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  box-shadow: none;
  line-height: 1;
  font-size: 20px;
}

.modal-close:hover {
  background: rgba(38, 38, 38, 0.06);
  color: var(--brand-charcoal);
  box-shadow: none;
}

.modal-title {
  margin: 0 0 14px;
  font-size: 18px;
  color: var(--brand-charcoal);
  font-weight: 700;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent);
  display: inline-block;
}

.modal-body {
  margin: 0 0 6px;
  color: var(--text);
  font-size: 15px;
  line-height: 1.85;
}

.modal-body strong {
  color: var(--brand-charcoal);
  font-size: 17px;
  margin: 0 4px;
  background: var(--accent-soft);
  padding: 2px 8px;
  border-radius: 8px;
}

.modal-question {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.modal-actions-stack {
  grid-template-columns: 1fr;
  margin-top: 14px;
}

/* ---------- Lead details modal ---------- */
.lead-details-summary {
  display: grid;
  gap: 14px;
}

.lead-detail-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.lead-detail-table th,
.lead-detail-table td {
  text-align: right;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 14px;
  vertical-align: top;
}

.lead-detail-table tr:last-child th,
.lead-detail-table tr:last-child td {
  border-bottom: none;
}

.lead-detail-table th {
  width: 38%;
  color: var(--text-soft);
  background: rgba(38, 38, 38, 0.04);
  font-weight: 600;
}

.lead-detail-table td {
  color: var(--text);
  background: var(--surface);
  line-height: 1.8;
}

.lead-detail-section-title {
  margin: 6px 0 -4px;
  color: var(--brand-charcoal);
  font-weight: 700;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lead-detail-section-title::before {
  content: "";
  width: 4px;
  height: 16px;
  background: var(--accent);
  border-radius: 4px;
}

/* ---------- Tel link ---------- */
.tel-link {
  color: var(--brand-charcoal);
  font-weight: 700;
  text-decoration: none;
  letter-spacing: 0.3px;
}

.tel-link:hover {
  color: var(--accent-strong);
  text-decoration: underline;
}

.tel-link::before {
  content: "تماس: ";
  color: var(--accent-strong);
  font-weight: 600;
}

/* ---------- Report section (collapsible) ---------- */
.report-section {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--surface-soft);
  animation: reportSlideDown 0.2s ease-out;
}

@keyframes reportSlideDown {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalPopIn {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes sheetSlideUp {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ---------- Responsive: tablet ---------- */
@media (max-width: 960px) {
  .lead-grid-3 {
    grid-template-columns: 1fr 1fr;
  }
  .lead-actions {
    grid-column: 1 / -1;
  }
}

/* ---------- Responsive: mobile ---------- */
@media (max-width: 720px) {
  body {
    font-size: 15px;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .app {
    max-width: 100%;
    padding: 14px 14px 24px;
  }

  .topbar {
    margin-bottom: 12px;
  }

  h1 {
    font-size: 20px;
    padding-bottom: 4px;
  }

  h1::after {
    width: 28px;
    height: 2px;
  }

  /* Bottom-fixed nav */
  nav.tabs {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    grid-template-columns: repeat(4, 1fr);
    background: var(--surface);
    border: none;
    border-top: 1px solid var(--border);
    border-radius: 0;
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    z-index: 50;
    box-shadow: 0 -8px 24px rgba(38, 38, 38, 0.07);
    margin-bottom: 0;
  }

  nav.tabs .tab {
    height: 56px;
  }

  nav.tabs .tab-label {
    font-size: 10px;
  }

  /* Auth switch and other plain .tabs grids */
  .auth-switch {
    grid-template-columns: 1fr 1fr;
  }

  .lookup-form {
    grid-template-columns: 1fr;
  }

  .lookup-form.single-row {
    grid-template-columns: 1fr;
  }

  .admin-actions {
    grid-template-columns: 1fr;
  }

  .lead-grid-3 {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .lead-card {
    padding: 14px;
  }

  .lead-actions button,
  button {
    min-height: 48px;
  }

  .filter-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* Sticky search at top of leads tab */
  #leadsTab .filter-grid {
    position: sticky;
    top: 0;
    z-index: 5;
    margin: -14px -14px 12px;
    padding: 12px 14px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }

  /* Modals as bottom sheets */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    max-width: 100%;
    width: 100%;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-height: 92vh;
    overflow-y: auto;
    padding: 20px 18px calc(18px + env(safe-area-inset-bottom));
    animation: sheetSlideUp 0.24s cubic-bezier(0.2, 0.9, 0.3, 1.1);
  }

  .modal.modal-large {
    max-width: 100%;
    max-height: 92vh;
  }

  .modal::before {
    content: "";
    display: block;
    width: 44px;
    height: 4px;
    margin: -6px auto 14px;
    background: var(--brand-stone);
    opacity: 0.55;
    border-radius: 4px;
  }

  .modal-close {
    top: 12px;
    left: 12px;
  }

  .modal-title {
    font-size: 17px;
  }

  .lead-detail-table th {
    width: 42%;
  }

  .lookup-table th,
  .lookup-table td {
    padding: 10px 6px;
    font-size: 13px;
  }

  /* Users list -> stacked cards on mobile */
  .users-table-wrap {
    overflow: visible;
  }

  .users-table {
    min-width: 0;
    border: none;
    background: transparent;
  }

  .users-table thead {
    display: none;
  }

  .users-table tbody {
    display: grid;
    gap: 12px;
  }

  .users-table tr {
    display: grid;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    box-shadow: var(--shadow-sm);
  }

  .users-table tr:hover td {
    background: transparent;
  }

  .users-table td {
    display: grid;
    grid-template-columns: 110px 1fr;
    align-items: start;
    gap: 8px;
    padding: 0;
    border: none;
    border-top: 1px dashed var(--border-soft);
    padding-top: 8px;
  }

  .users-table td:first-child {
    border-top: none;
    padding-top: 0;
  }

  .users-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    font-size: 12px;
  }

  .users-table td[data-label="کیف پول"] {
    grid-template-columns: 1fr;
  }

  .users-table td[data-label="کیف پول"]::before {
    margin-bottom: 4px;
  }

  .users-table .wallet-edit {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .users-table .wallet-edit-row {
    width: 100%;
    align-items: center;
    flex-wrap: nowrap;
  }

  .users-table .wallet-edit-row input {
    flex: 1 1 auto;
    max-width: none;
    min-width: 0;
  }

  .users-table .wallet-edit-row button {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 10px 14px;
  }
}

@media (max-width: 380px) {
  h1 {
    font-size: 18px;
  }

  nav.tabs .tab-label {
    font-size: 9px;
  }
}

/* ---------- OTP auth & shared wallet (APP-A parity) ---------- */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.balance-pill {
  display: flex;
  align-items: baseline;
  gap: 6px;
  background: var(--success-soft);
  padding: 8px 12px;
  border-radius: var(--radius-pill);
  font-size: 13px;
}

.balance-pill strong {
  font-size: 18px;
  color: var(--primary);
}

.balance-unit {
  color: var(--muted);
  font-size: 12px;
}

.auth-card .field span {
  display: block;
  margin-bottom: 4px;
}

.auth-card .field input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 16px;
  background: var(--surface-soft);
}

.auth-sub {
  margin-top: -6px;
}

.primary-btn {
  width: 100%;
  margin-top: 10px;
}

.wallet-hero {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  margin-bottom: 16px;
}

.coin-icon {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent-soft);
  position: relative;
}

.coin-icon::after {
  content: "";
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.85;
}

.amount-row {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
}

.amount-row .unit {
  font-size: 14px;
  font-weight: 400;
  color: var(--muted);
  margin-right: 4px;
}

.tariff-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--border-soft);
  font-size: 14px;
}

.tariff-price {
  color: var(--muted);
  white-space: nowrap;
  text-align: left;
}

.charge {
  margin-top: 16px;
}

.support-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  margin-top: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
}

.tx-card .tx-amount {
  font-weight: 700;
}

.amt-plus {
  color: var(--success);
}

.amt-minus {
  color: var(--danger);
}
