/* layout.css — structure, theme, responsive */

:root {
  --bg:         #ffffff;
  --surface:    #f8fafc;
  --border:     #e2e8f0;
  --accent:     #6366f1;
  --accent-hover: #4f46e5;
  --text:       #1e293b;
  --muted:      #475569;
  --ok:         #15803d;
  --err:        #dc2626;
  --canvas-bg:  #ffffff;
  --shadow:     rgba(0,0,0,0.12);

  /* Light-mode trace-type colors.
     The canvas is white, so edge strokes act as "ink": they need real
     luminance contrast against white, which the old mid-tone values lacked.
     Each edge is darkened to a 600/700-weight tone; node fills stay pale
     (50/100-weight) so near-black labels still read on them. */
  --tc-call-node: #dbeafe; --tc-call-edge: #1d4ed8;
  --tc-delegatecall-node: #fef3c7; --tc-delegatecall-edge: #b45309;
  --tc-staticcall-node: #ede9fe; --tc-staticcall-edge: #6d28d9;
  --tc-create-node: #d1fae5; --tc-create-edge: #047857;
  --tc-selfdestruct-node: #fee2e2; --tc-selfdestruct-edge: #b91c1c;
  --tc-callcode-node: #e4e4e7; --tc-callcode-edge: #52525b;

  --node-fill: #f1f5f9;
  --node-stroke: #475569;
  --node-glow: #94a3b8;
  --grid-color: #e2e8f0;
  --edge-color: #64748b;
  --path-color: #1e293b;
  --hl-color: #1e293b;

  /* Edge stroke opacity — tuned per theme. Partial transparency leaves a
     visible bright line on a dark canvas but washes toward white on a light
     one, so the light theme needs near-opaque strokes. */
  --edge-opacity: 0.85;
  --edge-opacity-strong: 1;
  --rail-opacity: 0.7;
}

html.dark {
  --bg:         #0f172a;
  --surface:    #1e293b;
  --border:     #334155;
  --accent:     #818cf8;
  --accent-hover: #a5b4fc;
  --text:       #f1f5f9;
  --muted:      #94a3b8;
  --ok:         #22c55e;
  --err:        #ef4444;
  --canvas-bg:  #0f172a;
  --shadow:     rgba(0,0,0,0.5);

  --tc-call-node: #1e3a8a; --tc-call-edge: #60a5fa;
  --tc-delegatecall-node: #78350f; --tc-delegatecall-edge: #fbbf24;
  --tc-staticcall-node: #4c1d95; --tc-staticcall-edge: #a78bfa;
  --tc-create-node: #064e3b; --tc-create-edge: #34d399;
  --tc-selfdestruct-node: #7f1d1d; --tc-selfdestruct-edge: #f87171;
  --tc-callcode-node: #27272a; --tc-callcode-edge: #a1a1aa;

  --node-fill: #1e293b;
  --node-stroke: #94a3b8;
  --node-glow: #475569;
  --grid-color: #334155;
  --edge-color: #475569;
  --path-color: #94a3b8;
  --hl-color: #cbd5e1;

  --edge-opacity: 0.6;
  --edge-opacity-strong: 1;
  --rail-opacity: 0.5;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* ── Header ── */

header {
  flex-shrink: 0;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-left {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}
header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
header .sub {
  font-size: 0.7rem;
  color: var(--muted);
  display: none;
}

@media (min-width: 640px) {
  header .sub { display: inline; }
  header { padding: 14px 28px; }
  header h1 { font-size: 1.35rem; }
}

/* ── Theme toggle ── */

#theme-toggle {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  flex-shrink: 0;
}
#theme-toggle:hover { background: var(--border); color: var(--text); }
#theme-toggle svg { width: 20px; height: 20px; }
.dark #theme-toggle .icon-sun { display: block; }
.dark #theme-toggle .icon-moon { display: none; }
#theme-toggle .icon-sun { display: none; }
#theme-toggle .icon-moon { display: block; }

/* ── Input bar ── */

.input-bar {
  flex-shrink: 0;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--surface);
}
.input-bar label {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  display: none;
}
#tx-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.8rem;
  padding: 8px 10px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#tx-input:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2); }
#tx-input::placeholder { color: var(--muted); }
#trace-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 9px 16px;
  cursor: pointer;
  transition: background 0.12s, transform 0.08s;
  white-space: nowrap;
}
#trace-btn:hover { background: var(--accent-hover); }
#trace-btn:active { transform: scale(0.97); }
#trace-btn:disabled { background: var(--muted); cursor: not-allowed; }
#status {
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
}
#status.ok  { color: var(--ok); }
#status.err { color: var(--err); }

@media (min-width: 480px) {
  .input-bar label { display: block; }
}
@media (min-width: 640px) {
  .input-bar { padding: 12px 28px; flex-wrap: nowrap; }
}

/* ── Main scroll ── */

.main-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

/* ── Panels ── */

