/* ============================================
   CSS Variables & Theme
   ============================================ */
:root {
    /* Colors - Light Theme */
    --bg-primary: #f8f9fc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f0f2f7;
    --bg-hover: #e8ebf2;
    --bg-editor: #ffffff;
    --bg-output: #fafbfe;

    --text-primary: #1a1d2e;
    --text-secondary: #5a5f7a;
    --text-tertiary: #8b90a5;
    --text-placeholder: #b0b4c8;

    --border-color: #e2e5f0;
    --border-focus: #4C8BF5;
    --border-hover: #c8cde0;

    --accent-primary: #4C8BF5;
    --accent-secondary: #06D6A0;
    --accent-tertiary: #00B4D8;
    --accent-warning: #FFB703;
    --accent-error: #EF476F;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.12);

    /* Syntax Highlighting - Light */
    --syn-keyword: #4C8BF5;
    --syn-function: #8B5CF6;
    --syn-string: #06D6A0;
    --syn-number: #FFB703;
    --syn-label: #EF476F;
    --syn-property: #00B4D8;
    --syn-comment: #9CA3AF;
    --syn-operator: #F97316;
    --syn-variable: #EC4899;
    --syn-bracket: #6B7280;
    --syn-relationship: #10B981;
    --syn-param: #8B5CF6;

    /* Line numbers */
    --line-bg: #f5f6fa;
    --line-color: #b0b4c8;
    --line-border: #e8ebf2;

    /* Sizing */
    --header-height: 64px;
    --toolbar-height: 56px;
    --status-height: 32px;
    --footer-height: 40px;
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

[data-theme="dark"] {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d2e;
    --bg-tertiary: #232740;
    --bg-hover: #2a2f4a;
    --bg-editor: #1a1d2e;
    --bg-output: #1e2236;

    --text-primary: #e8eaf0;
    --text-secondary: #a0a5c0;
    --text-tertiary: #6b7099;
    --text-placeholder: #4a4f6a;

    --border-color: #2a2f4a;
    --border-focus: #4C8BF5;
    --border-hover: #3a3f5a;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 36px rgba(0, 0, 0, 0.4);

    --syn-keyword: #6BA1F7;
    --syn-function: #A78BFA;
    --syn-string: #34D399;
    --syn-number: #FCD34D;
    --syn-label: #FB7185;
    --syn-property: #38BDF8;
    --syn-comment: #6B7280;
    --syn-operator: #FB923C;
    --syn-variable: #F472B6;
    --syn-bracket: #9CA3AF;
    --syn-relationship: #34D399;
    --syn-param: #A78BFA;

    --line-bg: #161929;
    --line-color: #4a4f6a;
    --line-border: #232740;
}

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    transition: background var(--transition-normal), color var(--transition-normal);
}

/* ============================================
   App Container
   ============================================ */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ============================================
   Header
   ============================================ */
.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

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

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

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.logo-text h1 {
    font-size: 1.25rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo-subtitle {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

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

/* ============================================
   Buttons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: inherit;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(76, 139, 245, 0.3);
}

.btn-primary:hover {
    background: #3a7be0;
    box-shadow: 0 4px 14px rgba(76, 139, 245, 0.4);
    transform: translateY(-1px);
}

.btn-primary:active {
    transform: translateY(0);
}

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

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px;
    border-radius: var(--radius-sm);
}

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

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

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

.btn-link {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    text-decoration: none;
    transition: color var(--transition-fast);
}

.btn-link:hover {
    color: var(--accent-primary);
}

/* ============================================
   Toolbar
   ============================================ */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    gap: 16px;
    border-bottom: 1px solid var(--border-color);
    flex-wrap: wrap;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.option-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.option-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.select-input {
    padding: 6px 28px 6px 10px;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%235a5f7a' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: all var(--transition-fast);
}

.select-input:hover {
    border-color: var(--border-hover);
}

.select-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.15);
}

/* Toggle Switch */
.toggle-group {
    gap: 0;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    white-space: nowrap;
}

.toggle-label input {
    display: none;
}

.toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    transition: all var(--transition-fast);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    background: white;
    border-radius: 50%;
    transition: all var(--transition-fast);
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.toggle-label input:checked + .toggle-switch {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.toggle-label input:checked + .toggle-switch::after {
    transform: translateX(16px);
}

/* ============================================
   Editor Container
   ============================================ */
.editor-container {
    display: flex;
    flex: 1;
    gap: 0;
    padding: 16px 0;
    min-height: 0;
}

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

.editor-panel:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(76, 139, 245, 0.1);
}

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

.panel-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.panel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.input-dot {
    background: var(--accent-primary);
}

.output-dot {
    background: var(--accent-secondary);
}

.panel-actions {
    display: flex;
    gap: 4px;
}

.editor-wrapper {
    display: flex;
    flex: 1;
    min-height: 300px;
    overflow: auto;
}

