/**
 * SC&MS Framework - Taxonomy Explorer Styles
 * Version: 0.3
 */

/* Self-hosted Inter font (privacy-friendly, no Google tracking) */
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 300;
    font-display: swap;
    src: url('../fonts/Inter-Light.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../fonts/Inter-Regular.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('../fonts/Inter-Medium.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 600;
    font-display: swap;
    src: url('../fonts/Inter-SemiBold.woff2') format('woff2');
}
@font-face {
    font-family: 'Inter';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../fonts/Inter-Bold.woff2') format('woff2');
}

/* ============================================
   CSS Custom Properties (Design Tokens)
   ============================================ */
:root {
    color-scheme: light;
    /* Brand Colors */
    --primary: #8B7355;
    --primary-dark: #6B5640;
    --primary-light: #A68B6F;
    --accent: #C4A57B;
    --accent-bright: #D4B896;
    
    /* Backgrounds */
    --bg-main: #FEFDFB;
    --bg-elevated: #FFFFFF;
    --bg-hover: #F8F6F3;
    --bg-active: #F0EDE8;
    
    /* Text Colors */
    --text-primary: #1A1614;
    --text-secondary: #6B6762;
    --text-tertiary: #9D9891;
    
    /* Borders */
    --border: #E5DFD6;
    --border-light: #F0EBE3;
    
    /* Status Colors */
    --success: #2D7D4E;
    --warning: #D97706;
    --danger: #DC2626;
    --info: #0369A1;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(139, 115, 85, 0.05);
    --shadow-md: 0 4px 6px rgba(139, 115, 85, 0.08);
    --shadow-lg: 0 10px 15px rgba(139, 115, 85, 0.1);
    
    /* Stage Colors - ABCDEF */
    --stage-a: #C47B5C;
    --stage-b: #8B7355;
    --stage-c: #A68B6F;
    --stage-d: #D4A574;
    --stage-e: #9B826A;
    --stage-f: #7D5F4A;
    
    /* Layout */
    --header-height: 72px;
    --sidebar-width: 280px;
}

/* ============================================
   Base Reset & Typography
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-dark);
}

/* ============================================
   Layout Container
   ============================================ */
.explorer-container {
    display: grid;
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    height: 100vh;
    max-width: 100vw;
}

/* ============================================
   Header
   ============================================ */
.explorer-header {
    grid-column: 1 / -1;
    background: rgba(254, 253, 251, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 2rem;
    box-shadow: var(--shadow-sm);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex: 1;
    min-width: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    color: var(--text-primary);
}

.logo-text {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--primary);
}

.version-badge {
    background: rgba(139, 115, 85, 0.1);
    color: var(--primary);
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    font-size: 0.75rem;
    font-weight: 600;
}

/* Search */
.header-search {
    position: relative;
    width: clamp(220px, 28vw, 360px);
}

.search-input {
    width: 100%;
    padding: 0.625rem 1rem 0.625rem 2.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s, background-color 0.2s;
    background: var(--bg-main);
    color: var(--text-primary);
    -webkit-text-fill-color: var(--text-primary);
    appearance: none;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 115, 85, 0.1);
}

.search-input::placeholder {
    color: var(--text-tertiary);
}

.search-input:-webkit-autofill,
.search-input:-webkit-autofill:hover,
.search-input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text-primary);
    box-shadow: 0 0 0 1000px var(--bg-main) inset;
    transition: background-color 5000s ease-in-out 0s;
}

.search-icon {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

/* Header Actions */
.header-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-left: 1rem;
}

/* Buttons */
.btn {
    padding: 0.625rem 1rem;
    border-radius: 8px;
    border: none;
    font-size: 0.875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    border-color: var(--primary);
    background: rgba(139, 115, 85, 0.06);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
    color: white;
}

/* ============================================
   Sidebar
   ============================================ */
.sidebar {
    background: var(--bg-elevated);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1.5rem 0;
}

.sidebar-section {
    padding: 0 1.25rem;
    margin-bottom: 2rem;
}

.sidebar-about p {
    font-size: 0.8125rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.sidebar-links {
    margin-top: 0.85rem;
    display: flex;
    gap: 0.625rem;
    flex-wrap: wrap;
}

.sidebar-links a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--primary);
    text-decoration: none;
    padding: 0.45rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    transition: background-color 0.2s, color 0.2s, border-color 0.2s;
}

.sidebar-links a:hover {
    border-color: var(--primary);
    background: rgba(139, 115, 85, 0.08);
    color: var(--primary-dark);
}

.sidebar-links a:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.sidebar-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-tertiary);
    margin-bottom: 0.75rem;
}

.stage-list {
    list-style: none;
}

.stage-item {
    margin-bottom: 0.5rem;
}

