/* ══════════════════════════════════════════════════════════════
   Components — reusable UI elements for dashboard pages.
   Stats, toolbar, tables, badges, buttons, modals, toast.
   ══════════════════════════════════════════════════════════════ */

/* ── App Shell ───────────────────────────────────────────── */
.app-view {
  display: none; flex: 1; padding-top: 66px;
  animation: fadeUp .5s ease both;
}
.app-view.visible { display: block; }

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 40px;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 66px;
  background: var(--surface); z-index: 100;
  backdrop-filter: blur(12px);
}
header .left { display: flex; align-items: center; gap: 16px; }
header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
header .tag {
  font-family: var(--mono); font-size: .7rem; font-weight: 400;
  color: var(--text-muted); letter-spacing: .08em; text-transform: uppercase;
}

.user-info {
  display: flex; align-items: center; gap: 12px;
  font-size: .85rem; color: var(--text-dim);
}
.user-info img {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid var(--border);
}

.sign-out-btn {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
  padding: 6px 14px; border-radius: var(--radius);
  font-family: var(--mono); font-size: .75rem;
  cursor: pointer; letter-spacing: .04em;
  transition: border-color .2s, color .2s;
}
.sign-out-btn:hover { border-color: var(--text-dim); color: var(--text); }

main { padding: 32px 40px 80px; }

/* ── Stats Bar ───────────────────────────────────────────── */
.stats-bar {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 36px;
}
.stat-card {
  background: var(--surface-raised); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg); padding: 20px 24px;
  transition: border-color .2s;
}
.stat-card:hover { border-color: var(--border); }
.stat-card .label {
  font-family: var(--mono); font-size: .7rem; font-weight: 400;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .1em; margin-bottom: 8px;
}
.stat-card .value {
  font-family: var(--mono); font-size: 1.8rem; font-weight: 600;
  letter-spacing: -0.02em;
}
.stat-card .value.purple { color: var(--purple); }
.stat-card .value.green  { color: var(--green); }
.stat-card .value.yellow { color: var(--yellow); }
.stat-card .value.clickable { cursor: pointer; }

