/* Layout: header, the three columns, sidebar, detail pane, resize handles and breakpoints. */
/* ==========================================================================
   Header (~125% scaled)
   ========================================================================== */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  height: 64px;
  flex-shrink: 0;
  z-index: 5;
  gap: 20px;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  min-width: 0;
  flex-shrink: 0;
}

.logo {
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  object-fit: contain;
}

.brand-text { min-width: 0; }

.brand-text h1 {
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.2px;
  line-height: var(--lh-title);
}

.brand-text .sub {
  font-size: var(--fs-sm);
  color: var(--muted);
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: var(--r-sm);
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  font-size: var(--fs-xl);
  cursor: pointer;
  color: var(--ink-secondary);
  transition: all .15s ease;
}

.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.header-actions {
  display: flex;
  gap: 14px;
  align-items: center;
  justify-content: flex-end;
  min-width: 0;
}

.header-actions .btn { flex-shrink: 0; }

/* Language switch: a compact segmented control in the seg-capsules style family. */
.seg-switch {
  display: inline-flex;
  flex-shrink: 0;
  gap: 2px;
  padding: 3px;
  background: var(--panel-subtle);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}

.seg-switch-btn {
  min-width: 34px;
  padding: 5px 9px;
  border: 0;
  border-radius: calc(var(--r-sm) - 2px);
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  transition: all .15s ease;
}

.seg-switch-btn:hover { color: var(--accent); }

.seg-switch-btn[aria-pressed="true"] {
  background: var(--panel);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.seg-switch-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: var(--r-full);
  background: var(--panel-subtle);
  border: 1px solid var(--border);
  font-size: var(--fs-md);
  color: var(--muted);
  max-width: 420px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-badge.running {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--faint);
  flex-shrink: 0;
}

#status { min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.status-badge.running .status-dot {
  background: var(--accent);
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 var(--pulse-ring); }
  70% { transform: scale(1); box-shadow: 0 0 0 5px var(--pulse-ring-end); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 var(--pulse-ring-end); }
}

/* ==========================================================================
   Main Layout Structure
   ========================================================================== */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  background: var(--bg);
  position: relative;
}

.layout-handle { position: relative; flex: 0 0 6px; cursor: col-resize; touch-action: none; background: transparent; z-index: 3; outline: none; }
.layout-handle::after { content: ''; position: absolute; width: 3px; height: 34px; left: 1.5px; top: calc(50% - 17px); border-radius: 999px; background: var(--border-strong); transition: background .15s, height .15s; }
.layout-handle:hover, .layout-handle:focus-visible { background: var(--accent-soft); }
.layout-handle:hover::after, .layout-handle:focus-visible::after { background: var(--accent); height: 54px; top: calc(50% - 27px); }
.layout.resizing, .layout.resizing * { cursor: col-resize !important; user-select: none !important; } /* important: a drag overrides every hover cursor and text selection */
.layout.resizing .layout-handle:focus { background: var(--accent-soft); }

/* ==========================================================================
   Left Sidebar (~125% scaled, width 300px)
   ========================================================================== */
aside#sidebar {
  width: var(--sidebar-width, 300px);
  padding: 14px 16px 22px;
  border-right: 1px solid var(--border);
  background: var(--panel);
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  transition: opacity .18s ease;
}

aside#sidebar.collapsed {
  width: 0;
  padding: 0;
  border-right: 0;
  overflow: hidden;
  opacity: 0;
}

.side-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-section-grow { flex: 1; }

.side-label {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.reset-link {
  padding: 2px 10px;
  border-radius: var(--r-full);
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  cursor: pointer;
  transition: all .15s ease;
}

.reset-link:hover {
  border-color: var(--accent-border);
  background: var(--accent-soft);
  color: var(--accent);
}

.filter-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--accent-border);
  border-radius: var(--r-md);
  background: var(--accent-soft);
  color: var(--accent);
}
.filter-summary-label { font-size: var(--fs-sm); font-weight: 500; }
.filter-summary-number { display: flex; align-items: baseline; gap: 5px; font-size: var(--fs-xs); white-space: nowrap; }
.filter-summary b { font-size: var(--fs-2xl); line-height: 1.15; font-weight: 700; letter-spacing: -.6px; font-variant-numeric: tabular-nums; }

/* Search Box */
.search-wrapper {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--faint);
  font-size: var(--fs-lg);
  pointer-events: none;
}

#search {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border-radius: var(--r-md);
  border: 1px solid var(--border);
  font-size: var(--fs-md);
  background: var(--panel);
  color: var(--ink);
  outline: none;
  transition: all .15s ease;
}

#search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

#search::placeholder {
  color: var(--faint);
}

/* Journal Navigation */
nav#journalNav {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

nav#journalNav button {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  gap: 9px;
  width: 100%;
  text-align: left;
  border: 0;
  background: none;
  padding: 7px 11px;
  border-radius: var(--r-sm);
  font-size: var(--fs-md);
  color: var(--ink-secondary);
  cursor: pointer;
  line-height: 1.35;
  transition: all .15s ease;
}

nav#journalNav button:hover {
  background: var(--panel-subtle);
  color: var(--ink);
}

nav#journalNav button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

nav#journalNav button::before { content:''; width:13px; height:13px; flex:none; border:1px solid var(--border-strong); border-radius:4px; background:var(--panel); }
nav#journalNav button.active::before { content:'✓'; color:var(--on-accent); background:var(--accent); border-color:var(--accent); font-size:var(--fs-xs); line-height:13px; text-align:center; }

.journal-group {
  font-size: var(--fs-xs);
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 9px 11px 2px;
  user-select: none;
}

/* ==========================================================================
   Center Main Area (~125% scaled)
   ========================================================================== */
