:root {
  --bg: #fafaf9;
  --surface: #ffffff;
  --surface-soft: #f5f5f4;
  --border: #ececec;
  --border-strong: #d4d4d4;
  --text: #0a0a0a;
  --text-muted: #737373;
  --text-soft: #a3a3a3;
  --accent: #dc2626;
  --accent-soft: #fef2f2;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --orange: #f97316;
  --blue: #3b82f6;
  --blue-soft: #dbeafe;
  --gold: #ca8a04;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-lift: 0 20px 50px -10px rgba(0,0,0,0.08);
  --mono: 'JetBrains Mono', ui-monospace, monospace;
  --sans: 'IBM Plex Sans Arabic', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0);
  -webkit-font-smoothing: antialiased;
}

.screen { width: 100%; }

/* ═══ AUTH SCREEN ═══ */
#screen-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background:
    radial-gradient(80% 60% at 50% -10%, rgba(220, 38, 38, 0.08), transparent 60%),
    linear-gradient(180deg, #ffffff 0%, #fafaf9 100%);
}

.auth-stage {
  width: 100%;
  max-width: 980px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 28px;
  align-items: center;
}

@media (min-width: 880px) {
  .auth-stage {
    grid-template-columns: 1.05fr 1fr;
    gap: 60px;
  }
}

/* Hero side */
.auth-hero { text-align: start; }
@media (max-width: 879px) {
  .auth-hero { text-align: center; }
  .auth-hero .hero-perks { display: inline-block; text-align: start; }
}

.brand-mark {
  display: inline-flex; align-items: center; gap: 12px;
  margin-bottom: 28px;
}
.brand-mark .logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent-soft);
  display: grid; place-items: center; font-size: 24px;
  box-shadow: 0 6px 16px rgba(220, 38, 38, 0.15);
}
.brand-mark .brand-name { font-weight: 700; font-size: 16px; }
.brand-mark .brand-tag { font-size: 12px; color: var(--text-muted); margin-top: 1px; }

.hero-title {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  margin: 0 0 16px;
}
.hero-title .accent { color: var(--accent); }
@media (min-width: 880px) { .hero-title { font-size: 44px; } }

.hero-lede {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.7;
  margin: 0 0 24px;
  max-width: 460px;
}
@media (max-width: 879px) { .hero-lede { margin-inline: auto; } }

.hero-perks {
  list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 10px;
}
.hero-perks li {
  display: flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--text);
}
.hero-perks .dot {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--green-soft); color: var(--green);
  display: grid; place-items: center; font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.hero-perks strong { font-weight: 600; }

/* Form side */
.auth-form-wrap {
  width: 100%;
  max-width: 420px;
  justify-self: center;
}
@media (min-width: 880px) { .auth-form-wrap { justify-self: end; } }
.auth-hero { justify-self: start; }
@media (max-width: 879px) { .auth-hero { justify-self: center; } }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px 24px;
  box-shadow: var(--shadow-lift);
}
.auth-card h2 {
  margin: 0 0 6px;
  font-size: 22px; font-weight: 700;
  letter-spacing: -0.01em;
}
.auth-card .muted {
  color: var(--text-muted); font-size: 14px;
  margin: 0 0 22px; line-height: 1.55;
}
.auth-card .muted strong { color: var(--text); font-weight: 600; }
.phone-mono { font-family: var(--mono); letter-spacing: 0.02em; }

.field { display: block; margin-bottom: 14px; }
.field-label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; color: var(--text-muted); font-weight: 600;
  margin-bottom: 8px;
}

.input-row {
  display: flex; align-items: stretch;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input-row:focus-within {
  border-color: var(--text);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.04);
}
.input-row .prefix {
  padding: 0 14px;
  background: var(--surface-soft);
  color: var(--text-muted);
  font-family: var(--mono); font-size: 14px; font-weight: 600;
  border-inline-end: 1px solid var(--border);
  display: flex; align-items: center;
}
.input-row input {
  flex: 1; min-width: 0;
  border: 0; background: transparent;
  padding: 14px;
  font-family: var(--mono); font-size: 16px;
  letter-spacing: 0.04em;
  outline: none;
  text-align: start;
  direction: ltr;
}

.solo-input {
  width: 100%;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  font-family: var(--sans); font-size: 15px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.solo-input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.04);
}

