/* ── Design tokens ─────────────────────────────────────────────── */
:root {
  --bg: #0a0f1f;
  --bg-2: #0e1428;
  --surface: #131b33;
  --surface-2: #1a2445;
  --surface-3: #222e57;
  --border: #26325c;
  --text: #eef1fb;
  --muted: #94a0c4;
  --primary: #7c6cff;
  --primary-2: #4f8bff;
  --grad: linear-gradient(135deg, #7c6cff 0%, #4f8bff 55%, #22d3ee 100%);
  --grad-warm: linear-gradient(135deg, #ff7a59 0%, #f43f8e 100%);
  --buy: #14c38e;
  --buy-bg: rgba(20, 195, 142, .14);
  --sell: #ff5470;
  --sell-bg: rgba(255, 84, 112, .14);
  --amber: #ffb020;
  --amber-bg: rgba(255, 176, 32, .14);
  --cyan: #22d3ee;
  --focus: rgba(124, 108, 255, .45);
  --shadow: 0 10px 30px rgba(3, 6, 20, .45);
  --shadow-sm: 0 1px 2px rgba(3, 6, 20, .35), 0 4px 14px rgba(3, 6, 20, .22);
  --ring: 0 0 0 3px var(--focus);
  --pane-head-h: 46px;
  --radius: 14px;
  --radius-sm: 10px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f5fd;
  --bg-2: #eaeefb;
  --surface: #ffffff;
  --surface-2: #f5f7ff;
  --surface-3: #e8ecfb;
  --border: #dbe1f5;
  --text: #141a33;
  --muted: #65708f;
  --primary: #5a49f0;
  --primary-2: #2f6df2;
  --buy: #0aa574;
  --buy-bg: rgba(10, 165, 116, .12);
  --sell: #e5304f;
  --sell-bg: rgba(229, 48, 79, .1);
  --amber: #d98a00;
  --amber-bg: rgba(217, 138, 0, .12);
  --focus: rgba(90, 73, 240, .3);
  --shadow: 0 10px 30px rgba(40, 55, 120, .12);
  --shadow-sm: 0 1px 2px rgba(40, 55, 120, .06), 0 4px 14px rgba(40, 55, 120, .07);
  color-scheme: light;
}
html[lang="ar"] { --font: 'Cairo', 'Inter', system-ui, sans-serif; }

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
a { color: var(--primary-2); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.up { color: var(--buy) !important; }
.down { color: var(--sell) !important; }

/* ── Logo ──────────────────────────────────────────────────────── */
.logo { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
.logo-mark { width: 34px; height: 34px; border-radius: 11px; background: var(--grad); color: #fff; display: grid; place-items: center; box-shadow: 0 6px 16px rgba(99, 102, 241, .4); }
.logo-img { max-height: 34px; max-width: 170px; object-fit: contain; }
.logo.big .logo-img { max-height: 48px; max-width: 220px; }
.logo.big .logo-mark { width: 44px; height: 44px; border-radius: 14px; }
.logo.big { font-size: 24px; }
.logo-for-dark { display: none; }
:root[data-theme="dark"] .logo-for-light { display: none; }
:root[data-theme="dark"] .logo-for-dark { display: inline-block; }

/* ── Buttons & inputs ──────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 10px 16px;
  font-weight: 600; cursor: pointer; transition: transform .08s, filter .15s, background .15s;
  background: var(--surface-3); color: var(--text); white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; filter: none; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 8px 20px rgba(99, 102, 241, .35); }
.btn-buy { background: var(--buy); color: #fff; }
.btn-sell { background: var(--sell); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-danger { background: var(--sell-bg); color: var(--sell); }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--border); cursor: pointer; color: var(--text);
}
.icon-btn:hover { border-color: var(--primary); }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="dark"] .i-moon { display: none; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .lbl { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.field .hint { font-size: 12px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; padding: 11px 13px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--focus); }
.input::placeholder { color: var(--muted); opacity: .7; }
.input-wrap { position: relative; }
.input-wrap .input { padding-inline-end: 64px; }
.input-wrap .peek { position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--primary-2); font-weight: 600; cursor: pointer; padding: 6px; }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 2px; }
.seg-btn { padding: 6px 11px; border-radius: 8px; color: var(--muted); font-weight: 600; font-size: 12.5px; cursor: pointer; border: 0; background: none; }
.seg-btn.on { background: var(--surface-3); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.seg-btn:hover { color: var(--text); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; background: var(--surface-3); color: var(--muted); }
.badge.buy { background: var(--buy-bg); color: var(--buy); }
.badge.sell { background: var(--sell-bg); color: var(--sell); }
.badge.warn { background: var(--amber-bg); color: var(--amber); }
.alert { padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 14px; }
.alert.err { background: var(--sell-bg); color: var(--sell); border: 1px solid rgba(255, 84, 112, .3); }
.alert.ok { background: var(--buy-bg); color: var(--buy); border: 1px solid rgba(20, 195, 142, .3); }
.alert.info { background: var(--amber-bg); color: var(--amber); }

.spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff; animation: sp .7s linear infinite; display: inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ── Toasts ────────────────────────────────────────────────────── */
.toasts { position: fixed; inset-inline-end: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 9999; max-width: min(380px, calc(100vw - 32px)); }
.toast {
  background: var(--surface-3); border: 1px solid var(--border); border-inline-start: 4px solid var(--primary);
  padding: 11px 14px; border-radius: 10px; box-shadow: var(--shadow); animation: tin .2s ease-out;
}
.toast.ok { border-inline-start-color: var(--buy); }
.toast.err { border-inline-start-color: var(--sell); }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* ── Modal ─────────────────────────────────────────────────────── */
.modal-back { position: fixed; inset: 0; background: rgba(4, 7, 20, .6); display: grid; place-items: center; z-index: 5000; padding: 16px; backdrop-filter: blur(3px); }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 22px; width: min(440px, 100%); box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal .row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ── Tables ────────────────────────────────────────────────────── */
.tbl-wrap { overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { position: sticky; top: 0; background: var(--surface); text-align: start; color: var(--muted); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tbl tr:hover td { background: var(--surface-2); }
.empty { padding: 34px 16px; text-align: center; color: var(--muted); }

/* ── Big notifications (top-centre, colour-coded) ─────────────── */
.toasts { inset: 78px 0 auto 0; margin-inline: auto; width: min(560px, calc(100vw - 24px)); max-width: none; pointer-events: none; z-index: 9999; gap: 10px; }
.toast {
  pointer-events: auto; position: relative; overflow: hidden; cursor: pointer;
  display: flex; align-items: center; gap: 14px; padding: 16px 18px; border-radius: 16px; border: 0;
  color: #fff; font-size: 17px; font-weight: 700; line-height: 1.35; letter-spacing: -.005em;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .45), 0 0 0 1px rgba(255, 255, 255, .12) inset;
  animation: tpop .32s cubic-bezier(.2, 1.3, .4, 1);
  background: linear-gradient(135deg, #6a5cff, #3d8bff);
}
.toast.ok { background: linear-gradient(135deg, #0fb37e, #16d39a); }
.toast.err { background: linear-gradient(135deg, #e5304f, #ff6a5a); }
.toast-ic { flex: none; width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, .22); display: grid; place-items: center; }
.toast-ic .spin { width: 20px; height: 20px; border-width: 3px; }
.toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast-x { flex: none; background: rgba(255, 255, 255, .18); border: 0; color: #fff; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 13px; }
.toast-x:hover { background: rgba(255, 255, 255, .32); }
.toast.timed::after { content: ''; position: absolute; inset: auto 0 0 0; height: 4px; background: rgba(255, 255, 255, .55); transform-origin: left; animation: tlife var(--life, 5s) linear forwards; }
[dir="rtl"] .toast.timed::after { transform-origin: right; }
.toast.out { opacity: 0; transform: translateY(-10px) scale(.97); transition: all .22s; }
@keyframes tpop { from { opacity: 0; transform: translateY(-18px) scale(.94); } }
@keyframes tlife { to { transform: scaleX(0); } }
@media (max-width: 560px) { .toasts { top: 64px; } .toast { font-size: 15.5px; padding: 14px; } }

/* ── Notification v2: clean card, colour only on icon + accent ── */
.toasts { width: min(520px, calc(100vw - 24px)); }
.toast {
  --c: var(--primary);
  background: var(--surface); color: var(--text); font-size: 15.5px; font-weight: 600; letter-spacing: 0;
  padding: 14px 14px 14px 16px; gap: 14px; border-radius: 14px;
  border: 1px solid var(--border); border-inline-start: 5px solid var(--c);
  box-shadow: 0 16px 40px rgba(2, 5, 20, .35), 0 0 0 4px color-mix(in srgb, var(--c) 14%, transparent);
}
.toast.ok { --c: var(--buy); background: var(--surface); }
.toast.err { --c: var(--sell); background: var(--surface); }
.toast.info { --c: var(--primary-2); background: var(--surface); }
.toast-ic { width: 38px; height: 38px; background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c); }
.toast-ic .spin { border-color: color-mix(in srgb, var(--c) 30%, transparent); border-top-color: var(--c); }
.toast-x { background: var(--surface-2); color: var(--muted); }
.toast-x:hover { background: var(--surface-3); color: var(--text); }
.toast.timed::after { background: var(--c); opacity: .7; height: 3px; }

/* ── Notification position: top-right corner, under the header ── */
.toasts { inset: 74px 18px auto auto; margin-inline: 0; width: min(420px, calc(100vw - 24px)); }
[dir="rtl"] .toasts { inset: 74px auto auto 18px; }
@media (max-width: 560px) { .toasts { inset: 62px 10px auto 10px; width: auto; } }
