:root {
  --ink: #1a1c23;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #e2e4ea;
  --accent: #2f6fed;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --warn: #b7791f;
  --ok: #1e7e34;
  --mono: "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--ink); }
.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.spacer { flex: 1; }
.hint { color: #667; font-size: 13px; }

.topbar { display: flex; align-items: center; gap: 14px; background: var(--ink); color: #fff; padding: 10px 18px; }
.topbar .logo { height: 26px; }
.app-title { font-weight: 600; letter-spacing: .4px; }
.version-picker { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.version-picker select { padding: 4px 8px; }
.badge { padding: 2px 8px; border-radius: 10px; font-size: 11px; background: #556; }
.badge.active { background: var(--ok); }
.badge.draft { background: var(--warn); }

.tabs { display: flex; gap: 2px; background: #262933; padding: 0 12px; }
.tab { background: none; border: none; color: #cfd3dd; padding: 10px 16px; cursor: pointer; font-size: 14px; border-bottom: 3px solid transparent; }
.tab.active { color: #fff; border-bottom-color: var(--accent); }

.banner { background: #fdf3d7; border-bottom: 1px solid #eadfa9; padding: 8px 18px; font-size: 13px; }

main { padding: 14px 18px; }
.tabpane { max-width: 1500px; margin: 0 auto; }

.split { display: flex; gap: 14px; align-items: flex-start; }
.list-pane { width: 320px; flex-shrink: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; max-height: 78vh; overflow: auto; }
.list-pane.wide { width: 440px; }
.edit-pane { flex: 1; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.edit-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }

.btn { border: 1px solid var(--line); background: #fff; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--danger); }
.btn.warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.small { padding: 2px 8px; font-size: 12px; }

input, select, textarea { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 13px; font-family: inherit; }
textarea { width: 100%; resize: vertical; }
#promptEditor { height: 62vh; font-family: var(--mono); font-size: 13px; line-height: 1.45; }
textarea.short { height: 90px; }
textarea.tall { height: 300px; font-size: 12px; }

.list-item { padding: 6px 8px; border-radius: 6px; cursor: pointer; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item:hover { background: #eef2fb; }
.list-item.selected { background: #dfe8fb; font-weight: 600; }
.list-item.deleted { color: #a33; text-decoration: line-through; opacity: 0.75; }
.list-group { margin: 8px 0 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #889; }

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 15px; }
.chip { display: inline-block; background: #e8eefb; color: #2c4a8f; border-radius: 10px; padding: 1px 9px; font-size: 12px; margin: 2px; font-family: var(--mono); }
.chip.gate { background: #f3e8fb; color: #6b2c8f; }
.tree { font-family: var(--mono); font-size: 12.5px; margin: 4px 0 0 6px; }
.tree ul { margin: 0; padding-left: 18px; list-style: none; border-left: 1px dotted #bbc; }
.tree li { padding: 1px 0; }

.rule-row { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel); }
.rule-head { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer; }
.rule-head .label { font-weight: 600; font-size: 13.5px; }
.rule-head .meta { color: #778; font-size: 12px; font-family: var(--mono); }
.rule-body { padding: 0 10px 10px; }
.rule-body textarea { height: 180px; font-family: var(--mono); font-size: 12px; }
.rule-row.disabled { opacity: .55; }

.supp-row { display: flex; gap: 10px; align-items: flex-start; padding: 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel); }
.supp-row select { max-width: 340px; }
.supp-list { flex: 1; }
.supp-item { display: inline-flex; align-items: center; gap: 4px; background: #fbeaea; border-radius: 10px; padding: 1px 8px; font-size: 12px; margin: 2px; }
.supp-item button { border: none; background: none; cursor: pointer; color: var(--danger); font-weight: 700; }

.vector-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 14px; max-height: 34vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.vector-grid label { display: flex; align-items: center; gap: 6px; font-size: 12.5px; font-family: var(--mono); }
.vector-grid label.true { color: var(--ok); font-weight: 700; }

.upload-form { border: 1px dashed var(--line); border-radius: 8px; padding: 10px; margin-bottom: 10px; display: flex; flex-direction: column; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }

table.stats { border-collapse: collapse; width: 100%; font-size: 12.5px; }
table.stats th, table.stats td { border-bottom: 1px solid var(--line); padding: 4px 8px; text-align: right; }
table.stats th { cursor: pointer; background: #f0f2f6; position: sticky; top: 0; }
table.stats td:first-child, table.stats th:first-child { text-align: left; font-family: var(--mono); }
tr.bad td { background: #fdf0ee; }
tr.perfect td { color: #9aa; }
.delta-up { color: var(--ok); font-weight: 700; }
.delta-down { color: var(--danger); font-weight: 700; }

.run-item { padding: 8px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; cursor: pointer; font-size: 12.5px; }
.run-item:hover { border-color: var(--accent); }
.run-item.selected { border-color: var(--accent); background: #eef2fb; }
.run-item .status { float: right; font-weight: 700; }
.status.Running { color: var(--warn); }
.status.Completed { color: var(--ok); }
.status.Failed { color: var(--danger); }

.mismatch { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.mismatch summary { padding: 8px 10px; cursor: pointer; font-size: 13px; }
.mismatch .diff { color: var(--danger); font-family: var(--mono); font-size: 12px; }
.mismatch pre { max-height: 300px; overflow: auto; background: #f7f8fa; margin: 0 10px 10px; padding: 8px; font-size: 11.5px; }

dialog { border: 1px solid var(--line); border-radius: 10px; width: min(900px, 90vw); max-height: 85vh; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; }
#modalBody { white-space: pre-wrap; max-height: 68vh; overflow: auto; background: #f7f8fa; padding: 10px; border-radius: 6px; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: 0 4px 14px rgba(0,0,0,.25); z-index: 50; }
.toast.error { background: var(--danger); }
h4 { margin: 14px 0 6px; }

/* Blazor additions */
.tabs a.tab { text-decoration: none; display: inline-block; }
#blazor-error-ui { position: fixed; bottom: 0; left: 0; right: 0; background: #b32121; color: #fff; padding: 10px 16px; z-index: 100; }
#blazor-error-ui .reload { color: #fff; }
#blazor-error-ui .dismiss { cursor: pointer; float: right; }
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 60; }
.modal-box { background: #fff; border-radius: 10px; width: min(900px, 90vw); max-height: 85vh; padding: 14px; display: flex; flex-direction: column; }
.modal-box pre { flex: 1; overflow: auto; background: #f7f8fa; padding: 10px; border-radius: 6px; white-space: pre-wrap; }

.chev { color: #8892a6; font-size: 11px; width: 14px; display: inline-block; }

.thumb { width: 72px; height: 52px; object-fit: cover; border-radius: 4px; background: #eef; }
.img-loading { display: inline-block; min-width: 72px; min-height: 52px; border-radius: 4px; background: #eef; color: #99a; font-size: 12px; text-align: center; line-height: 52px; vertical-align: middle; }
.tag-chip { display: inline-flex; align-items: center; gap: 4px; background: #e8eefb; color: #2c4a8f; border-radius: 10px; padding: 1px 9px; font-size: 12px; margin: 2px; }
.tag-chip button { border: none; background: none; cursor: pointer; color: #c0392b; font-weight: 700; }

/* Image viewer: thumbnail + full-screen zoom/pan */
img.zoomable { cursor: zoom-in; }
.viewer-overlay { position: fixed; inset: 0; background: rgba(12,14,20,.92); z-index: 200; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.viewer-image { max-width: 92vw; max-height: 82vh; border-radius: 6px; cursor: grab; transform-origin: center center; transition: transform .06s linear; user-select: none; -webkit-user-drag: none; }
.viewer-image.dragging { cursor: grabbing; transition: none; }
.viewer-bar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: rgba(26,28,35,.96); color: #fff; z-index: 210; }
.viewer-bar .btn { background: #2b2f3a; color: #fff; border-color: #3c4250; text-decoration: none; }
.viewer-bar .btn:hover { border-color: var(--accent); }
.viewer-bar .btn.danger { color: #ff8b7d; }
.viewer-title { font-size: 13px; font-family: var(--mono); opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 46vw; }
.viewer-zoom { font-size: 12px; font-family: var(--mono); min-width: 48px; text-align: center; }
.viewer-hint { position: fixed; bottom: 12px; left: 0; right: 0; text-align: center; color: #aab; font-size: 12px; z-index: 210; }

/* Stacked labelled controls that never overflow their pane */
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; min-width: 0; }
.stack select, .stack input { width: 100%; max-width: 100%; box-sizing: border-box; }
/* On narrow panes the two-up grid collapses to a single column */
@media (max-width: 1100px) {
  .grid2 { grid-template-columns: 1fr; }
}

/* Run performance / cost metric tiles */
.metrics { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.metric { background: #f0f2f6; border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-width: 104px; display: flex; flex-direction: column; gap: 2px; }
.metric-value { font-size: 17px; font-weight: 700; font-family: var(--mono); }
.metric-label { font-size: 11px; color: #667; text-transform: uppercase; letter-spacing: .4px; }

/* Inline trend sparkline */
svg.spark { vertical-align: middle; }

.topbar .user { font-size: 13px; opacity: .85; }

/* Full-screen sign-in splash shown before authentication */
.auth-splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: var(--ink, #1b2333);
    color: #fff;
    z-index: 1000;
}
.auth-splash-logo { height: 44px; opacity: .95; }
.auth-splash-text { font-size: 14px; letter-spacing: .3px; opacity: .85; margin: 0; }
.auth-spinner {
    width: 34px;
    height: 34px;
    border: 3px solid rgba(255, 255, 255, .25);
    border-top-color: #fff;
    border-radius: 50%;
    animation: auth-spin 0.8s linear infinite;
}
@keyframes auth-spin { to { transform: rotate(360deg); } }
