/*
 * GridQ Dashboard Portal — Styling System
 * 
 * Path: dashboard-portal/style.css
 * Description: Standalone CSS system incorporating responsive layouts, custom components, 
 * glassmorphism, animations, and portal layouts.
 */

:root {
  /* Backgrounds */
  --bg-primary: #08090c;
  --bg-card: rgba(16, 18, 27, 0.65);
  --bg-card-solid: #10121b;
  --bg-hover: rgba(30, 41, 59, 0.5);
  --bg-dark: #0a0e1a;
  --bg-input: #0d1017;

  /* Borders */
  --border: rgba(255, 255, 255, 0.06);
  --border-light: rgba(255, 255, 255, 0.12);
  --border-active: rgba(99, 102, 241, 0.4);

  /* Text */
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  /* Accent */
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.15);

  /* Semantic colors */
  --green: #10b981;
  --green-bg: rgba(16, 185, 129, 0.1);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.1);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.1);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.1);
  --orange: #f97316;
  --orange-bg: rgba(249, 115, 22, 0.1);
  --purple: #8b5cf6;
  --purple-bg: rgba(139, 92, 246, 0.1);

  /* Layout */
  --sidebar-width: 220px;
  --radius: 12px;
  --radius-sm: 8px;
}

/* ── Reset & Base ── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.mono {
  font-family: 'JetBrains Mono', monospace;
}

/* ── Dual Scrollbar Styling ── */
/* WebKit (Chrome, Safari, Edge) */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border-light) var(--bg-primary);
}

/* ── Application Layout ── */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #0f1629, #0a0e1a);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0;
  flex-shrink: 0;
}

.content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: rgba(17, 24, 39, 0.8);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  z-index: 10;
}

.topbar h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.view-container {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 2rem 2rem;
}

/* ── Navigation Components ── */
.logo {
  padding: 0 1.25rem 0.75rem;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.logo-icon {
  -webkit-text-fill-color: #6366f1;
}

.nav-section {
  padding: 0.75rem 1.25rem 0.25rem;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.55rem 1.25rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
  border-right: 2px solid transparent;
}

.nav-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-btn.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-right-color: var(--accent);
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.portal-back-link {
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  transition: color 0.15s;
  font-weight: 500;
  margin-bottom: 0.15rem;
}

.portal-back-link:hover {
  color: var(--accent);
}

/* ── Badges & Status Indicators ── */
.tenant-badge {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 4px;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid var(--border-active);
}

.tier-badge {
  font-size: 0.6rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: inline-block;
}

.tier-production {
  background: var(--green-bg);
  color: var(--green);
}

.tier-canary {
  background: var(--amber-bg);
  color: var(--amber);
}

.tier-staging {
  background: var(--blue-bg);
  color: var(--blue);
}

.env-badge {
  font-size: 0.6rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-block;
}

.env-badge.live {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.env-badge.paper {
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.suspended-badge {
  font-size: 0.55rem;
  font-weight: 700;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-block;
  background: rgba(245, 158, 11, 0.15);
  color: var(--amber);
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.portal-card-suspended {
  opacity: 0.7;
  border-color: rgba(245, 158, 11, 0.3);
}

.role-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  display: inline-block;
}

.role-badge.admin {
  background: var(--purple-bg);
  color: var(--purple);
}

.role-badge.viewer {
  background: var(--blue-bg);
  color: var(--blue);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online {
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}

.status-dot.offline {
  background: var(--text-dim);
}

.status-dot.pending {
  background: var(--amber);
  box-shadow: 0 0 6px var(--amber);
}

.conn-status {
  font-size: 0.72rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.conn-status.online {
  color: var(--green);
}

.conn-status.offline {
  color: var(--text-dim);
}

.conn-status.loading {
  color: var(--amber);
}

.topbar-conn-status {
  display: none;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.2rem 0.45rem;
  background: var(--bg-hover);
  border-radius: 4px;
}

.topbar-conn-status.online { color: var(--green); }
.topbar-conn-status.offline { color: var(--text-dim); }
.topbar-conn-status.loading { color: var(--amber); }

.btn-sign-out {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.35rem 0.55rem;
  border-color: var(--border-light);
}

.btn-sign-out:hover {
  color: var(--red);
  border-color: rgba(239, 68, 68, 0.4);
  background: var(--red-bg);
}

/* ── Pull to Refresh Indicator ── */
.pull-refresh-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0;
  height: 0;
  overflow: hidden;
  font-size: 0.75rem;
  color: var(--accent);
  background: rgba(13, 16, 23, 0.95);
  border-bottom: 1px solid transparent;
  transition: height 0.2s ease, padding 0.2s ease, opacity 0.2s ease;
  opacity: 0;
  pointer-events: none;
  font-weight: 500;
}

.pull-refresh-indicator.visible {
  height: 38px;
  padding: 0.5rem;
  opacity: 1;
  border-bottom-color: var(--border);
}

.pull-refresh-indicator.refreshing .pull-icon {
  animation: spin 0.8s linear infinite;
}

/* ── Mobile More Sheet Drawer ── */
.more-sheet-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  animation: fadeIn 0.2s ease-out;
}

.more-sheet {
  background: #0f1422;
  border-top: 1px solid var(--border-light);
  border-radius: 20px 20px 0 0;
  padding: 0.75rem 1rem calc(1.5rem + env(safe-area-inset-bottom));
  max-height: 80vh;
  max-height: 80dvh;
  overflow-y: auto;
  animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
}

@keyframes slideUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.more-sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  margin: 0 auto 0.75rem;
}

.more-sheet-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.more-sheet-header h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0;
}

.more-sheet-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.more-sheet-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem 0.5rem;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
}