.stage-btn {
    width: 100%;
    padding: 0.625rem 0.875rem;
    background: transparent;
    border: none;
    border-radius: 6px;
    text-align: left;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    color: var(--text-primary);
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.stage-btn:hover {
    background: var(--bg-hover);
}

.stage-btn.active {
    background: var(--bg-active);
    color: var(--primary-dark);
}

.stage-indicator {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.875rem;
    flex-shrink: 0;
    color: white;
}

/* Stage indicator colors */
.stage-A .stage-indicator { background: var(--stage-a); }
.stage-B .stage-indicator { background: var(--stage-b); }
.stage-C .stage-indicator { background: var(--stage-c); }
.stage-D .stage-indicator { background: var(--stage-d); }
.stage-E .stage-indicator { background: var(--stage-e); }
.stage-F .stage-indicator { background: var(--stage-f); }

.stage-label {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
    flex: 1;
}

.stage-name {
    font-weight: 500;
}

.stage-count {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 400;
}

/* ============================================
   Main Content Area
   ============================================ */
.main-content {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 2rem;
    min-width: 0;
}

.content-header {
    margin-bottom: 1.5rem;
}

.content-header-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.content-title {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.content-description {
    color: var(--text-secondary);
    font-size: 1.0625rem;
    line-height: 1.7;
    max-width: 65ch;
    margin: 0;
}

.content-stats-inline {
    display: flex;
    gap: 1.5rem;
    flex-shrink: 0;
}

.stat-item-inline {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.25rem;
}

.stat-number-inline {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.stat-label-inline {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-tertiary);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.breadcrumb-separator {
    color: var(--border);
}

/* ============================================
   Toolbar
   ============================================ */
.toolbar {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.toolbar-controls {
    display: flex;
    justify-content: flex-start;
}

.view-toggle {
    display: flex;
    gap: 0.5rem;
}

.toggle-btn {
    padding: 0.5rem 0.875rem;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.875rem;
    font-family: inherit;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
}

.toggle-btn:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

.toggle-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.toggle-btn svg {
    flex-shrink: 0;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.chip {
    padding: 0.375rem 0.75rem;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 16px;
    font-size: 0.8125rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.chip:hover {
    background: var(--primary-light);
    color: white;
}

.chip.chip-multiple {
    border-color: var(--primary);
    font-weight: 600;
}

.chip.chip-multiple:hover {
    background: var(--primary);
    color: white;
}

.chip.active {
    background: var(--primary);
    color: white;
}

.chip.active::after {
    content: ' ×';
    font-weight: bold;
}

/* ============================================
   Technique Grid
   ============================================ */
.technique-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.technique-card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    transition: all 0.2s;
    overflow: hidden;
    min-width: 0;
}

.technique-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.technique-card.highlight-match {
    background: rgba(139, 115, 85, 0.04);
    border-color: var(--primary-light);
}

.technique-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
}

.technique-id {
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--primary);
    background: rgba(139, 115, 85, 0.1);
    padding: 0.25rem 0.625rem;
    border-radius: 4px;
    font-family: 'Monaco', 'Consolas', monospace;
}

.technique-name {
    font-size: 1.125rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.technique-alias {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
    margin-bottom: 0.5rem;
}

.technique-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.875rem;
    overflow-wrap: break-word;
    word-wrap: break-word;
}

.technique-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

.tag {
    padding: 0.25rem 0.625rem;
    background: var(--bg-hover);
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    transition: all 0.2s;
    cursor: pointer;
}

.tag:hover {
    background: var(--accent);
    color: white;
}

/* Subtechniques */
.subtechniques {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
}

.subtechniques-title {
    font-weight: 600;
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.subtechnique-item {
    padding: 0.625rem 0.75rem;
    margin-bottom: 0.5rem;
    margin-left: 1rem;
    background: rgba(139, 115, 85, 0.03);
    border-radius: 6px;
    font-size: 0.8125rem;
    position: relative;
    transition: all 0.2s;
}

.subtechnique-item::before {
    content: '';
    position: absolute;
    left: -1rem;
    top: 50%;
    width: 0.75rem;
    height: 1px;
    background: var(--border);
}

.subtechnique-item:hover {
    background: rgba(139, 115, 85, 0.08);
}

.subtechnique-item.matched {
    background: rgba(139, 115, 85, 0.12);
}

.subtechnique-id {
    font-weight: 600;
    color: var(--primary);
    margin-right: 0.5rem;
    font-family: 'Monaco', 'Consolas', monospace;
    font-size: 0.75rem;
}

.subtechnique-name {
    font-weight: 600;
    color: var(--text-primary);
}

.subtechnique-description {
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: var(--text-tertiary);
    line-height: 1.5;
}

/* ============================================
   Technique List View
   ============================================ */
.technique-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.technique-list-item {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem 1.25rem;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 1rem;
    align-items: flex-start;
    transition: all 0.2s;
    cursor: pointer;
}

.technique-list-item:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.technique-list-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-sm);
}

.technique-list-item.highlight-match {
    background: rgba(139, 115, 85, 0.04);
    border-color: var(--primary-light);
}

.technique-list-content {
    flex: 1;
}

.technique-list-content .technique-name {
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.technique-list-tags {
    font-size: 0.8125rem;
    color: var(--text-tertiary);
}

.list-item-details {
    display: none;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-light);
}

.technique-list-item.expanded .list-item-details {
    display: block;
}

.expand-indicator {
    color: var(--text-tertiary);
    transition: transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ============================================
   Search Results
   ============================================ */
.search-result-group {
    margin-bottom: 2.5rem;
}

.search-result-group:not(:first-of-type) {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border-light);
}

.search-result-heading {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 1rem;
}

.search-result-count {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-tertiary);
}

/* ============================================
   States: Loading, Empty, Error
   ============================================ */
.loading-state,
.empty-state,
.error-state {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-tertiary);
}

