/* ============================================
   Hyperliquid Monitor PWA — Design System
   ============================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
  --bg-primary: #000000;
  --bg-card: #0a0a0a;
  --bg-header: #080808;

  --green: #00FF9D;
  --green-dim: rgba(0, 255, 157, 0.12);
  --green-border: rgba(0, 255, 157, 0.25);
  --red: #FF2E2E;
  --red-dim: rgba(255, 46, 46, 0.12);
  --red-border: rgba(255, 46, 46, 0.25);

  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.7);
  --text-tertiary: rgba(255, 255, 255, 0.38);
  --text-ghost: rgba(255, 255, 255, 0.15);

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-card: rgba(255, 255, 255, 0.12);

  --radius-sm: 6px;
  --radius-md: 10px;

  --font-main: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

/* --- Reset & Base --- */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  /* Lock viewport for "Fixed App" feel */
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* --- Loading Screen (Skeleton) --- */
#loading-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--bg-primary);
}
.skeleton-app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}
.sk-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  padding-top: calc(14px + var(--sat));
  border-bottom: 1px solid var(--border-subtle);
}
.sk-content {
  flex: 1;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sk-bar, .sk-pill, .sk-card {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, rgba(255,255,255,0.04) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.04) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
}
.sk-pills { display: flex; gap: 8px; }
.sk-pill { flex: 1; height: 32px; }
.sk-card { border: 1px solid var(--border-subtle); border-radius: var(--radius-md); }
.sk-hero { height: 100px; }
.sk-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sk-half { height: 60px; }
.sk-chart { flex: 1; min-height: 160px; }
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* --- App Layout (Fixed Viewport) --- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  opacity: 0;
  transition: opacity 0.5s ease;
}
#app.visible {
  opacity: 1;
}

/* --- Header --- */
#app-header {
  flex-shrink: 0; /* Never shrink */
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + var(--sat));
  background: var(--bg-header);
  border-bottom: 1px solid var(--border-subtle);
}

.header-left { display: flex; align-items: center; gap: 8px; }
.header-icon { font-size: 18px; filter: drop-shadow(0 0 6px var(--green)); }
.header-title {
  font-size: 14px; font-weight: 800; letter-spacing: 1px; color: var(--text-primary);
}

#sentiment-badge {
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 800;
  border: 1px solid transparent;
}
#sentiment-badge.bullish { color: var(--green); background: var(--green-dim); border-color: var(--green); }
#sentiment-badge.bearish { color: var(--red); background: var(--red-dim); border-color: var(--red); }
#sentiment-badge.neutral { color: #888; background: rgba(136,136,136,0.1); }
#sentiment-badge.extreme-bullish { color: #1B5E20; background: rgba(27, 94, 32, 0.2); border-color: #1B5E20; }
#sentiment-badge.extreme-bearish { color: #B71C1C; background: rgba(183, 28, 28, 0.2); border-color: #B71C1C; }
#sentiment-badge.mild-bullish { color: #A5D6A7; background: rgba(165, 214, 167, 0.1); border-color: #A5D6A7; }
#sentiment-badge.mild-bearish { color: #EF9A9A; background: rgba(239, 154, 154, 0.1); border-color: #EF9A9A; }


/* --- Alert Flash --- */
#alert-flash {
  position: fixed; inset: 0; z-index: 200; pointer-events: none;
  border: 12px solid transparent;
  animation: rainbowBorder 1s linear infinite;
}
@keyframes rainbowBorder {
  0%   { border-color: hsla(0, 80%, 60%, 0.35); }
  100% { border-color: hsla(360, 80%, 60%, 0.35); }
}

/* --- Main Content (Adaptive, No Scroll) --- */
#content {
  flex: 1;
  overflow: hidden;
  padding: 10px 16px;
  padding-bottom: calc(4px + var(--sab));
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* --- Asset Selector --- */
#asset-selector {
  flex-shrink: 0;
  display: flex;
  gap: 8px; /* Slightly wider gap */
  margin-bottom: 2px;
  justify-content: center; /* Center buttons */
  padding: 0 4px;
}
.asset-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.6);
  padding: 6px 0; /* Reduced padding slightly */
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
}
.asset-btn.active {
  background: rgba(0, 255, 157, 0.12);
  border-color: var(--green);
  color: var(--green);
  box-shadow: 0 0 10px rgba(0, 255, 157, 0.1); /* Add subtle glow */
}

/* --- Metric Cards --- */
.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 10px 12px; /* Reduce vertical padding */
  position: relative;
}

/* Hero Card (Compact) */
.hero-card {
  padding: 16px; /* Reduced from 20px */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.02);
}
.hero-card.updating { animation: rainbow-glow 1.5s linear infinite; }
.hero-card.bullish-border { border-color: rgba(0, 255, 157, 0.3); }
.hero-card.bearish-border { border-color: rgba(255, 46, 46, 0.3); }

.metric-header { display: flex; align-items: center; gap: 8px; margin-bottom: 2px; }
.metric-label { font-size: 10px; font-weight: 600; color: var(--text-secondary); letter-spacing: 1px; text-transform: uppercase; }

/* Delta Chip */
.metric-delta {
  font-size: 10px; font-weight: 700; font-family: var(--font-mono);
  padding: 2px 5px; border-radius: 3px; opacity: 0;
}
.metric-delta.visible { opacity: 1; }
.metric-delta.positive { color: var(--green); background: var(--green-dim); }
.metric-delta.negative { color: var(--red); background: var(--red-dim); }