.more-sheet-item .item-icon {
  font-size: 1.35rem;
  line-height: 1;
}

.more-sheet-item.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.25);
}

.more-sheet-item:active {
  transform: scale(0.95);
  background: var(--bg-hover);
}

.data-age {
  font-size: 0.7rem;
  color: var(--text-dim);
  font-family: 'JetBrains Mono', monospace;
  padding: 0.2rem 0.5rem;
  background: var(--bg-hover);
  border-radius: 4px;
}

.clock {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ── Buttons ── */
.btn {
  padding: 0.5rem 1.25rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: #4f46e5;
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-secondary {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-light);
}

.btn-secondary:hover {
  background: var(--bg-card-solid);
  border-color: var(--text-dim);
}

.btn-danger {
  background: var(--red-bg);
  color: var(--red);
  border: 1px solid rgba(239, 68, 68, 0.3);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:hover {
  background: var(--red);
  color: #fff;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border-light);
  color: var(--text-muted);
  padding: 0.35rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.btn-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ── Cards & Grid Layouts ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  position: relative;
  overflow: hidden;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-light);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent);
}

.accent-green::before { background: var(--green); }
.accent-blue::before { background: var(--blue); }
.accent-purple::before { background: var(--purple); }
.accent-amber::before { background: var(--amber); }
.accent-red::before { background: var(--red); }
.accent-orange::before { background: var(--orange); }
.accent-indigo::before { background: var(--accent); }
.accent-cyan::before { background: #06b6d4; }
.accent-teal::before { background: #14b8a6; }

.stat-label {
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.35rem;
}

.stat-card {
  min-width: 0;
}

.stat-value {
  font-size: clamp(1.15rem, 2.5vw, 1.5rem);
  font-weight: 700;
  min-width: 0;
}

.tier-primary {
  font-size: clamp(1.05rem, 2.5vw, 1.35rem);
  font-weight: 700;
  line-height: 1.2;
}

.tier-secondary {
  font-size: clamp(0.9rem, 2.2vw, 1.15rem);
  font-weight: 700;
  line-height: 1.2;
}

.tier-flex-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  width: 100%;
  flex-wrap: wrap;
  gap: 2px 6px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 1rem; }

/* ── Tables ── */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

th {
  text-align: left;
  padding: 0.75rem 1rem;
  color: var(--text-dim);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: rgba(10, 14, 26, 0.4);
}

td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

tr:last-child td {
  border-bottom: none;
}

tr:hover td {
  background: var(--bg-hover);
}

.pnl-pos { color: var(--green); font-weight: 600; }
.pnl-neg { color: var(--red); font-weight: 600; }

.side-buy { color: var(--green); font-weight: 600; }
.side-sell { color: var(--red); font-weight: 600; }

.grid-status-filled { color: var(--green); font-weight: 500; }
.grid-status-open { color: var(--amber); font-weight: 500; }
.grid-status-skipped { color: var(--text-dim); }

.row-filled { background: rgba(16, 185, 129, 0.03); }
.row-open { background: rgba(245, 158, 11, 0.03); }

/* ── Log Streams ── */
.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.log-header h3 {
  margin-bottom: 0;
}

.log-filters {
  display: flex;
  gap: 0.35rem;
}

.filter-btn {
  padding: 0.3rem 0.6rem;
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font: inherit;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}

.log-stream {
  height: calc(100vh - 220px);
  height: calc(100dvh - 220px);
  overflow-y: auto;
  overflow-x: hidden;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.78rem;
  line-height: 1.6;
}

.log-stream.mini {
  max-height: 320px;
}

.log-entry {
  padding: 0.25rem 0.5rem;
  border-radius: 3px;
  word-break: break-all;
  overflow-wrap: break-word;
  white-space: normal;
}

.log-entry:hover {
  background: var(--bg-hover);
}

.log-entry .ts {
  color: var(--text-dim);
}

.log-entry .lvl {
  font-weight: 600;
}

.log-entry .lvl-INFO { color: var(--blue); }
.log-entry .lvl-WARN { color: var(--amber); }
.log-entry .lvl-ERROR, .log-entry .lvl-FATAL { color: var(--red); }
.log-entry .lvl-DEBUG { color: var(--text-dim); }
.log-entry.dim { color: var(--text-dim); font-style: italic; }

/* ── Access Control Tab ── */
.access-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.access-form-card {
  margin-top: 1.5rem;
}

.access-form {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.access-form label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  min-width: 240px;
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent-glow);
}

