/* portal.css — Salesforce Pit Wall portal. Mirrors the brand chrome of
 * viz/top-bar and viz/dh-top-bar so the portal reads as the same product
 * surface. Tokens come from viz/dh-shared/dh-theme.css; this file uses
 * sRGB hex copies so we don't depend on any oklch() shim.
 */

:root {
  --bg-stage:    #0B1020;   /* outer stage — matches Pit Wall dashboard outer zone */
  --bg-0:        #0F1628;   /* primary panel base */
  --bg-1:        #1A1F2B;   /* lifted panel */
  --bg-2:        #232C50;
  --bg-grad-top: #1B2240;   /* top-bar gradient start */
  --bg-grad-bot: #131A30;   /* top-bar gradient end */

  --line:        rgba(168, 184, 220, 0.18);
  --line-soft:   rgba(168, 184, 220, 0.10);
  --line-strong: rgba(168, 184, 220, 0.32);

  --ink-0:       #F5F7FB;
  --ink-1:       #DDE2EE;
  --ink-2:       #97A2BE;
  --ink-3:       #6A7595;

  --cyan:        #5AC4E0;
  --violet:      #A88FE0;
  --lime:        #A8E862;
  --amber:       #E8B86E;
  --magenta:     #E66270;

  --cyan-glow:    rgba(90, 196, 224, 0.45);
  --violet-glow:  rgba(168, 143, 224, 0.45);
  --lime-glow:    rgba(168, 232, 98, 0.45);
  --amber-glow:   rgba(232, 184, 110, 0.45);

  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Inter', ui-sans-serif, -apple-system, system-ui, sans-serif;

  --radius-sm:   8px;
  --radius:      12px;
  --radius-lg:   18px;

  --topbar-h:    64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100%; min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(90, 196, 224, 0.07), transparent 60%),
    radial-gradient(900px 500px at 100% 100%, rgba(168, 143, 224, 0.05), transparent 70%),
    var(--bg-stage);
  color: var(--ink-0);
  font-family: var(--sans);
  font-feature-settings: "ss01", "tnum";
  -webkit-font-smoothing: antialiased;
}

body { display: flex; flex-direction: column; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ============================================================
 * TOP BAR — same chrome as the dashboards' top-bar viz extension
 * ============================================================ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 24px;
  align-items: center;
  height: var(--topbar-h);
  padding: 0 22px;
  background: linear-gradient(180deg, var(--bg-grad-top), var(--bg-grad-bot));
  border-bottom: 1px solid var(--line);
}

.tb-left  { display: flex; align-items: center; gap: 18px; min-width: 0; }
.tb-center{ display: flex; align-items: center; gap: 10px; justify-content: center; }
.tb-right { display: flex; align-items: center; gap: 14px; justify-content: flex-end; min-width: 0; }

.logo-box {
  display: flex; align-items: center; gap: 10px;
  background: rgba(34, 44, 80, 0.55);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
}
.logo-box img.sf-logo {
  height: 22px; width: auto; display: block;
  filter: drop-shadow(0 0 6px var(--cyan-glow));
}
.logo-box .logo-txt {
  font-family: var(--mono);
  font-size: 11px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--ink-0);
  white-space: nowrap;
}

.crumb {
  display: flex; flex-direction: column; gap: 2px; min-width: 0;
}
.crumb .title {
  font-family: var(--sans);
  font-size: 18px; font-weight: 600; letter-spacing: -0.005em;
  color: var(--ink-0);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.crumb .sub {
  font-family: var(--mono);
  font-size: 9px; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--ink-3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.mode-chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.18em;
  font-weight: 600;
  background: rgba(168, 232, 98, 0.14);
  color: var(--lime);
  border: 1px solid rgba(168, 232, 98, 0.4);
  padding: 7px 12px; border-radius: 999px;
}
.mode-chip i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--lime); box-shadow: 0 0 10px var(--lime);
}

.user-chip {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--mono);
  font-size: 10px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--ink-2);
  border: 1px solid var(--line-soft);
  padding: 6px 10px; border-radius: 999px;
  background: rgba(34, 44, 80, 0.45);
}
.user-chip strong {
  color: var(--ink-0); font-weight: 600;
  letter-spacing: 0.08em; text-transform: none;
}

/* ============================================================
 * LANDING PAGE
 * ============================================================ */
