/* sfqf_web app.css */
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, sans-serif; font-size: 14px; background: #f8f9fa; color: #212529; }
.navbar { background: #1a1a2e; color: #eee; padding: 0.6rem 1.2rem; display: flex; align-items: center; gap: 1.2rem; }
.nav-brand { color: #7eb8f7; font-weight: bold; font-size: 1.1rem; text-decoration: none; }
.nav-link { color: #ccc; text-decoration: none; font-size: 0.9rem; }
.nav-link:hover { color: #fff; }
.container { max-width: 1200px; margin: 1.5rem auto; padding: 0 1rem; }
h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 0.5rem; border-bottom: 1px solid #dee2e6; padding-bottom: 0.3rem; }
h3 { font-size: 0.95rem; margin: 0.8rem 0 0.3rem; }
table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; }
th { background: #e9ecef; text-align: left; padding: 0.4rem 0.6rem; font-size: 0.8rem; }
td { padding: 0.35rem 0.6rem; border-bottom: 1px solid #e9ecef; font-size: 0.8rem; vertical-align: top; }
tr:hover td { background: #f1f3f5; }
.badge { display: inline-block; padding: 0.15rem 0.45rem; border-radius: 3px; font-size: 0.75rem; font-weight: 600; }
.badge-running { background: #0d6efd; color: #fff; }
.badge-pass { background: #198754; color: #fff; }
.badge-fail { background: #dc3545; color: #fff; }
.badge-cached { background: #6c757d; color: #fff; }
.badge-latest { background: #0dcaf0; color: #000; }
.badge-error { background: #fd7e14; color: #fff; }
.badge-axis { background: #6f42c1; color: #fff; font-size: 0.65rem; }
.badge-info { background: #0dcaf0; color: #000; }
.btn { display: inline-block; padding: 0.35rem 0.75rem; border-radius: 4px; border: none; cursor: pointer; font-size: 0.85rem; text-decoration: none; }
.btn-primary { background: #0d6efd; color: #fff; }
.btn-primary:hover { background: #0b5ed7; }
.btn-secondary { background: #6c757d; color: #fff; }
.btn-secondary:hover { background: #5c636a; }
.btn-sm { padding: 0.2rem 0.5rem; font-size: 0.75rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.card { background: #fff; border: 1px solid #dee2e6; border-radius: 6px; padding: 1rem; margin-bottom: 1rem; }
.meta-row { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; font-size: 0.8rem; color: #495057; }
.meta-label { font-weight: 600; }
pre.netlist { background: #1e1e1e; color: #d4d4d4; padding: 1rem; border-radius: 4px; font-size: 0.75rem; overflow: auto; max-height: 400px; white-space: pre; }
/* Testbench connectivity graph — keep small, overflow-hidden */
.graph-wrap { border: 1px solid #dee2e6; border-radius: 4px; overflow: hidden; background: #fff; margin-bottom: 0.5rem; max-width: 640px; }
.graph-wrap svg { width: 100%; height: auto; }
.graph-caption { font-size: 0.75rem; color: #6c757d; font-style: italic; margin-bottom: 0.5rem; }
.trace-panel { min-height: 200px; }
.tab-bar { display: flex; gap: 0; border-bottom: 2px solid #dee2e6; margin-bottom: 0.8rem; }
.tab { padding: 0.4rem 0.9rem; cursor: pointer; border: 1px solid transparent; border-bottom: none; font-size: 0.85rem; background: transparent; }
.tab.active { background: #fff; border-color: #dee2e6; border-bottom-color: #fff; margin-bottom: -2px; font-weight: 600; }
.sweep-controls { display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap; margin-bottom: 0.8rem; }
.form-group label { display: block; font-size: 0.75rem; font-weight: 600; margin-bottom: 0.2rem; }
.form-group input, .form-group select { padding: 0.3rem 0.5rem; border: 1px solid #ced4da; border-radius: 4px; font-size: 0.85rem; width: 100px; }
.overridden-row td { color: #aaa; text-decoration: line-through; }
.run-meta { font-size: 0.78rem; color: #495057; }
.run-meta a { color: #0d6efd; }
.empty-state { color: #6c757d; font-style: italic; padding: 1.5rem 0; text-align: center; }
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: #333; color: #fff; padding: 0.6rem 1rem; border-radius: 5px; z-index: 999; font-size: 0.85rem; }
.toast.hidden { display: none; }
.toast.error { background: #dc3545; }
.toast.info { background: #0d6efd; }
.criteria-pass { color: #198754; font-weight: 600; }
.criteria-fail { color: #dc3545; font-weight: 600; }

/* Inbox upload area */
.upload-card { margin-bottom: 1rem; }
.upload-area {
  border: 2px dashed #ced4da;
  border-radius: 6px;
  padding: 2rem 1rem;
  text-align: center;
  color: #6c757d;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.upload-area.drag-over { border-color: #0d6efd; background: #f0f6ff; color: #0d6efd; }
.upload-icon { font-size: 2rem; margin-bottom: 0.4rem; }
.upload-pick { color: #0d6efd; cursor: pointer; text-decoration: underline; }

/* Internal cell graph */
/* Internal cell graph — allow horizontal scroll for large cells */
.internal-graph-wrap { overflow-x: auto; overflow-y: auto; max-height: 600px; max-width: 100%; border: 1px solid #dee2e6; border-radius: 4px; background: #fff; margin-bottom: 0.5rem; }
.internal-graph-wrap svg { display: block; height: auto; }

/* Layout layer view */
.layout-layers-container { }
.layout-legend { margin-top: 0.5rem; padding: 0.5rem; background: #f8f9fa; border-radius: 4px; }
.layer-toggle-btn { opacity: 1; }
.layer-toggle-btn:not(.active) { opacity: 0.35; }

/* ── Responsive table wrapper ── */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive table { margin-bottom: 0; }

/* ── Schematic SVG: scale to container width; height computed from viewBox ── */
.schematic-svg { width: 100%; height: auto; display: block; }

/* ── Testbench two-column layout (graph + netlist side-by-side) ── */
.tb-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; align-items: start; }
.tb-col-graph { min-width: 0; }
.tb-col-netlist { min-width: 0; }
.tb-col-netlist pre.netlist { max-height: 480px; margin: 0; }

/* ── Mobile: collapse to single column ── */
@media (max-width: 800px) {
  .tb-cols { grid-template-columns: 1fr; }
}

/* ── Mobile breakpoint (≤640 px) ── */
@media (max-width: 640px) {
  /* Navbar: wrap onto next line instead of overflowing */
  .navbar { flex-wrap: wrap; gap: 0.4rem 0.9rem; padding: 0.5rem 0.8rem; }
  .nav-brand { width: 100%; margin-bottom: 0.1rem; }

  /* Tighter container padding */
  .container { padding: 0 0.5rem; margin-top: 1rem; }

  /* All tables scroll horizontally on small screens */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  /* ...but tables already inside .table-responsive stay normal */
  .table-responsive table { display: table; overflow-x: visible; }

  /* Sweep controls and form inputs stack vertically */
  .sweep-controls { flex-direction: column; align-items: stretch; }
  .form-group input, .form-group select { width: 100%; max-width: 100%; }

  /* Param override inputs: let them shrink */
  input[type="text"][name] { width: 100% !important; }

  /* Schematic view: upstream native SVGs (may have hardcoded dimensions) scroll horizontally */
  #schematic-view { overflow-x: auto; }
  #schematic-view svg:not(.schematic-svg) { max-width: none; }

  /* Simulation run controls: stack vertically */
  #tab-single > div[style*="display:flex"] { flex-direction: column; align-items: stretch; }

  /* Cards: reduce side padding on mobile */
  .card { padding: 0.7rem; }

  /* Graph wraps: scroll rather than overflow */
  .graph-wrap, .internal-graph-wrap { max-width: 100%; overflow-x: auto; }

  /* Trace plots: don't force huge height on tiny screens */
  #plot-phase-combined, #plot-volt-combined { height: 280px !important; }
  #plot-sweep-passfail { height: 100px !important; }

  /* meta-row items: allow wrapping (already flex-wrap:wrap) */
  .meta-row { gap: 0.4rem 1rem; }

  /* Tier selector in schematic_view: wrap buttons */
  .card [style*="display:flex"] { flex-wrap: wrap; }
}

/* ── Reports ── */
.report-group { border: 1px solid #dee2e6; border-radius: 6px; margin-bottom: 0.7rem; background: #fff; }
.report-group-header { font-weight: 600; font-size: 0.9rem; padding: 0.5rem 0.8rem; cursor: pointer; display: flex; align-items: center; gap: 0.5rem; color: #212529; list-style: none; }
.report-group-header::-webkit-details-marker { display: none; }
.report-group-header::before { content: '▶'; font-size: 0.65rem; color: #6c757d; transition: transform 0.15s; }
details[open] .report-group-header::before { transform: rotate(90deg); }
.report-group-count { margin-left: auto; background: #e9ecef; border-radius: 10px; padding: 0.1rem 0.45rem; font-size: 0.75rem; font-weight: 600; color: #495057; }
.report-group-body { padding: 0.4rem 0.6rem 0.6rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.4rem; }
.report-card { display: block; padding: 0.6rem 0.8rem; background: #f8f9fa; border: 1px solid #dee2e6; border-radius: 4px; text-decoration: none; color: #212529; transition: border-color 0.1s, background 0.1s; }
.report-card:hover { border-color: #0d6efd; background: #f0f6ff; }
.report-card.attention { border-left: 3px solid #dc3545; }
.report-card-title { font-weight: 600; font-size: 0.85rem; line-height: 1.3; margin-bottom: 0.3rem; }
.report-card-meta { font-size: 0.72rem; color: #6c757d; display: flex; flex-wrap: wrap; gap: 0.3rem 0.7rem; }
.badge-warn { background: #fd7e14; color: #fff; }

/* Recent activity block */
.recent-activity-block { border: 1px solid #a3cfb5; border-radius: 6px; background: #f0f8f2; }
.recent-activity-table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.recent-activity-table th { background: #e8f5ed; text-align: left; padding: 0.35rem 0.6rem; font-weight: 600; color: #495057; border-bottom: 1px solid #c8e6d0; white-space: nowrap; }
.recent-activity-table td { padding: 0.28rem 0.6rem; border-bottom: 1px solid #e0f0e8; vertical-align: middle; }
.recent-activity-table tr:last-child td { border-bottom: none; }
.recent-activity-table tr:hover td { background: #e4f2ea; }
.ts-cell { white-space: nowrap; font-variant-numeric: tabular-nums; color: #495057; }
.recent-link { color: #0d6efd; text-decoration: none; font-weight: 500; }
.recent-link:hover { text-decoration: underline; }

/* Report detail layout */
.report-breadcrumb { font-size: 0.82rem; color: #6c757d; margin-bottom: 0.8rem; display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; overflow-wrap: anywhere; }
.report-breadcrumb a { color: #0d6efd; text-decoration: none; }
.report-breadcrumb a:hover { text-decoration: underline; }
.report-breadcrumb-sep { color: #adb5bd; }
/* min-width:0 on children prevents grid blowout when content is wide */
.report-detail-layout { display: grid; grid-template-columns: 1fr 260px; gap: 1.2rem; align-items: start; }
.report-detail-layout > * { min-width: 0; }
.report-reader-main { min-width: 0; overflow: hidden; }
.report-reader-aside { min-width: 0; }

/* Report reader body — style the rendered Markdown */
.report-reader-body { overflow-x: auto; overflow-wrap: break-word; word-wrap: break-word; word-break: break-word; }
.report-reader-body h1 { font-size: 1.3rem; }
.report-reader-body h2 { font-size: 1.1rem; }
.report-reader-body h3 { font-size: 0.95rem; }
.report-reader-body h4 { font-size: 0.88rem; }
.report-reader-body p, .report-reader-body li { overflow-wrap: break-word; word-break: break-word; }
.report-reader-body pre { background: #1e1e1e; color: #d4d4d4; padding: 0.8rem 1rem; border-radius: 4px; overflow-x: auto; font-size: 0.76rem; line-height: 1.5; white-space: pre; }
.report-reader-body code { background: #f1f3f5; padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.85em; overflow-wrap: anywhere; word-break: break-all; }
.report-reader-body pre code { background: none; padding: 0; font-size: inherit; word-break: normal; overflow-wrap: normal; }
.report-reader-body blockquote { border-left: 3px solid #0d6efd; margin: 0.6rem 0 0.6rem 0; padding: 0.3rem 0.8rem; background: #f8f9ff; color: #495057; border-radius: 0 4px 4px 0; }
.report-reader-body img { max-width: 100%; height: auto; border-radius: 4px; }
.report-reader-body table { width: 100%; border-collapse: collapse; overflow-x: auto; display: block; }
.report-reader-body th { background: #e9ecef; }
.report-reader-body td, .report-reader-body th { overflow-wrap: anywhere; word-break: break-word; min-width: 4rem; }
.report-reader-body details { border: 1px solid #dee2e6; border-radius: 4px; padding: 0.4rem 0.7rem; margin: 0.5rem 0; }
.report-reader-body summary { cursor: pointer; font-weight: 600; font-size: 0.85rem; }
.report-reader-body input[type="checkbox"] { margin-right: 0.3rem; }

/* Related links sidebar */
.related-links ul { list-style: none; padding: 0; margin: 0 0 0.6rem; }
.related-links li { padding: 0.15rem 0; font-size: 0.8rem; overflow-wrap: anywhere; word-break: break-all; }
.related-links a { overflow-wrap: anywhere; word-break: break-all; }
.related-links h3 { font-size: 0.82rem; margin: 0.6rem 0 0.2rem; color: #495057; text-transform: uppercase; letter-spacing: 0.03em; }

/* Report header meta — path and long values must wrap */
.report-reader-header code { overflow-wrap: anywhere; word-break: break-all; }
.report-reader-header .meta-row { overflow-wrap: anywhere; }

/* Mermaid diagram container */
.mermaid-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
  padding: 0.5rem 0;
}
.mermaid-wrap .mermaid { display: inline-block; min-width: 0; }
.mermaid-wrap svg {
  max-width: 100%;
  height: auto;
  display: block;
}
/* Fallback: if mermaid hasn't rendered yet, hide the raw source */
.mermaid:not([data-processed]) { font-size: 0; }

/* Mobile: collapse detail layout to single column */
@media (max-width: 800px) {
  .report-detail-layout { grid-template-columns: 1fr; }
  .report-group-body { grid-template-columns: 1fr; }
  .report-reader-aside { width: 100%; box-sizing: border-box; }
  /* Tables in report body: force horizontal scroll rather than layout break */
  .report-reader-body table { font-size: 0.75rem; }
  .report-reader-body th, .report-reader-body td { min-width: 3rem; padding: 0.25rem 0.4rem; }
  /* Headings scale down further on narrow screens */
  .report-reader-body h1 { font-size: 1.15rem; }
  .report-reader-body h2 { font-size: 1rem; }
  .report-reader-body h3 { font-size: 0.88rem; }
  /* Mermaid diagrams: allow horizontal scroll on mobile */
  .mermaid-wrap { margin: 0.6rem -0.5rem; padding: 0 0.5rem; }
}