select.input {
  min-width: 140px;
  cursor: pointer;
}

.input.mono {
  font-family: 'JetBrains Mono', monospace;
}

/* ── Trades View Date Filters ── */
.trades-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.trades-header h3 {
  margin-bottom: 0;
}

.date-filters {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.custom-date-row {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  background: var(--bg-dark);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  animation: fadeIn 0.2s ease-out;
}

.custom-date-row label {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.custom-date-row .input {
  min-width: 150px;
}

.stat-card.mini {
  padding: 0.75rem 1rem;
}

.stat-card.mini .stat-value {
  font-size: 1.15rem;
}

/* ── Pagination Load More ── */
.load-more-wrap {
  display: flex;
  justify-content: center;
  margin-top: 1.25rem;
}

/* ── Badge count ── */
.badge {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-hover);
  padding: 0.15rem 0.5rem;
  border-radius: 10px;
  margin-left: 0.5rem;
}

/* ── Portal Landing Hub Layout ── */
.portal-container {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 2rem;
  overflow-y: auto;
}

.portal-header {
  text-align: center;
  margin-bottom: 3rem;
}

.portal-logo {
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
}

.portal-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.portal-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
  max-width: 1200px;
  width: 100%;
  animation: fadeIn 0.3s ease-out;
}

.portal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  cursor: pointer;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.portal-card:hover {
  border-color: var(--accent);
  transform: translateY(-4px);
  box-shadow: 0 12px 32px rgba(99, 102, 241, 0.12);
}

.portal-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.portal-card-title h3 {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 0.25rem;
}

.portal-card-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.portal-card-badges {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.portal-card-metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
  margin: 0.25rem 0;
}

.portal-metric-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}

.portal-metric-value {
  font-size: 0.95rem;
  font-weight: 600;
}

.portal-card-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Access Denied Page ── */
.access-denied-container {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.access-denied-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3rem 2rem;
  text-align: center;
  max-width: 440px;
  width: 100%;
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  animation: fadeIn 0.3s ease-out;
}

.access-denied-icon {
  font-size: 4rem;
  margin-bottom: 1.25rem;
  line-height: 1;
}