.shell {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 32px clamp(16px, 3vw, 48px) 64px;
  gap: 32px;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 24px;
  padding: 8px 0 0;
}
.hero h1 {
  margin: 0;
  font-family: var(--sans);
  font-size: clamp(28px, 3.4vw, 44px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: -0.02em;
  color: var(--ink-0);
}
.hero h1 .accent {
  background: linear-gradient(120deg, var(--cyan), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero .lede {
  margin-top: 12px;
  font-size: clamp(13px, 1.2vw, 16px);
  color: var(--ink-2);
  max-width: 64ch; line-height: 1.55;
}
.hero .meta-strip {
  display: flex; gap: 12px; flex-wrap: wrap;
  align-items: center;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-3);
}
.hero .meta-strip .dot { color: var(--cyan); }

/* card grid */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 360px), 1fr));
  gap: 20px;
}
.card {
  position: relative;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-grad-bot));
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-lg);
  padding: 0;
  overflow: hidden;
  transition: transform .25s ease, border-color .25s ease, box-shadow .25s ease;
  text-decoration: none; color: inherit;
}
.card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: 0 18px 48px -24px rgba(0, 0, 0, 0.55);
}
.card .card-art {
  position: relative;
  aspect-ratio: 16 / 9;
  background: linear-gradient(160deg, #0E1325 0%, #1B2240 60%, #232C50 100%);
  border-bottom: 1px solid var(--line-soft);
  overflow: hidden;
}
/* Real Tableau workbook preview thumbnail. Drawn first so the SVG schematic
 * sits *underneath*; if the thumbnail fetch fails (`onerror`), the <img>
 * adds .failed and removes its src, revealing the schematic + gradient. */
.card .card-art .thumb {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  z-index: 2;
  filter: saturate(1.05) contrast(1.04);
  background: rgba(11, 16, 32, 0.4);
  transition: transform .3s ease, filter .3s ease;
}
.card:hover .card-art .thumb {
  transform: scale(1.025);
  filter: saturate(1.1) contrast(1.06);
}
.card .card-art .thumb.failed { display: none; }
/* Subtle gradient overlay on top of the thumb so the badge + accent ring
 * stay legible even with bright workbook screenshots. */
.card .card-art .art-overlay {
  position: absolute; inset: 0; z-index: 3;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(11, 16, 32, 0.05) 30%, rgba(11, 16, 32, 0.55) 100%),
    radial-gradient(120% 80% at 50% 0%, rgba(255,255,255,0.06), transparent 60%);
}
.card .card-art .schematic { position: absolute; inset: 14px; z-index: 1; }
.card .card-art .schematic .row {
  position: absolute; left: 0; right: 0; height: 14px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
}

/* Live-pace ribbon. Sits across the bottom third of the art area, on
 * top of the workbook thumbnail/schematic so the card reads as
 * actively streaming telemetry even at a glance. */
.card .card-art .card-spark {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 38%;
  width: 100%;
  display: block;
  z-index: 4;
  pointer-events: none;
  opacity: 0.92;
  mix-blend-mode: screen;
}
.card[data-live="1"] .card-art .card-spark {
  opacity: 1;
  filter: drop-shadow(0 0 6px rgba(157, 247, 156, 0.4));
}
.card .badge {
  position: absolute; top: 14px; right: 14px; z-index: 5;
  font-family: var(--mono); font-size: 9px; font-weight: 700;
  letter-spacing: 0.22em; text-transform: uppercase;
  padding: 5px 10px; border-radius: 999px;
  background: rgba(11, 16, 32, 0.78);
  backdrop-filter: blur(6px);
  border: 1px solid var(--line-soft);
  color: var(--ink-1);
}
.card.accent-cyan .badge   { color: var(--cyan);   border-color: rgba(90, 196, 224, 0.45); }
.card.accent-violet .badge { color: var(--violet); border-color: rgba(168, 143, 224, 0.45); }
.card.accent-lime .badge   { color: var(--lime);   border-color: rgba(168, 232, 98, 0.45); }
.card.accent-amber .badge  { color: var(--amber);  border-color: rgba(232, 184, 110, 0.45); }

/* Live pulse — added to .card[data-live="1"] when portal.js detects MQTT
 * is streaming and recent telemetry is flowing. The badge picks up a
 * green dot and a subtle glow so judges can see at a glance which
 * dashboards are reading from the live feed right now. */
