/* ============================================
   Substitution Guide — Stylesheet
   Theme-aware (dark/light), responsive, a11y
   ============================================ */

/* --- Controls --- */
.sg-controls {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.sg-card-count {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.sg-no-results {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--text-muted);
    font-size: 0.88rem;
}

/* --- Substitution Card Grid --- */
.sg-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 0.85rem;
}

.sg-card {
    background: var(--gradient-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.15rem;
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.sg-card:hover {
    border-color: var(--accent);
    box-shadow: 0 2px 12px var(--accent-glow);
}

.sg-card.expanded {
    border-color: var(--accent);
}

/* Card header row */
.sg-card-header {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.sg-card-name {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
    min-width: 0;
}

.sg-card-badge {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.18rem 0.55rem;
    border-radius: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}

.sg-badge-dram {
    color: #66d9ff;
    background: rgba(102, 217, 255, 0.12);
}

.sg-badge-cpu {
    color: #ffbb33;
    background: rgba(255, 187, 51, 0.12);
}

.sg-badge-74 {
    color: var(--accent);
    background: var(--accent-glow);
}

.sg-card-expand {
    font-size: 0.65rem;
    color: var(--text-muted);
    transition: transform 0.2s ease;
    flex-shrink: 0;
    margin-left: auto;
}

.sg-card.expanded .sg-card-expand {
    transform: rotate(90deg);
}

/* Card summary */
.sg-card-summary {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* Expanded detail area */
.sg-card-details {
    display: none;
    margin-top: 0.5rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.sg-card.expanded .sg-card-details {
    display: block;
}

.sg-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem 1rem;
}

.sg-detail-item {
    min-width: 0;
}

.sg-detail-item strong {
    display: block;
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.15rem;
    font-weight: 600;
}

.sg-detail-item span {
    color: var(--text-primary);
    font-size: 0.8rem;
    line-height: 1.45;
    word-break: break-word;
}

.sg-detail-full {
    grid-column: 1 / -1;
}

/* Safe / Unsafe substitution list */
.sg-subs-list {
    list-style: none;
    padding: 0;
    margin: 0.4rem 0 0 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.sg-subs-list li {
    font-size: 0.8rem;
    line-height: 1.45;
    color: var(--text-secondary);
    padding-left: 1.2rem;
    position: relative;
}

.sg-subs-list li::before {
    position: absolute;
    left: 0;
    font-weight: 700;
}

.sg-sub-safe::before {
    content: '\2713';
    color: var(--success);
}

.sg-sub-warn::before {
    content: '\26A0';
    color: var(--warning);
    font-size: 0.75rem;
}

.sg-sub-danger::before {
    content: '\2717';
    color: var(--error);
}

/* --- Dangerous Swap Cards --- */
.sg-danger-title {
    color: #ff4466;
}

.sg-danger-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 0.85rem;
}

.sg-danger-card {
    background: rgba(255, 68, 102, 0.06);
    border: 1px solid rgba(255, 68, 102, 0.25);
    border-left: 3px solid #ff4466;
    border-radius: var(--radius);
    padding: 1.15rem;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.sg-danger-card:hover {
    border-color: #ff4466;
    box-shadow: 0 2px 12px rgba(255, 68, 102, 0.15);
}

.sg-danger-card-title {
    font-family: var(--font-heading);
    font-size: 0.92rem;
    font-weight: 600;
    color: #ff4466;
    margin-bottom: 0.35rem;
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

.sg-danger-card-title svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.sg-danger-card-body {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.sg-danger-card-body strong {
    color: var(--text-primary);
}

.sg-danger-card-body code {
    font-family: var(--font-mono);
    font-size: 0.92em;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.05em 0.35em;
}

/* --- Logic Family Matrix --- */
.sg-matrix-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: 0.5rem;
}

.sg-matrix {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
    white-space: nowrap;
}

.sg-matrix th,
.sg-matrix td {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    text-align: center;
}

.sg-matrix th {
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.68rem;
    position: sticky;
    top: 0;
    z-index: 1;
}

.sg-matrix td {
    color: var(--text-primary);
    background: var(--gradient-card);
}

.sg-matrix td:first-child {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--accent);
    text-align: left;
    white-space: nowrap;
}

.sg-matrix .sg-yes {
    color: var(--success);
    font-weight: 600;
}

.sg-matrix .sg-no {
    color: var(--error);
    font-weight: 600;
}

.sg-matrix .sg-partial {
    color: var(--warning);
    font-weight: 600;
}

.sg-matrix-note {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.75rem;
    line-height: 1.55;
}

/* --- Responsive --- */
@media (max-width: 640px) {
    .sg-card-grid,
    .sg-danger-grid {
        grid-template-columns: 1fr;
    }

    .sg-detail-grid {
        grid-template-columns: 1fr;
    }

    .sg-matrix {
        font-size: 0.68rem;
    }

    .sg-matrix th,
    .sg-matrix td {
        padding: 0.4rem 0.5rem;
    }
}
