:root {
    /* A11y Purple Palette */
    --primary: #A29BFE;
    --primary-hover: #b4afff;
    --secondary: #6C5CE7;
    --accent: #00CEC9;
    --bg-main: #0D0A14;
    --bg-panel: rgba(25, 20, 36, 0.6);
    --bg-panel-hover: rgba(35, 28, 50, 0.8);
    --border-color: rgba(162, 155, 254, 0.15);
    
    /* Text Colors */
    --text-main: #F8F9FA;
    --text-muted: #A09EAb;
    --text-inverse: #000000;
    
    /* Semantic Colors */
    --error: #FF7675;
    --error-bg: rgba(255, 118, 117, 0.1);
    --warning: #FDCB6E;
    --warning-bg: rgba(253, 203, 110, 0.1);
    --success: #00B894;
    --success-bg: rgba(0, 184, 148, 0.1);
    --info: #74B9FF;
    --info-bg: rgba(116, 185, 255, 0.1);
    
    /* UI Constants */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-full: 9999px;
    --transition: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --glass-blur: blur(12px);
    
    /* Focus Ring */
    --focus-ring: 0 0 0 3px rgba(162, 155, 254, 0.5);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(108, 92, 231, 0.08) 0%, transparent 50%),
        radial-gradient(circle at 85% 30%, rgba(0, 206, 201, 0.05) 0%, transparent 50%);
    background-attachment: fixed;
}

/* Base Elements */
button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, [tabindex]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: 4px; /* fallback */
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--primary);
}

/* Layout */
.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    height: 100vh;
}

/* Glassmorphism Panels */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* Header */
.main-header {
    padding: 1rem 1.5rem;
    flex-shrink: 0;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

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

.actions {
    display: flex;
    gap: 1rem;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    transition: all var(--transition);
}

.btn-primary {
    background: linear-gradient(135deg, var(--secondary), var(--primary));
    color: white;
    border: 1px solid transparent;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(108, 92, 231, 0.4);
}

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

.btn-outline:hover:not(:disabled) {
    background: rgba(162, 155, 254, 0.1);
    border-color: var(--primary);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Main Content Layout */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex-grow: 1;
    min-height: 0;
}

.results-layout {
    display: flex;
    gap: 1.5rem;
    flex-grow: 1;
    min-height: 0;
}

/* Section Headers */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.section-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-main);
}

.badge {
    background: var(--bg-main);
    color: var(--text-muted);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid var(--border-color);
}

/* Code Input Section */
.code-input-section {
    display: flex;
    flex-direction: column;
    height: 30%;
    flex-shrink: 0;
}

.editor-container {
    flex-grow: 1;
    padding: 1rem;
    position: relative;
}

textarea#html-input {
    width: 100%;
    height: 100%;
    background: #000;
    color: #e0e0e0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    font-family: 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 0.9rem;
    resize: none;
    line-height: 1.5;
}

textarea#html-input:focus {
    border-color: var(--primary);
    box-shadow: var(--focus-ring);
}

/* Preview Section */
.preview-section {
    flex: 2;
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
}

.preview-container {
    flex-grow: 1;
    padding: 2rem;
    overflow: auto;
    position: relative;
    background: #ffffff; /* White background for accurate testing */
    color: #000000; /* Black text for preview */
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

/* Reset inner styles for preview */
.preview-container * {
    font-family: inherit;
    /* Don't force dark mode inside preview unless user HTML has it */
}

/* Custom interactive preview styles */
.a11y-preview-wrapper {
    position: relative;
}

/* Tab Order Badges */
.a11y-tab-badge {
    position: absolute;
    top: -10px;
    left: -10px;
    background: var(--primary);
    color: #000;
    font-size: 10px;
    font-weight: 800;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    pointer-events: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.5);
    border: 2px solid #fff;
    opacity: 0;
    transition: opacity 0.2s;
}

.show-tab-order .a11y-tab-badge {
    opacity: 1;
}

/* Preview Element Highlighting */
.a11y-focusable {
    position: relative;
}