.access-denied-card h1 {
  font-size: 1.6rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.access-denied-email {
  color: var(--accent);
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.85rem;
  margin: 0.5rem 0 1.75rem;
  word-break: break-all;
}

.access-denied-message {
  color: var(--text);
  font-size: 1.05rem;
  margin-bottom: 0.75rem;
}

.access-denied-hint {
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* ── Custom Modal Overlay ── */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  max-width: 460px;
  width: 90%;
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 16px 40px rgba(0,0,0,0.5);
}

.modal-card h3 {
  font-size: 1.2rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.modal-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  line-height: 1.4;
  white-space: pre-wrap;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ── Loading Overlay ── */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(8, 9, 12, 0.9);
  z-index: 999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1.25rem;
}

.loading-overlay.active {
  display: flex;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Animations ── */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.view-container > * {
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Mobile Responsive Layout (Bottom Tab Bar & Compact Native Views) ── */
@media (max-width: 768px) {
  .app {
    flex-direction: column;
  }

  /* Fixed Bottom Tab Bar */
  .sidebar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    top: auto;
    width: 100%;
    height: 56px;
    height: calc(56px + env(safe-area-inset-bottom));
    flex-direction: row;
    justify-content: space-around;
    align-items: stretch;
    padding: 3px 4px calc(3px + env(safe-area-inset-bottom)) 4px;
    background: rgba(13, 16, 23, 0.95);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border);
    border-right: none;
    border-bottom: none;
    z-index: 1000;
    overflow: visible;
  }

  .logo {
    display: none !important;
  }

  .nav-section {
    display: none !important;
  }

  .sidebar-footer {
    display: none !important;
  }

  /* Only primary 4 views + injected More button are shown in bottom bar */
  .sidebar .nav-btn {
    display: none !important;
  }

  .sidebar .nav-btn[data-view="dashboard"],
  .sidebar .nav-btn[data-view="trades"],
  .sidebar .nav-btn[data-view="calendar"],
  .sidebar .nav-btn[data-view="analytics"],
  .sidebar .nav-btn-more {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
    height: 100%;
    padding: 3px 2px;
    border: none;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-muted);
    background: transparent;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    transition: all 0.15s ease;
    touch-action: manipulation;
  }

  .sidebar .nav-btn .tab-icon {
    font-size: 1.15rem;
    line-height: 1.1;
  }

  .sidebar .nav-btn .tab-label {
    font-size: 0.65rem;
    line-height: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  .sidebar .nav-btn.active {
    color: #fff;
    background: var(--accent-glow);
    border-right-color: transparent;
    border-bottom: none;
    font-weight: 600;
  }

  /* Compact Topbar */
  .topbar {
    padding: max(0.45rem, env(safe-area-inset-top)) 0.75rem 0.45rem;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    min-height: 46px;
    gap: 0.5rem;
  }

  .topbar-left {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    min-width: 0;
    flex: 1;
  }

  .topbar h1 {
    font-size: 1rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .tenant-badge {
    font-size: 0.65rem;
    padding: 0.12rem 0.35rem;
    flex-shrink: 0;
  }

  .topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
  }

  .clock {
    display: none;
  }

  .topbar-conn-status {
    display: inline-flex;
  }

  .topbar-conn-status .status-text {
    display: none;
  }

  .data-age {
    font-size: 0.65rem;
    padding: 0.15rem 0.35rem;
  }

  .btn-sign-out {
    padding: 0.3rem 0.45rem;
    font-size: 0.8rem;
  }

  .btn-sign-out .sign-out-label {
    display: none;
  }

  /* View Container with bottom clearance for bottom tab bar */
  .view-container {
    padding: 0.75rem 0.75rem calc(68px + env(safe-area-inset-bottom)) 0.75rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }

  .grid-5 {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }

  .grid-4 {
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
  }

  .stat-card {
    padding: 0.7rem 0.65rem;
    min-width: 0;
  }

  .stat-label {
    font-size: 0.65rem;
    letter-spacing: 0.03em;
  }

  .stat-value {
    font-size: clamp(0.95rem, 3.8vw, 1.25rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stat-pct {
    font-size: clamp(0.65rem, 2vw, 0.78rem);
  }

  .tier-primary {
    font-size: clamp(0.95rem, 3.8vw, 1.25rem);
  }

  .tier-secondary {
    font-size: clamp(0.82rem, 3vw, 1.05rem);
  }

  .grid-3,
  .grid-2 {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  /* Calendar Responsive: 7 columns (drop weekly total on mobile) */
  .calendar-wrap {
    min-height: auto;
    gap: 1rem;
  }

  .calendar-header {
    padding: 0.75rem 1rem;
  }

  .calendar-month-year h2 {
    font-size: 1.1rem;
  }

  .calendar-month-pnl {
    font-size: 0.95rem;
  }

  .calendar-grid {
    grid-template-columns: repeat(7, 1fr) !important;
    padding: 0.6rem 0.4rem;
    gap: 0.3rem;
  }

  .calendar-day-header.week-total-header,
  .calendar-cell.week-total-cell {
    display: none !important;
  }

  .calendar-cell {
    min-height: 58px;
    padding: 0.25rem 0.3rem;
    border-radius: 6px;
  }

  .cell-day-num {
    font-size: 0.68rem;
  }

  .cell-pnl {
    font-size: 0.72rem;
    font-weight: 700;
  }

  .cell-counts {
    display: none !important;
  }

  /* Trades Date Filters as Horizontal Scrolling Pill Strip */
  .trades-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .date-filters {
    display: flex;
    overflow-x: auto;
    flex-wrap: nowrap;
    gap: 0.3rem;
    padding: 0.2rem 0;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .date-filters::-webkit-scrollbar {
    display: none;
  }

  .filter-btn {
    flex-shrink: 0;
    min-height: 34px;
    padding: 0.35rem 0.7rem;
    border-radius: 16px;
    font-size: 0.72rem;
    touch-action: manipulation;
  }

  .custom-date-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .custom-date-row .input {
    width: 100%;
    min-width: 0;
  }

  /* Tables Compact on Mobile */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 0.75rem;
  }

  th, td {
    padding: 0.5rem 0.6rem;
    white-space: nowrap;
  }

  thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #0f1320;
  }

  /* Log Stream on Mobile */
  .log-stream {
    height: calc(100dvh - 260px);
    font-size: 0.72rem;
  }

  .access-form {
    flex-direction: column;
    align-items: stretch;
  }
  
  .access-form .input {
    width: 100%;
    min-width: 0;
  }

  .modal-card {
    padding: 1.25rem;
    width: 92%;
    border-radius: 16px;
  }
  
  .portal-grid {
    grid-template-columns: 1fr;
  }
  
  .portal-container {
    padding: 1.5rem 0.75rem;
  }
  
  .portal-logo {
    font-size: 1.5rem;
  }
}

/* ── Intermediate Breakpoint for 5-column grids ── */
@media (max-width: 1100px) {
  .grid-5 {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.85rem;
  }
}

/* ── Mobile Landscape Optimization ── */
@media (max-height: 520px) and (orientation: landscape), (max-width: 950px) and (max-height: 520px) {
  :root {
    --sidebar-width: 56px;
  }

  .app {
    flex-direction: row !important;
  }

  .content {
    margin-bottom: 0 !important;
    padding-bottom: 0 !important;
  }

  .sidebar {
    width: 56px !important;
    padding: 0.4rem 0.2rem !important;
    align-items: center !important;
    position: relative !important;
    top: 0 !important;
    bottom: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    flex-direction: column !important;
    justify-content: flex-start !important;
    overflow-y: auto !important;
    border-right: 1px solid var(--border) !important;
    border-top: none !important;
    z-index: 100 !important;
  }

  .sidebar .logo {
    display: flex !important;
    font-size: 0 !important;
    padding: 0.35rem 0 !important;
    justify-content: center !important;
  }

  .sidebar .logo .logo-icon {
    font-size: 1.35rem !important;
    margin: 0 !important;
  }

  .sidebar .nav-section {
    display: none !important;
  }

  .sidebar .nav-btn {
    display: flex !important;
    flex: none !important;
    width: 44px !important;
    height: 36px !important;
    padding: 0 !important;
    justify-content: center !important;
    align-items: center !important;
    font-size: 0 !important;
    margin-bottom: 2px !important;
    border-radius: 6px !important;
    border-right: none !important;
    border-left: 3px solid transparent !important;
  }

  .sidebar .nav-btn .tab-icon {
    font-size: 1.15rem !important;
    margin: 0 !important;
  }

  .sidebar .nav-btn .tab-label {
    display: none !important;
  }

  .sidebar .nav-btn.active {
    border-left-color: var(--accent) !important;
    background: var(--accent-glow) !important;
  }

  .sidebar-footer {
    display: none !important;
  }

  /* Compact Topbar in landscape */
  .topbar {
    min-height: 38px !important;
    padding: 0.25rem 0.6rem !important;
  }

  .topbar h1 {
    font-size: 0.95rem !important;
  }

  .tenant-badge {
    font-size: 0.62rem !important;
    padding: 0.1rem 0.3rem !important;
  }

  /* View container in landscape */
  .view-container {
    padding: 0.5rem 0.6rem !important;
  }

  /* Grid layout reflow for landscape mobile */
  .grid-5 {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 0.55rem !important;
  }

  .grid-4 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.55rem !important;
  }

  .grid-3 {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.55rem !important;
  }

  .grid-2 {
    grid-template-columns: 1fr 1fr !important;
    gap: 0.55rem !important;
  }

  /* Stat cards compact padding & fluid text */
  .stat-card {
    padding: 0.5rem 0.6rem !important;
    min-width: 0 !important;
  }

  .stat-label {
    font-size: 0.62rem !important;
    margin-bottom: 0.2rem !important;
  }

  .stat-value {
    font-size: clamp(0.9rem, 2.4vw, 1.2rem) !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .stat-pct {
    font-size: clamp(0.62rem, 1.8vw, 0.75rem) !important;
  }

  .tier-primary {
    font-size: clamp(0.9rem, 2.4vw, 1.2rem) !important;
  }

  .tier-secondary {
    font-size: clamp(0.8rem, 2vw, 1rem) !important;
  }
}

/* ── Skeleton Loading (L-2) ── */
.skeleton {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.03) 75%);
  background-size: 200% 100%;
  animation: loading-skeleton 1.5s infinite linear;
  border-radius: var(--radius-sm);
  color: transparent !important;
  pointer-events: none;
}

.skeleton * {
  visibility: hidden;
}

@keyframes loading-skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Calendar Styles */
.calendar-wrap {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-height: calc(100vh - 160px);
}

.calendar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.5rem;
}

