* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #4285f4;
    --primary-dark: #1967d2;
    --primary-light: #669df6;
    --secondary: #34a853;
    --accent: #ea4335;
    --warning: #fbbc04;
    --success: #34a853;
    --danger: #ea4335;
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-surface: #ffffff;
    --bg-surface-alt: #f8f9fa;
    --bg-hover: #f1f3f4;
    --text-primary: #202124;
    --text-secondary: #5f6368;
    --text-tertiary: #80868b;
    --border: #dadce0;
    --border-light: #e8eaed;
    --shadow-1: 0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
    --shadow-2: 0 1px 2px 0 rgba(60,64,67,.3), 0 2px 6px 2px rgba(60,64,67,.15);
    --shadow-3: 0 2px 4px 0 rgba(60,64,67,.3), 0 4px 8px 3px rgba(60,64,67,.15);
    --shadow-hover: 0 4px 8px 0 rgba(60,64,67,.3), 0 8px 16px 4px rgba(60,64,67,.15);
}

body {
    font-family: 'Google Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #ffffff;
    min-height: 100vh;
    padding: 0;
    color: var(--text-primary);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-surface);
    border-radius: 16px;
    box-shadow: var(--shadow-2);
    overflow: hidden;
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: calc(100vh - 64px);
    margin-top: 64px;
    margin-bottom: 16px;
    border: 1px solid var(--border-light);
}

.editor-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-light);
    background: var(--bg-surface);
}

.preview-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    overflow: auto;
}

.panel-header {
    background: #ffffff;
    color: var(--text-primary);
    padding: 16px 24px;
    font-weight: 500;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-light);
}

.editor-panel .panel-header {
    background: #ffffff;
    color: var(--text-primary);
}

#codeInput {
    flex: 1;
    border: none;
    padding: 24px;
    font-family: 'Roboto Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 14px;
    resize: none;
    outline: none;
    background: #ffffff;
    color: var(--text-primary);
    line-height: 1.8;
    transition: background 0.2s;
}

#codeInput:focus {
    background: #fafbfc;
}

#codeInput::placeholder {
    color: var(--text-tertiary);
}

#preview {
    flex: 1;
    padding: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    position: relative;
    background: var(--bg-surface);
}

#preview svg {
    max-width: 100%;
    height: auto;
    filter: drop-shadow(0 2px 8px rgba(0, 0, 0, 0.1));
}

.editable-node {
    cursor: pointer !important;
    transition: opacity 0.2s;
}

.node-edit-overlay {
    position: fixed !important;
    background: white;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-3);
    padding: 12px;
    display: flex !important;
    align-items: center;
    gap: 8px;
    z-index: 10000 !important;
    min-width: 220px;
    visibility: visible !important;
}

.node-edit-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 0.2s;
}

.node-edit-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.1);
}

.node-edit-save,
.node-edit-cancel {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.node-edit-save {
    background: var(--primary);
    color: white;
}

.node-edit-save:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.node-edit-cancel {
    background: var(--bg-surface-alt);
    color: var(--text-secondary);
}

.node-edit-cancel:hover {
    background: var(--bg-hover);
}

#renderBtn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 24px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    box-shadow: var(--shadow-1);
    text-transform: none;
    letter-spacing: 0;
}

#renderBtn:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-2);
    transform: translateY(-1px);
}

#renderBtn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-1);
}

#saveBtn, #saveWithNameBtn {
    background: var(--success);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 24px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    box-shadow: var(--shadow-1);
    text-transform: none;
    letter-spacing: 0;
}

#saveBtn:hover, #saveWithNameBtn:hover {
    background: #2d8e47;
    box-shadow: var(--shadow-2);
    transform: translateY(-1px);
}

#saveBtn:active, #saveWithNameBtn:active {
    transform: translateY(0);
    box-shadow: var(--shadow-1);
}

.controls {
    padding: 16px 24px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    gap: 12px;
}

#diagramNameSection {
    padding: 16px 24px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-light);
}

#diagramName {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    transition: all 0.2s;
    font-weight: 400;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
}

#diagramName:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.1);
}

#diagramName::placeholder {
    color: var(--text-tertiary);
}

#diagramNameSection select {
    margin-top: 12px;
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--bg-surface);
    color: var(--text-primary);
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
}

#diagramNameSection select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(66, 133, 244, 0.1);
}

.error-message {
    color: var(--danger);
    padding: 20px;
}

.error-message strong {
    display: block;
    margin-bottom: 10px;
}

.error-message pre {
    background: #fce8e6;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    border-left: 3px solid var(--danger);
}

.header-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ffffff;
    color: var(--text-primary);
    padding: 8px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
    z-index: 1000;
    border-bottom: 1px solid var(--border-light);
    height: 64px;
}

.header-brand {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 22px;
    color: var(--text-primary);
}

.header-logo {
    width: 40px;
    height: 40px;
}

.header-title {
    color: var(--text-primary);
    font-weight: 400;
}

.header-nav {
    display: flex;
    gap: 16px;
    align-items: center;
}

.user-info {
    color: var(--text-secondary);
    font-weight: 400;
    padding: 8px 12px;
    background: var(--bg-surface-alt);
    border-radius: 20px;
    font-size: 14px;
}

.nav-link {
    color: var(--text-primary);
    text-decoration: none;
    font-weight: 400;
    padding: 8px 16px;
    border-radius: 20px;
    transition: all 0.2s;
    font-size: 14px;
}

.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.logout-btn {
    display: none;
    background: var(--danger);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 14px;
    box-shadow: var(--shadow-1);
}

.logout-btn:hover {
    background: #c5221f;
    box-shadow: var(--shadow-2);
    transform: translateY(-1px);
}

.logout-btn:active {
    transform: translateY(0);
}

.placeholder-text {
    color: var(--text-tertiary);
    font-size: 15px;
    text-align: center;
    font-weight: 400;
}

@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr 1fr;
        margin-top: 64px;
        border-radius: 0;
    }

    .editor-panel {
        border-right: none;
        border-bottom: 1px solid var(--border-light);
    }
    
    .header-nav {
        gap: 8px;
        font-size: 13px;
    }
    
    .nav-link {
        font-size: 13px;
        padding: 6px 12px;
    }
    
    .header-brand {
        font-size: 18px;
    }
}
