/* ============================================================
   main.css — Binance-style mobile trading app base styles
   Dark theme by default; light theme via [data-theme="light"]
   ============================================================ */

/* ── Variables ──────────────────────────────────────────────── */
:root,
[data-theme="dark"] {
  --bg-primary:   #0b0e11;
  --bg-card:      #1e2026;
  --bg-input:     #2b2f36;
  --bg-hover:     #2b2f36;
  --bg-overlay:   rgba(0, 0, 0, 0.72);

  --border:       #2b2f36;
  --border-light: #363c45;

  --accent:       #f0b90b;
  --accent-hover: #d4a309;
  --buy:          #0ecb81;
  --buy-hover:    #0bb872;
  --buy-bg:       rgba(14, 203, 129, 0.12);
  --sell:         #f6465d;
  --sell-hover:   #dd3d53;
  --sell-bg:      rgba(246, 70, 93, 0.12);

  --text-primary:   #eaecef;
  --text-secondary: #b7bdc6;
  --text-muted:     #848e9c;
  --text-inverse:   #1e2329;

  --shadow-sm:  0 1px 4px rgba(0, 0, 0, 0.4);
  --shadow-md:  0 4px 16px rgba(0, 0, 0, 0.5);
  --shadow-lg:  0 8px 32px rgba(0, 0, 0, 0.6);

  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --radius-xl:  16px;
  --radius-full: 9999px;

  --font-mono: 'Roboto Mono', 'SF Mono', 'Fira Code', monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  --header-h:    48px;
  --bottom-nav-h: 56px;
  --max-w:       480px;

  --transition: 160ms ease;
}

[data-theme="light"] {
  --bg-primary:   #fafafa;
  --bg-card:      #ffffff;
  --bg-input:     #f5f5f5;
  --bg-hover:     #f0f0f0;
  --bg-overlay:   rgba(0, 0, 0, 0.48);

  --border:       #eaecef;
  --border-light: #f0f0f0;

  --accent:       #f0b90b;
  --accent-hover: #d4a309;
  --buy:          #0ecb81;
  --buy-hover:    #0bb872;
  --buy-bg:       rgba(14, 203, 129, 0.08);
  --sell:         #f6465d;
  --sell-hover:   #dd3d53;
  --sell-bg:      rgba(246, 70, 93, 0.08);

  --text-primary:   #1e2329;
  --text-secondary: #474d57;
  --text-muted:     #848e9c;
  --text-inverse:   #eaecef;

  --shadow-sm:  0 1px 4px rgba(0, 0, 0, 0.08);
  --shadow-md:  0 4px 16px rgba(0, 0, 0, 0.12);
  --shadow-lg:  0 8px 32px rgba(0, 0, 0, 0.16);
}


/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover { text-decoration: underline; }

img, svg { display: block; max-width: 100%; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

ul, ol { list-style: none; }

table {
  border-collapse: collapse;
  width: 100%;
}


/* ── App shell ──────────────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  /* Mobile: narrow column centered; overridden to full-width on desktop */
  max-width: var(--max-w);
  margin-inline: auto;
  position: relative;
  background: var(--bg-primary);
}

/* Tablet 600px–959px: keep narrow column with border */
@media (min-width: 600px) and (max-width: 959px) {
  body { background: #08090b; }
  .app-shell {
    border-inline: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }
}

/* Desktop ≥960px: full-width, no side borders */
@media (min-width: 960px) {
  body { background: var(--bg-primary); }
  .app-shell {
    max-width: 100%;
    margin-inline: 0;
    border-inline: none;
    box-shadow: none;
    height: 100vh;
    overflow: hidden;
  }
}

.app-content {
  flex: 1;
  overflow-y: auto;
  padding-bottom: var(--bottom-nav-h);
  /* smooth momentum scroll on iOS */
  -webkit-overflow-scrolling: touch;
}


/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
}

.text-xs    { font-size: 11px; }
.text-sm    { font-size: 12px; }
.text-base  { font-size: 14px; }
.text-md    { font-size: 16px; }
.text-lg    { font-size: 18px; }
.text-xl    { font-size: 22px; }
.text-2xl   { font-size: 28px; }

.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-accent    { color: var(--accent); }
.text-buy       { color: var(--buy); }
.text-sell      { color: var(--sell); }

.font-mono  { font-family: var(--font-mono); }
.font-bold  { font-weight: 700; }
.font-medium { font-weight: 500; }

.truncate {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}


/* ── Layout helpers ─────────────────────────────────────────── */
.flex        { display: flex; }
.flex-col    { flex-direction: column; }
.items-center { align-items: center; }
.items-end   { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center  { justify-content: center; }
.gap-1  { gap: 4px; }
.gap-2  { gap: 8px; }
.gap-3  { gap: 12px; }
.gap-4  { gap: 16px; }

.w-full  { width: 100%; }
.h-full  { height: 100%; }
.grow    { flex: 1; }

.p-2  { padding: 8px; }
.p-3  { padding: 12px; }
.p-4  { padding: 16px; }
.px-3 { padding-inline: 12px; }
.px-4 { padding-inline: 16px; }
.py-2 { padding-block: 8px; }
.py-3 { padding-block: 12px; }

.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.divider {
  width: 100%;
  height: 1px;
  background: var(--border);
}


/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

.card-body { padding: 16px; }


/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 16px;
  height: 40px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  white-space: nowrap;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-sm { height: 32px; padding: 0 12px; font-size: 12px; }
.btn-lg { height: 48px; padding: 0 24px; font-size: 16px; }
.btn-full { width: 100%; }

/* Primary accent */
.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
}
.btn-primary:hover { background: var(--accent-hover); }

