/* ===== CSS Variables ===== */
:root {
    --primary: #3498DB;
    --primary-dark: #2980B9;
    --secondary: #95A5A6;
    --success: #2ECC71;
    --warning: #F39C12;
    --danger: #E74C3C;

    --bg-dark: #1E2A38;
    --bg-darker: #16202C;
    --bg-light: #F8FAFC;
    --bg-white: #FFFFFF;

    --text-primary: #2C3E50;
    --text-secondary: #7F8C8D;
    --text-light: #ECF0F1;

    --border: #E0E6ED;
    --border-dark: #34495E;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.15);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --transition: all 0.2s ease;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-light);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
}

/* ===== App Container ===== */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ===== Header ===== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 24px;
    background: var(--bg-dark);
    color: var(--text-light);
    box-shadow: var(--shadow-md);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: baseline;
    gap: 16px;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    letter-spacing: -0.5px;
}

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

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.doc-link {
    color: var(--text-light);
    text-decoration: none;
    font-size: 0.875rem;
    padding: 6px 12px;
    border: 1px solid var(--border-dark);
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.doc-link:hover {
    background: var(--border-dark);
}

/* ===== Diagram Tabs ===== */
.diagram-tabs {
    display: flex;
    background: var(--bg-darker);
    padding: 0 24px;
    gap: 4px;
}

.tab-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 3px solid transparent;
    position: relative;
}

.tab-btn:hover {
    color: var(--text-light);
    background: rgba(255, 255, 255, 0.05);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(52, 152, 219, 0.1);
}

.tab-icon {
    font-size: 1rem;
}

/* ===== Main Content ===== */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: var(--border);
}

/* ===== Resize Handle ===== */
.resize-handle {
    width: 6px;
    background: var(--border);
    cursor: col-resize;
    transition: background 0.2s ease;
    position: relative;
    z-index: 10;
}

.resize-handle:hover,
.resize-handle.dragging {
    background: var(--primary);
}

.resize-handle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 40px;
    background: repeating-linear-gradient(
        0deg,
        var(--text-secondary) 0px,
        var(--text-secondary) 2px,
        transparent 2px,
        transparent 6px
    );
    opacity: 0.5;
    border-radius: 2px;
}

.resize-handle:hover::after {
    opacity: 1;
}

/* ===== Panel Common ===== */
.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
}

.panel-header h2 {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

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

.divider {
    width: 1px;
    height: 20px;
    background: var(--border);
    margin: 0 8px;
}

/* ===== Editor Panel ===== */
.editor-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-white);
    overflow: hidden;
    min-width: 300px;
    max-width: 70%;
    width: 50%;
    flex-shrink: 0;
}

.editor-wrapper {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.line-numbers {
    min-width: 50px;
    padding: 16px 8px;
    background: #F5F7FA;
    color: var(--text-secondary);
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.6;
    text-align: right;
    user-select: none;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

#codeEditor {
    flex: 1;
    padding: 16px;
    border: none;
    resize: none;
    font-family: 'SF Mono', 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-white);
    outline: none;
    overflow: auto;
}

#codeEditor::placeholder {
    color: var(--text-secondary);
}

.editor-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: #F5F7FA;
    border-top: 1px solid var(--border);
}

.status {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

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

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

.editor-actions {
    display: flex;
    gap: 8px;
}

/* ===== Preview Panel ===== */
.preview-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-light);
    overflow: hidden;
    flex: 1;
    min-width: 300px;
}

.preview-wrapper {
    flex: 1;
    overflow: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    background:
        linear-gradient(90deg, var(--border) 1px, transparent 1px),
        linear-gradient(var(--border) 1px, transparent 1px);
    background-size: 20px 20px;
    background-color: #FAFBFC;
}

