/* =========================================================
   GCK Sentinel Pro — Responsive Design System
   Covers: 320px (small phone) → 4K screens
   ========================================================= */

/* ---------- CSS Custom Properties ---------- */
:root {
  --bg: #050505;
  --surface: #0a0a0a;
  --surface-1: #0d0d0d;
  --surface-2: #111111;
  --surface-strong: #161616;
  --surface-soft: #0d0d0d;
  --line: #1e293b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #ffffff;
  --muted: #94a3b8;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.2);
  --accent-2: #a855f7;
  --accent-3: #f43f5e;
  --danger: #f43f5e;
  --ok: #22c55e;
  --success: #22c55e;
  --loss: #f43f5e;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  --glass: blur(12px);
  --primary: #6366f1;
  --foreground: #ffffff;

  /* Layout tokens */
  --sidebar-width: 260px;
  --content-padding: 40px;
  --panel-padding: 28px;
  --border-radius: 20px;
  --border-radius-sm: 12px;
  --gap: 24px;
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Outfit', 'Inter', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--surface-strong); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--line); }

/* ---------- App Shell (Sidebar + Main) ---------- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
  background: radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.06) 0%, transparent 60%);
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  padding: 28px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  height: 100vh;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 1000;
}

/* Sidebar backdrop (mobile overlay) */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 999;
}
.sidebar-overlay.visible { display: block; }

/* ---------- Brand ---------- */
.brand { margin-bottom: 32px; flex-shrink: 0; }
.eyebrow {
  font-size: 9px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--accent);
  letter-spacing: 2.5px;
  margin-bottom: 6px;
  display: block;
}
.brand h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text), var(--muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ---------- Nav ---------- */
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-group { margin-bottom: 16px; }

.nav-item {
  display: flex;
  align-items: center;
  width: 100%;
  border: none;
  background: none;
  padding: 11px 14px;
  border-radius: var(--border-radius-sm);
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 13.5px;
  text-align: left;
  margin-bottom: 2px;
  font-family: inherit;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateX(3px);
}
.nav-item.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 6px 18px rgba(99, 102, 241, 0.35);
}

/* ---------- User Profile Card ---------- */
.user-profile {
  position: relative;
  overflow: hidden;
  margin-top: 12px;
  flex-shrink: 0;
}
.user-profile::after {
  content: '';
  position: absolute;
  bottom: -50px; right: -50px;
  width: 100px; height: 100px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  pointer-events: none;
}

/* ---------- Mobile Header ---------- */
.mobile-header {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 900;
  min-height: 60px;
}

.mobile-header .brand h1 {
  font-size: 16px;
  margin: 0;
}
.mobile-header .brand { margin-bottom: 0; }

.menu-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  transition: 0.2s;
  flex-shrink: 0;
}
.menu-toggle:hover { background: var(--accent); border-color: var(--accent); }

/* ---------- Main Content ---------- */
.content {
  padding: var(--content-padding);
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  min-width: 0; /* prevent overflow */
}

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 36px;
  gap: 16px;
  flex-wrap: wrap;
}
#pageTitle {
  font-size: 34px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -1px;
  line-height: 1.1;
}