.metric-value {
  font-size: 30px; /* Reduced from 32px */
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -1px;
}
.metric-value.green { color: var(--green); }
.metric-value.red { color: var(--red); }

/* Stats Grid (Long/Short) */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px; /* Tighter grid gap */
}
.secondary-card { padding: 8px 12px; }
.secondary-card .metric-label { font-size: 10px; margin-bottom: 2px; }
.secondary-card .metric-value { font-size: 15px; }

/* --- Chart Section (Flexible Height) --- */
#chart-section {
  flex: 1; /* Allow chart to expand to fill space if available */
  min-height: 160px; /* Reduced min height */
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 10px;
}
.chart-header { display: flex; justify-content: space-between; align-items: center; }
.section-title { font-size: 11px; font-weight: 700; color: var(--text-secondary); }
.chart-container {
  flex: 1; /* Fill parent */
  position: relative;
  width: 100%;
  min-height: 0; /* Crucial for flex child scroll/sizing */
}

/* Custom Dropdown Compact */
.custom-dropdown { position: relative; font-family: var(--font-mono); font-size: 11px; }
.dropdown-trigger {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,0.04); border-radius: 10px;
  padding: 3px 8px; font-size: 10px; cursor: pointer; color: var(--text-secondary);
}
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); right: 0; width: 110px;
  background: rgba(10,10,10,0.98); border: 1px solid var(--border-subtle);
  border-radius: 8px; padding: 4px 0; z-index: 999;
  opacity: 0; pointer-events: none; transform: translateY(-5px); transition: all 0.2s;
}
.custom-dropdown.open .dropdown-menu { opacity: 1; pointer-events: auto; transform: translateY(0); }
.dropdown-group { font-size: 9px; color: var(--text-tertiary); padding: 4px 8px; font-weight: 700; }
.dropdown-item { padding: 6px 12px; font-size: 11px; cursor: pointer; color: var(--text-secondary); }
.dropdown-item:hover { background: rgba(255,255,255,0.05); color: #fff; }
.dropdown-item.active { color: var(--green); background: rgba(0,255,157,0.08); }


/* Button & Icons */
.header-right { display: flex; gap: 8px; }

/* --- Footer --- */
#app-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 16px;
  flex-shrink: 0;
}
#last-update, #last-change {
  font-size: 10px;
  color: #ffffff; /* User requested pure white */
  font-weight: 600;
  letter-spacing: 0.5px;
}
.icon-btn {
  width: 28px; height: 28px;
  background: rgba(255,255,255,0.05);
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.1);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-tertiary);
  cursor: pointer;
}
.icon-btn.active { color: var(--green); border-color: var(--green); }

/* Animation Keyframes (Preserved for functionality) */
@keyframes rainbow-glow {
  0% { border-color: rgba(255, 0, 0, 0.5); }
  50% { border-color: rgba(208, 222, 33, 0.5); }
  100% { border-color: rgba(47, 201, 226, 0.5); }
}

/* --- Connection Status Indicator --- */
.conn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
  align-self: center;
  transition: background-color 0.3s;
}
.conn-dot.online { background: var(--green); box-shadow: 0 0 4px var(--green); }
.conn-dot.offline { background: var(--red); box-shadow: 0 0 4px var(--red); animation: blink 1.5s infinite; }
.conn-dot.error { background: #ff9800; box-shadow: 0 0 4px #ff9800; animation: blink 1.5s infinite; }
@keyframes blink { 0%,100% { opacity:1; } 50% { opacity:0.3; } }

/* --- Pull to Refresh --- */
#ptr-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 0;
  opacity: 0;
  overflow: hidden;
  transition: opacity 0.2s;
  flex-shrink: 0;
}
#ptr-indicator.ptr-hidden { height: 0 !important; opacity: 0 !important; }
.ptr-spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.1);
  border-top-color: var(--green);
  border-radius: 50%;
}
#ptr-indicator.ptr-ready .ptr-spinner,
#ptr-indicator.ptr-loading .ptr-spinner {
  animation: spin 0.6s linear infinite;
}
.ptr-text { font-size: 10px; color: var(--text-tertiary); }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- Value Update Animation --- */
.value-updating {
  animation: value-pop 0.4s ease;
}
@keyframes value-pop {
  0% { transform: scale(1); }
  30% { transform: scale(1.06); opacity: 0.7; }
  100% { transform: scale(1); opacity: 1; }
}

/* --- Chart Switcher --- */
#chart-switcher {
    flex-shrink: 0;
    display: flex;
    background: rgba(255,255,255,0.05);
    padding: 3px;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid var(--border-subtle);
}
.switch-btn {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 11px;
    font-weight: 600;
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: var(--font-main);
}
.switch-btn.active {
    background: rgba(255,255,255,0.08); /* Darker default active */
    color: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

/* Specific active colors matching the metric */
.switch-btn.active[data-chart="net"] { color: var(--green); background: rgba(0, 255, 157, 0.1); }
.switch-btn.active[data-chart="long"] { color: var(--green); background: rgba(0, 255, 157, 0.1); }
.switch-btn.active[data-chart="short"] { color: var(--red); background: rgba(255, 46, 46, 0.1); }