.diagram-canvas {
    background: var(--bg-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    min-height: 200px;
    transition: transform 0.2s ease;
}

.diagram-canvas svg {
    display: block;
    border-radius: var(--radius-md);
}

.zoom-level {
    font-size: 0.75rem;
    color: var(--text-secondary);
    min-width: 40px;
    text-align: center;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

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

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

.btn-primary kbd {
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
    font-size: 0.7rem;
    font-family: inherit;
}

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

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

.btn-icon {
    padding: 6px;
    background: transparent;
    color: var(--text-secondary);
    border: none;
}

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

.btn-small {
    padding: 4px;
}

/* ===== Examples Sidebar ===== */
.examples-sidebar {
    position: fixed;
    right: -320px;
    top: 0;
    bottom: 0;
    width: 320px;
    background: var(--bg-white);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    display: flex;
    flex-direction: column;
    transition: right 0.3s ease;
}

.examples-sidebar.open {
    right: 0;
}

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

.sidebar-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.examples-list {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.example-item {
    padding: 12px;
    margin-bottom: 8px;
    background: var(--bg-light);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    border: 2px solid transparent;
}

.example-item:hover {
    border-color: var(--primary);
}

.example-item h4 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.example-item p {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.example-item .example-type {
    display: inline-block;
    padding: 2px 8px;
    background: var(--primary);
    color: white;
    font-size: 0.65rem;
    border-radius: 10px;
    margin-bottom: 8px;
    text-transform: uppercase;
}

/* ===== Toggle Buttons ===== */
.toggle-examples-btn {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 30px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 150;
    transition: var(--transition);
}

.toggle-examples-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
}

.toggle-syntax-btn {
    position: fixed;
    left: 20px;
    bottom: 20px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-dark);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 1.2rem;
    font-weight: bold;
    cursor: pointer;
    box-shadow: var(--shadow-md);
    z-index: 150;
    transition: var(--transition);
}

.toggle-syntax-btn:hover {
    background: var(--bg-darker);
    transform: scale(1.1);
}

/* ===== Syntax Help ===== */
.syntax-help {
    position: fixed;
    left: 20px;
    bottom: 70px;
    width: 350px;
    max-height: 400px;
    background: var(--bg-white);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 150;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.syntax-help.open {
    display: flex;
}

.help-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--bg-dark);
    color: var(--text-light);
    font-weight: 600;
    font-size: 0.875rem;
}

.help-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.help-section {
    margin-bottom: 16px;
}

.help-section h4 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.help-section pre {
    background: #F5F7FA;
    padding: 12px;
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', 'Consolas', monospace;
    font-size: 0.75rem;
    overflow-x: auto;
    border-left: 3px solid var(--primary);
}

.help-section code {
    color: var(--text-primary);
}

/* ===== Error Message ===== */
.error-message {
    padding: 20px;
    background: #FEE2E2;
    color: var(--danger);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    border: 1px solid #FECACA;
}

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

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

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

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

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    .main-content {
        flex-direction: column;
    }

    .editor-panel {
        width: 100% !important;
        max-width: 100%;
        min-height: 40%;
        height: 50%;
    }

    .resize-handle {
        width: 100%;
        height: 6px;
        cursor: row-resize;
    }

    .resize-handle::after {
        width: 40px;
        height: 4px;
        background: repeating-linear-gradient(
            90deg,
            var(--text-secondary) 0px,
            var(--text-secondary) 2px,
            transparent 2px,
            transparent 6px
        );
    }

    .preview-panel {
        min-height: 200px;
    }

    .examples-sidebar {
        width: 100%;
        right: -100%;
    }

    .syntax-help {
        width: calc(100% - 40px);
        left: 20px;
        right: 20px;
    }
}

@media (max-width: 768px) {
    .app-header {
        padding: 10px 16px;
    }

    .app-header h1 {
        font-size: 1.2rem;
    }

    .subtitle {
        display: none;
    }

    .diagram-tabs {
        padding: 0 12px;
        overflow-x: auto;
    }

    .tab-btn {
        padding: 10px 14px;
        font-size: 0.8rem;
    }

    .tab-btn span:last-child {
        display: none;
    }

    .panel-header {
        padding: 8px 12px;
    }

    .toggle-examples-btn span {
        display: none;
    }

    .toggle-examples-btn {
        padding: 12px;
        border-radius: 50%;
    }
}

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

.rendering .status {
    animation: pulse 1s infinite;
}

/* ===== Dark Mode (Optional) ===== */
@media (prefers-color-scheme: dark) {
    /* 다크 모드 지원 시 여기에 스타일 추가 */
}

/* ===== Component Reference Modal ===== */
.component-reference-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.component-reference-overlay.active {
    display: flex;
}

.component-reference-modal {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 900px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

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

.reference-header h2 {
    font-size: 1.25rem;
    color: var(--text-primary);
}

.reference-nav {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--bg-light);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
}

.reference-nav-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

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

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

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

.component-card {
    background: var(--bg-light);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.component-card:last-child {
    margin-bottom: 0;
}

.component-card h3 {
    font-size: 1rem;
    color: var(--primary);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.component-card h3 .component-icon {
    font-size: 1.2rem;
}

.component-card .description {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-bottom: 12px;
    line-height: 1.5;
}

.component-card .syntax-box {
    background: var(--bg-darker);
    color: var(--text-light);
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.85rem;
    margin-bottom: 12px;
    overflow-x: auto;
}

.component-card .syntax-box code {
    white-space: pre;
}

.component-card .params {
    margin-top: 12px;
}

.component-card .params-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.component-card .param-item {
    display: flex;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.component-card .param-item:last-child {
    border-bottom: none;
}

.component-card .param-name {
    font-family: monospace;
    background: var(--bg-white);
    padding: 2px 6px;
    border-radius: 3px;
    color: var(--primary-dark);
    font-weight: 600;
    white-space: nowrap;
}

.component-card .param-desc {
    color: var(--text-secondary);
    flex: 1;
}

.component-card .param-optional {
    color: var(--warning);
    font-size: 0.75rem;
}

.component-card .examples {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.component-card .examples-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.component-card .example-code {
    background: var(--bg-white);
    border: 1px solid var(--border);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-family: monospace;
    font-size: 0.8rem;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.component-card .example-code:last-child {
    margin-bottom: 0;
}

/* Toggle Reference Button */
.toggle-reference-btn {
    position: fixed;
    bottom: 80px;
    right: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-lg);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    transition: var(--transition);
    z-index: 100;
}

.toggle-reference-btn:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

@media (max-width: 768px) {
    .toggle-reference-btn span {
        display: none;
    }

    .toggle-reference-btn {
        padding: 12px;
        border-radius: 50%;
    }

    .component-reference-modal {
        max-height: 90vh;
    }

    .reference-nav {
        flex-wrap: nowrap;
    }
}
