/* Reusable components */

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: var(--fs-md); white-space: nowrap;
  border: 1px solid transparent; transition: var(--transition);
  user-select: none;
}
.btn:disabled, .btn.is-loading { opacity: .55; cursor: not-allowed; pointer-events: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-sm { padding: 5px 10px; font-size: var(--fs-sm); }
.btn-lg { padding: 11px 22px; font-size: var(--fs-lg); }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-success { background: var(--success); color: #04231a; }
.btn-success:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: #2c0a0d; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-outline-danger { border-color: var(--danger); color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger-soft); }
.btn-buy { background: var(--success); color: #04231a; }
.btn-sell { background: var(--danger); color: #2c0a0d; }
.btn .spinner { width: 14px; height: 14px; }

/* ---- Cards ---- */
.card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius); overflow: hidden;
}
.card-pad { padding: var(--sp-4); }
.card-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--border-color);
  font-weight: 600;
}
.card-body { padding: var(--sp-4); }
.card-title { font-size: var(--fs-md); }

/* Stat tiles */
.stat {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius); padding: var(--sp-4);
}
.stat-label { color: var(--text-muted); font-size: var(--fs-sm); margin-bottom: 6px; }
.stat-value { font-size: var(--fs-xl); font-weight: 700; font-family: var(--font-mono); }
.stat-sub { font-size: var(--fs-sm); margin-top: 4px; }

/* ---- Badges / pills ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.badge-neutral { background: var(--bg-hover); color: var(--text-secondary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info    { background: var(--accent-soft); color: var(--accent-hover); }
.badge-long  { background: var(--success-soft); color: var(--success); }
.badge-short { background: var(--danger-soft); color: var(--danger); }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border-color); overflow-x: auto; }
.tabs::-webkit-scrollbar { height: 0; }
.tab {
  padding: 9px 14px; color: var(--text-muted); font-weight: 600; font-size: var(--fs-md);
  border-bottom: 2px solid transparent; white-space: nowrap; transition: var(--transition);
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--text-primary); border-bottom-color: var(--accent); }
.tab-badge { margin-left: 6px; background: var(--bg-hover); color: var(--text-secondary); border-radius: var(--radius-pill); padding: 0 6px; font-size: var(--fs-xs); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.seg { display: inline-flex; background: var(--bg-input); border: 1px solid var(--border-color); border-radius: var(--radius-sm); padding: 2px; }
.seg button { padding: 5px 12px; border-radius: 4px; font-weight: 600; font-size: var(--fs-sm); color: var(--text-muted); }
.seg button.active { background: var(--bg-elevated); color: var(--text-primary); }

/* ---- Tables ---- */
.table-wrap { width: 100%; overflow-x: auto; }
table.data { font-size: var(--fs-md); }
table.data th {
  text-align: left; font-weight: 600; color: var(--text-muted); font-size: var(--fs-sm);
  padding: 10px 12px; border-bottom: 1px solid var(--border-color); white-space: nowrap;
  position: sticky; top: 0; background: var(--bg-card); z-index: 1;
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--border-color); white-space: nowrap; }
table.data tbody tr:hover { background: var(--bg-hover); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--font-mono); }
table.data tr:last-child td { border-bottom: none; }
.table-empty { padding: var(--sp-10); text-align: center; color: var(--text-muted); }

/* ---- Dropdown ---- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; right: 0; top: calc(100% + 6px); min-width: 200px; z-index: 70;
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-radius: var(--radius); box-shadow: var(--shadow-md); padding: 6px;
  opacity: 0; visibility: hidden; transform: translateY(-4px); transition: var(--transition);
}
.dropdown.open .dropdown-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-menu a, .dropdown-menu button {
  display: flex; width: 100%; align-items: center; gap: var(--sp-2);
  padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-secondary);
  font-size: var(--fs-md); text-align: left;
}
.dropdown-menu a:hover, .dropdown-menu button:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-menu a:focus-visible, .dropdown-menu button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.dropdown-divider { height: 1px; background: var(--border-color); margin: 6px 0; }

/* ---- Modal ----
 * z-index 160 keeps a modal / NX.confirm above every drawer layer
 * (admin detail/review drawer 150, deposit drawer 140, mobile nav drawer 120,
 * positions drawer 101) so a confirm opened from inside a drawer is visible and
 * clickable. Still below the toast stack (200). */