main {
  flex: 1;
  container-type: inline-size;
  padding: 16px 24px 28px;
  overflow-y: auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ==========================================================================
   Right Detail Pane(s) & Dual Comparison (~125% scaled)
   ========================================================================== */
.detail-pane {
  display: flex;
  flex-shrink: 0;
  width: var(--detail-width, 460px);
  border-left: 1px solid var(--border);
  background: var(--panel);
  z-index: 2;
  box-shadow: var(--shadow-pane);
}

.detail-pane.two {
  width: var(--detail-width, 860px);
}

.pane {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pane + .pane {
  border-left: 1px solid var(--border);
}

.pane-header {
  position: relative;
  padding-right: 42px; /* avoid close-button collision */
}

.pane h2 {
  font-size: var(--fs-xl);
  font-weight: 700;
  line-height: var(--lh-title);
  color: var(--ink);
  letter-spacing: -0.2px;
}

.pane-close {
  position: absolute;
  top: 18px;
  right: 18px;
  border: 1px solid transparent;
  background: var(--panel-subtle);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: var(--fs-xl);
  color: var(--muted);
  cursor: pointer;
  transition: all .15s ease;
  z-index: 2;
}

.pane-close:hover {
  background: var(--danger-soft);
  color: var(--danger);
}

.mobile-layout-button, .sidebar-backdrop { display: none; }

/* Mobile-only chrome: the list toolbar row and the drawer footer. Desktop never sees them. */
.mobile-toolbar, .drawer-footer { display: none; }

@media (min-width: 761px) and (max-width: 1100px) {
  header { padding-inline: 18px; }
  .brand { gap: 10px; }
  .brand-text .sub { font-size: var(--fs-xs); }
  .status-badge { max-width: 240px; }
  main { padding: 14px 12px 24px; }
  aside#sidebar { padding-inline: 12px; }
  aside#sidebar.collapsed { padding-inline: 0; }
  .pane { padding: 20px 16px; }
  .pane h2 { font-size: var(--fs-xl); }
  .pane-close { top: 14px; right: 12px; }
}

@media (max-width: 760px) {
  /* Single-line header: the subtitle goes away and the status badge keeps only its dot. */
  header {
    height: auto;
    min-height: 52px;
    padding: 8px 12px;
    flex-wrap: nowrap;
    gap: 10px;
  }
  .brand { gap: 9px; flex: 1 1 auto; }
  .brand-text h1 { font-size: var(--fs-lg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-text .sub { display: none; }
  .brand .logo { width: 32px; height: 32px; }
  #sidebarToggle { width: 36px; height: 36px; flex-shrink: 0; }
  .header-actions { width: auto; gap: 8px; justify-content: flex-end; }
  .status-badge { max-width: none; padding: 5px; font-size: var(--fs-xs); }
  #status { display: none; }
  .seg-switch-btn { min-width: 30px; }
  #settingsBtn { min-height: 30px; padding: 4px 10px; font-size: var(--fs-sm); }
  .layout > .layout-handle { display: none; }
  main { width: 100%; padding: 12px 12px 24px; gap: 12px; }

  /* List toolbar row: layout.js moves the search box and the toggle here. */
  .mobile-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  .mobile-toolbar .search-wrapper { flex: 1 1 auto; }
  .mobile-toolbar #sidebarToggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 64px;
    height: 38px;
    padding: 0 12px;
    gap: 6px;
    font-size: var(--fs-md);
    flex-shrink: 0;
  }
  .mobile-toolbar #sidebarToggle .filter-count {
    min-width: 17px;
    height: 17px;
    padding: 0 5px;
    border-radius: var(--r-full);
    background: var(--accent);
    color: var(--on-accent);
    font-size: var(--fs-xs);
    font-weight: 600;
    line-height: 17px;
    text-align: center;
  }
  /* Facet groups live in the drawer; the emptied search section and the midbar hide. */
  main > .midbar { display: none; }
  .side-section.drawer-emptied { display: none; }
  aside#sidebar .facet-group { grid-template-columns: 1fr; }

  /* Drawer footer: clear filters and show the filtered list. */
  .drawer-footer {
    display: flex;
    gap: 10px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
  }
  .drawer-footer .btn { flex: 1 1 auto; }

  .sidebar-backdrop:not(.hidden) {
    display: block;
    position: absolute;
    inset: 0;
    z-index: 30;
    background: var(--backdrop);
    backdrop-filter: blur(2px);
  }
  aside#sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    z-index: 31;
    width: min(344px, calc(100% - 28px));
    padding: 12px 16px 24px;
    box-shadow: var(--shadow-drawer);
    overscroll-behavior: contain;
  }
  aside#sidebar.collapsed { display: none; }
  .mobile-layout-button {
    display: flex;
    align-items: center;
    flex: 0 0 auto;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--panel);
    color: var(--ink-secondary);
    font: inherit;
    font-size: var(--fs-md);
    font-weight: 600;
    cursor: pointer;
  }
  .mobile-layout-button:hover { border-color: var(--accent-border); background: var(--accent-soft); }
  .mobile-layout-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  #sidebarClose { justify-content: space-between; margin-bottom: -2px; }

  .detail-pane, .detail-pane.two {
    position: absolute;
    inset: 0;
    z-index: 20;
    width: 100%;
    flex-direction: column;
    border: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }
  #detailBack {
    position: sticky;
    top: 0;
    z-index: 4;
    border: 0;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 13px 16px;
  }
  .detail-pane .pane {
    flex: 1 0 auto;
    overflow: visible;
    padding: 20px 18px 28px;
  }
  .detail-pane .pane + .pane { border-left: 0; border-top: 1px solid var(--border); }
  .pane h2 { font-size: var(--fs-xl); overflow-wrap: anywhere; }
  .pane-close { top: 16px; right: 14px; }
}