/* ── Admin Tabs ──────────────────────────────────────────── */
.admin-tabs {
  display: flex; gap: 4px; background: var(--surface-raised);
  border-radius: var(--radius); padding: 4px; border: 1px solid var(--border-subtle);
  margin-bottom: 28px; width: fit-content;
}
.admin-tab {
  padding: 10px 28px; border-radius: 6px; border: none; background: none;
  color: var(--text-dim); font-family: var(--brand); font-size: .875rem;
  font-weight: 500; cursor: pointer; transition: all .15s;
}
.admin-tab:hover { color: var(--text); }
.admin-tab.active { background: var(--purple); color: #fff; font-weight: 600; }

/* ── Search Bar ──────────────────────────────────────────── */
.search-bar { margin-bottom: 16px; }
.search-bar input {
  width: 100%; max-width: 400px; height: 40px;
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0 16px;
  color: var(--text); font-family: var(--brand); font-size: .85rem;
  outline: none; transition: border-color .2s;
}
.search-bar input:focus { border-color: var(--purple); }
.search-bar input::placeholder { color: var(--text-muted); }

/* ── Toolbar ─────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px;
}
.filter-tabs {
  display: flex; gap: 4px; background: var(--surface-raised);
  border-radius: var(--radius); padding: 4px;
  border: 1px solid var(--border-subtle);
}
.filter-tab {
  padding: 8px 18px; border-radius: 6px; border: none; background: none;
  color: var(--text-dim); font-family: var(--mono); font-size: .75rem;
  font-weight: 400; cursor: pointer; transition: all .15s; letter-spacing: .03em;
}
.filter-tab:hover { color: var(--text); }
.filter-tab.active { background: var(--purple); color: #fff; font-weight: 500; }
.filter-tab .count {
  display: inline-block; min-width: 18px; text-align: center;
  margin-left: 6px; padding: 1px 6px; border-radius: 9px;
  font-size: .625rem; background: #ffffff15;
}
.filter-tab.active .count { background: #ffffff30; }

.create-btn {
  background: var(--surface-raised); color: var(--purple);
  border: 1px solid var(--purple-dim); padding: 10px 22px;
  border-radius: var(--radius); font-family: var(--mono);
  font-size: .75rem; font-weight: 500;
  cursor: pointer; transition: all .15s; letter-spacing: .02em;
}
.create-btn:hover {
  background: var(--purple); color: #fff; border-color: var(--purple);
}

/* ── Table ────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface-raised); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.table-wrap::-webkit-scrollbar { height: 6px; }
.table-wrap::-webkit-scrollbar-track { background: var(--surface-raised); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
table { width: 100%; min-width: 1000px; border-collapse: collapse; }
thead th {
  font-family: var(--mono); font-size: .75rem; font-weight: 400;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: .1em;
  padding: 14px 18px; text-align: left; white-space: nowrap;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; background: var(--surface-raised);
}
thead th.sortable { cursor: pointer; user-select: none; transition: color .15s; }
thead th.sortable:hover { color: var(--text-dim); }
thead th.sorted { color: var(--text); }
tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background .12s;
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface-hover); }
td { padding: 14px 18px; font-size: .875rem; vertical-align: middle; }
td.code {
  font-family: var(--mono); font-weight: 600; font-size: .85rem;
  letter-spacing: .04em; color: var(--purple);
}
.code { font-family: var(--mono); font-weight: 600; color: var(--purple); letter-spacing: .04em; }
td.mono {
  font-family: var(--mono); font-size: .8rem; font-weight: 400;
  color: var(--text-dim);
}
td.conversions { font-family: var(--mono); font-weight: 600; font-size: .9rem; }
td .msg-preview {
  display: block; font-size: .75rem; color: var(--text-dim);
  font-style: italic; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
td .dim { color: var(--text-muted); }
.username-tag { display: block; font-size: .75rem; color: #E8A87C; margin-top: 2px; }
.email-link {
  color: var(--purple-light) !important; text-decoration: none !important;
  transition: color .15s;
}
.email-link:hover { color: #fff !important; text-decoration: underline !important; }
.actions { display: flex; gap: 6px; white-space: nowrap; }

/* ── Social links ────────────────────────────────────────── */
.social-cell { display: flex; align-items: center; gap: 10px; }
.social-cell .social-list { flex: 1; }
.social-divider { width: 1px; align-self: stretch; background: var(--border); }
.social-list { display: flex; flex-direction: column; gap: 4px; }
.social-row {
  display: flex !important; align-items: center; gap: 6px;
  font-family: var(--mono); font-size: .75rem;
  color: #9B91E8 !important; text-decoration: none !important;
  line-height: 1.4; min-width: 0;
}
.social-row.dim { color: var(--text-muted) !important; }
a.social-row:visited { color: #9B91E8 !important; }
a.social-row:hover { color: #FFFFFE !important; }
.social-badge {
  font-family: var(--mono); font-size: .625rem; font-weight: 700;
  color: var(--text-muted); min-width: 20px; text-align: center;
  flex-shrink: 0;
}
.social-handle {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 140px;
}

/* ── Badges ──────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px;
  font-family: var(--mono); font-size: .7rem; font-weight: 500;
  letter-spacing: .04em; text-transform: uppercase;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; }
.badge.pending  { background: var(--yellow-bg); color: var(--yellow); }
.badge.pending::before  { background: var(--yellow); animation: pulse-dot 2s ease-in-out infinite; }
.badge.approved { background: var(--green-bg); color: var(--green); }
.badge.approved::before { background: var(--green); }
.badge.rejected { background: var(--red-bg); color: var(--red); }
.badge.rejected::before { background: var(--red); }
.badge.active   { background: var(--green-bg); color: var(--green); }
.badge.active::before   { background: var(--green); }
.badge.inactive { background: var(--red-bg); color: var(--red); }
.badge.inactive::before { background: var(--red); }

/* ── Action Buttons ──────────────────────────────────────── */
.action-btn {
  padding: 6px 14px; border-radius: 6px; border: 1px solid;
  font-family: var(--mono); font-size: .7rem; font-weight: 500;
  cursor: pointer; transition: all .15s; letter-spacing: .02em; background: none;
}
.action-btn.approve { border-color: var(--green); color: var(--green); }
.action-btn.approve:hover { background: var(--green); color: var(--surface); }
.action-btn.reject  { border-color: var(--red); color: var(--red); }
.action-btn.reject:hover  { background: var(--red); color: var(--surface); }
.action-btn.toggle  { border-color: var(--border); color: var(--text-dim); }
.action-btn.toggle:hover  { border-color: var(--text-dim); color: var(--text); }
.action-btn:disabled { opacity: .3; cursor: not-allowed; }

/* ── Modals ──────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: #00000088;
  backdrop-filter: blur(6px); z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn .2s ease;
}
.modal {
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 520px; max-height: 85vh;
  overflow-y: auto; animation: slideUp .3s cubic-bezier(.16,1,.3,1);
  box-shadow: 0 40px 80px #00000060;
}
.modal-header {
  padding: 24px 28px 0;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { font-size: 1.3rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--border); background: none;
  color: var(--text-dim); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; transition: all .15s;
}
.modal-close:hover { border-color: var(--text-dim); color: var(--text); }
.modal-body { padding: 20px 28px 28px; }
.form-row { margin-bottom: 16px; }
.form-row label {
  display: block; font-family: var(--mono); font-size: .7rem; font-weight: 400;
  color: var(--text-muted); text-transform: uppercase;
  letter-spacing: .08em; margin-bottom: 6px;
}
.form-row input[type="text"],
.form-row input[type="email"],
.form-row input[type="number"] {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 14px; color: var(--text);
  font-family: var(--mono); font-size: .85rem; outline: none;
  transition: border-color .2s;
}
.form-row input:focus { border-color: var(--purple); }
.form-row input::placeholder { color: var(--text-muted); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 16px;
}
.checkbox-row input[type="checkbox"] {
  appearance: none; width: 18px; height: 18px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--surface); cursor: pointer;
  position: relative; transition: all .15s; flex-shrink: 0;
}
.checkbox-row input[type="checkbox"]:checked {
  background: var(--purple); border-color: var(--purple);
}
.checkbox-row input[type="checkbox"]:checked::after {
  content: '\2713'; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: .7rem; font-weight: 600;
}
.checkbox-row label {
  font-size: .85rem; color: var(--text-dim); cursor: pointer; margin: 0;
}
.modal-actions {
  display: flex; gap: 10px; justify-content: flex-end; padding-top: 8px;
}
.modal-btn {
  padding: 10px 24px; border-radius: var(--radius);
  font-family: var(--mono); font-size: .75rem; font-weight: 500;
  cursor: pointer; transition: all .15s; letter-spacing: .02em;
}
.modal-btn.cancel {
  background: none; border: 1px solid var(--border); color: var(--text-dim);
}
.modal-btn.cancel:hover { border-color: var(--text-dim); color: var(--text); }
.modal-btn.submit {
  background: var(--purple); border: 1px solid var(--purple); color: #fff;
}
.modal-btn.submit:hover { box-shadow: 0 4px 20px var(--purple-dim); }
.modal-btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── User search (modals) ────────────────────────────────── */
.search-results {
  height: 172px; overflow-y: auto;
  margin-top: 4px; border-radius: var(--radius);
}
.search-result-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; cursor: pointer;
  background: var(--surface); border-bottom: 1px solid var(--border-subtle);
  transition: background .1s;
}
.search-result-item:hover { background: var(--surface-hover); }
.search-result-item.selected { background: var(--surface-hover); border-left: 2px solid var(--purple); }
.search-result-item:first-child { border-radius: var(--radius) var(--radius) 0 0; }
.search-result-item:last-child { border-radius: 0 0 var(--radius) var(--radius); border-bottom: none; }
.search-result-email { font-family: var(--mono); font-size: .875rem; color: var(--text); }
.search-result-meta { font-size: .75rem; color: var(--text-muted); }
.search-loading, .search-empty {
  padding: 12px 14px; font-size: .8rem; color: var(--text-muted);
  background: var(--surface); border-radius: var(--radius);
}
.selected-user-wrap { height: 96px; margin: 16px 0; }
.selected-user-card {
  position: relative;
  background: var(--surface); border: 1px solid var(--purple-dim);
  border-radius: var(--radius);
  width: 100%; height: 96px;
  font-size: .85rem;
}
.selected-user-info {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  display: flex; flex-direction: column; gap: 3px;
  font-family: var(--mono); font-size: .875rem;
}
.selected-user-card.empty .selected-user-info {
  color: var(--text-muted);
  flex-direction: row;
}
.selected-user-card.empty .selected-user-info div:empty { display: none; }
.selected-user-clear {
  position: absolute; right: 16px; top: 50%; transform: translateY(-50%);
}

/* ── Toast ────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 28px; right: 28px;
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 20px;
  font-family: var(--mono); font-size: .8rem; color: var(--text);
  z-index: 2000;
  animation: slideUp .3s cubic-bezier(.16,1,.3,1), fadeOut .3s ease 2.5s forwards;
  box-shadow: 0 12px 40px #00000040;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }

/* ── Empty State ─────────────────────────────────────────── */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-muted); font-family: var(--mono); font-size: .85rem;
}