/* OTP row — bulletproof equal columns */
.otp-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 18px;
  direction: ltr;
}
.otp-row input {
  width: 100%;
  min-width: 0;
  font-family: var(--mono);
  font-size: 24px; font-weight: 700;
  text-align: center;
  padding: 16px 0;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  outline: none;
  transition: all 0.15s;
  -moz-appearance: textfield;
}
.otp-row input::-webkit-outer-spin-button,
.otp-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.otp-row input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.05);
}
.otp-row input:not(:placeholder-shown), .otp-row input:valid:not([value=""]) {
  border-color: var(--text);
}

.otp-hint {
  font-size: 12px; color: var(--orange);
  background: #fff7ed; padding: 8px 12px; border-radius: 8px;
  margin: 0 0 14px; font-weight: 500;
  text-align: center;
}

/* Buttons */
.primary-btn {
  width: 100%; padding: 15px 16px;
  background: var(--text); color: #fff;
  border: 0; border-radius: 12px;
  font-family: inherit; font-size: 15px; font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.1s, opacity 0.15s;
}
.primary-btn:hover { opacity: 0.92; }
.primary-btn:active { transform: scale(0.985); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.primary-btn .btn-loader { font-family: var(--mono); letter-spacing: 2px; }

.link-btn {
  background: transparent; border: 0;
  color: var(--text-muted); font-family: inherit; font-size: 13px;
  cursor: pointer; padding: 12px; text-decoration: none;
  width: 100%; margin-top: 4px;
}
.link-btn:hover { color: var(--text); }
.link-btn.inline { width: auto; margin: 0; padding: 0; font-size: 12px; color: var(--blue); text-decoration: underline; }
.link-btn.close { color: var(--text-muted); }

.error-text {
  color: var(--red); font-size: 13px; margin: 12px 0 0;
  background: var(--red-soft); padding: 10px 12px; border-radius: 8px;
  line-height: 1.5;
}

.auth-fineprint {
  font-size: 11.5px; color: var(--text-soft);
  margin: 14px 0 0; text-align: center;
  line-height: 1.5;
}

/* ═══ APP TOPBAR ═══ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex; align-items: center; justify-content: space-between;
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px;
}
.topbar .brand .logo {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px; border-radius: 9px;
  background: var(--accent-soft); font-size: 18px;
}
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--surface-soft); border: 0;
  font-family: var(--mono); font-weight: 700; font-size: 14px;
  cursor: pointer; color: var(--text);
}

.main {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
}

/* ═══ HERO BALANCE ═══ */
.hero-balance {
  background: linear-gradient(135deg, #0a0a0a 0%, #1a1a1a 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 26px 22px;
  margin-bottom: 18px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
.hero-balance::before {
  content: ''; position: absolute; inset: -50% -20% auto auto;
  width: 70%; height: 120%; border-radius: 50%;
  background: radial-gradient(circle, rgba(220, 38, 38, 0.25), transparent 65%);
  pointer-events: none;
}
.hero-balance > * { position: relative; z-index: 1; }
.balance-label {
  font-size: 12.5px; color: rgba(255,255,255,0.6);
  font-weight: 500; letter-spacing: 0.02em;
}
.balance-amount {
  font-family: var(--mono); font-size: 40px; font-weight: 700;
  letter-spacing: -0.02em;
  margin: 6px 0 4px; line-height: 1.1;
}
.balance-amount .currency {
  font-size: 16px; opacity: 0.55; font-weight: 500; margin-inline-start: 6px;
}
.balance-meta {
  font-size: 12px; color: rgba(255,255,255,0.55);
}
.hero-actions {
  display: flex; gap: 8px; justify-content: center;
  margin-top: 18px;
}
.hero-btn {
  flex: 1; padding: 11px 14px;
  background: rgba(255,255,255,0.08);
  color: #fff; border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: all 0.15s;
}
.hero-btn:hover { background: rgba(255,255,255,0.14); }
.hero-btn:active { transform: scale(0.97); }
.hero-btn.primary { background: var(--accent); border-color: var(--accent); }
.hero-btn.primary:hover { background: #ef4444; }

/* ═══ STATS ═══ */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px;
  margin-bottom: 22px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
}
.stat .lbl { font-size: 11.5px; color: var(--text-muted); font-weight: 500; }
.stat .val {
  font-family: var(--mono); font-size: 16px; font-weight: 700;
  margin-top: 4px; letter-spacing: -0.02em;
}

/* ═══ BLOCKS ═══ */
.block { margin-bottom: 22px; }
.block-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 4px 10px;
}
.block-head h3 { margin: 0; font-size: 14px; font-weight: 600; color: var(--text-muted); letter-spacing: 0.02em; }
.block-sub { font-size: 12px; color: var(--text-soft); }

/* Codes list */
.codes-list { display: flex; flex-direction: column; gap: 10px; }
.code-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 14px;
  transition: border-color 0.15s;
}
.code-card:hover { border-color: var(--border-strong); }
.code-card .top {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 12px; gap: 12px;
}
.code-card .code-name {
  font-family: var(--mono); font-size: 17px; font-weight: 700;
  letter-spacing: 0.02em;
}
.code-card .nick { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }
.code-card .split-badges { display: flex; gap: 4px; flex-shrink: 0; }
.code-card .split-badges span {
  font-size: 10.5px; padding: 2px 7px; border-radius: 5px;
  font-family: var(--mono); font-weight: 600;
}
.code-card .split-badges .cust { background: var(--blue-soft); color: var(--blue); }
.code-card .split-badges .comm { background: var(--green-soft); color: var(--green); }
.code-stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  border-top: 1px dashed var(--border); padding-top: 12px;
  gap: 8px;
}
.code-stats .cs-cell { text-align: center; }
.code-stats .cs-lbl { font-size: 10.5px; color: var(--text-muted); }
.code-stats .cs-val { font-family: var(--mono); font-size: 14px; font-weight: 600; margin-top: 2px; }
.code-stats .cs-val.green { color: var(--green); }
.code-card .sync-warn {
  display: flex; align-items: center; gap: 6px;
  background: #fff7ed; color: var(--orange);
  font-size: 11.5px; padding: 6px 10px; border-radius: 6px;
  margin-top: 10px;
}

