:root {
  --bg-primary: #F2F2F7;
  --bg-secondary: #FFFFFF;
  --bg-card: #FFFFFF;
  --bg-card-2: #F2F2F7;
  --text-primary: #000000;
  --text-secondary: #6C6C70;
  --text-tertiary: #AEAEB2;
  --accent-gold: #C9A84C;
  --accent-gold-light: #F0D080;
  --accent-gold-dark: #A07830;
  --profit: #34C759;
  --loss: #FF3B30;
  --separator: rgba(60, 60, 67, 0.12);
  --tab-bar-bg: rgba(249, 249, 249, 0.85);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.06);
  --shadow-card: 0 2px 8px rgba(0,0,0,0.06);
  --radius-card: 14px;
  --radius-btn: 12px;
  --radius-pill: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --tab-height: 49px;
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;

  /* Metal accent colours */
  --metal-XAU: #C9A84C;
  --metal-XAG: #A8A9AD;
  --metal-XPT: #6B90C2;
  --metal-XPD: #8B7EC8;
}

[data-theme="dark"] {
  --bg-primary: #1C1C1E;
  --bg-secondary: #2C2C2E;
  --bg-card: #2C2C2E;
  --bg-card-2: #3A3A3C;
  --text-primary: #FFFFFF;
  --text-secondary: #98989F;
  --text-tertiary: #636366;
  --separator: rgba(255, 255, 255, 0.08);
  --tab-bar-bg: rgba(28, 28, 30, 0.85);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 4px 12px rgba(0,0,0,0.2);
  --shadow-card: 0 2px 8px rgba(0,0,0,0.25);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  height: 100%;
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--bg-primary);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

#root {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  padding-top: var(--safe-top);
}

#screen-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding-bottom: calc(var(--tab-height) + var(--safe-bottom) + 8px);
}

.screen {
  min-height: 100%;
  padding: 0 0 20px;
}

/* Typography */
.text-title-lg { font-size: 28px; font-weight: 700; letter-spacing: -0.4px; line-height: 1.15; }
.text-title    { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; line-height: 1.2; }
.text-headline { font-size: 17px; font-weight: 600; line-height: 1.35; }
.text-body     { font-size: 15px; font-weight: 400; line-height: 1.45; }
.text-subhead  { font-size: 13px; font-weight: 400; color: var(--text-secondary); line-height: 1.4; }
.text-caption  { font-size: 11px; font-weight: 500; color: var(--text-secondary); letter-spacing: 0.2px; }

/* Color utilities */
.profit  { color: var(--profit) !important; }
.loss    { color: var(--loss) !important; }
.gold    { color: var(--accent-gold) !important; }
.muted   { color: var(--text-secondary) !important; }

/* Screen header */
.screen-header {
  padding: 12px 20px 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
}

.screen-header.with-back {
  padding-left: 8px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 2px;
  color: var(--accent-gold);
  font-size: 17px;
  font-weight: 400;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  -webkit-user-select: none;
  user-select: none;
}

.back-btn:active { opacity: 0.6; }

.back-btn svg { margin-right: 2px; }

/* Section label */
.section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 18px 20px 6px;
}

/* Divider */
.divider {
  height: 0.5px;
  background: var(--separator);
  margin: 0 20px;
}

.divider-full {
  height: 0.5px;
  background: var(--separator);
}

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 40px;
  text-align: center;
  gap: 12px;
}

.empty-state-icon {
  font-size: 56px;
  line-height: 1;
  margin-bottom: 8px;
}

.empty-state h3 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 15px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Loading state */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-2) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 8px;
}

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

/* Scrollable padding helper */
.px-20 { padding-left: 20px; padding-right: 20px; }
.py-16 { padding-top: 16px; padding-bottom: 16px; }
.mt-12 { margin-top: 12px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }

/* Demo badge */
.demo-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(201, 168, 76, 0.15);
  color: var(--accent-gold);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  border: 1px solid rgba(201, 168, 76, 0.3);
}

/* Stale badge */
.stale-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255, 59, 48, 0.1);
  color: var(--loss);
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 6px;
}

/* Alert / banner */
.banner {
  margin: 12px 20px;
  padding: 12px 16px;
  border-radius: var(--radius-card);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
  line-height: 1.45;
}

.banner.info {
  background: rgba(201, 168, 76, 0.12);
  border: 1px solid rgba(201, 168, 76, 0.25);
  color: var(--accent-gold-dark);
}

[data-theme="dark"] .banner.info {
  color: var(--accent-gold-light);
}

.banner-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.banner-text { flex: 1; }
.banner-text strong { display: block; font-weight: 600; margin-bottom: 2px; }

/* Toast */
#toast {
  position: fixed;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 16px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(50, 50, 52, 0.95);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 18px;
  border-radius: 20px;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 1000;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Confirm dialog overlay */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 900;
  display: flex;
  align-items: flex-end;
  padding-bottom: var(--safe-bottom);
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.dialog-sheet {
  width: 100%;
  background: var(--bg-card);
  border-radius: 14px 14px 0 0;
  padding: 24px 20px 16px;
  animation: slideUp 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.dialog-title { font-size: 17px; font-weight: 700; margin-bottom: 6px; text-align: center; }
.dialog-msg   { font-size: 14px; color: var(--text-secondary); text-align: center; margin-bottom: 20px; }
.dialog-btns  { display: flex; flex-direction: column; gap: 10px; }
