/* ============================================
   Circuit Block Diagnostics Visualizer — Styles
   Theme-aware (dark/light), responsive, a11y
   ============================================ */

/* --- Main Layout --- */
.cv-layout {
    display: grid;
    grid-template-columns: 1fr 360px;
    gap: 1.5rem;
    align-items: start;
}

.cv-left {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* --- Shared Card --- */
.cv-card {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    position: relative;
    overflow: hidden;
}

.cv-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--gradient-accent);
    opacity: 0.5;
}

.cv-card-title {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cv-card-title svg {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

/* --- Mode Toggle (Normal / Fault) --- */
.cv-mode-bar {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.cv-mode-switch {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    user-select: none;
}

.cv-mode-switch input {
    display: none;
}

.cv-toggle-track {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: all var(--transition);
    flex-shrink: 0;
}

.cv-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition);
}

.cv-mode-switch input:checked ~ .cv-toggle-track {
    background: var(--error);
    border-color: var(--error);
}

.cv-mode-switch input:checked ~ .cv-toggle-track .cv-toggle-thumb {
    left: 22px;
    background: #fff;
}

.cv-mode-switch input:focus-visible ~ .cv-toggle-track {
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.cv-mode-label {
    font-family: var(--font-heading);
    font-weight: 600;
}

.cv-mode-label--normal { color: var(--accent); }
.cv-mode-label--fault  { color: var(--error); }

.cv-fault-select {
    padding: 0.45rem 0.8rem;
    font-family: var(--font-body);
    font-size: 0.82rem;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color var(--transition);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%235e5e78' viewBox='0 0 16 16'%3E%3Cpath d='M1.5 5.5l6.5 6.5 6.5-6.5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    padding-right: 2rem;
    min-width: 240px;
}

.cv-fault-select:focus {
    outline: none;
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(255,68,102,0.15);
}

.cv-fault-select:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* --- SVG Schematic --- */
.cv-schematic-wrap {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    overflow-x: auto;
}

.cv-schematic-wrap svg {
    width: 100%;
    height: auto;
    min-width: 600px;
    display: block;
}

/* Blocks */
.cv-block {
    cursor: pointer;
    transition: filter 0.2s ease;
    transform: translateZ(0);
}

.cv-block:hover {
    filter: drop-shadow(0 0 8px var(--accent));
}

.cv-block:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 4px;
}

.cv-block.active rect {
    stroke: var(--accent);
    stroke-width: 2.5;
}

.cv-block.fault rect {
    stroke: var(--error);
    stroke-width: 2.5;
    fill: rgba(255,68,102,0.08);
}

.cv-block.fault text.cv-block-label {
    fill: var(--error);
}

/* Traces */
.cv-trace {
    transition: stroke 0.3s ease, stroke-width 0.3s ease, opacity 0.3s ease;
}

.cv-trace.highlight {
    stroke: var(--accent);
    stroke-width: 2.5;
}

.cv-trace.dead {
    stroke: var(--error);
    stroke-dasharray: 6,4;
    opacity: 0.4;
}

/* Animated flow dots */
@keyframes cv-flow {
    to { stroke-dashoffset: -20; }
}

.cv-trace.flowing {
    stroke-dasharray: 4,6;
    animation: cv-flow 0.8s linear infinite;
}

.cv-trace.flowing.highlight {
    stroke-dasharray: 4,6;
}

/* Test Points */
.cv-tp {
    cursor: pointer;
    transform-origin: center center;
    transform-box: fill-box;
    transition: filter 0.2s ease;
}

.cv-tp:hover {
    filter: drop-shadow(0 0 6px var(--accent));
}

.cv-tp:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.cv-tp.active circle {
    fill: var(--accent);
    stroke: var(--accent);
}

.cv-tp.active text {
    fill: var(--bg-primary);
    font-weight: 700;
}

/* Fault badge (SVG) */
.cv-fault-badge {
    display: none;
}

.cv-block.fault .cv-fault-badge {
    display: block;
}

/* --- Oscilloscope --- */
.cv-scope-wrap {
    position: relative;
}

.cv-scope-screen {
    background: #0a0a0a;
    border: 2px solid #1a1a2a;
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

.cv-scope-screen canvas {
    display: block;
    width: 100%;
    height: 220px;
}

.cv-scope-label {
    position: absolute;
    top: 0.5rem;
    left: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: rgba(0,255,136,0.6);
    pointer-events: none;
    z-index: 2;
}

.cv-scope-probe-label {
    position: absolute;
    top: 0.5rem;
    right: 0.75rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    font-weight: 600;
    color: #00ff88;
    pointer-events: none;
    z-index: 2;
}

.cv-scope-readout {
    position: absolute;
    bottom: 0.5rem;
    left: 0.75rem;
    right: 0.75rem;
    display: flex;
    justify-content: space-between;
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: rgba(0,255,136,0.5);
    pointer-events: none;
    z-index: 2;
}

/* Scope controls */
.cv-scope-controls {
    display: flex;
    gap: 1rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
    align-items: flex-end;
    position: relative;
    z-index: 5;
}

.cv-scope-ctrl {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
    min-width: 100px;
}

.cv-scope-ctrl label {
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.cv-scope-ctrl input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
    padding: 6px 0;
    margin: 0;
}

.cv-scope-ctrl input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-primary);
}

.cv-scope-ctrl input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--accent);
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid var(--bg-primary);
}

.cv-hold-btn {
    padding: 0.45rem 1rem;
    font-family: var(--font-heading);
    font-size: 0.78rem;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.cv-hold-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.cv-hold-btn.active {
    background: var(--accent);
    color: var(--bg-primary);
    border-color: var(--accent);
}

/* --- Inspector Panel (right sidebar) --- */
.cv-inspector {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.cv-inspector-placeholder {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 2rem 0;
    line-height: 1.6;
}

.cv-inspector-placeholder svg {
    display: block;
    margin: 0 auto 0.75rem;
    opacity: 0.35;
}

.cv-info-title {
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 0.75rem;
}

.cv-info-title.fault-active {
    color: var(--error);
}

.cv-info-grid {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
}

.cv-info-field label {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.15rem;
}

.cv-info-field p {
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.55;
}

/* Fault Diagnostic Drawer */
.cv-fault-drawer {
    border: 1px solid rgba(255,68,102,0.2);
    background: rgba(255,68,102,0.04);
    border-radius: var(--radius);
    padding: 1rem;
}

.cv-fault-drawer-title {
    font-family: var(--font-heading);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--error);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.cv-fault-field {
    margin-bottom: 0.65rem;
}

.cv-fault-field:last-child {
    margin-bottom: 0;
}

.cv-fault-field strong {
    display: block;
    font-size: 0.68rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.15rem;
    font-weight: 600;
}

.cv-fault-field p {
    color: var(--text-secondary);
    font-size: 0.8rem;
    line-height: 1.5;
}

/* --- Responsive --- */
@media (max-width: 1024px) {
    .cv-layout {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .cv-card {
        padding: 1rem;
    }

    .cv-scope-screen canvas {
        height: 180px;
    }

    .cv-scope-controls {
        gap: 0.75rem;
    }

    .cv-mode-bar {
        flex-direction: column;
        align-items: flex-start;
    }

    .cv-fault-select {
        min-width: unset;
        width: 100%;
    }
}
