/* ============================================
   Hardware Diagnostic Flowchart — Stylesheet
   Theme-aware (uses themes.css variables), responsive, a11y
   ============================================ */

/* --- Controls row --- */
.hd-controls {
    display: flex;
    align-items: flex-end;
    gap: 1.25rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.hd-board {
    flex: 1;
    min-width: 240px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    line-height: 1.5;
    padding-bottom: 0.4rem;
}

.hd-safety {
    font-size: 0.8rem;
    line-height: 1.55;
    color: var(--text-secondary);
    padding: 0.7rem 1rem;
    margin-bottom: 1.25rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius);
}

.hd-safety strong { color: var(--warning); }

/* --- Breadcrumb trail --- */
.hd-breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.3rem;
    margin-bottom: 1.25rem;
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: 0.72rem;
}

.hd-crumb {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    color: var(--text-secondary);
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font: inherit;
    transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.hd-crumb:hover,
.hd-crumb:focus-visible {
    color: var(--accent);
    border-color: var(--border-hover);
    background: var(--accent-glow);
    outline: none;
}

.hd-crumb--current {
    color: var(--text-primary);
    font-weight: 600;
    cursor: default;
}

.hd-crumb-sep { color: var(--text-muted); }

.hd-crumb-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.2rem;
    height: 1.2rem;
    padding: 0 0.25rem;
    font-size: 0.62rem;
    font-weight: 700;
    color: var(--bg-primary);
    background: var(--accent);
    border-radius: 4px;
}

.hd-crumb-ans {
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    border: 1px solid currentColor;
}

.hd-crumb-ans--yes    { color: var(--success); }
.hd-crumb-ans--no     { color: var(--error); }
.hd-crumb-ans--unsure { color: var(--warning); }

/* --- Two-column layout --- */
.hd-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 1.25rem;
    align-items: start;
}

.hd-main {
    min-width: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    min-height: 320px;
}

.hd-heading {
    font-family: var(--font-heading);
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
    line-height: 1.35;
}

.hd-sub {
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.55;
    margin: 0.5rem 0 1.25rem;
}

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

.hd-error {
    color: var(--error);
    font-size: 0.85rem;
}

/* --- Symptom picker --- */
.hd-symptom-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 0.85rem;
}

.hd-symptom {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    text-align: left;
    padding: 1.1rem 1.2rem;
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: var(--font-body);
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.hd-symptom:hover,
.hd-symptom:focus-visible {
    border-color: var(--accent);
    box-shadow: 0 2px 14px var(--accent-glow);
    transform: translateY(-2px);
    outline: none;
}

.hd-symptom-label {
    font-family: var(--font-heading);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
}

.hd-symptom-desc {
    font-size: 0.78rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.hd-symptom-go {
    margin-top: auto;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent);
}

/* --- Diagnostic step --- */
.hd-node-head {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.hd-step-badge {
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--bg-primary);
    background: var(--accent);
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    margin-top: 0.15rem;
}

.hd-step-badge--result {
    background: var(--gradient-accent);
}

.hd-equipment {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1rem;
}

.hd-equipment .hd-label {
    width: 100%;
    margin-bottom: 0.1rem;
}

.hd-pill {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    color: var(--accent);
    background: var(--accent-glow);
    border: 1px solid var(--border-hover);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    white-space: nowrap;
}

.hd-warning {
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-primary);
    background: rgba(255, 68, 102, 0.08);
    border: 1px solid var(--error);
    border-radius: 8px;
    padding: 0.7rem 0.9rem;
    margin-bottom: 1rem;
}

.hd-warning strong { color: var(--error); }

.hd-steps {
    margin: 0 0 1rem;
    padding-left: 0;
    list-style: none;
    counter-reset: hdstep;
}

.hd-steps li {
    counter-increment: hdstep;
    position: relative;
    padding: 0.55rem 0 0.55rem 2.3rem;
    font-size: 0.86rem;
    line-height: 1.6;
    color: var(--text-primary);
    border-bottom: 1px dashed var(--border);
}

.hd-steps li:last-child { border-bottom: none; }

.hd-steps li::before {
    content: counter(hdstep);
    position: absolute;
    left: 0;
    top: 0.6rem;
    width: 1.5rem;
    height: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--accent-glow);
    border: 1px solid var(--border-hover);
    border-radius: 50%;
}

.hd-expect,
.hd-hint,
.hd-notes {
    padding: 0.8rem 1rem;
    margin-bottom: 1rem;
    background: var(--bg-card-solid);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: var(--radius);
}

.hd-expect p,
.hd-hint p,
.hd-notes p,
.hd-verdict {
    margin: 0;
    font-size: 0.84rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.hd-expect p { color: var(--text-primary); font-family: var(--font-mono); font-size: 0.78rem; }

.hd-hint { border-left-color: var(--warning); animation: benchFadeIn 0.3s ease; }

/* --- Action buttons --- */
.hd-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1.25rem;
}