.show-tab-order .a11y-focusable {
    outline: 2px dashed rgba(162, 155, 254, 0.5);
    outline-offset: 4px;
}

.a11y-active-focus {
    outline: 3px solid var(--accent) !important;
    outline-offset: 2px !important;
    position: relative;
    z-index: 10;
}

.show-tab-order .a11y-active-focus .a11y-tab-badge {
    background: var(--accent);
    transform: scale(1.2);
}

/* Live Feedback Panel */
.live-feedback-panel {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    border-radius: 0 0 var(--radius) var(--radius);
    background: rgba(10, 8, 16, 0.9);
    border-top: 1px solid var(--primary);
}

.live-feedback-panel h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.sr-text {
    font-family: 'Menlo', monospace;
    font-size: 0.9rem;
    color: var(--accent);
    min-height: 1.5rem;
    word-break: break-all;
}

/* Audit Results Section */
.audit-results-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 350px;
}

.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.stat-card {
    padding: 1rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.highlight-error { color: var(--error); }
.highlight-success { color: var(--success); }
.highlight-warning { color: var(--warning); }

.full-height-panel {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-color);
}

.tab-btn {
    flex: 1;
    padding: 1rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(162, 155, 254, 0.05);
}

.tab-btn:hover:not(.active) {
    color: var(--text-main);
    background: rgba(255, 255, 255, 0.02);
}

.tab-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 1rem;
}

.tab-content[hidden] {
    display: none;
}

/* Issue List */
.issue-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.issue-card {
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 1rem;
    border-left: 4px solid var(--border-color);
}

.issue-card.error { border-left-color: var(--error); }
.issue-card.warning { border-left-color: var(--warning); }
.issue-card.info { border-left-color: var(--info); }
.issue-card.success { border-left-color: var(--success); }

.issue-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.issue-title {
    font-weight: 600;
    font-size: 0.95rem;
}

.issue-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

.issue-code {
    background: #000;
    padding: 0.5rem;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.8rem;
    color: #ccc;
    overflow-x: auto;
    margin-bottom: 0.5rem;
    border: 1px solid #333;
}

.issue-suggestion {
    font-size: 0.85rem;
    color: var(--success);
    background: var(--success-bg);
    padding: 0.5rem;
    border-radius: 4px;
}

/* Flow Diagram */
.flow-diagram {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.5rem;
}

.flow-node {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    cursor: pointer;
}

.flow-node:hover {
    border-color: var(--primary);
    background: rgba(162, 155, 254, 0.1);
}

.flow-node-index {
    background: var(--primary);
    color: #000;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.flow-node-content {
    flex-grow: 1;
    overflow: hidden;
}

.flow-node-tag {
    font-size: 0.8rem;
    color: var(--accent);
    font-family: monospace;
    font-weight: 600;
}

.flow-node-text {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.flow-arrow {
    text-align: center;
    color: var(--border-color);
    margin: -0.25rem 0;
}

/* Empty States */
.empty-state, .empty-issue-state, .empty-flow-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    height: 100%;
    color: var(--text-muted);
    gap: 1rem;
    padding: 2rem;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.slider {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 20px;
    background-color: rgba(255,255,255,0.1);
    border-radius: 20px;
    transition: .4s;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-muted);
    border-radius: 50%;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--primary);
    border-color: var(--primary);
}

input:focus-visible + .slider {
    box-shadow: var(--focus-ring);
}

input:checked + .slider:before {
    transform: translateX(20px);
    background-color: #000;
}

.toggle-label {
    font-size: 0.85rem;
    font-weight: 500;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.toast {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 1rem 1.5rem;
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: slideIn 0.3s ease forwards;
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 1024px) {
    .results-layout {
        flex-direction: column;
    }
    
    .audit-results-section {
        height: 500px;
    }
}

@media (max-width: 768px) {
    .app-container {
        padding: 1rem;
        height: auto;
        min-height: 100vh;
    }
    
    .header-content {
        flex-direction: column;
        gap: 1rem;
        align-items: flex-start;
    }
    
    .actions {
        width: 100%;
    }
    
    .actions .btn {
        flex: 1;
        justify-content: center;
    }
}