.calendar-month-year {
  text-align: center;
}

.calendar-month-year h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.calendar-month-pnl {
  font-size: 1.1rem;
  font-weight: 700;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr) 130px;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.calendar-day-header {
  text-align: center;
  padding: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}

.week-total-header {
  color: var(--accent);
  border-bottom: 1px dashed var(--accent);
}

.calendar-cell {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-height: 85px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  transition: all 0.2s ease-in-out;
  cursor: pointer;
}

.calendar-cell:hover:not(.other-month):not(.week-total-cell) {
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
  transform: translateY(-2px);
}

.calendar-cell.other-month {
  opacity: 0.25;
  cursor: default;
}

.calendar-cell.today {
  border-color: var(--accent);
  background: linear-gradient(185deg, var(--bg-dark), var(--accent-glow));
}

.cell-day-num {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.calendar-cell.today .cell-day-num {
  color: var(--accent);
}

.cell-pnl {
  font-size: 0.85rem;
  font-weight: 600;
  text-align: right;
  margin-top: auto;
}

.cell-counts {
  font-size: 0.65rem;
  color: #e2e8f0;
  text-align: right;
  margin-top: 2px;
  font-family: 'JetBrains Mono', monospace;
}

.week-total-cell {
  background: var(--accent-glow);
  border: 1px dashed var(--accent);
  color: var(--text);
  cursor: default;
}

.week-total-val {
  font-size: 0.95rem;
  font-weight: 700;
  text-align: right;
  margin-top: auto;
}

.calendar-details-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  animation: fadeIn 0.3s ease-in-out;
}

