:root {
  --bg: #f6f5f2;
  --paper: #ffffff;
  --ink: #2a2733;
  --muted: #7a7785;
  --line: #ebe8e1;
  --teal: #3d3868;
  --teal-dark: #2f2a52;
  --gold: #cbb79f;
  --gold-soft: #f7f1ea;
  --danger: #a14b4b;
  --ok: #2f7d56;
  --pending: #b8873a;
  --shadow: 0 10px 28px rgba(42, 39, 51, 0.06);
  --radius: 20px;
  --sidebar-w: 260px;
  --mobile-bar-h: 58px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Vazirmatn, Tahoma, sans-serif;
  background:
    radial-gradient(900px 420px at 100% 0%, rgba(203, 183, 159, 0.18) 0%, transparent 55%),
    radial-gradient(700px 360px at 0% 100%, rgba(61, 56, 104, 0.05) 0%, transparent 50%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}
body.nav-locked { overflow: hidden; }

a { color: var(--teal); text-decoration: none; }
.muted { color: var(--muted); }
.flash {
  background: #eaf7f0;
  border: 1px solid #cfe8d8;
  color: #245c3d;
  padding: 12px 16px;
  border-radius: 14px;
  margin-bottom: 18px;
}

/* —— Shell —— */
.shell {
  display: flex;
  min-height: 100vh;
  position: relative;
}
.mobile-bar { display: none; }
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(42, 39, 51, 0.38);
  z-index: 40;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #fffdfb;
  color: var(--ink);
  border-left: 1px solid var(--line);
  padding: 24px 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 50;
}
.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 22px;
  padding: 4px 6px;
}
.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 14px;
  background: #0b0b0b;
  border: 1px solid #eadfce;
  flex-shrink: 0;
  display: block;
}
.brand-logo.sm {
  width: 34px;
  height: 34px;
  border-radius: 11px;
}
.mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--gold-soft);
  color: var(--teal);
  display: grid;
  place-items: center;
  font-weight: 800;
  border: 1px solid #eadfce;
  flex-shrink: 0;
}
.mark.sm {
  width: 34px;
  height: 34px;
  border-radius: 11px;
  font-size: 13px;
}
.brand h1 { font-size: 17px; margin: 0; color: var(--teal-dark); line-height: 1.35; }
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav a {
  display: block;
  width: 100%;
  text-align: right;
  background: transparent;
  border: 0;
  color: var(--ink);
  font: inherit;
  padding: 12px 14px;
  border-radius: 14px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav a:hover { background: #f4f1eb; }
.nav a.active {
  background: #efeaf8;
  color: var(--teal-dark);
  font-weight: 700;
}
.side-note {
  margin-top: 10px;
  background: #f7f1ea;
  border: 1px solid #eadfce;
  color: #6d5d4b;
  border-radius: 16px;
  padding: 12px 13px;
  font-size: 12px;
  line-height: 1.8;
}
.side-note.warn {
  background: #fff4e8;
  border-color: #f0d7b4;
  color: #8a5b1f;
}
.logout-form { margin-top: 12px; }
.logout-btn { width: 100%; }

.main {
  flex: 1;
  padding: 28px 30px 48px;
  min-width: 0;
  width: 100%;
}

/* —— Page chrome —— */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 24px; color: var(--teal-dark); }

.dash-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 22px;
}
.dash-head h2 { margin: 8px 0 4px; font-size: 26px; color: var(--teal-dark); }
.dash-head-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.role-pill {
  display: inline-flex;
  align-items: center;
  background: #f3eee7;
  color: var(--teal);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}

