:root {
    --bg: #0a0c10;
    --bg-card: #12161d;
    --bg-elev: #161b23;
    --border: #232a35;
    --border-hi: #313b49;
    --text: #e6edf3;
    --muted: #8b949e;
    --accent: #4cc2ff;
    --accent-2: #7c5cff;
    --ok: #3fb950;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

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

/* Top bar */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; }
.brand img { width: 28px; height: 28px; border-radius: 7px; box-shadow: 0 0 0 1px var(--border); }
.brand em { color: var(--muted); font-style: normal; font-weight: 500; font-size: 0.85rem; }
.topbar-tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

.tbtn {
    background: var(--bg-elev);
    border: 1px solid var(--border-hi);
    color: var(--text);
    padding: 7px 13px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-family: inherit;
    cursor: pointer;
    transition: border-color .15s ease, background .15s ease;
    text-decoration: none;
    display: inline-block;
}
.tbtn:hover { border-color: var(--accent); }
.tbtn.sm { padding: 5px 10px; font-size: 0.8rem; }
.tbtn.ghost { background: transparent; color: var(--muted); }
.tbtn[data-toggle="true"] { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #06121c; font-weight: 600; }

/* Workspace */
.workspace { flex: 1; display: grid; grid-template-columns: 280px 1fr 300px; min-height: 0; }

.panel {
    background: var(--bg-card);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.panel-left { border-right: 1px solid var(--border); }
.panel-right { border-left: 1px solid var(--border); }

.dock { padding: 16px; border-bottom: 1px solid var(--border); }
.dock h3 {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--muted);
    margin-bottom: 12px;
}

.kv { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.kv li { display: flex; justify-content: space-between; gap: 12px; font-size: 0.85rem; }
.kv span { color: var(--muted); }
.kv strong { font-weight: 600; font-variant-numeric: tabular-nums; }

.hist { width: 100%; height: 120px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; display: block; margin-bottom: 12px; }

.field { margin-bottom: 10px; }
.field label { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); margin-bottom: 4px; }
.field input[type=range] { width: 100%; accent-color: var(--accent); }

.field-sm { display: flex; flex-direction: column; gap: 4px; }
.field-sm.wide { margin-bottom: 10px; }
.field-sm label { font-size: 0.72rem; color: var(--muted); }
.field-sm input, .roi-coords input {
    background: var(--bg);
    border: 1px solid var(--border-hi);
    border-radius: 6px;
    color: var(--text);
    padding: 6px 8px;
    font-size: 0.82rem;
    font-family: inherit;
    width: 100%;
}
.roi-coords { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 6px; margin: 10px 0; }
.row { display: flex; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; margin-bottom: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.samples { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.samples img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--border-hi);
    cursor: pointer;
    transition: border-color .15s ease, transform .15s ease;
}
.samples img:hover { border-color: var(--accent); transform: translateY(-1px); }
.samples img.active { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 45%, transparent); }

.hint { font-size: 0.75rem; color: var(--muted); margin-top: 10px; line-height: 1.5; }
kbd {
    background: var(--bg);
    border: 1px solid var(--border-hi);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 0.72rem;
    font-family: ui-monospace, monospace;
}

/* Pipeline */
.pipeline { display: flex; flex-direction: column; gap: 8px; }
.pstep {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
}
.pstep-head { display: flex; align-items: center; gap: 8px; }
.pstep-head label { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; cursor: pointer; flex: 1; }
.pstep-head input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.pstep.on { border-color: var(--border-hi); }
.pstep-param { margin-top: 8px; display: none; }
.pstep.on .pstep-param.has-param { display: block; }
.pstep-param label { display: flex; justify-content: space-between; font-size: 0.74rem; color: var(--muted); margin-bottom: 4px; }
.pstep-param input[type=range] { width: 100%; accent-color: var(--accent-2); }

/* Viewer */
.viewer { position: relative; background: #06080b; overflow: hidden; min-height: 0; }
.viewer canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: grab; }
.viewer canvas.panning { cursor: grabbing; }
.viewer canvas.roi-mode { cursor: crosshair; }
.viewer canvas.measure-mode { cursor: crosshair; }

.viewer-hint {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    color: var(--muted);
    pointer-events: none;
    padding: 24px;
}
.viewer-hint strong { color: var(--text); font-size: 1.2rem; }
.viewer-hint span { max-width: 420px; font-size: 0.9rem; }
.viewer-hint.hidden { display: none; }

.statusbar {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    background: rgba(10, 12, 16, 0.85);
    border-top: 1px solid var(--border);
    padding: 5px 14px;
    font-size: 0.78rem;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    backdrop-filter: blur(6px);
    pointer-events: none;
}

@media (max-width: 900px) {
    body { overflow: auto; }
    .app { height: auto; }
    .workspace { grid-template-columns: 1fr; }
    .viewer { height: 60vh; }
    .panel { max-height: none; }
}
