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

:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f7;
    --bg-tertiary: #eeeef2;
    --bg-hover: #e8e8ee;
    --bg-active: #dddde5;
    --bg-input: #ffffff;
    --border: #d8d8e0;
    --border-light: #c8c8d4;
    --text: #1a1a2e;
    --text-secondary: #555570;
    --text-muted: #8888a0;
    --accent: #6366f1;
    --accent-hover: #4f46e5;
    --accent-soft: rgba(99, 102, 241, 0.1);
    --success: #16a34a;
    --success-soft: rgba(22, 163, 74, 0.1);
    --error: #dc2626;
    --error-soft: rgba(220, 38, 38, 0.08);
    --warning: #d97706;
    --warning-soft: rgba(217, 119, 6, 0.1);
    --radius: 8px;
    --radius-sm: 4px;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', sans-serif;
    --header-h: 48px;
    --tab-h: 40px;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text);
    font-size: 13px;
    line-height: 1.5;
}

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

#top-bar {
    height: var(--header-h);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
    z-index: 100;
}

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

.top-left { flex: 1; }
.top-center { flex: 0; }
.top-right { flex: 1; justify-content: flex-end; }

.logo-text {
    font-weight: 800;
    font-size: 16px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-right: 12px;
}

.top-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

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

.accent-btn {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.accent-btn:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
    color: #fff;
}

.success-btn {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}

.success-btn:hover {
    background: #16a34a;
    border-color: #16a34a;
    color: #fff;
}

#status-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-idle { background: var(--text-muted); }
.dot-working { background: var(--accent); animation: pulse 1s ease infinite; }
.dot-success { background: var(--success); }
.dot-error { background: var(--error); }

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

#main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#left-panel {
    width: 420px;
    min-width: 300px;
    max-width: 600px;
    display: flex;
    flex-direction: column;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
}

#resize-handle {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background 0.2s;
}

#resize-handle:hover, #resize-handle.active {
    background: var(--accent);
}

#right-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-primary);
}

#prompt-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#prompt-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

#prompt-actions {
    display: flex;
    gap: 6px;
}

.pill-btn {
    padding: 4px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all 0.15s;
}

.pill-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
}

.pill-btn.active-pill {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-msg {
    max-width: 100%;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.6;
    word-break: break-word;
}

.chat-msg.user {
    background: var(--accent-soft);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--text);
    align-self: flex-end;
}

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

.chat-msg.success {
    background: var(--success-soft);
    border: 1px solid rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.chat-msg.error {
    background: var(--error-soft);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: var(--error);
}

.chat-msg.info {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
}

.chat-msg h4 {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.8;
}

.chat-msg pre {
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 8px;
    margin-top: 6px;
    font-family: var(--font-mono);
    font-size: 11px;
    overflow-x: auto;
    white-space: pre-wrap;
    max-height: 200px;
    overflow-y: auto;
}

.chat-msg ul {
    margin: 4px 0 4px 16px;
    font-size: 12px;
}

.chat-welcome {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.chat-welcome h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.chat-welcome p {
    font-size: 13px;
    max-width: 300px;
    margin: 0 auto;
}

#prompt-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#prompt-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 10px 12px;
    font-family: var(--font-sans);
    font-size: 13px;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    min-height: 44px;
    max-height: 150px;
}

#prompt-input:focus {
    border-color: var(--accent);
}

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

#prompt-controls {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
}

.send-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.send-button:hover { background: var(--accent-hover); }
.send-button:disabled { opacity: 0.4; cursor: not-allowed; }

#right-tabs {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    height: var(--tab-h);
    flex-shrink: 0;
    padding: 0 8px;
    gap: 2px;
    align-items: flex-end;
}

.tab-btn {
    padding: 8px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.tab-btn:hover {
    color: var(--text-secondary);
}

.tab-btn.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.tab-badge {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
}

#right-content {
    flex: 1;
    overflow: hidden;
    position: relative;
}

.tab-pane {
    display: none;
    position: absolute;
    inset: 0;
    overflow-y: auto;
}

.tab-pane.active {
    display: block;
}

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

.empty-state h3 {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 13px;
    max-width: 300px;
    text-align: center;
}

.empty-icon {
    opacity: 0.3;
}

#code-viewer {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#code-filepath {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-secondary);
}