.empty-state {
  background: var(--surface); border: 1px dashed var(--border-strong);
  border-radius: var(--radius); padding: 32px 20px;
  text-align: center; color: var(--text-muted);
}
.empty-state .icon { font-size: 38px; margin-bottom: 8px; }
.empty-state h4 { font-size: 14px; font-weight: 600; color: var(--text); margin: 8px 0 4px; }
.empty-state p { font-size: 13px; margin: 0; }

/* Withdrawals */
.withdrawals-list { display: flex; flex-direction: column; gap: 8px; }
.withdrawal-row {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.withdrawal-row .amt { font-family: var(--mono); font-size: 15px; font-weight: 700; }
.withdrawal-row .meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; font-family: var(--mono); }
.status {
  font-size: 11px; padding: 3px 8px; border-radius: 5px; font-weight: 600;
  white-space: nowrap;
}
.status.pending { background: #fff7ed; color: var(--orange); }
.status.approved { background: var(--blue-soft); color: var(--blue); }
.status.paid { background: var(--green-soft); color: var(--green); }
.status.rejected { background: var(--red-soft); color: var(--red); }

/* ═══ SHEET ═══ */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
  z-index: 90; backdrop-filter: blur(2px);
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: #fff; border-radius: 22px 22px 0 0;
  transform: translateY(100%); transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 100; max-height: 92vh; overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  box-shadow: 0 -10px 40px rgba(0,0,0,0.12);
}
.sheet.open { transform: translateY(0); }
.sheet-handle {
  width: 36px; height: 4px; background: #d4d4d4; border-radius: 2px;
  margin: 10px auto 4px;
}
.sheet-body { padding: 14px 20px 24px; }
.sheet-body h3 { margin: 4px 0 4px; font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.sheet-body .muted { color: var(--text-muted); font-size: 13.5px; margin: 0 0 20px; }

.field input[type="text"],
.field input[type="number"],
.field input[type="tel"] {
  width: 100%; padding: 13px 14px;
  border: 1.5px solid var(--border); border-radius: 12px;
  background: var(--surface);
  font-family: var(--sans); font-size: 15px;
  outline: none; transition: all 0.15s;
}
.field input:focus {
  border-color: var(--text);
  box-shadow: 0 0 0 4px rgba(0,0,0,0.04);
}
.field input.ok { border-color: var(--green); }
.field input.bad { border-color: var(--red); }
.field input[type="text"]:not(.solo-input) { font-family: var(--mono); letter-spacing: 0.04em; }
.field-hint {
  display: block; font-size: 11.5px; color: var(--text-muted); margin-top: 6px;
}
.field-hint.ok { color: var(--green); font-weight: 600; }
.field-hint.bad { color: var(--red); font-weight: 600; }

.amount-input { position: relative; }
.amount-input input { padding-inline-end: 50px; }
.amount-input .amount-suffix {
  position: absolute; inset-inline-end: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 13px;
}

/* Split controls — slider-based, total always = 20% */
.split-controls {
  background: var(--surface-soft); border-radius: 14px;
  padding: 16px 16px 18px; margin-bottom: 14px;
}
.split-header {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12.5px; color: var(--text-muted); font-weight: 600;
  margin-bottom: 16px;
}
.split-pill {
  font-size: 10.5px; padding: 3px 8px; border-radius: 999px;
  background: var(--text); color: #fff; font-weight: 500;
}

.split-readout {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; gap: 12px;
}
.readout-side { flex: 1; text-align: center; }
.readout-side .r-lbl {
  font-size: 12px; color: var(--text-muted); font-weight: 500;
  margin-bottom: 4px;
}
.readout-side .r-val {
  font-family: var(--mono); font-size: 28px; font-weight: 700;
  letter-spacing: -0.02em;
}
.readout-side.cust .r-val { color: var(--blue); }
.readout-side.comm .r-val { color: var(--green); }
.readout-divider {
  color: var(--text-soft); font-size: 18px;
  padding: 0 6px;
}

/* One-bar slider: visual bar + invisible range on top */
.split-track-wrap {
  position: relative;
  height: 32px;
  display: flex; align-items: center;
}
.split-bar {
  position: absolute; inset: 50% 0 auto 0;
  transform: translateY(-50%);
  height: 8px;
  display: flex; overflow: hidden;
  border-radius: 4px;
  pointer-events: none;
}
.split-bar-fill { height: 100%; transition: width 0.15s ease-out; }
.split-bar-fill.cust { background: var(--blue); }
.split-bar-fill.comm { background: var(--green); }

.split-slider {
  position: relative; z-index: 2;
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 32px;
  background: transparent;
  outline: none; cursor: pointer; padding: 0; margin: 0;
  touch-action: pan-x; /* horizontal only, no page scroll */
  direction: rtl;
}
.split-slider::-webkit-slider-runnable-track {
  background: transparent; height: 32px; border: 0;
}
.split-slider::-moz-range-track {
  background: transparent; height: 32px; border: 0;
}
.split-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px; height: 26px;
  background: #fff;
  border: 2px solid var(--text);
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
  margin-top: 3px; /* center on the 32px track */
  transition: transform 0.1s;
}
.split-slider::-webkit-slider-thumb:active { cursor: grabbing; transform: scale(1.1); }
.split-slider::-moz-range-thumb {
  width: 26px; height: 26px;
  background: #fff;
  border: 2px solid var(--text);
  border-radius: 50%;
  cursor: grab;
  box-shadow: 0 4px 12px rgba(0,0,0,0.18);
}

/* Toast */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(120%);
  background: var(--text); color: #fff;
  padding: 12px 18px; border-radius: 10px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  z-index: 200; transition: transform 0.3s;
  max-width: calc(100% - 32px);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* Skeleton */
.skel {
  display: inline-block;
  background: linear-gradient(90deg, #f5f5f4 0%, #ececec 50%, #f5f5f4 100%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
  border-radius: 4px; height: 1em;
}
.hero-balance .skel {
  background: linear-gradient(90deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.15) 50%, rgba(255,255,255,0.05) 100%);
  background-size: 200% 100%; animation: shimmer 1.5s infinite;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Sheet on desktop = centered modal */
@media (min-width: 768px) {
  .sheet {
    inset: auto;
    left: 50%;
    right: auto;
    bottom: 5vh;
    width: 480px;
    max-height: 85vh;
    border-radius: 18px;
    transform: translateX(-50%) translateY(110vh);
  }
  .sheet.open { transform: translateX(-50%) translateY(0); }
}