.card[data-live="1"] .badge {
  border-color: rgba(157, 247, 156, 0.55);
  color: var(--lime);
  box-shadow: 0 0 18px rgba(157, 247, 156, 0.20);
}
.card[data-live="1"] .badge::before {
  content: '';
  display: inline-block;
  width: 6px; height: 6px;
  margin-right: 7px; vertical-align: middle;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 10px var(--lime);
  animation: cardLivePulse 1.4s ease-in-out infinite;
}
@keyframes cardLivePulse {
  0%, 100% { opacity: 1;   transform: scale(1); }
  50%      { opacity: 0.55; transform: scale(0.78); }
}

.card .card-body {
  padding: 18px 20px 20px;
  display: flex; flex-direction: column; gap: 12px;
  flex: 1 1 auto;
}
.card .card-body h2 {
  margin: 0;
  font-size: 19px; font-weight: 600;
  color: var(--ink-0);
  letter-spacing: -0.01em;
}
.card .card-body .sub {
  font-family: var(--mono);
  font-size: 10px; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--ink-3);
  margin-top: -4px;
}
.card .card-body .blurb {
  color: var(--ink-2); font-size: 14px; line-height: 1.55;
}
.card .chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: auto;
}
.card .chips span {
  font-family: var(--mono);
  font-size: 9px; letter-spacing: 0.18em;
  text-transform: uppercase;
  padding: 5px 9px; border-radius: 999px;
  border: 1px solid var(--line-soft);
  color: var(--ink-2);
  background: rgba(34, 44, 80, 0.45);
}
.card .open-cta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase;
}
.card.accent-cyan   .open-cta { color: var(--cyan); }
.card.accent-violet .open-cta { color: var(--violet); }
.card.accent-lime   .open-cta { color: var(--lime); }
.card.accent-amber  .open-cta { color: var(--amber); }

/* schematic accent strokes per card — purely decorative, hint at the
   shape of each dashboard so the cards feel custom without needing
   real screenshots. */
.card.accent-cyan   .card-art .schematic .row.accent { background: linear-gradient(90deg, transparent, var(--cyan-glow)); }
.card.accent-violet .card-art .schematic .row.accent { background: linear-gradient(90deg, transparent, var(--violet-glow)); }
.card.accent-lime   .card-art .schematic .row.accent { background: linear-gradient(90deg, transparent, var(--lime-glow)); }
.card.accent-amber  .card-art .schematic .row.accent { background: linear-gradient(90deg, transparent, var(--amber-glow)); }

/* ============================================================
 * STATUS BLOCK on landing
 * ============================================================ */
.status-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 16px;
}
.status-card {
  background: var(--bg-0);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.status-card .lbl {
  font-family: var(--mono); font-size: 9px; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--ink-3);
}
.status-card .val {
  font-family: var(--mono); font-size: 18px; font-weight: 600;
  color: var(--ink-0); margin-top: 4px;
  font-variant-numeric: tabular-nums; letter-spacing: 0.04em;
}
.status-card.ok .val   { color: var(--lime); }
.status-card.warn .val { color: var(--amber); }
.status-card.bad .val  { color: var(--magenta); }

/* ============================================================
 * VIEWER PAGE
 * ============================================================ */
.viewer-shell {
  display: flex; flex-direction: column;
  flex: 1 1 auto;
  width: 100%; height: calc(100vh - var(--topbar-h));
  background: var(--bg-stage);
}
.viewer-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 10px clamp(12px, 2vw, 22px);
  background: linear-gradient(180deg, rgba(11, 16, 32, 0.85), rgba(11, 16, 32, 0.55));
  border-bottom: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 11px;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: var(--ink-2);
}
.viewer-toolbar .left,
.viewer-toolbar .right { display: flex; align-items: center; gap: 12px; }
.viewer-toolbar a.back {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--ink-2);
  border: 1px solid var(--line-soft);
  padding: 7px 12px; border-radius: 999px;
  transition: color .2s ease, border-color .2s ease;
}
.viewer-toolbar a.back:hover { color: var(--cyan); border-color: rgba(90, 196, 224, 0.45); }
.viewer-toolbar .pill {
  padding: 5px 9px; border: 1px solid var(--line-soft);
  border-radius: 999px; color: var(--ink-3);
  background: rgba(34, 44, 80, 0.4);
}
.viewer-toolbar .actions button {
  appearance: none; border: 1px solid var(--line-soft);
  background: rgba(34, 44, 80, 0.45);
  color: var(--ink-2);
  padding: 7px 12px; border-radius: 999px;
  font-family: var(--mono); font-size: 10px; letter-spacing: 0.18em;
  text-transform: uppercase; cursor: pointer;
  transition: color .2s ease, border-color .2s ease;
}
.viewer-toolbar .actions button:hover { color: var(--cyan); border-color: rgba(90, 196, 224, 0.45); }
.viewer-toolbar .actions button.primary {
  color: var(--violet);
  border-color: rgba(168, 143, 224, 0.45);
  background: rgba(168, 143, 224, 0.08);
}