/* Buy */
.btn-buy {
  background: var(--buy);
  color: #fff;
  border-radius: var(--radius-sm);
}
.btn-buy:hover { background: var(--buy-hover); }

/* Sell */
.btn-sell {
  background: var(--sell);
  color: #fff;
  border-radius: var(--radius-sm);
}
.btn-sell:hover { background: var(--sell-hover); }

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Icon-only */
.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
}
.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

/* Tab-style toggle */
.btn-tab {
  flex: 1;
  height: 36px;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
}
.btn-tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}


/* ── Inputs ─────────────────────────────────────────────────── */
.input {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color var(--transition);
}

.input::placeholder { color: var(--text-muted); }

.input:focus {
  border-color: var(--accent);
  outline: none;
}

.input-sm { height: 32px; font-size: 12px; padding: 0 8px; }

/* Input with left/right adornments */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group .input {
  padding-inline: 36px;
}

.input-group .input-prefix,
.input-group .input-suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 12px;
  pointer-events: none;
}

.input-group .input-prefix { left: 10px; }
.input-group .input-suffix { right: 10px; }

/* When only suffix (no prefix), reset left padding */
.input-group.no-prefix .input { padding-left: 12px; }
/* When only prefix, reset right padding */
.input-group.no-suffix .input { padding-right: 12px; }

.input-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.input-error {
  border-color: var(--sell) !important;
}

.input-error-msg {
  font-size: 11px;
  color: var(--sell);
  margin-top: 4px;
}

/* Select */
.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23848e9c' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  cursor: pointer;
}

.select:focus { border-color: var(--accent); }


/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color var(--transition), border-color var(--transition);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  color: var(--text-primary);
  border-bottom-color: var(--accent);
}

.tab:hover:not(.active) { color: var(--text-secondary); }


/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

.badge-buy  { background: var(--buy-bg);  color: var(--buy); }
.badge-sell { background: var(--sell-bg); color: var(--sell); }
.badge-neutral { background: var(--bg-hover); color: var(--text-muted); }


/* ── Modal ──────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom, 0);
  /* starts hidden */
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: var(--max-w);
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 240ms cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 40px;
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--border-light);
  margin: 10px auto 4px;
  flex-shrink: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
  flex-shrink: 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px 20px;
  -webkit-overflow-scrolling: touch;
}

/* Centered dialog variant (not bottom-sheet) */
.modal-overlay.centered {
  align-items: center;
  padding: 16px;
}

.modal-overlay.centered .modal {
  border-radius: var(--radius-xl);
  transform: scale(0.92);
  transition: transform 200ms cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 200ms ease;
  opacity: 0;
}

.modal-overlay.centered.open .modal {
  transform: scale(1);
  opacity: 1;
}


/* ── Toast notifications ────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: calc(var(--max-w) - 32px);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-card);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text-primary);
  pointer-events: all;
  transform: translateY(-8px);
  opacity: 0;
  animation: toast-in 280ms cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.toast.removing {
  animation: toast-out 220ms ease forwards;
}

.toast-icon {
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.toast-success { border-left: 3px solid var(--buy); }
.toast-success .toast-icon { background: var(--buy-bg); color: var(--buy); }

.toast-error { border-left: 3px solid var(--sell); }
.toast-error .toast-icon { background: var(--sell-bg); color: var(--sell); }

.toast-warning { border-left: 3px solid var(--accent); }
.toast-warning .toast-icon { background: rgba(240, 185, 11, 0.12); color: var(--accent); }

.toast-info { border-left: 3px solid var(--text-muted); }
.toast-info .toast-icon { background: var(--bg-hover); color: var(--text-muted); }

.toast-msg { flex: 1; line-height: 1.4; }

@keyframes toast-in {
  to { transform: translateY(0); opacity: 1; }
}

@keyframes toast-out {
  to { transform: translateY(-8px); opacity: 0; }
}


/* ── Loading spinner ────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 640ms linear infinite;
  flex-shrink: 0;
}

.spinner-sm { width: 14px; height: 14px; border-width: 2px; }
.spinner-lg { width: 32px; height: 32px; border-width: 3px; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Full-screen loading overlay */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--bg-primary);
  z-index: 50;
  color: var(--text-muted);
  font-size: 13px;
}

/* Skeleton shimmer */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-card) 0%,
    var(--bg-hover) 50%,
    var(--bg-card) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}


/* ── Theme toggle ───────────────────────────────────────────── */
.theme-toggle {
  position: relative;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.theme-toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.theme-toggle-track {
  position: absolute;
  inset: 0;
  border-radius: var(--radius-full);
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
}

.theme-toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: transform var(--transition), background var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle input:checked ~ .theme-toggle-track {
  background: rgba(240, 185, 11, 0.2);
  border-color: var(--accent);
}

.theme-toggle input:checked ~ .theme-toggle-track .theme-toggle-thumb {
  transform: translateX(20px);
  background: var(--accent);
}


/* ── Scrollbar ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }


/* ── Utility ────────────────────────────────────────────────── */
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.no-select { user-select: none; -webkit-user-select: none; }

.tap-target {
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Number coloring */
.num-up   { color: var(--buy); }
.num-down { color: var(--sell); }
.num-flat { color: var(--text-muted); }


/* toast position on all screen sizes */
@media (min-width: 600px) {
  .toast-container { top: calc(var(--header-h) + 16px); }
}