/* ---------- Panel ---------- */
.panel {
  background: var(--surface);
  border-radius: var(--border-radius);
  border: 1px solid var(--border);
  padding: var(--panel-padding);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  min-width: 0;
}
.panel::before {
  content: '';
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  background: linear-gradient(135deg, rgba(255,255,255,0.02) 0%, transparent 100%);
  pointer-events: none;
}
.panel-header h3 {
  margin: 0 0 20px 0;
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---------- Grid System ---------- */
.grid { display: grid; gap: var(--gap); min-width: 0; }
.grid.two-up { grid-template-columns: 1fr 1fr; }
.grid.three-up { grid-template-columns: repeat(3, 1fr); }
.grid.four-up { grid-template-columns: repeat(4, 1fr); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }

/* ---------- Metric Strip ---------- */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--gap);
  margin-bottom: 28px;
}
.metric-card {
  padding: 22px;
  background: var(--surface-2);
  border-radius: 18px;
  border: 1px solid var(--border);
  text-align: left;
  transition: 0.3s;
  min-width: 0;
}
.metric-card:hover { border-color: var(--accent); transform: translateY(-3px); }
.metric-card span {
  display: block;
  font-size: 10px;
  color: var(--muted);
  font-weight: 800;
  text-transform: uppercase;
  margin-bottom: 8px;
  letter-spacing: 1px;
}
.metric-card strong {
  font-size: 26px;
  color: var(--text);
  font-weight: 800;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Buttons ---------- */
.button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  padding: 12px 24px;
  border-radius: var(--border-radius-sm);
  font-weight: 700;
  cursor: pointer;
  transition: all 0.25s;
  font-family: inherit;
  font-size: 13px;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(99, 102, 241, 0.4);
}
.button.secondary {
  background: var(--surface-strong);
  color: var(--text);
  border: 1px solid var(--border);
}
.button.secondary:hover { background: var(--surface-2); }
.button.danger {
  background: linear-gradient(135deg, #f43f5e, #fb7185);
  box-shadow: 0 6px 18px rgba(244, 63, 94, 0.3);
}
.button.small { padding: 6px 12px; font-size: 11px; }
.button.full { width: 100%; justify-content: center; }

/* ---------- Status Lines ---------- */
.status-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
  gap: 12px;
  flex-wrap: wrap;
}
.status-line strong { color: var(--text); flex-shrink: 0; }
.status-line input, .status-line select {
  max-width: 200px;
  padding: 8px 12px;
  font-size: 13px;
}

/* ---------- Form Inputs ---------- */
input, select, textarea {
  padding: 12px 16px;
  border-radius: var(--border-radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
  background: var(--surface-strong);
  color: var(--text);
  width: 100%;
  transition: 0.3s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---------- Page Visibility ---------- */
.page { display: none; }
.page.active { display: block; animation: fadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); }

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

/* ---------- Loader ---------- */
.loader {
  width: 36px; height: 36px;
  border: 3px solid var(--surface-strong);
  border-top: 3px solid var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 20px auto;
}
@keyframes spin {
  0%   { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ---------- Badges & Tags ---------- */
.badge {
  padding: 3px 10px;
  border-radius: 50px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  background: var(--surface-strong);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.regime-tag {
  padding: 7px 14px;
  border-radius: 50px;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.3);
  white-space: nowrap;
}

/* ---------- Charts ---------- */
#priceChart, #indicatorChart {
  width: 100%;
  border-radius: 10px;
  margin-top: 10px;
  background: rgba(0,0,0,0.2);
  display: block;
}
.chart-line { fill: none; stroke-width: 2.5; stroke-linecap: round; filter: drop-shadow(0 0 6px rgba(99, 102, 241, 0.3)); }
.chart-line.price { stroke: var(--text); }
.chart-line.cool  { stroke: var(--accent); }
.chart-line.warm  { stroke: var(--danger); }
.chart-line.soft  { stroke: var(--ok); }

/* ---------- Utility ---------- */
.profit { color: var(--ok) !important; }
.loss   { color: var(--danger) !important; }
.muted  { color: var(--muted); }

/* Table responsive wrapper */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 12px; min-width: 480px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-weight: 800; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); }

/* Stack form */
.stack-form { display: flex; flex-direction: column; gap: 0; }
.stack-output { color: var(--muted); font-size: 13px; }

/* =========================================================
   RESPONSIVE BREAKPOINTS
   ========================================================= */

/* ---------- 1400px — Large Desktop ---------- */
@media (max-width: 1400px) {
  :root { --content-padding: 32px; }
  .grid.four-up { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- 1200px — Desktop ---------- */
@media (max-width: 1200px) {
  :root {
    --sidebar-width: 240px;
    --content-padding: 28px;
  }
  .metric-strip { grid-template-columns: repeat(2, 1fr); }
  #pageTitle { font-size: 28px; }
}

/* ---------- 1024px — Small Desktop / Tablet Landscape ---------- */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 220px;
    --content-padding: 24px;
    --panel-padding: 22px;
    --gap: 20px;
  }
  .grid.three-up { grid-template-columns: repeat(2, 1fr); }
  .brand h1 { font-size: 20px; }
  .nav-item { font-size: 13px; padding: 10px 12px; }
}