.metric-row {
  display: grid;
  grid-template-columns: 1.35fr repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.metric-row.secondary {
  grid-template-columns: repeat(4, 1fr);
}
.metric-card, .panel, .card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.metric-card h3, .panel h3, .card h3 {
  margin: 0 0 8px;
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}
.metric-value { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; color: var(--teal-dark); word-break: break-word; }
.metric-value.sm { font-size: 18px; line-height: 1.5; }
.metric-meta {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}
.metric-hero {
  background: linear-gradient(150deg, #ffffff 0%, #faf6f1 100%);
}
.trend {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 600;
}
.trend.up { background: #eaf7f0; color: var(--ok); }
.trend.down { background: #fbebea; color: var(--danger); }

.dash-mid {
  display: grid;
  grid-template-columns: 1.45fr 0.9fr;
  gap: 14px;
  margin-bottom: 14px;
}
.dash-mid.secondary { grid-template-columns: 1.1fr 0.9fr; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-head h3 { margin: 0; color: var(--teal-dark); font-size: 16px; font-weight: 700; }
.soft-chip {
  background: var(--gold-soft);
  color: var(--teal);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
}
.linkish { color: var(--muted); font-size: 13px; }
.linkish:hover { color: var(--teal); }
.chart-wrap { height: 260px; position: relative; }
.status-bubbles {
  min-height: 190px;
  display: grid;
  place-items: center;
  position: relative;
  margin: 8px 0 18px;
}
.status-orb {
  width: var(--size);
  height: var(--size);
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 14px;
  box-shadow: 0 10px 24px rgba(42,39,51,.08);
  position: absolute;
}
.status-orb.paid {
  background: #4a446e;
  inset-inline-end: 18%;
  top: 18%;
}
.status-orb.pending {
  background: var(--gold);
  color: #4a3d2d;
  inset-inline-start: 18%;
  bottom: 18%;
}
.status-orb.failed {
  background: #e3ddd4;
  color: var(--teal);
  inset-inline-start: 42%;
  top: 8%;
}
.status-legend { display: grid; gap: 10px; }
.status-legend > div {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.paid { background: #4a446e; }
.dot.pending { background: var(--gold); }
.dot.failed { background: #e3ddd4; }

.type-list, .donor-list { display: grid; gap: 14px; }
.type-row .type-top,
.type-row .type-bottom {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
}
.type-row .type-top strong { color: var(--ink); }
.type-row .type-bottom { color: var(--muted); margin-top: 6px; }
.bar {
  height: 8px;
  border-radius: 999px;
  background: #f1ece5;
  overflow: hidden;
  margin-top: 8px;
}
.bar > span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #6b6494, var(--gold));
  border-radius: inherit;
}
.donor-row { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: var(--gold-soft);
  color: var(--teal);
  display: grid;
  place-items: center;
  font-weight: 700;
  flex-shrink: 0;
}
.donor-info { flex: 1; min-width: 0; }
.donor-info strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.donor-info span { color: var(--muted); font-size: 12px; }
.donor-total { font-weight: 700; font-size: 13px; white-space: nowrap; }

.recent-panel { margin-top: 2px; }
.modern-table th {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: #faf8f5;
}
.modern-table tr:hover td { background: #fcfbf9; }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.card .num { font-size: 28px; font-weight: 800; }
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}
.table-wrap table { min-width: 720px; }
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-size: 14px;
  vertical-align: middle;
}
th { color: var(--muted); font-weight: 600; white-space: nowrap; }
.badge {
  display: inline-flex;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge.paid { background: #eaf7f0; color: var(--ok); border-color: #cfe8d8; }
.badge.pending { background: #fff7ea; color: var(--pending); border-color: #f0dfb5; }
.badge.failed, .badge.rejected { background: #fbebea; color: var(--danger); border-color: #f0c9c9; }
.badge.off { background: #f1f0ee; color: #777; }
.badge.on { background: #eaf7f0; color: var(--ok); }

.thumb {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  object-fit: cover;
  border: 1px solid var(--line);
  display: block;
  background: #f4f1eb;
}
.thumb.empty {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: #f4f1eb;
  border: 1px dashed #ddd6cb;
  display: inline-block;
}
.upload-box {
  border: 1px dashed #d8d0c4;
  border-radius: 16px;
  padding: 16px;
  background: #faf8f5;
}
.upload-preview {
  width: 140px;
  height: 140px;
  max-width: 100%;
  object-fit: cover;
  border-radius: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
}

.btn, button.btn, input[type=submit] {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  background: var(--teal);
  color: white;
  padding: 10px 16px;
  border-radius: 12px;
  font: inherit;
  cursor: pointer;
  min-height: 42px;
  text-align: center;
  transition: filter 0.15s ease, transform 0.1s ease;
}
.btn:hover, button.btn:hover { filter: brightness(1.05); }
.btn:active, button.btn:active { transform: translateY(1px); }
.btn.gold { background: var(--gold); color: #3f3428; }
.btn.ghost { background: transparent; color: var(--teal); border: 1px solid var(--line); }
.btn.danger { background: var(--danger); }
.btn.small { padding: 7px 11px; font-size: 13px; min-height: 36px; }

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: stretch;
}
.filters > input,
.filters > select {
  flex: 1 1 180px;
  min-width: 0;
}
.filters > .btn,
.filters > button {
  flex: 0 0 auto;
}

input, textarea, select {
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: white;
  color: var(--ink);
  width: 100%;
  max-width: 100%;
  min-height: 42px;
}
textarea { min-height: 110px; resize: vertical; }
label { display: block; margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.field { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* —— Login —— */
.login-page .login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 16px;
}
.login-card { width: min(420px, 100%); }
.login-brand { margin-bottom: 8px; }
.login-brand h1 {
  margin: 0;
  font-size: 22px;
  color: var(--teal-dark);
}
.login-brand .muted { margin: 4px 0 0; }
.login-form { margin-top: 18px; }
.login-form input { width: 100%; }
.login-submit { width: 100%; margin-top: 4px; }
.error {
  background: #fbebea;
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 10px;
  margin: 12px 0 0;
  font-size: 14px;
  line-height: 1.7;
}

.runtime-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.runtime-item {
  background: #faf8f5;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  display: grid;
  gap: 4px;
}
.runtime-item.runtime-wide { grid-column: 1 / -1; }
.runtime-label {
  font-size: 12px;
  color: var(--muted);
}
.runtime-item strong {
  font-size: 14px;
  color: var(--teal-dark);
  word-break: break-word;
}
.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px !important;
  direction: ltr;
  text-align: left;
}

.phone {
  width: min(420px, 100%);
  margin: 0 auto;
  background: #1d1a28;
  border-radius: 36px;
  padding: 18px 14px 24px;
  color: white;
  box-shadow: var(--shadow);
}
.phone-screen {
  background: #faf8f5;
  color: var(--ink);
  border-radius: 24px;
  min-height: 560px;
  padding: 16px;
  display: flex;
  flex-direction: column;
}
.phone-screen .bubbles { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.phone-screen .bubble {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 16px;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.8;
}
.phone-screen .bubble.bot { background: white; border: 1px solid var(--line); align-self: flex-start; }
.phone-screen .bubble.invoice { background: var(--gold-soft); align-self: flex-start; }
.keys { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.keys button { background: white; color: var(--teal); border: 1px solid var(--teal); padding: 6px 10px; border-radius: 10px; font-size: 12px; }

.hero {
  max-width: 980px;
  margin: 0 auto;
  padding: 48px 20px 80px;
}
.hero-card {
  background: var(--paper);
  border-radius: 28px;
  padding: 42px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.hero h1 { font-size: 36px; margin: 0 0 10px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 28px; }
.step { background: #f7f5f1; border-radius: 16px; padding: 16px; }
.step b { display: block; margin-bottom: 6px; }

/* —— Tablet —— */
@media (max-width: 1100px) {
  .metric-row,
  .metric-row.secondary,
  .dash-mid,
  .dash-mid.secondary {
    grid-template-columns: 1fr 1fr;
  }
  .grid { grid-template-columns: 1fr 1fr; }
  .main { padding: 22px 20px 40px; }
}

/* —— Mobile —— */
@media (max-width: 900px) {
  .mobile-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--mobile-bar-h);
    padding: 0 12px;
    background: rgba(255, 253, 251, 0.94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .mobile-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
  }
  .mobile-brand strong {
    font-size: 14px;
    color: var(--teal-dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .mobile-bar-link {
    font-size: 13px;
    color: var(--teal);
    font-weight: 600;
    padding: 8px 10px;
    border-radius: 10px;
    white-space: nowrap;
  }
  .menu-toggle {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
  }
  .menu-toggle span {
    display: block;
    width: 16px;
    height: 2px;
    background: var(--teal-dark);
    border-radius: 2px;
  }

  .shell { display: block; }
  .sidebar-backdrop {
    display: block;
  }
  .sidebar-backdrop[hidden] { display: none !important; }

  .sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(300px, 86vw);
    height: 100vh;
    border-left: 1px solid var(--line);
    border-bottom: 0;
    transform: translateX(105%);
    transition: transform 0.22s ease;
    box-shadow: none;
  }
  .shell.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: -12px 0 40px rgba(42, 39, 51, 0.14);
  }

  .main {
    padding: 16px 14px 36px;
  }

  .metric-row,
  .metric-row.secondary,
  .dash-mid,
  .dash-mid.secondary,
  .grid,
  .form-grid,
  .steps {
    grid-template-columns: 1fr;
  }

  .dash-head {
    flex-direction: column;
    align-items: stretch;
  }
  .dash-head h2 { font-size: 22px; }
  .dash-head-actions .btn,
  .topbar .btn,
  .topbar .actions .btn {
    flex: 1 1 auto;
  }
  .topbar {
    align-items: stretch;
  }
  .topbar h2 { font-size: 20px; }

  .metric-card, .panel, .card {
    padding: 16px;
    border-radius: 16px;
  }
  .metric-value { font-size: 24px; }
  .chart-wrap { height: 220px; }
  .status-bubbles { min-height: 160px; }

  .filters {
    flex-direction: column;
  }
  .filters > input,
  .filters > select,
  .filters > .btn,
  .filters > button {
    width: 100%;
    flex: none;
  }

  .table-wrap {
    margin-inline: -4px;
    padding-bottom: 4px;
  }
  .table-wrap::after {
    content: "برای دیدن ستون‌های بیشتر به چپ/راست بکشید";
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: var(--muted);
  }
  .table-wrap table { min-width: 640px; }
  th, td { padding: 11px 8px; font-size: 13px; }

  .runtime-grid { grid-template-columns: 1fr; }

  .donor-total { font-size: 12px; }
  .hero-card { padding: 24px 18px; }
  .hero h1 { font-size: 26px; }
  .phone-screen { min-height: 480px; }
}

@media (max-width: 480px) {
  .dash-head-actions {
    display: grid;
    grid-template-columns: 1fr;
  }
  .panel-head {
    align-items: flex-start;
  }
  .login-wrap { padding: 18px 12px; }
  .login-card { padding: 16px; }
}
