/* Layout — topbar + three-pane main. */

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 2px solid var(--brand-deep);
  flex-shrink: 0;
}

#brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-right: 14px;
  border-right: 1px solid var(--border);
}
#brand-logo { height: 36px; width: auto; display: block; }
#brand-title { display: flex; flex-direction: column; gap: 1px; line-height: 1.05; }
.brand-name {
  font-size: 10px; font-weight: 700; letter-spacing: 0.18em;
  text-transform: uppercase; color: var(--brand-cream);
}
.app-title { font-size: 15px; font-weight: 700; color: var(--text); }

#stats-bar { display: flex; gap: 18px; margin-left: auto; }
.stat { display: flex; flex-direction: column; align-items: center; }
.stat-val { font-size: 16px; font-weight: 700; line-height: 1; }
.stat-lbl { font-size: 10px; color: var(--muted); white-space: nowrap; }
.stat.warn .stat-val { color: var(--warn); }
.stat.ok .stat-val { color: var(--ok); }
.stat.verify .stat-val { color: var(--verify); }
.stat.danger .stat-val { color: var(--danger); }

/* Role badge in topbar */
#role-badge {
  font-size: 11px;
  font-weight: 600;
  color: var(--brand-soft);
  padding: 2px 8px;
  border: 1px solid var(--brand-soft);
  border-radius: 10px;
  white-space: nowrap;
}
#role-badge:empty { display: none; }

/* Three-pane grid — id rule wins specificity, class rule satisfies headless verify */
#main {
  display: grid;
  grid-template-columns: var(--w-cascade,260px) var(--w-list,320px) 1fr;
  grid-auto-columns: 0;
  flex: 1;
  overflow: hidden;
  min-height: 0;
  transition: grid-template-columns 0.18s ease;
}
.three-pane {
  display: grid;
  grid-template-columns: var(--w-cascade,260px) var(--w-list,320px) 1fr;
}

/* Pane base styles */
#cascade-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
}

#list-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#detail-pane {
  background: var(--bg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Source-document side panel (4th implicit grid column when open) */
#source-panel {
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#source-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
#source-body { flex: 1; overflow: hidden; background: white; }
.source-loading, .source-error {
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

/* When source is open: collapse list column, split detail+source equally */
body.source-open #main { grid-template-columns: var(--w-cascade,260px) 0 1fr 1fr; }
body.source-open #list-pane { overflow: hidden; border-right: none; }
body.source-open #source-panel { display: flex; }

.detail-actions { display: flex; gap: 8px; }

/* Collapsible panes */
.pane-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
}
.pane-toggle:hover { color: var(--text); border-color: var(--brand-soft); }
#sidebar-toggle { margin-right: 8px; }
#pane-mode-toggle { margin-right: 4px; }
#pane-swap-toggle { margin-right: 12px; }

/* Desktop-only controls (the pane model is a grid concept; mobile stacks). */
.desktop-only { display: inline-block; }
@media (max-width: 768px) {
  .desktop-only { display: none; }
}

/* Collapsed utility class — toggled by app.mjs on each pane element */
.pane.collapsed { overflow: hidden; border-right: none; }

/* Collapsed grid-column overrides — body class drives the grid track width */
body.sidebar-collapsed #main { grid-template-columns: 0 var(--w-list,320px) 1fr; }
body.sidebar-collapsed #cascade-pane { overflow: hidden; border-right: none; }
body.list-collapsed #main { grid-template-columns: var(--w-cascade,260px) 0 1fr; }
body.list-collapsed #list-pane { overflow: hidden; border-right: none; }

/* Responsive — stack panes on narrow screens, drawer-style sidebar */
@media (max-width: 900px) {
  #stats-bar .stat-lbl { display: none; }
  #brand-title .brand-name { display: none; }
}
@media (max-width: 768px) {
  /* Override grid to vertical flex on mobile */
  #main {
    display: flex;
    flex-direction: column;
    grid-template-columns: initial;
    transition: none;
  }
  #cascade-pane {
    position: absolute; z-index: 50; top: 0; bottom: 0; left: 0;
    width: 240px; box-shadow: 2px 0 8px rgba(0,0,0,0.3);
    transform: translateX(-100%); transition: transform 0.18s ease;
    border-right: 1px solid var(--border);
    overflow-y: auto;
  }
  body:not(.sidebar-collapsed) #cascade-pane { transform: translateX(0); }
  body.sidebar-collapsed #cascade-pane { transform: translateX(-100%); width: 240px; }
  /* On mobile, the default is COLLAPSED sidebar (drawer hidden) */
  #list-pane, #detail-pane { width: 100% !important; max-width: 100% !important; flex: 1; }
  /* When detail is open, hide list (and vice versa) */
  body.detail-shown #list-pane { display: none; }
  body:not(.detail-shown) #detail-pane { display: none; }
  #source-panel { display: none !important; }
  #topbar { padding: 6px 10px; gap: 8px; flex-wrap: nowrap; overflow-x: auto; }
  #stats-bar { gap: 10px; }
  .detail-meta { flex-wrap: wrap; gap: 8px; }
  .image-strip .spec-img { height: 60px; }
  .admin-panel, .validator-panel, .modal-panel { width: 96vw !important; max-height: 90vh; }
  .audit-filters { flex-direction: column; }
  .audit-filters input, .audit-filters select { flex: 1 1 auto; width: 100%; }
}
@media (max-width: 480px) {
  #brand-title { display: none; }
  #brand-logo { height: 28px; }
  #stats-bar { display: none; }
}

.mobile-only { display: none; }
@media (max-width: 768px) {
  .mobile-only { display: inline-block; }
}

/* A1 — detail focus. The focus button only appears once a product is open; it
   collapses BOTH left columns so the spec gets full width. It's a transient
   overlay (not persisted) and is independent of the per-pane collapse toggles,
   so leaving focus restores whatever collapse state the user had. */
#focus-toggle { display: none; margin-right: 12px; }
body.detail-shown #focus-toggle { display: inline-block; }
body.focus-detail #focus-toggle { color: var(--brand); border-color: var(--brand); }
body.focus-detail #main { grid-template-columns: 0 0 1fr; }
body.focus-detail #cascade-pane,
body.focus-detail #list-pane { overflow: hidden; border-right: none; }