.error-state {
    color: var(--danger);
}

.error-state h2 {
    margin-bottom: 0.5rem;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   Mobile Menu Toggle
   ============================================ */
.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 999px;
    padding: 0.25rem;
    cursor: pointer;
    color: var(--primary);
    align-items: center;
    justify-content: center;
}

.mobile-menu-toggle svg {
    width: 22px;
    height: 22px;
}

.mobile-menu-toggle:hover {
    background: rgba(139, 115, 85, 0.1);
}

.mobile-menu-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
}

.sidebar-overlay.active {
    display: block;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 1280px) {
    .explorer-header {
        padding: 0 1rem;
    }

    .header-left {
        flex: 1;
        min-width: 0;
        gap: 0.75rem;
    }

}

@media (max-width: 1024px) {
    .explorer-container {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        position: fixed;
        left: -280px;
        top: var(--header-height);
        bottom: 0;
        width: var(--sidebar-width);
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.mobile-open {
        left: 0;
    }

    .mobile-menu-toggle {
        display: flex;
    }
    
    .header-search {
        flex: 1;
        max-width: 500px;
    }
}

@media (max-width: 768px) {
    .explorer-header {
        padding: 0 0.75rem;
        gap: 0.5rem;
        flex-wrap: wrap;
        align-items: center;
    }

    .header-left {
        width: 100%;
        min-width: 0;
        gap: 0.625rem;
    }

    .header-search {
        width: 100%;
        max-width: none;
        flex: 1 1 100%;
        order: 3;
    }

    .search-input {
        font-size: 0.8125rem;
    }

    .header-actions {
        display: none;
    }

    .technique-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .main-content {
        padding: 1rem;
    }

    .content-title {
        font-size: 1.5rem;
    }

    .content-header-top {
        flex-direction: column;
        gap: 0.75rem;
    }

    .content-stats-inline {
        align-self: flex-start;
    }

    .stat-item-inline {
        align-items: flex-start;
    }

    /* Hide Grid/List toggle on mobile — grid (single column) is the only sensible layout */
    .view-toggle {
        display: none;
    }

    /* Horizontal scrolling tag strip */
    .filter-chips {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 0.25rem;
        scrollbar-width: none;
        margin: 0 -1rem;
        padding-left: 1rem;
        padding-right: 1rem;
    }

    .filter-chips::-webkit-scrollbar {
        display: none;
    }

    .chip {
        flex-shrink: 0;
    }

    /* Fade hint on right edge to signal scrollability */
    .toolbar-left {
        position: relative;
    }

    .toolbar-left::after {
        content: '';
        position: absolute;
        right: 0;
        top: 0;
        bottom: 0;
        width: 2rem;
        background: linear-gradient(to right, transparent, var(--bg-main));
        pointer-events: none;
    }

    .technique-card {
        padding: 1rem;
    }
}

@media (max-width: 480px) {
    .header-search {
        width: 100%;
    }

    .header-left {
        gap: 0.5rem;
    }

    .header-actions {
        gap: 0.375rem;
    }

    .logo-text {
        font-size: 1.125rem;
    }

    .main-content {
        padding: 0.75rem;
    }

    .content-title {
        font-size: 1.25rem;
    }

    .content-description {
        font-size: 0.9375rem;
    }

    .stat-number-inline {
        font-size: 1.25rem;
    }

    .stat-label-inline {
        font-size: 0.625rem;
    }

    .chip {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }

    .filter-chips {
        margin: 0 -0.75rem;
        padding-left: 0.75rem;
        padding-right: 0.75rem;
    }

    .technique-card {
        padding: 0.875rem;
    }

    .technique-name {
        font-size: 1rem;
    }

    .technique-description {
        font-size: 0.8125rem;
    }

    .btn {
        padding: 0.375rem 0.75rem;
        font-size: 0.8125rem;
    }
}