.line-numbers {
    padding: 16px 0;
    min-width: 48px;
    background: var(--line-bg);
    border-right: 1px solid var(--line-border);
    text-align: right;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    line-height: 1.7;
    color: var(--line-color);
    user-select: none;
    overflow: hidden;
}

.line-numbers span {
    display: block;
    padding: 0 12px;
}

.editor-textarea {
    flex: 1;
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.7;
    color: var(--text-primary);
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    tab-size: 4;
    white-space: pre;
    overflow: auto;
}

.editor-textarea::placeholder {
    color: var(--text-placeholder);
}

.editor-output {
    flex: 1;
    padding: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.875rem;
    line-height: 1.7;
    color: var(--text-primary);
    background: var(--bg-output);
    white-space: pre;
    overflow: auto;
    min-height: 100%;
}

.editor-output .placeholder-text {
    color: var(--text-placeholder);
    font-style: italic;
}

/* ============================================
   Divider
   ============================================ */
.divider {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 48px;
    gap: 8px;
    flex-shrink: 0;
}

.divider-line {
    flex: 1;
    width: 1px;
    background: var(--border-color);
}

.divider-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(76, 139, 245, 0.3);
    transition: all var(--transition-fast);
}

.divider-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 14px rgba(76, 139, 245, 0.4);
}

.divider-btn:active {
    transform: scale(0.95);
}

/* ============================================
   Status Bar
   ============================================ */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--status-height);
    padding: 0 4px;
    border-top: 1px solid var(--border-color);
}

.status-left, .status-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.status-item {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.status-divider {
    color: var(--border-color);
    font-size: 0.7rem;
}

.status-item.success {
    color: var(--accent-secondary);
}

.status-item.error {
    color: var(--accent-error);
}

/* ============================================
   Syntax Highlighting
   ============================================ */
.syn-keyword {
    color: var(--syn-keyword);
    font-weight: 600;
}

.syn-function {
    color: var(--syn-function);
    font-weight: 500;
}

.syn-string {
    color: var(--syn-string);
}

.syn-number {
    color: var(--syn-number);
}

.syn-label {
    color: var(--syn-label);
    font-weight: 500;
}

.syn-property {
    color: var(--syn-property);
}

.syn-comment {
    color: var(--syn-comment);
    font-style: italic;
}

.syn-operator {
    color: var(--syn-operator);
    font-weight: 600;
}

.syn-variable {
    color: var(--syn-variable);
}

.syn-bracket {
    color: var(--syn-bracket);
}

.syn-relationship {
    color: var(--syn-relationship);
    font-weight: 500;
}

.syn-param {
    color: var(--syn-param);
}

/* ============================================
   Toast
   ============================================ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast-icon {
    color: var(--accent-secondary);
    flex-shrink: 0;
}

/* ============================================
   Modal
   ============================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    backdrop-filter: blur(4px);
}

.modal-overlay.show {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 440px;
    transform: scale(0.95);
    transition: transform var(--transition-normal);
}

.modal-overlay.show .modal {
    transform: scale(1);
}

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

.modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
}

.modal-body {
    padding: 16px 20px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.shortcut-item:last-child {
    border-bottom: none;
}

.shortcut-keys {
    display: flex;
    align-items: center;
    gap: 4px;
}

kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    padding: 2px 8px;
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 1px 0 var(--border-color);
}

/* ============================================
   Footer
   ============================================ */
.footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: var(--footer-height);
    font-size: 0.75rem;
    color: var(--text-tertiary);
    border-top: 1px solid var(--border-color);
}

.footer-divider {
    opacity: 0.4;
}

/* ============================================
   Animations
   ============================================ */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.formatting {
    animation: pulse 0.6s ease-in-out;
}

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

::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
    .app-container {
        padding: 0 12px;
    }

    .editor-container {
        flex-direction: column;
        gap: 0;
    }

    .divider {
        flex-direction: row;
        width: 100%;
        height: 48px;
        padding: 0;
    }

    .divider-line {
        height: 1px;
        width: auto;
        flex: 1;
    }

    .editor-wrapper {
        min-height: 200px;
        max-height: 40vh;
    }

    .toolbar {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 0;
    }

    .toolbar-left, .toolbar-right {
        width: 100%;
        flex-wrap: wrap;
    }

    .toolbar-right {
        justify-content: flex-end;
    }
}

@media (max-width: 600px) {
    .logo-text h1 {
        font-size: 1rem;
    }

    .logo-subtitle {
        display: none;
    }

    .option-label {
        display: none;
    }

    .toggle-label span:last-child {
        display: none;
    }

    .status-bar {
        flex-direction: column;
        height: auto;
        padding: 4px 8px;
        gap: 2px;
    }

    .footer {
        flex-wrap: wrap;
        height: auto;
        padding: 8px;
        text-align: center;
    }
}