.calendar-details-panel h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Analytics & Visualization View Layout ── */

.analytics-view {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  animation: fadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* ── Analytics Toolbar ── */
.analytics-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.85rem 1.25rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.analytics-toolbar-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.analytics-toolbar-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.analytics-toolbar-title {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
}

.analytics-refresh-btn {
  padding: 0.35rem 0.65rem;
}

/* ── Analytics inline note (truncation / error banner) ── */
.analytics-note {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--amber);
  background: var(--amber-bg);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
}

.analytics-note[hidden] {
  display: none;
}

.analytics-date-filters {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.analytics-date-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  background: var(--bg-dark);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s ease;
}

.analytics-date-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border-light);
}

.analytics-date-btn.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ── Collapsible Group Cards ── */
.analytics-group {
  padding: 0;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--bg-card);
  border: 1px solid var(--border);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.analytics-group:hover {
  border-color: var(--border-light);
}

.analytics-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  background: rgba(15, 22, 41, 0.4);
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background 0.15s ease;
}

.analytics-group-header:hover {
  background: var(--bg-hover);
}

.analytics-group-title {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.analytics-group-title h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.group-icon {
  font-size: 1.1rem;
}

.btn-group-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.toggle-icon {
  font-size: 0.75rem;
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  display: inline-block;
}

.analytics-group-header.collapsed .toggle-icon {
  transform: rotate(-90deg);
}

.analytics-group-header.collapsed {
  border-bottom: none;
}

.analytics-group-body {
  padding: 1.25rem;
  transition: all 0.3s ease;
}

.analytics-group-body.collapsed {
  display: none;
}

/* ── Analytics Responsive Grid & Chart Cards ── */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1.25rem;
}

