/* Rig Graph Viewer — dark theme */

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

:root {
  --bg: #1a1b1e;
  --bg2: #25262b;
  --bg3: #2c2d33;
  --border: #3a3b42;
  --text: #d4d5db;
  --text-dim: #7c7d87;
  --accent: #4c8cf0;
  --success: #37b24d;
  --failure: #e03131;
  --skipped: #6c757d;
  --running: #1971c2;
  --pending: #495057;
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

/* ---- Layout ---- */

#app { display: flex; flex-direction: column; height: 100vh; }

header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 48px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

header h1 { font-size: 15px; font-weight: 600; color: var(--text); }

.breadcrumb {
  display: flex; align-items: center; gap: 6px; color: var(--text-dim); font-size: 13px;
}
.breadcrumb a { color: var(--accent); text-decoration: none; cursor: pointer; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { color: var(--border); }

.header-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.refresh-indicator {
  font-size: 12px; color: var(--text-dim);
  display: none;
}
.refresh-indicator.active { display: block; color: var(--accent); }

#main { flex: 1; overflow: hidden; display: flex; }

/* ---- Run List ---- */

#run-list-view { flex: 1; overflow-y: auto; padding: 16px; }

.section-title {
  font-size: 13px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 12px;
}

table {
  width: 100%; border-collapse: collapse;
  background: var(--bg2); border-radius: var(--radius);
  overflow: hidden;
}
th, td { padding: 10px 14px; text-align: left; }
th {
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
tr:not(:last-child) td { border-bottom: 1px solid var(--border); }
tr:hover td { background: var(--bg3); cursor: pointer; }

.status-badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 3px; font-size: 12px; font-weight: 600;
}
.status-SUCCESS  { background: #1c3a26; color: var(--success); }
.status-FAILURE  { background: #3a1c1c; color: var(--failure); }
.status-RUNNING  { background: #1c2d4a; color: #74c0fc; }
.status-SKIPPED  { background: #2a2b32; color: var(--skipped); }
.status-UNKNOWN  { background: #2a2b32; color: var(--text-dim); }
.status-PENDING  { background: #2a2b32; color: var(--text-dim); }

/* ---- Graph View ---- */

#graph-view {
  flex: 1; display: none; overflow: hidden;
  flex-direction: column;  /* vertical stack: canvas on top, detail panel below */
}
#graph-view.active { display: flex; }

#graph-canvas-wrap {
  flex: 1; overflow: auto; padding: 24px; position: relative;
  min-height: 0;  /* required for flex child to shrink below content size */
}

#graph-svg { display: block; }

/* ---- Node Detail Panel (bottom slide-up) ---- */

#detail-panel {
  background: var(--bg2);
  border-top: 2px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
  /* Collapsed by default; height transitions open/close */
  height: 0;
  transition: height 0.25s ease;
}
#detail-panel.active { height: 40vh; }

.panel-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.panel-header h2 { font-size: 14px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-close { cursor: pointer; color: var(--text-dim); font-size: 18px; }
.panel-close:hover { color: var(--text); }

.panel-body { flex: 1; overflow-y: auto; padding: 12px 16px; }

.detail-row {
  display: flex; justify-content: space-between;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.detail-row:last-child { border-bottom: none; }
.detail-label { color: var(--text-dim); flex-shrink: 0; margin-right: 12px; }
.detail-value { text-align: right; word-break: break-all; }

.section-header {
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.04em;
  margin: 14px 0 6px;
}

.file-list { list-style: none; }
.file-item {
  display: flex; justify-content: space-between;
  padding: 4px 0; font-size: 12px; font-family: var(--mono);
  border-bottom: 1px solid var(--border);
}
.file-item:last-child { border-bottom: none; }
.file-name { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

.log-viewer {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px 12px; font-family: var(--mono); font-size: 11px;
  max-height: 280px; overflow-y: auto; white-space: pre-wrap; word-break: break-all;
  color: var(--text-dim); line-height: 1.6;
  margin-top: 6px;
}

/* Live log: blue border to indicate active streaming. */
.log-viewer.log-live {
  border-color: var(--running);
  border-left: 3px solid var(--accent);
}

.subgraph-link {
  margin-top: 10px; padding: 8px 12px;
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 13px; cursor: pointer; color: var(--accent);
  display: flex; align-items: center; gap: 6px;
}
.subgraph-link:hover { background: var(--border); }

/* ---- SVG Node Styles ---- */

@keyframes running-pulse {
  0%, 100% { stroke-opacity: 1; }
  50% { stroke-opacity: 0.35; }
}

.node-box {
  rx: 8; ry: 8;
  stroke-width: 2;
  cursor: pointer;
  transition: opacity 0.15s;
}
.node-box:hover { opacity: 0.85; }

.node-box.status-SUCCESS  { fill: #1c3a26; stroke: var(--success); }
.node-box.status-FAILURE  { fill: #3a1c1c; stroke: var(--failure); }
.node-box.status-RUNNING  { fill: #1c2d4a; stroke: #60a5fa; stroke-width: 2.5;
                             animation: running-pulse 1.5s ease-in-out infinite; }
.node-box.status-SKIPPED  { fill: #2a2b32; stroke: var(--skipped); }
.node-box.status-PENDING  { fill: var(--bg3); stroke: #505062; }
.node-box.status-UNKNOWN  { fill: var(--bg3); stroke: #505062; }

.node-box.selected { stroke-width: 3; }

.layer-label { pointer-events: none; font-size: 16px; font-weight: 600; fill: var(--text-dim); opacity: 0.5; text-anchor: middle; }
.node-label { pointer-events: none; font-size: 12px; font-weight: 500; fill: var(--text); }
.node-duration { pointer-events: none; font-size: 10px; fill: var(--text-dim); }
.node-status-icon { pointer-events: none; font-size: 11px; }

.edge { fill: none; stroke: var(--border); stroke-width: 1.5; opacity: 0.7; }
.edge.dep-edge { stroke: #3a4a5c; transition: stroke 0.3s, opacity 0.3s; }

/* ---- Loading / Error ---- */

.loading {
  display: flex; align-items: center; justify-content: center;
  height: 200px; color: var(--text-dim); font-size: 14px;
}

.error-msg {
  background: #3a1c1c; border: 1px solid #7d2020;
  color: #ff8080; padding: 12px 16px; border-radius: var(--radius);
  margin: 16px; font-size: 13px;
}

/* ---- Error Banner (FAILED node prominent message) ---- */

.error-banner {
  background: #3a1c1c; border: 1px solid var(--failure);
  color: #ff8080; padding: 10px 14px; border-radius: var(--radius);
  margin-bottom: 12px; font-size: 13px; font-family: var(--mono);
  white-space: pre-wrap; word-break: break-all;
}

/* ---- File Entry (output files with expandable content) ---- */

.file-entry {
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.file-entry-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 10px;
  background: var(--bg3);
  font-size: 12px; font-family: var(--mono);
}

.file-size { color: var(--text-dim); flex-shrink: 0; margin-left: 8px; }

.file-binary {
  padding: 6px 10px;
  font-size: 12px; color: var(--text-dim); font-family: var(--mono);
  font-style: italic;
}

.file-thumbnail {
  max-width: 100%; max-height: 200px;
  display: block; margin: 8px auto;
  border-radius: 4px;
}

.file-content {
  background: var(--bg);
  padding: 8px 10px;
  font-family: var(--mono); font-size: 11px;
  max-height: 200px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-all;
  color: var(--text-dim); line-height: 1.5;
}

.show-contents-btn {
  display: block; width: 100%;
  padding: 6px 10px;
  background: var(--bg3); border: none; border-top: 1px solid var(--border);
  color: var(--accent); font-size: 12px; cursor: pointer; text-align: left;
}
.show-contents-btn:hover { background: var(--border); }

.truncated-notice {
  display: block; padding: 4px 10px;
  font-size: 11px; color: var(--text-dim); font-style: italic;
  border-top: 1px solid var(--border);
  font-family: var(--font);
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
