/* ============================================================
   UniTradeX base layer — design tokens + responsive foundation
   Load BEFORE page CSS:  <link rel="stylesheet" href="/assets/css/base.css">
   ============================================================ */

:root {
  /* Palette (matches existing slate/navy theme) */
  --bg: #0f172a;
  --bg-deep: #020617;
  --surface: #1e293b;
  --surface-2: #334155;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #38bdf8;
  --success: #22c55e;
  --success-deep: #16a34a;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #0ea5e9;

  /* Aliases used by older page CSS (style.css etc.) */
  --bg-card: #1e293b;
  --card: #1e293b;

  /* Spacing & shape */
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
  --pad-page: 2rem;

  color-scheme: dark;
}

body.light-mode {
  --bg: #f1f5f9;
  --bg-deep: #e2e8f0;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --border: rgba(15, 23, 42, 0.1);
  --text: #0f172a;
  --text-muted: #475569;
  --shadow: 0 6px 16px rgba(15, 23, 42, 0.12);
  --bg-card: #ffffff;
  --card: #ffffff;

  color-scheme: light;
}

/* ---------- Sensible global defaults ---------- */

img, svg, video, canvas {
  max-width: 100%;
  height: auto;
}

/* Prevent horizontal scroll from stray fixed/absolute elements */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* Inputs: 16px floor stops iOS auto-zoom; comfortable tap targets */
input, select, textarea, button {
  font-size: max(16px, 1em);
  font-family: inherit;
}

button, .btn, [role="button"], input[type="submit"] {
  min-height: 44px;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* Respect PWA notches / home indicators */
@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Reduce motion for users who ask for it */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Utilities ---------- */

/* Wrap any wide table:  <div class="table-wrap"><table>... */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.table-wrap table {
  min-width: 600px;
  width: 100%;
}

.hide-mobile { display: initial; }
.only-mobile { display: none; }

/* Skeleton loading shimmer:  <div class="skeleton" style="height:20px"></div> */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: skeleton-wave 1.4s infinite;
  border-radius: 6px;
  min-height: 1em;
}

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

/* ---------- Toasts (used by window.toast in common.js) ---------- */

#toast-stack {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  z-index: 100000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(420px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  animation: toast-in 0.25s ease;
  pointer-events: auto;
}

.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }

.toast.leaving {
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
}

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

/* ---------- Wallet menu items (POST forms styled like links) ---------- */

.wallet-menu form { margin: 0; }

.wallet-menu-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 0;
  padding: 0.75rem;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  font-size: 1rem;
  font-weight: normal;
}

.wallet-menu form:last-child .wallet-menu-item { border-bottom: none; }

.wallet-menu-item:hover { background: var(--surface-2); }

.wallet-menu-item.active { color: var(--success); }

.wallet-menu-item small {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

/* ---------- Responsive breakpoints ---------- */

@media (max-width: 900px) {
  :root { --pad-page: 1.25rem; }
}

@media (max-width: 640px) {
  :root { --pad-page: 0.875rem; }

  section {
    padding: var(--pad-page);
    margin: 0.5rem;
    border-radius: var(--radius);
  }

  header {
    padding: 0.75rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  header h1 { font-size: 1.2rem; }

  /* Fixed wallet badge: keep it inside the viewport on phones */
  .wallet-point {
    right: 0.75rem;
    top: 0.75rem;
  }

  .wallet-menu {
    min-width: 200px;
    max-width: calc(100vw - 1.5rem);
  }

  .hide-mobile { display: none !important; }
  .only-mobile { display: initial; }

  /* Stack any .grid / flex rows that declare themselves responsive */
  .stack-mobile {
    display: flex !important;
    flex-direction: column !important;
  }

  .stack-mobile > * {
    width: 100% !important;
  }
}
