/* ================================================================
   INVERSIONES APP — Dark Theme
   Optimizado para iPhone / iOS Safari PWA
   ================================================================ */

/* ── Custom Properties ─────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-primary:   #090B10;
  --bg-card:      #10121A;
  --bg-elevated:  #181B25;
  --bg-hover:     #1E2230;

  /* Borders */
  --border:       rgba(255, 255, 255, 0.07);
  --border-mid:   rgba(255, 255, 255, 0.11);

  /* Text */
  --text-primary:   #E8ECF4;
  --text-secondary: #8B90A8;
  --text-muted:     #454860;

  /* Semantic */
  --green:      #00C896;
  --green-dim:  rgba(0, 200, 150, 0.12);
  --red:        #FF4060;
  --red-dim:    rgba(255, 64, 96, 0.12);
  --purple:     #7C5CE9;
  --purple-dim: rgba(124, 92, 233, 0.12);
  --gold:       #F0A840;
  --gold-dim:   rgba(240, 168, 64, 0.12);
  --blue:       #3B82F6;
  --blue-dim:   rgba(59, 130, 246, 0.12);
  --teal:       #06B6D4;
  --teal-dim:   rgba(6, 182, 212, 0.12);

  /* Safe areas (iOS notch / home bar) */
  --sat: env(safe-area-inset-top,    44px);
  --sar: env(safe-area-inset-right,   0px);
  --sab: env(safe-area-inset-bottom, 34px);
  --sal: env(safe-area-inset-left,    0px);

  /* Radii */
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-xl: 22px;

  /* Transitions */
  --trans-fast: 0.15s ease;
  --trans-mid:  0.25s ease;
}

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

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  min-height: 100%;
  min-height: -webkit-fill-available;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display',
               'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Prevent body scroll bounce showing white on overscroll */
  background-attachment: fixed;
}

/* Hide scrollbars (keep scroll functionality) */
::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; -ms-overflow-style: none; }

a { color: var(--purple); text-decoration: none; }
a:active { opacity: 0.7; }

/* ── App Container ─────────────────────────────────────────────── */
#app {
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ── Pull-to-Refresh Indicator ─────────────────────────────────── */
.ptr-indicator {
  position: fixed;
  top: calc(var(--sat) + 8px);
  left: 50%;
  z-index: 300;
  width: 34px;
  height: 34px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-mid);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: translateX(-50%) translateY(-70px);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.ptr-indicator.visible {
  transform: translateX(-50%) translateY(0);
}

.ptr-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-mid);
  border-top-color: var(--purple);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

/* ── Header ─────────────────────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 200;
  background: rgba(9, 11, 16, 0.88);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border-bottom: 1px solid var(--border);
  padding:
    calc(var(--sat) + 10px)
    calc(16px + var(--sar))
    12px
    calc(16px + var(--sal));
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  background: var(--purple-dim);
  border: 1px solid rgba(124, 92, 233, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-name {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Live badge */
.live-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--green-dim);
  border: 1px solid rgba(0, 200, 150, 0.22);
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 0.8px;
}

.live-dot {
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: breathe 2s ease-in-out infinite;
}

/* Icon button */
.icon-btn {
  width: 34px;
  height: 34px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--trans-fast), transform var(--trans-fast);
}

.icon-btn:active {
  transform: scale(0.90);
  background: var(--bg-elevated);
}

.icon-btn.spinning svg {
  animation: spin 0.9s linear infinite;
}

/* Update time */
.update-time {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Global Market Card ─────────────────────────────────────────── */
.global-card {
  margin: 14px 16px 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-height: 68px;
}

.global-skeleton {
  height: 68px;
  background: linear-gradient(90deg,
    var(--bg-card) 25%,
    var(--bg-elevated) 50%,
    var(--bg-card) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s infinite;
}

.global-content {
  display: flex;
  align-items: stretch;
  height: 68px;
}

.global-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 10px 4px;
}

.global-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.4px;
  text-transform: uppercase;
}

.global-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.2px;
}

