/* iSAT — Layout */

/* Demo shell — full iframe canvas */
.demo-shell {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--color-surface);
  overflow: hidden;
}

/* Top navigation bar */
.top-nav {
  display: flex;
  align-items: center;
  height: 44px;
  background: var(--color-white);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-6);
  z-index: var(--z-nav);
  flex-shrink: 0;
  gap: var(--space-6);
}

.top-nav .nav-wordmark {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  text-decoration: none;
  flex-shrink: 0;
}

.top-nav .nav-wordmark img,
.top-nav .nav-wordmark svg {
  height: 22px;
  width: auto;
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0;
  flex: 1;
  height: 100%;
}

.nav-link {
  display: flex;
  align-items: center;
  height: 44px;
  padding: 0 var(--space-4);
  color: var(--color-muted);
  text-decoration: none;
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  border-bottom: 2px solid transparent;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--color-text);
}

.nav-link.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

.nav-right {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin-left: auto;
}

/* User avatar chip */
.user-avatar-chip {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-pill);
  transition: background var(--transition-fast);
}

.user-avatar-chip:hover {
  background: var(--color-surface);
}

.user-avatar-chip .avatar-initials {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-white);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  display: flex;
  align-items: center;
  justify-content: center;
}

.user-avatar-chip .avatar-chevron {
  color: var(--color-muted);
  font-size: 10px;
}

/* Breadcrumb strip */
.breadcrumb {
  display: flex;
  align-items: center;
  height: 32px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--space-6);
  flex-shrink: 0;
  gap: var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--color-muted);
}

.breadcrumb a {
  color: var(--color-muted);
  text-decoration: none;
}

.breadcrumb a:hover {
  color: var(--color-text);
  text-decoration: underline;
}

.breadcrumb .crumb-sep {
  color: var(--color-border);
  font-size: 0.65rem;
}

.breadcrumb .crumb-current {
  color: var(--color-text);
  font-weight: var(--font-weight-medium);
}

/* Scrollable content area */
.content-area {
  flex: 1;
  min-width: 0;       /* allow flex item to shrink below content width */
  overflow-y: auto;
  overflow-x: hidden;
  /* Reserve room at the bottom so an inline panel (e.g. citation expand)
     near the end of the page can still scroll fully into view. */
  scroll-padding-bottom: 96px;
}

/* Inner page container */
.page-container {
  padding: 20px 24px 96px;
  width: 100%;
}

/* Page header (H1 + subtitle) */
.page-header {
  margin-bottom: var(--space-6);
}

.page-header h1 {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-bold);
  color: var(--color-text);
  margin: 0 0 var(--space-1) 0;
  line-height: 1.3;
}

.page-header .page-subtitle {
  font-size: var(--font-size-sm);
  color: var(--color-muted);
  margin: 0;
}

/* Sub-tab bar (for Signals section) */
.sub-tab-bar {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-6);
  background: var(--color-white);
}

.sub-tab {
  display: flex;
  align-items: center;
  padding: var(--space-3) var(--space-6);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  color: var(--color-muted);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

.sub-tab:hover {
  color: var(--color-text);
}

.sub-tab.active {
  color: var(--color-primary);
  border-bottom-color: var(--color-primary);
}

/* Two-column layout for evidence screen */
.two-col-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: var(--space-6);
  align-items: start;
}

/* Three-column panel grid for evidence screen */
.evidence-panels {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-4);
  align-items: start;
}

/* ============================================================
   Responsive — mobile-first overrides
   Desktop is the base; these adapt down to tablet and phone.
   Every HTML page already sets <meta name="viewport">.
   ============================================================ */

/* Tablet and below — collapse multi-column layouts to a single column */
@media (max-width: 900px) {
  .two-col-layout,
  .evidence-panels {
    grid-template-columns: 1fr;
  }
}

/* Wide data tables scroll horizontally instead of breaking the layout.
   Wrap any table in <div class="table-scroll"> for clean column alignment. */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Tablet / large phone */