.chart-card {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: border-color 0.2s ease;
  max-width: 100%;
  box-sizing: border-box;
  overflow: hidden;
}

.chart-card:hover {
  border-color: var(--border-active);
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.chart-header-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.chart-header h4 {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.chart-type-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chart-type-badge.tv {
  background: rgba(16, 185, 129, 0.12);
  color: var(--green);
  border: 1px solid rgba(16, 185, 129, 0.25);
}

.chart-type-badge.cjs {
  background: rgba(99, 102, 241, 0.12);
  color: var(--accent);
  border: 1px solid rgba(99, 102, 241, 0.25);
}

.chart-container {
  position: relative;
  width: 100%;
  max-width: 100%;
  height: 280px;
  min-height: 280px;
  border-radius: 4px;
  overflow: hidden;
  box-sizing: border-box;
}

.tv-chart-box {
  width: 100%;
  height: 100%;
}

.chart-container canvas {
  width: 100% !important;
  max-width: 100% !important;
  height: 100% !important;
  display: block;
}

/* ── Chart footnote (set by app.js setChartFootnote) ──
   Lives on the .chart-card in normal flow, under the fixed-height chart
   container — never absolutely positioned, so it cannot overlap the canvas. */
.chart-footnote {
  margin-top: 0.4rem;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-muted);
}

/* ── Group-7 strategy stats row (profit factor / expectancy tiles) ── */
.analytics-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.stat-tile {
  background: var(--bg-dark);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  transition: border-color 0.2s ease;
}

.stat-tile:hover {
  border-color: var(--border-active);
}

.stat-tile-value {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-tile-value.stat-good {
  color: var(--green);
}

.stat-tile-value.stat-bad {
  color: var(--red);
}

.stat-tile-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.stat-tile-sub {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── Chart overlay (empty / error states, set by app.js setChartOverlay) ── */
.chart-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 1rem 1.25rem;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--text-muted);
  background: rgba(8, 9, 12, 0.6);
  backdrop-filter: blur(2px);
  border-radius: 4px;
  z-index: 3;
}

.chart-overlay--empty {
  color: var(--text-muted);
}

.chart-overlay--error {
  color: var(--red);
  border-left: 3px solid var(--red);
  background: rgba(239, 68, 68, 0.1);
}

/* Visually hidden but accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Chart Skeleton Shimmer Animation ── */
.chart-skeleton {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.02) 25%, rgba(255, 255, 255, 0.07) 50%, rgba(255, 255, 255, 0.02) 75%);
  background-size: 200% 100%;
  animation: loading-skeleton 1.5s infinite linear;
  border-radius: 4px;
  z-index: 2;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.chart-skeleton.loaded {
  opacity: 0;
  pointer-events: none;
}

