/* =========================================================================
   Auto-Cuan — UI theme layer
   =========================================================================

   Loaded AFTER the inline <style> block in index.html so it wins without
   !important. It is deliberately a restyle of the component classes that
   already exist (.panel, .action-card, .dashboard-hero, .empty-state, …)
   rather than new markup: the app converges on one card language, one radius
   scale and one type scale without touching behaviour.

   Sections
     1. Tokens
     2. Base + typography
     3. Surfaces and cards
     4. Header and desktop navigation
     5. Mobile bottom navigation + menu sheet
     6. Tables, forms, misc
     7. Reduced motion
   ========================================================================= */

/* ---- 1. Tokens --------------------------------------------------------- */
:root {
  --ac-bg: #0b0e14;
  --ac-bg-elevated: #0f1319;

  --ac-surface-1: linear-gradient(150deg, rgba(22, 29, 41, 0.86), rgba(12, 17, 25, 0.78));
  --ac-surface-2: rgba(16, 22, 33, 0.72);
  --ac-surface-3: rgba(2, 6, 23, 0.34);

  --ac-line: rgba(148, 163, 184, 0.12);
  --ac-line-strong: rgba(148, 163, 184, 0.20);

  --ac-text: #f1f5f9;
  --ac-text-muted: #94a3b8;
  --ac-text-dim: #6b7a90;

  --ac-accent: #34d399;
  --ac-accent-strong: #10b981;
  --ac-accent-soft: rgba(16, 185, 129, 0.10);
  --ac-accent-line: rgba(52, 211, 153, 0.30);

  /* One radius scale instead of the 12/16/17/18/22/24px mix. */
  --ac-radius-sm: 10px;
  --ac-radius-md: 14px;
  --ac-radius-lg: 16px;
  --ac-radius-xl: 20px;

  /* One shadow ramp: surfaces sit at 1, page-level shells at 2. */
  --ac-shadow-1: 0 8px 24px rgba(0, 0, 0, 0.20);
  --ac-shadow-2: 0 20px 52px rgba(0, 0, 0, 0.26);

  --ac-space-1: 6px;
  --ac-space-2: 10px;
  --ac-space-3: 14px;
  --ac-space-4: 18px;
  --ac-space-5: 24px;

  --ac-fab-size: 56px;
  --ac-safe-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---- 1b. Viewport height ------------------------------------------------
   iOS Safari and Android Chrome both size 100vh to the viewport with the URL bar
   COLLAPSED, so a 100vh shell overshoots the visible area and shifts as the bar
   hides and shows. `dvh` tracks the real viewport; the `vh` line stays first as the
   fallback for engines that do not support it. */
body, #dashboardScreen, .landing-shell { min-height: 100vh; }
.sidebar { height: 100vh; }
#page-analisis { min-height: calc(100vh - 120px); }
#aiSection { min-height: calc(100vh - 64px); }

@supports (height: 100dvh) {
  body, #dashboardScreen, .landing-shell { min-height: 100dvh; }
  .sidebar { height: 100dvh; }
  #page-analisis { min-height: calc(100dvh - 120px); }
  #aiSection { min-height: calc(100dvh - 64px); }
}

/* The app footer sits at the foot of the shell; keep it clear of the home indicator. */
#dashboardScreen > footer { padding-bottom: var(--ac-safe-bottom); }

/* ---- 2. Base + typography ---------------------------------------------- */
body {
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Numbers in a trading dashboard must line up column to column. */
.panel b, .panel-title, .ps-level b, .dashboard-card b,
.tabular, [class*="tabular-nums"] {
  font-variant-numeric: tabular-nums;
}

/* ---- 3. Surfaces and cards --------------------------------------------- */
.panel {
  background: var(--ac-surface-1);
  border: 1px solid var(--ac-line);
  border-radius: var(--ac-radius-lg);
  padding: var(--ac-space-4);
  box-shadow: var(--ac-shadow-1);
}

.panel-header {
  align-items: flex-start;
  gap: var(--ac-space-3);
  margin-bottom: var(--ac-space-3);
}

.panel-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.005em;
  color: var(--ac-text);
}

.panel-subtitle {
  margin-top: 3px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ac-text-muted);
}

/* Section band: a labelled group of panels on the dashboard. Gives the page a
   scannable rhythm (act now → live radar → history) instead of one flat stack. */
