/* style.css — Fluid Converter (glass morphism, multi-asset)
 *
 * Design tokens mirror the prototype's developer handoff. Uses OKLCH for
 * perceptually uniform palette (supported on Safari 16.4+, Chrome 111+ —
 * iPhone 16 Pro on iOS 18 has full support).
 */

:root {
  /* Fonts */
  --font-display: 'Iowan Old Style', 'Charter', Georgia, serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;

  /* Default: dark mode (space / frosted glass) */
  --bg: oklch(14% 0.015 240);
  --bg-gradient: linear-gradient(135deg, oklch(12% 0.02 240), oklch(22% 0.03 240));

  --surface-1: rgba(30, 35, 45, 0.5);
  --surface-2: rgba(40, 45, 60, 0.3);
  --surface-active: rgba(60, 65, 80, 0.6);
  --surface-sheet: rgba(25, 30, 40, 0.85);

  --fg: oklch(98% 0.005 240);
  --muted: oklch(70% 0.02 240);
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.2);

  --accent-navy: oklch(40% 0.12 250);
  --accent-aqua: oklch(65% 0.15 200);
  --accent-aqua-bright: oklch(75% 0.16 195);

  --positive: oklch(75% 0.12 160);
  --negative: oklch(70% 0.15 20);
  --warn: oklch(75% 0.13 80);

  --tab-bar-height: 84px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: oklch(98% 0.01 240);
    --bg-gradient: linear-gradient(135deg, oklch(95% 0.01 240), oklch(99% 0.005 240));

    --surface-1: rgba(255, 255, 255, 0.6);
    --surface-2: rgba(255, 255, 255, 0.4);
    --surface-active: rgba(255, 255, 255, 0.8);
    --surface-sheet: rgba(245, 245, 250, 0.85);

    --fg: oklch(20% 0.03 240);
    --muted: oklch(50% 0.03 240);
    --border: rgba(0, 0, 0, 0.06);
    --border-strong: rgba(0, 0, 0, 0.12);

    --accent-navy: oklch(30% 0.12 250);
    --accent-aqua: oklch(50% 0.15 200);

    --positive: oklch(55% 0.12 160);
    --negative: oklch(50% 0.15 20);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--fg);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
  min-height: 100vh;
  min-height: 100dvh;
}

/* Ambient background orbs for depth */
.bg-orbs {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.6;
}
.orb-1 {
  width: 300px; height: 300px;
  background: var(--accent-navy);
  top: -10%; left: -20%;
}
.orb-2 {
  width: 250px; height: 250px;
  background: var(--accent-aqua);
  bottom: 20%; right: -25%;
}

/* App shell */
.app {
  position: relative;
  z-index: 1;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding-top: max(20px, env(safe-area-inset-top));
  padding-bottom: calc(var(--tab-bar-height) + max(0px, env(safe-area-inset-bottom)));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

/* Glass utility */
.glass {
  background: var(--surface-1);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border);
}

/* Display font helper */
.display-font {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
}

h1, h2 { margin: 0; line-height: 1.1; }

/* Header */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 4px 20px 4px;
}
.header h1 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
.header .header-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.header .offline-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--negative);
  box-shadow: 0 0 8px var(--negative);
  display: none;
}
.header.is-offline .offline-dot { display: inline-block; }
.header.is-offline .header-status .label { color: var(--negative); }

/* View switcher */
.view {
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.3s cubic-bezier(0.2, 0.8, 0.2, 1),
              transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.view.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}
.view-stack { position: relative; flex: 1; display: flex; flex-direction: column; }
.view-stack > .view:not(.active) { position: absolute; inset: 0; }

/* Converter cards */
.converter-card {
  border-radius: 32px;
  padding: 22px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}

.asset-selector {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface-active);
  border-radius: 20px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  width: fit-content;
  cursor: pointer;
  border: 1px solid var(--border);
  color: var(--fg);                   /* explicit — buttons don't inherit */
  transition: background 0.2s;
  user-select: none;
}
.asset-selector:active { background: var(--surface-2); transform: scale(0.98); }
.asset-selector svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;               /* picks up explicit fg color above */
}