@media (max-width: 760px) {
  .top-nav {
    padding: 0 var(--space-3);
    gap: var(--space-2);
  }
  /* Keep nav labels but let the bar scroll sideways when it overflows.
     The edge fade hints that the nav is scrollable; combined with nav.js
     centring the active link, neighbouring tabs peek on both sides. */
  .nav-links {
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    -webkit-mask-image: linear-gradient(to right, transparent 0, #000 20px, #000 calc(100% - 20px), transparent 100%);
    mask-image: linear-gradient(to right, transparent 0, #000 20px, #000 calc(100% - 20px), transparent 100%);
  }
  .nav-links::-webkit-scrollbar { display: none; }
  .nav-link {
    padding: 0 var(--space-3);
    font-size: var(--font-size-xs);
    white-space: nowrap;
    flex-shrink: 0;
  }
  .breadcrumb { padding: 0 var(--space-3); }
  .page-container { padding: 16px 16px 80px; }

  /* Safety net: clip stray horizontal overflow at the scroll container.
     Wide tables keep their own internal overflow-x:auto and still swipe. */
  .content-area { overflow-x: hidden; }
  .page-container { max-width: 100%; width: auto; }
  .page-header h1,
  .page-header .page-subtitle { overflow-wrap: anywhere; }
  canvas { max-width: 100% !important; }

  /* Any table not already in a scroll wrapper becomes swipe-scrollable.
     display:block + nowrap keeps columns at natural width and scrolls the
     overflow instead of squashing cells. The audit table is excluded — it
     scrolls inside .audit-table-wrap and needs display:table for sticky thead. */
  .page-container table:not(.no-scroll):not(.audit-table) {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }

  /* Let grid/flex layout items shrink to the viewport instead of being
     stretched wide by a nowrap table or long content (min-width:auto). */
  .two-col-layout, .evidence-layout, .evidence-panels-col,
  .competitive-grid, .temporal-grid, .assessment-layout,
  .impact-layout, .final-layout, .workspace-layout, .diff-layout,
  .two-col-layout > *, .evidence-layout > *, .evidence-panels-col > *,
  .competitive-grid > *, .temporal-grid > *, .assessment-layout > *,
  .impact-layout > *, .final-layout > *, .workspace-layout > *,
  .diff-layout > *, .evidence-panel {
    min-width: 0;
  }
}

/* Toolbar (Edit / Export / Copy / Start Over) wraps instead of overflowing */
@media (max-width: 640px) {
  .assessment-toolbar {
    flex-wrap: wrap;
    row-gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
  }
  .assessment-toolbar .toolbar-label {
    flex: 1 0 100%;
    margin-right: 0;
  }
}

/* Small phones — stack metric/card grids and let dense rows wrap */
@media (max-width: 540px) {
  .summary-cards,
  .metrics-strip,
  .safety-grid,
  .stats-grid,
  .card-grid { grid-template-columns: 1fr !important; }

  /* Metric callout rows: label on its own line, value + count beneath —
     stops the label column from being crushed on narrow phones.
     !important because components.css loads after this file. */
  .metric-row { flex-wrap: wrap; }
  .metric-row .metric-label { flex: 1 0 100% !important; margin-bottom: 2px; }
  .metric-row .metric-value { min-width: 0 !important; text-align: left; }
  .metric-row .metric-count { min-width: 0 !important; margin-left: var(--space-3); }
  /* Inline flex rows that use space-between (header + badge) wrap instead
     of forcing the page wider than the viewport */
  .page-container [style*="space-between"] {
    flex-wrap: wrap;
    gap: var(--space-2);
  }
  /* Long unbroken strings (IDs, hashes) wrap rather than overflow */
  .page-container { overflow-wrap: anywhere; }
}

/* Phone */
@media (max-width: 480px) {
  .top-nav { height: 48px; }
  .top-nav .nav-wordmark img,
  .top-nav .nav-wordmark svg { height: 18px; }
  .nav-right { display: none; }            /* drop avatar chip to save width */
  .page-container { padding: 12px 12px 72px; }
  .page-header h1,
  .page-container > h1 { font-size: var(--font-size-xl); line-height: 1.25; }
  .page-subtitle { font-size: var(--font-size-xs); }
}