#code-toggle {
    display: flex;
    gap: 2px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.toggle-btn {
    padding: 3px 10px;
    font-size: 11px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.toggle-btn.active {
    background: var(--accent);
    color: #fff;
}

#code-content {
    flex: 1;
    overflow: auto;
    padding: 16px;
    margin: 0;
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.7;
    background: var(--bg-primary);
    color: var(--text);
    tab-size: 4;
}

#code-content code {
    display: block;
    white-space: pre;
}

.code-line {
    display: flex;
}

.line-num {
    display: inline-block;
    width: 40px;
    text-align: right;
    padding-right: 16px;
    color: var(--text-muted);
    user-select: none;
    flex-shrink: 0;
}

.line-text {
    flex: 1;
    white-space: pre;
}

#file-tree-panel {
    padding: 8px;
}

.tree-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    transition: all 0.1s;
    white-space: nowrap;
}

.tree-item:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.tree-item.active {
    background: var(--accent-soft);
    color: var(--accent);
}

.tree-item.dir {
    color: var(--text);
    font-weight: 500;
}

.tree-icon {
    flex-shrink: 0;
    opacity: 0.6;
}

.tree-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-size {
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
}

#changes-content {
    padding: 16px;
}

.change-group {
    margin-bottom: 16px;
}

.change-group h4 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.change-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.1s;
}

.change-file:hover {
    background: var(--bg-hover);
}

.change-badge {
    font-size: 9px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
    flex-shrink: 0;
}

.badge-added { background: var(--success-soft); color: var(--success); }
.badge-modified { background: var(--warning-soft); color: var(--warning); }
.badge-deleted { background: var(--error-soft); color: var(--error); }

.diff-block {
    margin-top: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.diff-label {
    padding: 4px 10px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.diff-label-before { background: var(--error-soft); color: var(--error); }
.diff-label-after { background: var(--success-soft); color: var(--success); }

.diff-lines {
    padding: 8px 12px;
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.6;
    overflow-x: auto;
    background: var(--bg-primary);
}

.diff-line-num {
    display: inline-block;
    width: 30px;
    text-align: right;
    margin-right: 12px;
    color: var(--text-muted);
    user-select: none;
}

.verifier-section {
    margin-top: 16px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
}

.verifier-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
}

.v-pass { background: var(--success-soft); color: var(--success); }
.v-fail { background: var(--error-soft); color: var(--error); }

.check-list {
    margin-top: 8px;
    font-size: 12px;
}

.check-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
}

.check-icon { font-size: 14px; flex-shrink: 0; }

#db-content {
    padding: 16px;
}

.db-table {
    margin-bottom: 20px;
}

.db-table h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.db-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    font-family: var(--font-mono);
}

.db-grid th {
    text-align: left;
    padding: 6px 10px;
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.db-grid td {
    padding: 5px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.db-grid tr:hover td {
    background: var(--bg-hover);
}

.status-pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.sp-uploaded { background: var(--accent-soft); color: var(--accent); }
.sp-built { background: var(--warning-soft); color: var(--warning); }
.sp-blocked { background: var(--error-soft); color: var(--error); }
.sp-approved { background: var(--success-soft); color: var(--success); }

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 480px;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
}

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

.modal-header h3 {
    font-size: 14px;
    font-weight: 600;
}

.close-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
}

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

.modal-body {
    overflow-y: auto;
    padding: 8px;
}

.ws-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.1s;
}

.ws-item:hover {
    background: var(--bg-hover);
}

.ws-item.active {
    background: var(--accent-soft);
}

.ws-info {
    flex: 1;
    min-width: 0;
}

.ws-name {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.ws-delete-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    opacity: 0;
    transition: all 0.15s;
}

.ws-item:hover .ws-delete-btn {
    opacity: 1;
}

.ws-delete-btn:hover {
    background: var(--error-soft);
    color: var(--error);
}

#preview-container {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#preview-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 8px;
}

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

.preview-tool-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-primary);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    flex-shrink: 0;
}

.preview-tool-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border-light);
}

.preview-url-bar {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 300px;
}

@media (max-width: 800px) {
    #main-layout {
        flex-direction: column;
    }
    #left-panel {
        width: 100% !important;
        max-width: none;
        height: 40%;
    }
    #resize-handle {
        display: none;
    }
    #right-panel {
        height: 60%;
    }
}

.mode-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-right: 6px;
    vertical-align: middle;
}

.mode-fast {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

.mode-smart {
    background: #e3f2fd;
    color: #1565c0;
    border: 1px solid #90caf9;
}