/* ── Mobile Responsiveness for Analytics ── */
@media (max-width: 900px) {
  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .analytics-stats-row {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .chart-card {
    padding: 0.75rem;
  }

  .chart-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
  }

  .chart-header-actions {
    width: 100%;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }

  .chart-header-actions::-webkit-scrollbar {
    display: none;
  }

  .chart-container {
    height: 240px;
    min-height: 240px;
  }

  .analytics-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .analytics-toolbar-right {
    justify-content: space-between;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  .analytics-grid {
    grid-template-columns: 1fr;
  }

  .chart-container {
    height: 240px;
    min-height: 240px;
  }
}

/* ── Touch target sizing & feedback (coarse pointers only) ── */
@media (pointer: coarse) {
  .nav-btn, .filter-btn, .btn, .btn-icon, .btn-primary, .btn-secondary, .btn-danger,
  .more-sheet-item, .analytics-date-btn, .btn-group-toggle, .calendar-cell {
    touch-action: manipulation;
  }

  .nav-btn:active,
  .filter-btn:active,
  .btn:active,
  .btn-icon:active,
  .more-sheet-item:active,
  .stat-card:active,
  .portal-card:active,
  .calendar-cell:active:not(.other-month) {
    transform: scale(0.96);
    opacity: 0.85;
    transition: transform 0.06s ease, opacity 0.06s ease;
  }

  /* Disable hover transform/shadow on coarse touch to avoid sticking */
  .stat-card:hover { transform: none; }
  .portal-card:hover { transform: none; box-shadow: none; }
  .calendar-cell:hover:not(.other-month):not(.week-total-cell) { transform: none; box-shadow: none; }

  .analytics-date-btn {
    min-height: 38px;
    padding: 0.4rem 0.8rem;
  }

  .btn-group-toggle {
    min-height: 38px;
    min-width: 38px;
    padding: 0.45rem;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .chart-skeleton,
  .skeleton {
    animation: none;
  }

  .toggle-icon {
    transition: none;
  }

  .analytics-view {
    animation: none;
  }
}

/* ── Focus visibility ── */
.analytics-date-btn:focus-visible,
.btn-group-toggle:focus-visible,
.analytics-group-header:focus-visible,
.analytics-refresh-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Rotation Gate Status Panel ── */
.rotation-gate-panel {
  margin-bottom: 1rem;
  padding: 1rem 1.25rem;
  border-radius: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
}

.gate-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.gate-panel-header h4 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.gate-mode-badge {
  font-size: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.gate-panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.6rem;
}

.gate-metric {
  display: flex;
  flex-direction: column;
  background: var(--bg-card-hover, rgba(255, 255, 255, 0.03));
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.gate-metric-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 0.2rem;
}

.gate-info-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  font-size: 0.65rem;
  font-family: inherit;
  font-weight: 700;
  color: var(--text-muted);
  cursor: help;
  opacity: 0.65;
  transition: opacity 0.15s ease, color 0.15s ease, background-color 0.15s ease;
  user-select: none;
  margin-left: 4px;
}

.gate-info-icon:hover,
.gate-info-icon:focus {
  opacity: 1;
  color: var(--accent, #38bdf8);
  background: rgba(56, 189, 248, 0.18);
  outline: none;
}

.gate-metric-value {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gate-metric-master {
  grid-column: 1 / -1;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.8rem;
  background: var(--bg-card-hover, rgba(255, 255, 255, 0.05));
  border-left: 3px solid var(--accent, #3b82f6);
}

.gate-metric-master .gate-metric-label {
  margin-bottom: 0;
  font-size: 0.78rem;
  font-weight: 600;
}

.gate-metric-master .gate-metric-value {
  font-size: 0.95rem;
  font-weight: 700;
}

/* State coloring classes */
.state-normal { color: var(--green, #22c55e) !important; }
.state-watch { color: var(--amber, #f59e0b) !important; }
.state-eligible { color: var(--red, #ef4444) !important; }
.state-braked { color: var(--blue, #3b82f6) !important; }
.state-inactive { color: var(--text-muted, #94a3b8) !important; }

/* Full width chart card */
.chart-card-full {
  grid-column: 1 / -1;
}

/* Educational widget & planning tool */
.analytics-educational-widget,
.analytics-planning-tool {
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  background: var(--bg-card);
}

.analytics-educational-widget summary,
.analytics-planning-tool summary {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.analytics-educational-widget summary:hover,
.analytics-planning-tool summary:hover {
  color: var(--text);
}

/* Simulator controls & results */
.sim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  padding: 0.75rem;
  background: var(--bg-card-hover, rgba(255, 255, 255, 0.02));
  border-radius: 6px;
  margin-bottom: 0.75rem;
}

.sim-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.sim-input {
  width: 75px;
  padding: 0.3rem 0.5rem;
  font-size: 0.82rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-input, rgba(0, 0, 0, 0.2));
  color: var(--text);
}

.sim-run-btn {
  padding: 0.35rem 0.8rem;
  font-size: 0.8rem;
  border-radius: 4px;
}

.sim-results {
  margin-top: 0.75rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.sim-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

.sim-table th, .sim-table td {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  text-align: left;
}

.sim-table th {
  background: var(--bg-card-hover, rgba(255, 255, 255, 0.04));
  color: var(--text);
  font-weight: 600;
}