/* ── Detail Page ─────────────────────────────────────────── */
.detail-section { margin-top: 32px; }
.detail-heading {
  font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: .06em;
  font-family: var(--mono); font-size: .75rem;
  margin-bottom: 16px; padding-bottom: 8px;
  border-bottom: 1px solid var(--border-subtle);
}
.detail-grid { display: flex; flex-direction: column; gap: 12px; }
.detail-row { display: flex; gap: 16px; align-items: baseline; }
.detail-label {
  font-family: var(--mono); font-size: .75rem; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em;
  min-width: 100px; flex-shrink: 0;
}
.detail-row > span:last-child { font-size: .9rem; color: var(--text); }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 800px) {
  header { padding: 16px 20px; flex-wrap: wrap; gap: 12px; }
  header .left { width: 100%; }
  header .tag { display: none; }
  main { padding: 16px; }
  .stats-bar { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .stat-card { padding: 14px 16px; }
  .stat-card .value { font-size: 1.4rem; }
  .toolbar { flex-direction: column; gap: 12px; align-items: stretch; }
  .filter-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .filter-tab { white-space: nowrap; padding: 8px 14px; }
  .create-btn { text-align: center; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 700px; }
  .modal { width: calc(100% - 32px); max-height: 90vh; }
  .form-grid { grid-template-columns: 1fr; }
  .toast { left: 16px; right: 16px; bottom: 16px; }
  .partner-actions { flex-direction: column; }
}

@media (max-width: 480px) {
  .stat-card .label { font-size: .6rem; }
  .stat-card .value { font-size: 1.2rem; }
  header h1 { font-size: 1.2rem; }
  .user-info span { display: none; }
  .modal { width: calc(100% - 16px); }
  .modal-body { padding: 16px 20px 20px; }
}