/* Device picker — desktop / tablet / phone segmented control */
.viewer-toolbar .device-pick {
  display: inline-flex;
  border: 1px solid var(--line-soft);
  border-radius: 999px;
  background: rgba(34, 44, 80, 0.45);
  padding: 2px;
}
.viewer-toolbar .device-pick button {
  appearance: none;
  border: 0; background: transparent;
  color: var(--ink-3);
  padding: 6px 12px;
  font-family: var(--mono); font-size: 10px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase;
  border-radius: 999px;
  cursor: pointer;
  transition: color .2s ease, background .2s ease;
}
.viewer-toolbar .device-pick button:hover { color: var(--ink-1); }
.viewer-toolbar .device-pick button.on {
  color: var(--ink-0);
  background: rgba(90, 196, 224, 0.18);
  box-shadow: inset 0 0 0 1px rgba(90, 196, 224, 0.45);
}

@media (max-width: 640px) {
  .viewer-toolbar .device-pick { display: none; }
}

.viewer-frame {
  flex: 1 1 auto;
  position: relative;
  display: flex; align-items: stretch; justify-content: stretch;
  background: var(--bg-stage);
  overflow: hidden;
}
.viewer-frame tableau-viz {
  width: 100%; height: 100%;
  --tableau-loading-spinner-color: var(--violet);
}
.viewer-overlay {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px;
  color: var(--ink-2);
  text-align: center;
  padding: 32px;
  background: var(--bg-stage);
  pointer-events: none;
  transition: opacity .35s ease;
}
.viewer-overlay.hidden { opacity: 0; pointer-events: none; }
.viewer-overlay .ring {
  width: 56px; height: 56px; border-radius: 50%;
  border: 3px solid rgba(168, 143, 224, 0.18);
  border-top-color: var(--violet);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.viewer-overlay .lbl {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--ink-2);
}
.viewer-overlay .detail {
  font-size: 13px; color: var(--ink-3); max-width: 56ch; line-height: 1.6;
}
.viewer-overlay.error .ring { display: none; }
.viewer-overlay.error .lbl  { color: var(--magenta); }

/* ============================================================
 * RESPONSIVE — iPad portrait / landscape, big screens, mobile
 * ============================================================ */

/* Big screens (1920+): widen container, lift cards a touch. */
@media (min-width: 1920px) {
  .shell { max-width: 1840px; }
  .card .card-body { padding: 22px 26px 24px; }
  .card .card-body h2 { font-size: 22px; }
  .hero h1 { font-size: 48px; }
}

/* iPad landscape (1024-1366) — 2-3 cards per row, slightly tighter spacing. */
@media (min-width: 1024px) and (max-width: 1366px) {
  .shell { padding-left: 24px; padding-right: 24px; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* iPad portrait / small laptop (768-1023). */
@media (max-width: 1023px) {
  .topbar { grid-template-columns: 1fr auto; padding: 0 16px; }
  .tb-center { display: none; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
  .hero { grid-template-columns: 1fr; }
  .viewer-toolbar { font-size: 10px; }
}

/* Phone (≤640): single column, stacked toolbar, hide non-essential chips. */
@media (max-width: 640px) {
  :root { --topbar-h: 56px; }
  .topbar { gap: 12px; padding: 0 12px; }
  .logo-box { padding: 4px 8px; }
  .logo-box .logo-txt { display: none; }
  .crumb .title { font-size: 15px; }
  .crumb .sub { display: none; }
  .user-chip { display: none; }
  .shell { padding: 20px 16px 48px; gap: 24px; }
  .cards { grid-template-columns: 1fr; gap: 14px; }
  .card .card-art { aspect-ratio: 16 / 7; }
  .viewer-toolbar { flex-wrap: wrap; padding: 8px 12px; }
  .viewer-toolbar .pill { display: none; }
  .viewer-toolbar a.back { padding: 6px 10px; }
}

/* Touch device niceties: bigger hit targets, no hover transforms. */
@media (hover: none) {
  .card:hover { transform: none; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