.hd-btn {
    padding: 0.6rem 1.15rem;
    font-family: var(--font-heading);
    font-size: 0.82rem;
    font-weight: 600;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--bg-primary);
}

.hd-btn:hover:not(:disabled) {
    transform: translateY(-2px);
}

.hd-btn:disabled { opacity: 0.6; cursor: default; }

.hd-btn--pass   { background: var(--success); }
.hd-btn--fail   { background: var(--error); color: #fff; }
.hd-btn--unsure { background: var(--warning); }
.hd-btn--primary { background: var(--accent); }

.hd-btn--pass:hover:not(:disabled)   { box-shadow: 0 4px 15px var(--accent-glow); }
.hd-btn--fail:hover:not(:disabled)   { box-shadow: 0 4px 15px rgba(255, 68, 102, 0.25); }
.hd-btn--unsure:hover:not(:disabled) { box-shadow: 0 4px 15px rgba(255, 187, 51, 0.25); }
.hd-btn--primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 4px 15px var(--accent-glow); }

.hd-btn--ghost,
.hd-btn--danger {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}

.hd-btn--ghost:hover { color: var(--accent); border-color: var(--accent); }
.hd-btn--danger { margin-left: auto; }
.hd-btn--danger:hover { color: var(--error); border-color: var(--error); }

/* --- Outcome card --- */
.hd-verdict {
    margin-bottom: 1.25rem;
    color: var(--text-primary);
}

.hd-culprits {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    margin-bottom: 1.25rem;
}

.hd-culprit {
    display: flex;
    gap: 0.9rem;
    padding: 0.8rem 1rem;
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.hd-culprit-ref {
    flex-shrink: 0;
    align-self: flex-start;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent-secondary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    padding: 0.25rem 0.5rem;
    border-radius: 6px;
    white-space: nowrap;
}

.hd-culprit-body strong {
    display: block;
    font-size: 0.84rem;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.hd-culprit-body p {
    margin: 0;
    font-size: 0.8rem;
    line-height: 1.55;
    color: var(--text-secondary);
}

.hd-summary-preview {
    margin: 1rem 0 0;
    padding: 1rem;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    line-height: 1.55;
    color: var(--text-secondary);
    background: var(--code-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow: auto;
    user-select: all;
}

/* --- Chip pinout inspector --- */
.hd-side {
    position: sticky;
    top: 90px;
}

.hd-chip-card {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem;
}

.hd-chip-card .hd-label { margin-bottom: 0.6rem; }

.hd-chip-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.hd-chip-tabs:empty { display: none; }

.hd-chip-title {
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 0.25rem;
}

.hd-chip-note {
    font-size: 0.72rem;
    line-height: 1.5;
    color: var(--text-muted);
    margin: 0 0 0.75rem;
}

.hd-chip-svg-wrap {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem;
    max-height: 420px;
    overflow: auto;
    display: flex;
    justify-content: center;
}

.hd-chip-svg-wrap svg {
    width: 100%;
    height: auto;
    max-height: 400px;
}

.hd-pin { cursor: pointer; outline: none; }

.hd-pin:hover rect,
.hd-pin:focus rect {
    stroke: var(--accent);
    stroke-width: 1.5;
}

.hd-pin.active rect {
    fill: var(--accent-glow);
    stroke: var(--accent);
    stroke-width: 2;
}

.hd-pin.active text { fill: var(--accent); }

.hd-pin-table {
    margin-top: 0.75rem;
}

.hd-pin-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.hd-pin-row:last-child { border-bottom: none; }

.hd-pin-key {
    flex-shrink: 0;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding-top: 0.15rem;
}

.hd-pin-val {
    font-family: var(--font-mono);
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--accent);
    text-align: right;
    line-height: 1.45;
}

.hd-chip-placeholder[hidden],
.hd-hint[hidden],
.hd-summary-preview[hidden],
#hdChipInspector[hidden] {
    display: none;
}

.hd-chip-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.5;
    padding: 1.5rem 0.5rem;
}

/* --- Responsive --- */
@media (max-width: 900px) {
    .hd-layout { grid-template-columns: minmax(0, 1fr); }
    .hd-side { position: static; }
}

@media (max-width: 600px) {
    .hd-main { padding: 1.1rem; }
    .hd-pill { white-space: normal; }
    .hd-crumb { text-align: left; }
    .hd-actions .hd-btn { flex: 1 1 45%; }
    .hd-btn--danger { margin-left: 0; }
    .hd-culprit { flex-direction: column; gap: 0.5rem; }
    .hd-breadcrumb { font-size: 0.68rem; }
}
