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

:root {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d30;
    --text-primary: #cccccc;
    --text-secondary: #808080;
    --accent: #007acc;
    --accent-hover: #0098ff;
    --border: #3e3e42;
    --success: #4ec9b0;
    --warning: #ce9178;
    --error: #f48771;
}

html.light-theme,
body.light-theme {
    --bg-primary: #ffffff;
    --bg-secondary: #f3f3f3;
    --bg-tertiary: #e8e8e8;
    --text-primary: #1e1e1e;
    --text-secondary: #6e6e6e;
    --border: #d4d4d4;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: 48px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    overflow: hidden;
}

.header-right {
    display: flex;
    gap: 8px;
}

.logo-link {
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 6px;
    transition: all 0.2s;
}

.logo-link:hover {
    background: var(--bg-tertiary);
}

.logo {
    width: 28px;
    height: 28px;
}

/* Tabs */
.tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
    flex: 1;
    scrollbar-width: none;
}

.tabs::-webkit-scrollbar {
    display: none;
}

.tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    font-size: 13px;
}

.tab:hover {
    background: var(--bg-primary);
}

.tab.active {
    background: var(--bg-primary);
    border: 1px solid var(--accent);
}

.tab-name {
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tab-modified {
    color: var(--warning);
}

.tab-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0 4px;
    font-size: 16px;
}

.tab-close:hover {
    color: var(--error);
}

/* Buttons */
.btn, .btn-small {
    background: none;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn:hover, .btn-small:hover {
    background: var(--bg-tertiary);
}

.btn-small {
    padding: 4px;
}

.btn-primary {
    background: var(--accent);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
}

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

.btn-primary:disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
}

/* Two-Panel Layout */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.left-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-right: 1px solid var(--border);
}

.right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: all 0.3s;
    position: relative;
}

.right-panel.collapsed {
    flex: 0 0 0;
    min-width: 0;
    overflow: hidden;
}

.panel-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 8px;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
    pointer-events: none;
}

.right-panel:hover .panel-actions {
    opacity: 1;
    pointer-events: all;
}

.panel-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.panel-action-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 122, 204, 0.4);
}

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

.editor {
    flex: 1;
    width: 100%;
    height: 100%;
}

/* Smart Panel - Match Monaco Editor EXACTLY for synchronized scrolling */
.panel-content {
    flex: 1;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 0;
    margin: 0;
    background: var(--bg-primary);
    /* Exact Monaco padding */
    padding-top: 4px;
    padding-left: 70px; /* Match Monaco gutter */
    padding-right: 30px; /* Match Monaco scrollbar space */
}

.panel-empty,
.panel-loading,
.panel-error,
.panel-info {
    padding: 0;
    margin: 0;
    color: var(--text-secondary);
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    line-height: 19px;
    white-space: pre-wrap;
}

.panel-error {
    color: var(--error);
}

.panel-info {
    color: var(--accent);
}


/* Markdown Content - EXACTLY Match Monaco for scroll sync */
.markdown-content {
    color: var(--text-primary);
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    line-height: 19px;
    margin: 0;
    padding: 0;
}

.markdown-content h1,
.markdown-content h2,
.markdown-content h3 {
    color: var(--accent);
    margin: 0;
    padding: 0;
    font-weight: 600;
    line-height: 19px;
}

.markdown-content h1 { font-size: 21px; line-height: 38px; }
.markdown-content h2 { font-size: 18px; line-height: 38px; }
.markdown-content h3 { font-size: 16px; line-height: 28px; }

.markdown-content p {
    margin: 0;
    padding: 0;
    white-space: pre-wrap;
    line-height: 19px;
}

.markdown-content code {
    background: var(--bg-tertiary);
    padding: 0 4px;
    border-radius: 2px;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 14px;
}

.markdown-content pre {
    background: var(--bg-tertiary);
    padding: 0;
    overflow-x: auto;
    margin: 0;
    line-height: 19px;
}

.markdown-content ul,
.markdown-content ol {
    padding-left: 20px;
    margin: 0;
    line-height: 19px;
}

.markdown-content li {
    line-height: 19px;
    margin: 0;
    padding: 0;
}

.markdown-content blockquote {
    border-left: 2px solid var(--accent);
    padding-left: 12px;
    margin: 0;
    line-height: 19px;
    color: var(--text-secondary);
}

/* Smart Analysis - EXACTLY Match Monaco for scroll sync */
.smart-analysis {
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 14px;
    line-height: 19px;
    margin: 0;
    padding: 0;
    animation: fadeIn 0.3s ease-in;
}

.smart-analysis.streaming {
    opacity: 0.8;
}

.smart-analysis.streaming::after {
    content: '▊';
    animation: blink 1s infinite;
    color: var(--accent);
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* Status Bar */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 16px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-secondary);
    height: 24px;
}

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

.ai-status {
    color: var(--text-secondary);
    font-weight: 400;
    font-size: 11px;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ai-status::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all 0.3s;
}

/* Different states */
.ai-status.idle::before {
    background: var(--text-secondary);
}

.ai-status.waiting::before {
    background: var(--warning);
}

.ai-status.active::before {
    background: var(--accent);
    animation: pulse 1.5s ease-in-out infinite;
}

.ai-status.streaming::before {
    background: var(--success);
    animation: pulse 0.8s ease-in-out infinite;
}

.ai-status.error::before {
    background: var(--error);
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.3); }
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-header h2 {
    font-size: 18px;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 28px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
}

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

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
}

.setting-group {
    margin-bottom: 20px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    font-size: 14px;
}

.setting-group input[type="text"],
.setting-group input[type="password"],
.setting-group input[type="number"],
.setting-group select,
.setting-group textarea {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 10px;
    font-family: inherit;
    font-size: 14px;
}

.setting-group textarea {
    resize: vertical;
    min-height: 80px;
}

.setting-group input:focus,
.setting-group select:focus,
.setting-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-group small {
    display: block;
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 12px;
}

.setting-group small a {
    color: var(--accent);
    text-decoration: none;
}

.setting-group small a:hover {
    text-decoration: underline;
}

.setting-group input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

/* Command Palette */
.command-palette {
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 90%;
    max-width: 600px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

#commandInput {
    width: 100%;
    background: var(--bg-tertiary);
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
    padding: 16px;
    font-family: inherit;
    font-size: 16px;
}

#commandInput:focus {
    outline: none;
}

.command-list {
    max-height: 400px;
    overflow-y: auto;
}

.command-item {
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.command-item:hover,
.command-item.selected {
    background: var(--bg-tertiary);
}

.command-name {
    font-weight: 500;
}

.command-shortcut {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Monaco Error Decorations */
.inline-error {
    border-bottom: 2px wavy var(--error);
}

.error-glyph {
    background: var(--error);
    width: 4px !important;
    margin-left: 3px;
}

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

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

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 5px;
}

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