.modal-backdrop {
  position: fixed; inset: 0; background: var(--bg-overlay); z-index: 160;
  display: flex; align-items: center; justify-content: center; padding: var(--sp-4);
  opacity: 0; visibility: hidden; transition: var(--transition);
}
.modal-backdrop.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-card); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); width: 100%; max-width: 440px;
  box-shadow: var(--shadow-lg); transform: translateY(8px) scale(.98); transition: var(--transition);
  max-height: 90vh; display: flex; flex-direction: column;
}
.modal-backdrop.open .modal { transform: none; }
.modal-lg { max-width: 720px; }
.modal-header { padding: var(--sp-4); border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: var(--fs-lg); }
.modal-body { padding: var(--sp-4); overflow-y: auto; }
.modal-footer { padding: var(--sp-4); border-top: 1px solid var(--border-color); display: flex; gap: var(--sp-2); justify-content: flex-end; }
.modal-close { color: var(--text-muted); font-size: 20px; line-height: 1; padding: 4px; }
.modal-close:hover { color: var(--text-primary); }

/* ---- Toasts ---- */
.toast-stack { position: fixed; top: calc(var(--header-h) + 12px); right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast {
  background: var(--bg-elevated); border: 1px solid var(--border-strong);
  border-left-width: 3px; border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow-md);
  display: flex; gap: 10px; align-items: flex-start;
  animation: toast-in 180ms ease;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } }
.toast.out { opacity: 0; transform: translateX(20px); transition: 180ms ease; }
.toast-success { border-left-color: var(--success); }
.toast-danger  { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
.toast-info    { border-left-color: var(--accent); }
.toast-title { font-weight: 600; font-size: var(--fs-md); }
.toast-msg { color: var(--text-secondary); font-size: var(--fs-sm); margin-top: 2px; }
.toast-x { margin-left: auto; color: var(--text-muted); }

/* ---- Tooltip ---- */
[data-tooltip] { position: relative; }
[data-tooltip]:hover::after {
  content: attr(data-tooltip); position: absolute; bottom: calc(100% + 6px); left: 50%;
  transform: translateX(-50%); background: #000; color: #fff; font-size: var(--fs-xs);
  padding: 5px 8px; border-radius: 4px; white-space: nowrap; z-index: 90; pointer-events: none;
}

/* ---- Alerts ---- */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: var(--fs-md); border: 1px solid transparent; }
.alert[hidden] { display: none; }
.alert.shake { animation: shake .35s ease; }
@keyframes shake { 10%,90%{transform:translateX(-1px)} 30%,70%{transform:translateX(2px)} 50%{transform:translateX(-3px)} }
.alert-success { background: var(--success-soft); color: var(--success); border-color: rgba(23,185,138,.3); }
.alert-danger  { background: var(--danger-soft); color: var(--danger); border-color: rgba(240,97,109,.3); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: rgba(243,175,74,.3); }
.alert-info    { background: var(--accent-soft); color: var(--accent-hover); border-color: rgba(47,111,237,.3); }

/* ---- Pagination ---- */
.pagination { display: flex; gap: 4px; align-items: center; justify-content: flex-end; margin-top: var(--sp-4); }
.pagination button {
  min-width: 32px; height: 32px; padding: 0 8px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-color); color: var(--text-secondary); font-size: var(--fs-sm);
}
.pagination button:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.pagination button.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Skeleton / loading ---- */
.skeleton { background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-elevated) 37%, var(--bg-hover) 63%); background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 4px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
.skeleton-row { height: 14px; margin: 8px 0; }
.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.25);
  border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state { display: flex; align-items: center; justify-content: center; gap: 10px; padding: var(--sp-8); color: var(--text-muted); }
.empty-state { text-align: center; padding: var(--sp-8); color: var(--text-muted); }
.empty-state .empty-icon { font-size: 30px; opacity: .5; margin-bottom: 8px; }

/* ---- Misc ---- */
.divider { height: 1px; background: var(--border-color); margin: var(--sp-4) 0; }
.kv { display: flex; justify-content: space-between; padding: 6px 0; font-size: var(--fs-md); }
.kv .k { color: var(--text-muted); }
.kv .v { font-family: var(--font-mono); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: var(--bg-elevated); border: 1px solid var(--border-color); border-radius: var(--radius-pill); font-size: var(--fs-sm); }
.error-code { font-size: 72px; font-weight: 800; color: var(--accent); font-family: var(--font-mono); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-hover); display: grid; place-items: center; font-weight: 700; font-size: var(--fs-sm); }