.global-change {
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.global-change.positive { color: var(--green); }
.global-change.negative { color: var(--red); }

.global-divider {
  width: 1px;
  background: var(--border);
  align-self: stretch;
  margin: 10px 0;
}

/* ── Ticker Bar ──────────────────────────────────────────────────── */
.ticker-wrap {
  overflow-x: auto;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.ticker-inner {
  display: flex;
  gap: 8px;
  align-items: center;
  min-width: max-content;
}

.ticker-placeholder {
  font-size: 12px;
  color: var(--text-muted);
}

.ticker-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  white-space: nowrap;
  cursor: default;
  transition: background var(--trans-fast);
}

.ticker-chip:active { background: var(--bg-elevated); }

.ticker-sym {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.2px;
}

.ticker-price {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}

.ticker-change {
  font-size: 11px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.ticker-change.positive { color: var(--green); }
.ticker-change.negative { color: var(--red); }

/* ── Main Content ────────────────────────────────────────────────── */
.main {
  padding-bottom: calc(28px + var(--sab));
}

/* ── Section ─────────────────────────────────────────────────────── */
.section {
  margin: 20px 16px 0;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.section-badge {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 9px;
  letter-spacing: 0.3px;
}

/* ── Asset List ───────────────────────────────────────────────────── */
.asset-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

/* ── Skeleton Rows ───────────────────────────────────────────────── */
.skeleton-row {
  height: 70px;
  position: relative;
  overflow: hidden;
  background: var(--bg-card);
}

.skeleton-row:not(:last-child) {
  border-bottom: 1px solid var(--border);
}

.skeleton-row::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.04) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.6s ease-in-out infinite;
}

/* ── Asset Row ───────────────────────────────────────────────────── */
.asset-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 15px;
  position: relative;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: background var(--trans-fast);
  /* iOS: enable hardware acceleration for smooth touch */
  -webkit-transform: translateZ(0);
}

.asset-row:not(:last-child)::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 71px; /* start after icon */
  right: 0;
  height: 1px;
  background: var(--border);
}

.asset-row:active {
  background: var(--bg-elevated);
}

/* Icon container */
.asset-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
}

.asset-icon img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ETF icon (square with color) */
.asset-icon.etf-icon {
  border-radius: var(--radius-sm);
}

/* Info block */
.asset-info {
  flex: 1;
  min-width: 0;
}

.asset-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.asset-sub {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

/* Price block (right side) */
.asset-price-block {
  text-align: right;
  flex-shrink: 0;
}

.asset-price {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
  margin-bottom: 3px;
  white-space: nowrap;
}

.asset-change {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.asset-change.positive {
  color: var(--green);
  background: var(--green-dim);
}

.asset-change.negative {
  color: var(--red);
  background: var(--red-dim);
}

/* ── Error State ─────────────────────────────────────────────────── */
.error-state {
  padding: 28px 16px;
  text-align: center;
}

.error-emoji {
  font-size: 30px;
  line-height: 1;
  margin-bottom: 10px;
}

.error-msg {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.error-note {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: -8px;
  margin-bottom: 16px;
}

.retry-btn {
  background: var(--purple-dim);
  border: 1px solid rgba(124, 92, 233, 0.28);
  color: var(--purple);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 9px 20px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform var(--trans-fast), background var(--trans-fast);
}

.retry-btn:active {
  transform: scale(0.95);
  background: rgba(124, 92, 233, 0.2);
}

/* ── Footer ───────────────────────────────────────────────────────── */
.footer {
  margin: 24px 16px 0;
  text-align: center;
}

.footer p {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.8;
}

.footer-sub {
  color: var(--text-muted);
  opacity: 0.6;
}

/* ── Toast ────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: calc(16px + var(--sab));
  left: 50%;
  transform: translateX(-50%) translateY(calc(100% + 20px));
  background: var(--bg-elevated);
  border: 1px solid var(--border-mid);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  padding: 11px 20px;
  border-radius: var(--radius-md);
  white-space: nowrap;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  pointer-events: none;
}

.toast.visible {
  transform: translateX(-50%) translateY(0);
}

/* ── Animations ───────────────────────────────────────────────────── */
@keyframes spin {
  to { transform: rotate(360deg); }
}

@keyframes breathe {
  0%, 100% { opacity: 1;   transform: scale(1);   }
  50%       { opacity: 0.4; transform: scale(0.75); }
}

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

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

/* Applied to newly rendered rows */
.asset-row {
  animation: fadeSlideUp 0.28s ease forwards;
}

/* Stagger delays for list items */
.asset-row:nth-child(1) { animation-delay: 0.00s; }
.asset-row:nth-child(2) { animation-delay: 0.04s; }
.asset-row:nth-child(3) { animation-delay: 0.08s; }
.asset-row:nth-child(4) { animation-delay: 0.12s; }
.asset-row:nth-child(5) { animation-delay: 0.16s; }
.asset-row:nth-child(6) { animation-delay: 0.20s; }
.asset-row:nth-child(7) { animation-delay: 0.24s; }
.asset-row:nth-child(8) { animation-delay: 0.28s; }

/* ── Responsive (tablet / small desktop preview) ─────────────────── */
@media (min-width: 480px) {
  #app {
    border-left:  1px solid var(--border);
    border-right: 1px solid var(--border);
    min-height: 100vh;
  }
}

/* ── Reduced motion ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
