:root {
    --bg-primary: #0f0f1a;
    --bg-secondary: #16162a;
    --bg-tertiary: #1e1e3f;
    --bg-hover: #2a2a50;
    --bg-card: #252550;
    
    --text-primary: #f0f0ff;
    --text-secondary: #a0a0c0;
    --text-muted: #6a6a9a;
    --text-accent: #00d4ff;
    
    --accent-cyan: #00d4ff;
    --accent-purple: #a855f7;
    --accent-pink: #ec4899;
    --accent-green: #22c55e;
    --accent-yellow: #eab308;
    --accent-red: #ef4444;
    --accent-orange: #f97316;
    
    --border-color: #2a2a50;
    --border-hover: #3a3a70;
    
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    
    --gradient-primary: linear-gradient(135deg, var(--accent-cyan), var(--accent-purple));
    --gradient-glow: linear-gradient(135deg, rgba(0, 212, 255, 0.3), rgba(168, 85, 247, 0.3));
    
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    
    --sidebar-width: 260px;
    --header-height: 70px;
}

.light-mode {
    --bg-primary: #f8f9fc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #eef0f5;
    --bg-hover: #e2e5ec;
    --bg-card: #ffffff;
    
    --text-primary: #1a1a2e;
    --text-secondary: #4a4a6a;
    --text-muted: #7a7a9a;
    --text-accent: #0891b2;
    
    --border-color: #d1d5db;
    --border-hover: #9ca3af;
    
    --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.6;
}

/* App Wrapper */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 24px 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo .highlight {
    font-weight: 400;
    opacity: 0.8;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 12px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 24px;
}

.nav-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-left: 12px;
}

.nav-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 16px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s ease;
}

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

.nav-btn.active {
    background: var(--gradient-glow);
    color: var(--accent-cyan);
    border: 1px solid rgba(0, 212, 255, 0.3);
}

.nav-btn svg {
    opacity: 0.7;
}

.nav-btn.active svg {
    opacity: 1;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.toggle {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-tertiary);
    border-radius: 24px;
    transition: 0.3s;
    border: 1px solid var(--border-color);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px;
    width: 18px;
    left: 2px;
    bottom: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.3s;
}

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

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: white;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
}

.quick-stats {
    display: flex;
    gap: 16px;
}

.stat-item {
    flex: 1;
    text-align: center;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}

.stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-cyan);
}

.stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.main-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-left h2 {
    font-size: 1.4rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 12px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: 0 4px 15px rgba(0, 212, 255, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 212, 255, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

/* Sections */
.section {
    display: none;
    flex: 1;
    padding: 24px 32px;
    flex-direction: column;
    gap: 20px;
}

.section.active {
    display: flex;
}

/* Editor Grid */
.editor-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 20px;
    flex: 1;
    min-height: 0;
}

.panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 0.95rem;
}

.panel-title svg {
    color: var(--accent-cyan);
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

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

.match-count {
    font-size: 0.85rem;
    color: var(--accent-green);
    font-weight: 600;
}

/* Pattern Panel */
.pattern-input-wrapper {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    gap: 8px;
    background: var(--bg-tertiary);
}

.pattern-delimiter {
    font-family: var(--font-mono);
    font-size: 1.4rem;
    color: var(--accent-purple);
    font-weight: 600;
}

.pattern-input {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--text-primary);
    outline: none;
    transition: all 0.2s ease;
}

.pattern-input:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

.pattern-input::placeholder {
    color: var(--text-muted);
}

.flags-input {
    width: 70px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    font-family: var(--font-mono);
    font-size: 1rem;
    color: var(--accent-yellow);
    text-align: center;
    outline: none;
    transition: all 0.2s ease;
}

.flags-input:focus {
    border-color: var(--accent-yellow);
    box-shadow: 0 0 0 3px rgba(234, 179, 8, 0.1);
}

.error-display {
    padding: 10px 20px;
    background: rgba(239, 68, 68, 0.1);
    border-left: 3px solid var(--accent-red);
    color: var(--accent-red);
    font-size: 0.875rem;
    display: none;
}

.error-display.show {
    display: block;
}

/* Text Panel */
.text-input {
    flex: 1;
    background: var(--bg-primary);
    border: none;
    padding: 16px 20px;
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.7;
    color: var(--text-primary);
    resize: none;
    outline: none;
}

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