/* ---------- 768px — Tablet & Mobile ---------- */
@media (max-width: 768px) {
  :root {
    --content-padding: 18px;
    --panel-padding: 18px;
    --gap: 16px;
  }

  /* Show mobile header */
  .mobile-header { display: flex; }

  /* Hide sidebar, slide in on .open */
  .app-shell {
    grid-template-columns: 1fr;
    display: block; /* stack vertically */
  }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    width: 280px;
    max-width: 85vw;
    height: 100vh;
    transform: translateX(-100%);
    box-shadow: 20px 0 60px rgba(0,0,0,0.85);
    padding: 20px 14px;
    z-index: 1000;
  }
  .sidebar.open { transform: translateX(0); }

  /* Collapse grids to single column */
  .grid.two-up,
  .grid.three-up,
  .grid.four-up,
  .metric-strip {
    grid-template-columns: 1fr;
  }
  .span-2, .span-3 { grid-column: span 1; }

  #pageTitle { font-size: 24px; letter-spacing: -0.5px; }

  /* Topbar stacks */
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    margin-bottom: 24px;
    gap: 14px;
  }
  .topbar > div { width: 100%; }
  .topbar > div:nth-child(2) { max-width: 100% !important; margin: 0 !important; }
  .topbar > div:last-child { display: flex; flex-wrap: wrap; gap: 8px; }

  /* Quick probe form full width */
  #globalProbeForm { width: 100%; }

  /* Regime tags smaller */
  .regime-tag { font-size: 10px; padding: 5px 10px; }

  /* Metric cards */
  .metric-card { padding: 16px; }
  .metric-card strong { font-size: 22px; }

  /* Panels */
  .panel { padding: 16px; border-radius: 16px; }
  .panel-header h3 { font-size: 16px; margin-bottom: 14px; }

  /* Buttons — keep manageable size */
  .button { padding: 11px 18px; font-size: 13px; }

  /* Status line: stack on very small */
  .status-line input, .status-line select { max-width: 100%; }

  /* Chart forms wrap */
  #chartForm { flex-wrap: wrap; gap: 6px; }
  #chartForm input { width: 100%; }

  /* Hero card (dashboard) */
  .hero-card { flex-direction: column !important; }
  .hero-card > div:last-child { width: 100% !important; }

  /* Probe form full width */
  #probeForm { width: 100%; }
}

/* ---------- 480px — Small Phone ---------- */
@media (max-width: 480px) {
  :root {
    --content-padding: 14px;
    --panel-padding: 14px;
    --gap: 12px;
  }

  .mobile-header { padding: 12px 14px; min-height: 54px; }
  .mobile-header .brand h1 { font-size: 15px; }

  #pageTitle { font-size: 20px; }

  .brand h1 { font-size: 18px; }
  .nav-item { font-size: 13px; padding: 10px 12px; }

  .metric-card { padding: 14px; }
  .metric-card strong { font-size: 20px; }
  .metric-card span { font-size: 9px; }

  .button { padding: 10px 16px; font-size: 12px; }
  .button.full { width: 100%; }

  .panel { border-radius: 14px; }
  .panel-header h3 { font-size: 15px; }

  input, select, textarea { padding: 10px 14px; font-size: 13px; }

  /* Stack topbar controls tighter */
  .topbar { gap: 10px; margin-bottom: 18px; }
  .regime-tag { font-size: 9px; padding: 4px 8px; }

  /* Kill switch full width on mobile */
  #emergencyKillBtn { font-size: 12px; padding: 10px; }

  /* Sector scanner button — full width */
  #scanSectorBtn { width: 100%; margin-top: 10px; }
  #sectorSelect { width: 100%; }
}