.panels {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.panel {
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 400px;
  overflow: hidden;
  border-bottom: 1px solid var(--border);
}
.panel-head {
  flex-shrink: 0;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
}
.panel-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.panel-hint {
  font-size: 0.65rem;
  color: var(--muted);
  white-space: nowrap;
  margin-left: auto;
  display: none;
}
.panel-tip {
  /* Hover details, relocated from the in-canvas SVG tooltip. flex: 1 +
     min-width: 0 lets it claim the slack between title and hint and
     truncate instead of shoving the hint off the row. Empty when idle —
     the :empty hook below restores the hint. */
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.7rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.panel-tip .tip-main { color: var(--hl-color); }
.panel-tip .tip-sub  { color: var(--muted); font-size: 0.65rem; margin-left: 10px; }
/* While the tip is showing, the "hover → details" hint is redundant — and
   the tip needs the width. The tip precedes the hint in the head, so a
   plain sibling combinator does it — no :has(), whose :empty invalidation
   is unreliable in some WebKit builds. Specificity (0,3,0) still outranks
   the media-query display:block below. */
.panel-tip:not(:empty) ~ .panel-hint { display: none; }
.canvas-wrap {
  flex: 1;
  min-height: 300px;
  overflow: hidden;
  position: relative;
  background: var(--canvas-bg);
}
.canvas-wrap svg {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
}
.canvas-wrap svg:active { cursor: grabbing; }
.empty {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: 0.75rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
  pointer-events: none;
}

@media (min-width: 480px) {
  .panel-hint { display: block; }
}
@media (min-width: 640px) {
  .panel-head { padding: 10px 16px; gap: 12px; }
}
@media (min-width: 900px) {
  .panels {
    flex-direction: row;
    height: 50vh;
    min-height: 360px;
  }
  .panel {
    flex: 1;
    min-height: 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }
  .panel:last-child { border-right: none; }
}

/* ── Footer ── */

footer {
  flex-shrink: 0;
  padding: 6px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--muted);
  background: var(--surface);
}
@media (min-width: 640px) {
  footer { padding: 8px 28px; font-size: 0.7rem; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Occurrences panel (third panel) — two tabs: Root / Internal
   ══════════════════════════════════════════════════════════════════════════ */

.results {
  display: none;
  border-top: 1px solid var(--border);
}
.results.visible { display: block; }

.results-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
}
@media (min-width: 640px) {
  .results-head { padding: 10px 28px; }
}
.results-title {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

/* ── Tabs ── */

.results-tabs {
  display: flex;
  gap: 4px;
}
.results-tab {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 12px;
  cursor: pointer;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.results-tab:hover { color: var(--text); background: var(--bg); }
.results-tab.active {
  color: var(--text);
  background: var(--bg);
  border-color: var(--border);
}
.tab-count {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.66rem;
  font-weight: 500;
  color: var(--muted);
}
.results-tab.active .tab-count { color: var(--accent); }

/* ── Panes ── */

.results-pane[hidden] { display: none; }


/* ── Grid.js — fully styled from app tokens (no Grid.js theme CSS loaded) ──
   Grid.js renders the table + pager markup with its gridjs-* classes; all
   visual styling lives here so it matches the app in both themes and there is
   no theme stylesheet to fight. */

.results-pane { padding: 4px 12px 12px; }
@media (min-width: 640px) {
  .results-pane { padding: 4px 28px 14px; }
}

.gridjs-container { width: 100%; color: var(--text); }
.gridjs-wrapper { width: 100%; overflow-x: auto; border-radius: 6px; }

table.gridjs-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.gridjs-th,
.gridjs-td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: transparent;
}

.gridjs-th {
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.gridjs-td {
  color: var(--text);
  font-size: 0.72rem;
}

.gridjs-tr:hover .gridjs-td { background: var(--surface); }

/* Cell content. Transaction + addresses + path are monospace and, by default
   (narrow viewports / fixed table layout), ellipsize within their column. */
.cell-mono {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.grid-tx {
  color: var(--accent);
  text-decoration: none;
}
.grid-tx:hover { color: var(--accent-hover); text-decoration: underline; }

/* Wide viewport: enough real estate to show full hashes/addresses. Release the
   clamp so the full text (already in the DOM) shows; the table stops fixing
   column widths so columns size to content. Below this width, the rules above
   truncate with ellipsis. */
@media (min-width: 1100px) {
  table.gridjs-table { table-layout: auto; }
  .cell-mono {
    white-space: nowrap;
    overflow: visible;
    text-overflow: clip;
    max-width: none;
  }
  .gridjs-td { word-break: normal; }
}

/* ── Pager (Grid.js renders it; styled to the app) ── */
.gridjs-pagination {
  color: var(--muted);
  font-size: 0.7rem;
  margin-top: 8px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}
.gridjs-pagination .gridjs-summary { color: var(--muted); }
.gridjs-pagination .gridjs-pages { display: flex; gap: 4px; }
.gridjs-pagination .gridjs-pages button {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 500;
  padding: 5px 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
.gridjs-pagination .gridjs-pages button:hover:not(:disabled) {
  background: var(--surface);
  border-color: var(--accent);
}
.gridjs-pagination .gridjs-pages button.gridjs-currentPage {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}
.gridjs-pagination .gridjs-pages button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Loading bar */
.gridjs-loading-bar {
  background-color: var(--surface);
  opacity: 0.6;
}

/* Grid.js injects a hidden temp element; keep it out of the way */
.gridjs-temp { position: absolute; }