.ac-section { margin-top: var(--ac-space-5); }
.ac-section:first-child { margin-top: 0; }

.ac-section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--ac-space-3);
  margin-bottom: var(--ac-space-3);
  padding-bottom: var(--ac-space-2);
  border-bottom: 1px solid var(--ac-line);
}

.ac-section-title {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ac-text-muted);
}

.ac-section-hint {
  font-size: 11px;
  line-height: 1.5;
  color: var(--ac-text-dim);
}

.dashboard-hero {
  border-radius: var(--ac-radius-xl);
  border-color: rgba(52, 211, 153, 0.16);
  box-shadow: var(--ac-shadow-2);
}

.dashboard-card {
  border: 1px solid var(--ac-line);
  background: var(--ac-surface-2);
  border-radius: var(--ac-radius-lg);
  box-shadow: var(--ac-shadow-1);
}

.chart-shell, .portfolio-shell {
  background: var(--ac-surface-1);
  border: 1px solid var(--ac-line);
  border-radius: var(--ac-radius-xl);
  box-shadow: var(--ac-shadow-2);
}

.feature-card {
  border: 1px solid var(--ac-line);
  background: var(--ac-surface-2);
  border-radius: var(--ac-radius-lg);
}

.action-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 96px;
  padding: var(--ac-space-3);
  background: var(--ac-surface-2);
  border: 1px solid var(--ac-line);
  border-radius: var(--ac-radius-md);
  box-shadow: var(--ac-shadow-1);
}

.action-card:hover {
  border-color: var(--ac-accent-line);
  background: rgba(16, 185, 129, 0.06);
}

.action-card .action-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--ac-radius-sm);
  background: var(--ac-accent-soft);
  margin-bottom: var(--ac-space-2);
}

.action-card .action-icon svg { width: 17px; height: 17px; }

.dash-badge {
  padding: 4px 9px;
  border-color: var(--ac-line-strong);
  background: rgba(15, 23, 42, 0.55);
  font-weight: 600;
  letter-spacing: 0.01em;
}

.dash-section-note {
  border-radius: var(--ac-radius-md);
  padding: var(--ac-space-2) var(--ac-space-3);
  line-height: 1.6;
}

.empty-state {
  border-radius: var(--ac-radius-md);
  border-color: var(--ac-line);
  background: var(--ac-surface-3);
  padding: var(--ac-space-5) var(--ac-space-4);
}

.empty-state-text { color: var(--ac-text-muted); }

/* ---- 4. Header and desktop navigation ---------------------------------- */
.app-header {
  background: rgba(11, 14, 20, 0.82);
  border-bottom: 1px solid var(--ac-line);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
}

.nav-btn {
  border-radius: var(--ac-radius-sm);
  font-weight: 600;
  color: var(--ac-text-muted);
}

.nav-btn:hover:not(.disabled) {
  color: var(--ac-text);
  background: rgba(148, 163, 184, 0.08);
  border-color: var(--ac-line);
}

.nav-btn.active {
  color: #6ee7b7;
  background: var(--ac-accent-soft);
  border-color: var(--ac-accent-line);
  box-shadow: inset 0 -2px 0 rgba(52, 211, 153, 0.45);
}

/* ---- 5. Floating mobile navigation launcher ---------------------------- */
/* Below 1024px the scrolling header strip is replaced by a draggable, edge-snapping
   circular launcher. `#mainNav` stays in the DOM as the source of truth for
   mobile-nav.js and for the runtimes that inject buttons into it — only its display
   is dropped.

   A floating control reserves no layout space, which is deliberate: the previous
   fixed bottom bar required padding <body>, and with border-box that shrank the
   100vh body content box below the 100vh shell, leaving a dead band containing the
   footer at the foot of every page. */
.ac-launcher, .ac-navpanel { display: none; }