/* Asset / market glyphs */
.asset-ico { width: 1.15em; margin-right: 7px; text-align: center; color: var(--text-secondary); }
.asset-ico.fa-bitcoin { color: #f7931a; }
.asset-ico.fa-ethereum { color: #8a92b2; }
.asset-ico.fa-coins { color: #f3af4a; }
.asset-ico.fa-droplet { color: #4aa8f3; }
.ticker-symbol .asset-ico { font-size: 1em; color: var(--text-primary); }
.asset-row-logo .asset-ico { margin: 0; width: auto; }
.icon-btn { width: 34px; height: 34px; border-radius: var(--radius-sm); display: grid; place-items: center; color: var(--text-secondary); }
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ---- Notification bell / Chat icon ---- */
.notif-bell, .chat-icon { position: relative; font-size: 15px; transition: color .15s ease, background .15s ease; }
.notif-bell.has-unread, .chat-icon.has-unread { color: var(--text-primary); }
.chat-icon { text-decoration: none; }
.notif-bell:active { transform: translateY(1px); }
.notif-badge {
  position: absolute; top: -3px; right: -3px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: grid; place-items: center;
  background: var(--danger); color: #fff;
  font-family: var(--font-sans); font-size: 10px; font-weight: 700; line-height: 1;
  border-radius: 999px; border: 2px solid var(--bg-secondary);
  box-shadow: 0 0 0 1px rgba(240,97,109,.35);
  animation: notif-pop .18s ease;
  pointer-events: none;
}
.notif-badge[hidden] { display: none; }
@keyframes notif-pop { from { transform: scale(0); } 60% { transform: scale(1.15); } to { transform: scale(1); } }

.notif-dropdown .notif-menu {
  width: 344px; max-width: calc(100vw - 24px);
  padding: 0; overflow: hidden;
  display: flex; flex-direction: column;
}
.notif-menu-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border-color);
  font-size: var(--fs-sm); font-weight: 600; color: var(--text-primary);
}
.notif-markall {
  width: auto; padding: 2px 4px; border-radius: var(--radius-sm);
  font-size: var(--fs-xs); font-weight: 600; color: var(--accent);
}
.notif-markall:hover { background: var(--accent-soft); color: var(--accent-hover); }
.notif-menu-list { max-height: 380px; overflow-y: auto; overscroll-behavior: contain; }
.notif-menu-empty { text-align: center; color: var(--text-muted); font-size: var(--fs-sm); padding: 28px 14px; }

.notif-row {
  display: grid; grid-template-columns: 8px 1fr auto; gap: 10px;
  align-items: start; padding: 11px 14px;
  border-bottom: 1px solid var(--border-color);
  transition: background .12s ease;
}
.notif-row:last-child { border-bottom: none; }
.notif-row:hover { background: var(--bg-hover); }
.notif-row.unread { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.notif-row-dot { width: 7px; height: 7px; border-radius: 50%; margin-top: 5px; background: var(--text-faint); }
.notif-row.unread .notif-row-dot { background: var(--accent); }
.notif-row-dot.notif-lvl-success { background: var(--success); }
.notif-row-dot.notif-lvl-warning { background: var(--warning); }
.notif-row-dot.notif-lvl-danger,
.notif-row-dot.notif-lvl-security { background: var(--danger); }
.notif-row-body { min-width: 0; }
.notif-row-title { font-size: var(--fs-sm); font-weight: 600; color: var(--text-primary); }
.notif-row.unread .notif-row-title { font-weight: 700; }
.notif-row-text {
  font-size: var(--fs-xs); color: var(--text-secondary); margin-top: 2px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.notif-row-time { font-size: var(--fs-xs); color: var(--text-muted); white-space: nowrap; }
.notif-menu-foot {
  display: block; text-align: center; padding: 10px;
  font-size: var(--fs-sm); color: var(--accent);
  border-top: 1px solid var(--border-color);
}
.notif-menu-foot:hover { background: var(--bg-hover); color: var(--accent-hover); }