/* ---------- 360px — Very Small Phone ---------- */
@media (max-width: 360px) {
  :root { --content-padding: 10px; --panel-padding: 12px; }
  #pageTitle { font-size: 18px; }
  .metric-card strong { font-size: 18px; }
  .nav-item { font-size: 12px; padding: 9px 10px; }
}

/* =========================================================
   SPECIFIC COMPONENT OVERRIDES FOR MOBILE
   ========================================================= */

/* Topbar probe form row */
@media (max-width: 768px) {
  .topbar-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    width: 100%;
  }
  .topbar-actions > * { flex: 1 1 auto; }
}

/* Intelligence Hub — probe result on mobile */
@media (max-width: 768px) {
  #probeDecision {
    min-height: 120px !important;
  }
}

/* Sector scan controls stacked on mobile */
@media (max-width: 600px) {
  .sector-controls {
    flex-direction: column !important;
  }
  .sector-controls select,
  .sector-controls button {
    width: 100%;
  }
}

/* Broker hub links */
@media (max-width: 480px) {
  .broker-card {
    flex-direction: column !important;
    gap: 10px;
  }
  .broker-card .button { width: 100%; justify-content: center; }
}

/* Admin table scrollable */
@media (max-width: 768px) {
  .admin-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 520px; }
}

/* Coupon + payment grid stacked on mobile */
@media (max-width: 600px) {
  .grid.two-up.admin-coupon-grid { grid-template-columns: 1fr; }
}

/* Chart Form — horizontal on desktop, vertical on mobile */
@media (max-width: 600px) {
  #chartForm {
    flex-direction: column;
    gap: 8px;
  }
  #chartForm input[name="symbol"] {
    width: 100% !important;
  }
  #chartForm select {
    width: 100%;
  }
  #chartForm button {
    width: 100%;
  }
}

/* Journal form status-line inputs full width on mobile */
@media (max-width: 480px) {
  .status-line {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .status-line input,
  .status-line select {
    max-width: 100%;
    width: 100%;
  }
}

/* =========================================================
   HERO CARD (Dashboard)
   ========================================================= */
.hero-card {
  display: flex;
  gap: var(--gap);
  align-items: flex-start;
  flex-wrap: wrap;
  margin-bottom: var(--gap);
  background: var(--surface);
  border-radius: var(--border-radius);
  border: 1px solid var(--border);
  padding: var(--panel-padding);
  box-shadow: var(--shadow);
}
.hero-card > div:first-child { flex: 1; min-width: 200px; }
.hero-card > div:last-child { width: 300px; flex-shrink: 0; }

@media (max-width: 768px) {
  .hero-card > div:last-child { width: 100%; }
}

/* =========================================================
   ACCENT / STACK NOTE
   ========================================================= */
.accent-note {
  padding: 14px 18px;
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  font-size: 13px;
}

/* =========================================================
   LARGE SCREEN ENHANCEMENTS (1440px+)
   ========================================================= */
@media (min-width: 1440px) {
  :root {
    --sidebar-width: 280px;
    --content-padding: 48px;
    --panel-padding: 32px;
  }
  #pageTitle { font-size: 40px; }
  .metric-strip { grid-template-columns: repeat(4, 1fr); }
  .metric-card strong { font-size: 30px; }
}

@media (min-width: 1920px) {
  :root { --content-padding: 56px; }
  .metric-strip { grid-template-columns: repeat(5, 1fr); }
}

/* ---------- Ribbon for Discounts ---------- */
.ribbon-wrapper {
  width: 100px;
  height: 100px;
  overflow: hidden;
  position: absolute;
  top: 0;
  right: 0;
  pointer-events: none;
}
.ribbon {
  font-weight: 800;
  font-size: 10px;
  color: #fff;
  text-transform: uppercase;
  text-align: center;
  line-height: 20px;
  transform: rotate(45deg);
  position: relative;
  padding: 4px 0;
  left: -5px;
  top: 15px;
  width: 150px;
  background: linear-gradient(135deg, var(--danger), #ff4d4d);
  box-shadow: 0 4px 10px rgba(244, 63, 94, 0.4);
  letter-spacing: 1px;
}

.panel {
  position: relative;
}