@media (max-width: 1023px) {
  .mobile-nav-row { display: none !important; }

  .ac-launcher {
    position: fixed;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    width: var(--ac-fab-size);
    height: var(--ac-fab-size);
    padding: 0;
    border: 1px solid rgba(52, 211, 153, 0.34);
    border-radius: 999px;
    background: radial-gradient(circle at 32% 26%, rgba(52, 211, 153, 0.34), rgba(9, 14, 22, 0.94) 62%);
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.44), inset 0 1px 0 rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(14px);
    color: #6ee7b7;
    cursor: grab;
    /* Idle at reduced opacity so it reads as an overlay control, not page content. */
    opacity: 0.58;
    touch-action: none;
    transition: opacity 0.18s ease, transform 0.18s ease, left 0.22s cubic-bezier(0.22, 1, 0.36, 1);
  }

  .ac-launcher.ac-hidden { display: none; }
  .ac-launcher:hover, .ac-launcher:focus-visible { opacity: 1; }
  .ac-launcher:focus-visible { outline: 2px solid rgba(52, 211, 153, 0.75); outline-offset: 3px; }
  .ac-launcher.ac-launcher-open { opacity: 1; transform: scale(1.04); }
  /* No position transition mid-drag, or the control lags the finger. */
  .ac-launcher.ac-launcher-dragging { opacity: 1; cursor: grabbing; transition: none; }

  .ac-launcher-ring {
    position: absolute;
    inset: 5px;
    border: 1px solid rgba(148, 163, 184, 0.20);
    border-radius: 999px;
    pointer-events: none;
  }

  .ac-launcher-icon { display: flex; pointer-events: none; }
  .ac-launcher-icon svg { width: 24px; height: 24px; }

  .ac-navpanel { position: fixed; inset: 0; z-index: 41; display: block; }
  .ac-navpanel.hidden { display: none; }

  .ac-navpanel-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 14, 0.52);
    backdrop-filter: blur(2px);
  }

  .ac-navpanel-card {
    position: absolute;
    width: min(320px, calc(100vw - 24px));
    max-height: min(60vh, 460px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 12px;
    border: 1px solid var(--ac-line-strong);
    border-radius: var(--ac-radius-xl);
    background: rgba(13, 18, 27, 0.97);
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.52);
    animation: acPanelIn 0.16s cubic-bezier(0.22, 1, 0.36, 1);
  }

  @keyframes acPanelIn { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: none; } }

  .ac-navpanel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--ac-space-2);
    margin-bottom: var(--ac-space-2);
  }

  .ac-navpanel-title {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ac-text-muted);
  }

  .ac-navpanel-close {
    width: 30px;
    height: 30px;
    border: 1px solid var(--ac-line);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.6);
    color: var(--ac-text-muted);
    font-size: 17px;
    line-height: 1;
    cursor: pointer;
  }

  .ac-navpanel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }

  .ac-navpanel-item {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 48px;
    padding: 10px 11px;
    border: 1px solid var(--ac-line);
    border-radius: var(--ac-radius-md);
    background: var(--ac-surface-2);
    color: #d7e0ec;
    font-size: 12.5px;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
  }

  .ac-navpanel-item .ac-nav-icon { display: flex; flex: 0 0 auto; }
  .ac-navpanel-item .ac-nav-icon svg { width: 17px; height: 17px; }
  .ac-navpanel-item .ac-nav-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .ac-navpanel-item.active {
    border-color: var(--ac-accent-line);
    background: var(--ac-accent-soft);
    color: #6ee7b7;
  }
}

/* ---- 5b. Fullscreen chart viewer --------------------------------------- */
/* Shared by the Chart page and Pattern so both read as the same viewer. */
.ac-viewer {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: flex;
  flex-direction: column;
  background: #080c12;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.ac-viewer-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--ac-space-3);
  flex: 0 0 auto;
  padding: 12px 14px;
  border-bottom: 1px solid var(--ac-line);
  background: rgba(11, 15, 22, 0.96);
}

.ac-viewer-heading { min-width: 0; }
.ac-viewer-title { font-size: 15px; font-weight: 700; color: var(--ac-text); }
.ac-viewer-subtitle { margin-top: 2px; font-size: 11.5px; color: var(--ac-text-muted); }
.ac-viewer-actions { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }

.ac-viewer-btn {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 9px 13px;
  border: 1px solid var(--ac-line-strong);
  border-radius: var(--ac-radius-sm);
  background: rgba(15, 23, 42, 0.7);
  color: #cbd5e1;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.ac-viewer-btn:hover { border-color: var(--ac-accent-line); color: #6ee7b7; }
.ac-viewer-close { border-color: rgba(148, 163, 184, 0.3); }

.ac-viewer-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ac-viewer-chart { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.ac-viewer-main {
  width: 100%;
  /* renderLightweightChart sets an explicit pixel height from
     chartDims('fullscreen', …); shrinking would fight it. */
  flex: 0 0 auto;
  min-height: 0;
}
.ac-viewer-rsi { width: 100%; flex: 0 0 auto; border-top: 1px solid rgba(148, 163, 184, 0.10); }

.ac-viewer-metrics {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 8px 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.10);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 640px) { .ac-viewer-metrics { grid-template-columns: repeat(8, minmax(0, 1fr)); } }

.ac-viewer-hint {
  flex: 0 0 auto;
  padding: 6px 12px 10px;
  color: var(--ac-text-dim);
  font-size: 10.5px;
  text-align: center;
}

.ac-viewer-imageframe {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  /* The frame owns every gesture so the page behind can never scroll or bounce. */
  touch-action: none;
  overscroll-behavior: contain;
  background: #0b0e14;
}

.ac-viewer-image {
  max-width: 100%;
  max-height: 100%;
  transform-origin: center center;
  will-change: transform;
  user-select: none;
  -webkit-user-drag: none;
}

.ac-viewer-imageframe[data-zoomed="1"] { cursor: grab; }
.ac-viewer-empty { padding: 32px; color: var(--ac-text-muted); font-size: 12.5px; text-align: center; }

/* ---- 6. Tables, forms, misc -------------------------------------------- */
/* Header rows read as labels, not data. Kept at the inherited size so the
   dense screener tables do not reflow. */
th {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ac-text-muted);
}

/* A horizontally scrolling table must not hand its overscroll to the page —
   that is what makes a sideways swipe trigger back-navigation on Android and
   rubber-band the whole document on iOS. */
.overflow-x-auto, .overflow-y-auto, .nav-scroll-container {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* ---- 6b. Mobile refinement --------------------------------------------- */
@media (max-width: 640px) {
  .panel { padding: var(--ac-space-3); }
  .ac-section { margin-top: var(--ac-space-4); }
  .action-card { min-height: 88px; }
  button, [role="button"] { touch-action: manipulation; }

  /* Comfortable targets everywhere, not just where a utility happened to set one. */
  .nav-btn, .screener-tab, .nk-screener-tab, .dt-screener-tab { min-height: 40px; }

  /* The sticky header must clear the notch. */
  .app-header { padding-top: env(safe-area-inset-top, 0px); }

  /* Side padding follows the safe area on notched landscape orientations. */
  .page-content {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }

  /* Bottom sheets and dialogs stay clear of the home indicator. */
  [role="dialog"] { padding-bottom: env(safe-area-inset-bottom, 0px); }

  /* Tighter rhythm: cards carried desktop-sized gaps into a 390px column. */
  .dashboard-hero { border-radius: var(--ac-radius-lg); }
  .ac-section-head { margin-bottom: var(--ac-space-2); }
}

/* On the narrowest phones the section hint competes with its own heading. */
@media (max-width: 479px) {
  .ac-section-hint { display: none; }
}

/* ---- 6c. Glow / readability balance ------------------------------------
   The hero and panel gradients were competing with body copy. Softening the
   decorative layers keeps the premium feel while text contrast wins. */
.dashboard-hero::after { opacity: 0.55; }
.glow-emerald { box-shadow: 0 0 16px rgba(16, 185, 129, 0.18), 0 0 44px rgba(16, 185, 129, 0.06); }
.glow-emerald:hover { box-shadow: 0 0 22px rgba(16, 185, 129, 0.30), 0 0 58px rgba(16, 185, 129, 0.12); }

/* ---- 7. Reduced motion -------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .ac-launcher, .ac-navpanel-card, .action-card, .panel { transition: none !important; animation: none !important; }
}

/* AUTO_CUAN_DESKTOP_HEADER_CENTER_V1 */
/* Keep the navigation centered on the viewport instead of centering it only
   inside the space left between unequal brand and account groups. */
@media (min-width: 1280px) {
  .app-header > .header-shell > .flex {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
    align-items: center;
    column-gap: 16px;
  }

  .app-header > .header-shell > .flex > :first-child {
    justify-self: start;
  }

  .app-header > .header-shell > .flex > .desktop-nav {
    justify-self: center;
    width: max-content;
    max-width: none;
    flex: none;
  }

  .app-header > .header-shell > .flex > :last-child {
    justify-self: end;
  }
}