.text-stats {
    display: flex;
    gap: 16px;
    padding: 10px 20px;
    background: var(--bg-tertiary);
    font-size: 0.8rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

/* Results Panel */
.results-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    background: var(--bg-primary);
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.match-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    transition: all 0.2s ease;
}

.match-item:hover {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 1px rgba(0, 212, 255, 0.2);
}

.match-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.match-number {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--accent-cyan);
    background: rgba(0, 212, 255, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
}

.match-position {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.match-text {
    font-family: var(--font-mono);
    font-size: 0.9rem;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius-sm);
    word-break: break-all;
}

.match-text mark {
    background: var(--accent-cyan);
    color: var(--bg-primary);
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
}

.groups-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}

.groups-title {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
}

.group-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    margin-bottom: 6px;
}

.group-number {
    color: var(--accent-purple);
    font-family: var(--font-mono);
    font-weight: 600;
    min-width: 30px;
}

.group-value {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    flex: 1;
    word-break: break-all;
}

/* Preview Panel */
.preview-panel {
    flex: 0 0 auto;
    max-height: 300px;
}

.preview-content {
    flex: 1;
    overflow: auto;
    padding: 20px;
    background: var(--bg-primary);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    line-height: 1.8;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.preview-placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.match-highlight {
    background: var(--accent-cyan);
    color: var(--bg-primary);
    padding: 2px 4px;
    border-radius: 4px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0, 212, 255, 0.4);
}

.match-highlight.group-1 { background: var(--accent-purple); color: white; }
.match-highlight.group-2 { background: var(--accent-pink); color: white; }
.match-highlight.group-3 { background: var(--accent-green); color: white; }
.match-highlight.group-4 { background: var(--accent-yellow); color: var(--bg-primary); }
.match-highlight.group-5 { background: var(--accent-orange); color: white; }

/* Reference Section */
.reference-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 20px;
}

.ref-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
}

.ref-card h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: var(--accent-cyan);
    display: flex;
    align-items: center;
    gap: 10px;
}

.ref-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ref-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

.ref-item:hover {
    background: var(--bg-hover);
    transform: translateX(4px);
}

.ref-item code {
    font-family: var(--font-mono);
    font-size: 0.95rem;
    color: var(--accent-purple);
    font-weight: 600;
    min-width: 80px;
}

.ref-item span {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

/* Library Section */
.library-header {
    text-align: center;
    margin-bottom: 20px;
}

.library-header h3 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.library-header p {
    color: var(--text-muted);
}

.library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 20px;
}

.library-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.library-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-primary);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.library-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--accent-cyan);
}

.library-item:hover::before {
    transform: scaleX(1);
}

.library-item-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.library-icon {
    width: 44px;
    height: 44px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.library-item h4 {
    font-size: 1.1rem;
    font-weight: 600;
}

.library-item p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    line-height: 1.5;
}

.library-pattern {
    background: var(--bg-tertiary);
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent-cyan);
    overflow-x: auto;
    white-space: nowrap;
}

/* Reference Drawer */
.reference-drawer {
    position: fixed;
    right: -400px;
    top: 0;
    width: 400px;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    z-index: 200;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
}

.reference-drawer.open {
    right: 0;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.drawer-header h3 {
    font-size: 1.1rem;
}

.drawer-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 16px 24px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: 12px;
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 1000;
}

.toast.show {
    transform: translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--accent-green);
}

.toast.error {
    border-color: var(--accent-red);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Selection */
::selection {
    background: var(--accent-cyan);
    color: var(--bg-primary);
}

/* Responsive */
@media (max-width: 1400px) {
    .editor-grid {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: 1fr 1fr;
    }
    
    .results-panel {
        grid-column: span 2;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .editor-grid {
        grid-template-columns: 1fr;
    }
    
    .results-panel {
        grid-column: span 1;
    }
}

@media (max-width: 768px) {
    .main-header {
        flex-direction: column;
        height: auto;
        padding: 16px;
        gap: 16px;
    }
    
    .section {
        padding: 16px;
    }
    
    .reference-grid,
    .library-grid {
        grid-template-columns: 1fr;
    }
}

/* Mobile menu button */
.mobile-menu-btn {
    display: none;
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: 56px;
    height: 56px;
    background: var(--gradient-primary);
    border: none;
    border-radius: 50%;
    color: white;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 150;
    align-items: center;
    justify-content: center;
}

@media (max-width: 1024px) {
    .mobile-menu-btn {
        display: flex;
    }
}