.input-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 6px;
}
.currency-symbol {
  font-size: 32px;
  color: var(--muted);
  flex-shrink: 0;
}
.giant-input {
  background: transparent;
  border: 0;
  font-size: 44px;
  color: var(--fg);
  width: 100%;
  outline: none;
  padding: 0;
  margin: 0;
  font-family: var(--font-display);
  letter-spacing: -0.01em;
  /* ≥16px prevents iOS Safari from zooming on focus */
  min-width: 0;
}
.giant-input::placeholder { color: var(--muted); opacity: 0.4; }
.asset-name {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

.swap-btn {
  align-self: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  color: var(--fg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: -16px auto;
  z-index: 10;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
  padding: 0;
  position: relative;
}
.swap-btn:active { transform: scale(0.92); }
.swap-btn svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* Freshness indicator under converter */
.freshness {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin: 12px 0 4px;
}
.freshness.fresh { color: var(--muted); }
.freshness.stale-warn { color: var(--warn); }
.freshness.stale-bad { color: var(--negative); }

.refresh-button {
  background: transparent;
  border: 1px solid var(--border);
  color: inherit;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.refresh-button.spinning { animation: spin 0.6s linear; }

/* Quick reference table */
.quick-ref-container {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quick-ref-header {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--muted);
  text-transform: uppercase;
  padding-left: 16px;
}
.quick-ref-table {
  border-radius: 24px;
  padding: 10px 18px;
  display: flex;
  flex-direction: column;
}
.quick-ref-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 0;
  font-variant-numeric: tabular-nums;
}
.quick-ref-row + .quick-ref-row { border-top: 1px solid var(--border); }
.ref-base {
  font-size: 14px;
  color: var(--muted);
}
.ref-target {
  font-size: 14px;
  color: var(--fg);
  font-weight: 600;
}

/* Portfolio tab */
.portfolio-header {
  padding: 8px 4px 16px 4px;
}
.portfolio-header .balance-label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.giant-balance {
  font-size: 42px;
  margin: 8px 0 14px 0;
  font-weight: normal;
}
.pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 600;
  gap: 4px;
}
.pill.positive {
  background: color-mix(in srgb, var(--positive) 15%, transparent);
  color: var(--positive);
}
.pill.negative {
  background: color-mix(in srgb, var(--negative) 15%, transparent);
  color: var(--negative);
}
.pill svg { width: 11px; height: 11px; stroke: currentColor; stroke-width: 3; fill: none; }

.asset-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
}
.asset-row {
  display: flex;
  align-items: center;
  padding: 14px 18px;
  border-radius: 24px;
  gap: 14px;
}
.asset-icon {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  border: 1px solid var(--border);
  color: var(--accent-aqua);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.asset-info { flex: 1; min-width: 0; }
.asset-title {
  font-weight: 600;
  font-size: 15px;
}
.asset-qty {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.asset-price-info { text-align: right; }
.asset-value {
  font-weight: 600;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}
.asset-price {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
  transition: color 0.4s ease, text-shadow 0.4s ease;
}

/* Live tick animations (when WebSocket-style update arrives) */
.tick-up {
  color: var(--positive) !important;
  text-shadow: 0 0 8px color-mix(in srgb, var(--positive) 50%, transparent);
}
.tick-down {
  color: var(--negative) !important;
  text-shadow: 0 0 8px color-mix(in srgb, var(--negative) 50%, transparent);
}

/* Bottom tab bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  height: var(--tab-bar-height);
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  padding-top: 8px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-top: 1px solid var(--border);
  background: var(--surface-1);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
}

/* Watchlist actions — Add, Edit, Delete */
.watchlist-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 4px 0 8px;
}
.empty-watchlist {
  text-align: center;
  padding: 32px 24px 24px;
  border-radius: 24px;
  margin-top: 12px;
}
.empty-watchlist h2 {
  margin: 0 0 8px 0;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 500;
}
.empty-watchlist p {
  margin: 0 0 18px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: color-mix(in srgb, var(--accent-aqua) 18%, transparent);
  color: var(--accent-aqua);
  border: 1px solid color-mix(in srgb, var(--accent-aqua) 35%, transparent);
  font-weight: 600;
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 18px;
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-primary:active { background: color-mix(in srgb, var(--accent-aqua) 25%, transparent); }
.btn-primary svg {
  width: 14px;
  height: 14px;
  stroke: currentColor;
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  padding: 8px 14px;
  border-radius: 100px;
  cursor: pointer;
}
.btn-ghost:active { background: var(--surface-2); }

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.icon-button {
  background: transparent;
  border: 0;
  color: var(--muted);
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  padding: 0;
}
.icon-button:active { background: var(--surface-2); }
.icon-button.danger:active { color: var(--negative); }
.icon-button svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Quantity edit field that replaces the qty text inline when row is being edited */
.qty-edit-input {
  background: var(--surface-active);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 12px;
  width: 110px;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  outline: none;
}
.qty-edit-input:focus { border-color: var(--accent-aqua); }

/* Add/Edit sheet quantity input */
.qty-input-row {
  padding: 16px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.qty-input-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}
.qty-input {
  background: var(--surface-active);
  border: 1px solid var(--border);
  color: var(--fg);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 18px;
  font-family: var(--font-body);
  font-variant-numeric: tabular-nums;
  outline: none;
  width: 100%;
}
.qty-input:focus { border-color: var(--accent-aqua); }

.sheet-footer {
  padding: 12px 20px max(20px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
.tab {
  background: transparent;
  border: 0;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 18px;
  transition: color 0.2s;
  font-family: var(--font-body);
}
.tab.active { color: var(--accent-aqua); }
.tab svg {
  width: 22px;
  height: 22px;
  stroke: currentColor;
  stroke-width: 2.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Asset selector sheet (modal) */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.sheet-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 65vh;
  border-radius: 28px 28px 0 0;
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: flex;
  flex-direction: column;
  background: var(--surface-sheet);
  -webkit-backdrop-filter: blur(40px);
  backdrop-filter: blur(40px);
  border-top: 1px solid var(--border-strong);
  padding-bottom: max(20px, env(safe-area-inset-bottom));
}
.sheet-overlay.active .sheet { transform: translateY(0); }

.sheet-header {
  padding: 20px 24px;
  font-weight: 600;
  text-align: center;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.sheet-close {
  position: absolute;
  right: 16px;
  top: 16px;
  width: 28px;
  height: 28px;
  background: var(--surface-active);
  border: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  color: var(--fg);
}
.sheet-list {
  padding: 12px 16px 24px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sheet-list::-webkit-scrollbar { display: none; }

.asset-select-row {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-radius: 18px;
  background: var(--surface-2);
  cursor: pointer;
  transition: background 0.15s;
  border: 0;
  text-align: left;
  width: 100%;
  color: var(--fg);
  font-family: var(--font-body);
  gap: 12px;
}
.asset-select-row:hover { background: var(--surface-active); }
.asset-select-row .asset-icon {
  width: 36px;
  height: 36px;
  font-size: 11px;
  margin-right: 0;
}

/* Hide native scrollbars but keep scrollability */
::-webkit-scrollbar { width: 0; height: 0; }
