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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    height: 100vh;
    overflow: hidden;
    color: #333;
}

#app {
    display: flex;
    height: 100vh;
}

aside#sidebar {
    width: 240px;
    min-width: 240px;
    background: #1e1e2e;
    color: #cdd6f4;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #313244;
}

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

.sidebar-header h1 {
    font-size: 18px;
    font-weight: 600;
}

.sidebar-header button {
    background: #89b4fa;
    color: #1e1e2e;
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
}

#site-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

#site-list li {
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 2px;
}

#site-list li:hover {
    background: #313244;
}

#site-list li.active {
    background: #45475a;
    color: #fff;
}

#site-list li .slug {
    display: block;
    font-size: 11px;
    color: #6c7086;
    margin-top: 2px;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid #313244;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-footer-row {
    display: flex;
    gap: 6px;
}

.sidebar-footer-row button {
    flex: 1;
    padding: 7px;
    background: #313244;
    color: #cdd6f4;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.sidebar-footer-row button:hover {
    background: #45475a;
}

.sidebar-footer > button {
    width: 100%;
    padding: 8px;
    background: #313244;
    color: #cdd6f4;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.sidebar-footer > button:hover {
    background: #45475a;
}

main#workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #f8f9fa;
    overflow: hidden;
}

#empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #888;
    font-size: 16px;
}

.hidden { display: none !important; }

#site-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

#site-header h2 {
    font-size: 16px;
    font-weight: 600;
}

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

.header-actions button, .header-actions a, .panel-actions button {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    text-decoration: none;
    color: #333;
    display: inline-block;
}

.header-actions button:hover, .header-actions a:hover, .panel-actions button:hover {
    background: #f0f0f0;
}

#btn-delete-site {
    color: #e74c3c;
    border-color: #e74c3c;
}

#site-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

#file-panel {
    width: 280px;
    min-width: 280px;
    border-right: 1px solid #e0e0e0;
    background: #fff;
    display: flex;
    flex-direction: column;
}

#file-panel.drop-active {
    background: #e3f2fd;
    outline: 2px dashed #1976d2;
    outline-offset: -4px;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    font-size: 13px;
    font-weight: 500;
}

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

#file-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 4px;
}

#file-list li {
    padding: 8px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#file-list li:hover {
    background: #f0f0f0;
}

#file-list li .icon {
    font-size: 14px;
    width: 16px;
    text-align: center;
}

#file-list li .name { flex: 1; }

#file-list li .icon.loading {
    color: transparent;
    position: relative;
    display: inline-block;
}

#file-list li .icon.loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 12px;
    margin: -6px 0 0 -6px;
    border: 2px solid #ccc;
    border-top-color: #666;
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to { transform: rotate(360deg); }
}

#file-list li .delete-btn {
    opacity: 0;
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
}

#file-list li:hover .delete-btn { opacity: 1; }

#editor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #fff;
}

#editor {
    flex: 1;
    padding: 12px;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 13px;
    border: none;
    resize: none;
    outline: none;
    line-height: 1.5;
}

#preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

#site-iframe {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
}

#env-view {
    padding: 20px;
    overflow-y: auto;
    height: 100%;
}

#env-view header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

#env-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.env-row {
    display: flex;
    gap: 8px;
    align-items: center;
}

.env-row input {
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.env-row input.env-key { width: 200px; }
.env-row input.env-value { flex: 1; }

.env-row button {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 16px;
    padding: 4px 8px;
}

dialog {
    border: none;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 4px 24px rgba(0,0,0,0.15);
    max-width: 400px;
    width: 90%;
}

dialog::backdrop {
    background: rgba(0,0,0,0.4);
}

dialog h3 {
    margin-bottom: 16px;
}

dialog label {
    display: block;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 500;
}

dialog input {
    display: block;
    width: 100%;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 16px;
}

.dialog-actions button {
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
}

#btn-cancel-site {
    background: #f0f0f0;
    border: 1px solid #ddd;
}

#btn-confirm-site, #btn-conflict-reuse {
    background: #89b4fa;
    border: none;
    color: #1e1e2e;
    font-weight: 500;
}

#btn-conflict-reset {
    background: #f38ba8;
    border: none;
    color: #1e1e2e;
    font-weight: 500;
}

#dialog-conflict p {
    margin-bottom: 16px;
    font-size: 14px;
    color: #555;
}

#chat-panel {
    width: 380px;
    min-width: 380px;
    border-left: 1px solid #e0e0e0;
    background: #fff;
    display: flex;
    flex-direction: column;
}

#preview-panel.hidden ~ #editor-panel.hidden ~ #chat-panel {
    flex: 1;
    width: auto;
    min-width: 0;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    user-select: text;
    -webkit-user-select: text;
}

.chat-msg {
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.4;
    max-width: 90%;
    word-wrap: break-word;
    white-space: pre-wrap;
    user-select: text;
    -webkit-user-select: text;
}

.chat-msg::selection {
    background: #2563eb;
    color: #fff;
}

.chat-msg::-moz-selection {
    background: #2563eb;
    color: #fff;
}

.chat-user {
    background: #89b4fa;
    color: #1e1e2e;
    align-self: flex-end;
}

.chat-assistant {
    background: #f0f0f0;
    color: #333;
    align-self: flex-start;
}

.chat-tool-call {
    background: #e8e8e8;
    color: #666;
    font-size: 11px;
    font-family: monospace;
    align-self: flex-start;
    border-left: 3px solid #89b4fa;
}

.chat-tool-result {
    background: #f8f8f8;
    color: #888;
    font-size: 11px;
    font-family: monospace;
    align-self: flex-start;
    border-left: 3px solid #a6e3a1;
}

.chat-assistant.markdown-body p { margin: 0 0 0.5em; }
.chat-assistant.markdown-body p:last-child { margin-bottom: 0; }
.chat-assistant.markdown-body pre { background: #1e1e2e; color: #cdd6f4; padding: 8px; border-radius: 4px; overflow-x: auto; font-size: 12px; }
.chat-assistant.markdown-body code { background: #e0e0e0; padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.chat-assistant.markdown-body pre code { background: none; padding: 0; }
.chat-assistant.markdown-body ul, .chat-assistant.markdown-body ol { margin: 0.3em 0; padding-left: 1.5em; }
.chat-assistant.markdown-body h1, .chat-assistant.markdown-body h2, .chat-assistant.markdown-body h3 { margin: 0.4em 0 0.2em; font-size: 1em; }

.chat-loading {
    background: transparent;
    color: #888;
    font-style: italic;
    align-self: flex-start;
}

#chat-provider-bar {
    padding: 6px 12px 0;
}

#chat-provider-select {
    width: 100%;
    padding: 4px 8px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 12px;
    background: #fafafa;
}

#chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid #e0e0e0;
}

#chat-input {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    resize: none;
    outline: none;
    font-family: inherit;
}

#btn-send-chat {
    padding: 8px 16px;
    background: #89b4fa;
    color: #1e1e2e;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    font-size: 13px;
}

#btn-send-chat:hover {
    background: #74a8f7;
}

#btn-send-chat.stop-btn {
    background: #f38ba8;
    font-size: 16px;
    line-height: 1;
}

#btn-send-chat.stop-btn:hover {
    background: #e06c8a;
}

#config-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#config-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

#config-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.config-tabs {
    display: flex;
    gap: 0;
    padding: 0 20px;
    background: #fff;
    border-bottom: 1px solid #e0e0e0;
}

.config-tab {
    padding: 10px 20px;
    border: none;
    background: none;
    font-size: 13px;
    font-weight: 500;
    color: #666;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}

.config-tab:hover {
    color: #333;
}

.config-tab.active {
    color: #333;
    border-bottom-color: #89b4fa;
}

.config-tab-content {
    display: none;
}

.config-tab-content.active {
    display: block;
}

.config-form {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}

.config-section {
    margin-bottom: 24px;
}

.config-section h3 {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #555;
}

.ai-providers-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.ai-providers-header h3 {
    margin-bottom: 0;
}

.ai-providers-header button {
    padding: 4px 10px;
    border: 1px solid #89b4fa;
    border-radius: 4px;
    background: #fff;
    color: #333;
    font-size: 12px;
    cursor: pointer;
}

.ai-provider-item {
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 12px;
    background: #fafafa;
}

.ai-provider-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

.ai-provider-header input {
    flex: 1;
    font-weight: 600;
}

.ai-provider-header button {
    background: none;
    border: none;
    color: #e74c3c;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 6px;
}

.config-section label {
    display: block;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 500;
}

.config-section input:not([type="checkbox"]) {
    display: block;
    width: 100%;
    max-width: 400px;
    margin-top: 4px;
    padding: 8px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
}

.config-section .hint {
    font-size: 12px;
    color: #888;
    margin-top: -8px;
    margin-bottom: 12px;
}

/* Cron Panel */
#cron-panel {
    width: 400px;
    min-width: 350px;
    border-left: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    background: #fafafa;
}

#cron-content {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.cron-job-item {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 12px;
    margin-bottom: 8px;
}

.cron-job-info {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.cron-job-info strong {
    font-size: 13px;
}

.cron-schedule {
    font-family: monospace;
    font-size: 12px;
    color: #666;
    background: #f0f0f0;
    padding: 1px 6px;
    border-radius: 3px;
}

.cron-type {
    font-size: 11px;
    color: #fff;
    background: #6b7280;
    padding: 1px 5px;
    border-radius: 3px;
}

.cron-job-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.cron-job-actions button {
    font-size: 11px;
    padding: 2px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
}

.cron-job-actions button:hover {
    background: #f0f0f0;
}

.cron-job-actions button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.cron-job-status {
    font-size: 12px;
    margin-top: 6px;
    padding: 4px 8px;
    border-radius: 4px;
}

.cron-job-status.running {
    color: #2563eb;
    background: #eff6ff;
}

.cron-job-status.success {
    color: #16a34a;
    background: #f0fdf4;
}

.cron-job-status.failed {
    color: #dc2626;
    background: #fef2f2;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    cursor: pointer;
}

#cron-logs-section {
    margin-top: 16px;
    border-top: 1px solid #e0e0e0;
    padding-top: 12px;
}

#cron-logs-section h4 {
    font-size: 13px;
    margin: 0 0 8px 0;
    color: #555;
}

.cron-log-item {
    font-size: 12px;
    padding: 6px 8px;
    margin-bottom: 4px;
    border-radius: 4px;
    border-left: 3px solid #ccc;
}

.cron-log-item.log-ok {
    border-left-color: #22c55e;
    background: #f0fdf4;
}

.cron-log-item.log-error {
    border-left-color: #ef4444;
    background: #fef2f2;
}

.log-time {
    color: #888;
    font-size: 11px;
}

.log-status {
    font-size: 11px;
    font-weight: 500;
}

.log-summary {
    color: #555;
    font-size: 11px;
    margin-top: 2px;
    white-space: pre-wrap;
    word-break: break-all;
}

/* Users */
.user-filter {
    margin-bottom: 12px;
}

.user-filter input {
    width: 100%;
    max-width: 300px;
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.user-batch-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-size: 13px;
}

.user-batch-bar button {
    padding: 4px 10px;
    border: 1px solid #ddd;
    border-radius: 3px;
    background: #fff;
    cursor: pointer;
    font-size: 12px;
}

.user-batch-bar button.danger {
    color: #e74c3c;
    border-color: #e74c3c;
}

.user-batch-bar button:hover {
    background: #f0f0f0;
}

#user-batch-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 8px;
    padding: 4px 10px;
    background: #f0f4ff;
    border: 1px solid #89b4fa;
    border-radius: 4px;
}

.user-checkbox {
    width: 13px;
    height: 13px;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.user-checkbox-placeholder {
    display: inline-block;
    width: 13px;
    height: 13px;
    flex-shrink: 0;
    text-align: center;
    line-height: 13px;
    color: #ccc;
}

.user-checkbox-placeholder::after {
    content: "\26D4";
    font-size: 10px;
}

.user-add-form {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    align-items: center;
}

.user-add-form input, .user-add-form select {
    padding: 6px 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
}

.user-add-form input[type="text"] { width: 140px; }
.user-add-form input[type="password"] { width: 140px; }

.user-add-form button {
    padding: 6px 12px;
    background: #89b4fa;
    color: #1e1e2e;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
}

.user-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    font-size: 13px;
}

.user-item .user-name { font-weight: 500; min-width: 100px; }
.user-item .user-role { color: #666; font-size: 12px; background: #f0f0f0; padding: 2px 6px; border-radius: 3px; }
.user-item .user-role.admin { background: #89b4fa; color: #1e1e2e; }
.user-item button {
    background: none;
    border: none;
    color: #e74c3c;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
}

.user-item .user-disable-btn,
.user-item .user-enable-btn {
    font-size: 11px;
    padding: 2px 8px;
    border: 1px solid #ddd;
    border-radius: 3px;
    cursor: pointer;
    margin-left: auto;
}

.user-item .user-disable-btn {
    color: #e74c3c;
    border-color: #e74c3c;
}

.user-item .user-enable-btn {
    color: #22c55e;
    border-color: #22c55e;
}

.user-item.user-disabled {
    opacity: 0.5;
}

.user-role-select {
    padding: 2px 6px;
    font-size: 12px;
    border: 1px solid #ddd;
    border-radius: 3px;
}

#dialog-export,
#dialog-import {
    margin: auto;
    max-width: 460px;
    width: 90%;
}

.dialog-checklist {
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid #eee;
    border-radius: 4px;
    padding: 8px;
    margin-bottom: 12px;
}

.dialog-checklist .checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    font-size: 13px;
    cursor: pointer;
}

.dialog-checklist .checkbox-label input {
    width: auto;
    margin: 0;
}

label.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 8px;
    cursor: pointer;
}

label.checkbox-label input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.file-upload-label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    border: 2px dashed #ddd;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    color: #666;
    margin-bottom: 8px;
}

.file-upload-label:hover {
    border-color: #89b4fa;
    color: #333;
}

#import-step-upload.drag-over .file-upload-label {
    border-color: #89b4fa;
    background: #f0f4ff;
    color: #333;
}

.file-upload-label input[type="file"] {
    display: none;
}

.import-status {
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 13px;
    margin-top: 8px;
}

.import-status.running {
    background: #eff6ff;
    color: #2563eb;
}

.import-status.success {
    background: #f0fdf4;
    color: #16a34a;
}

.import-status.failed {
    background: #fef2f2;
    color: #dc2626;
}

#dialog-cron-job {
    margin: auto;
    max-width: 520px;
    width: 95%;
    padding: 28px 32px;
}

#dialog-cron-job h3 {
    font-size: 16px;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid #eee;
}

#dialog-cron-job form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#dialog-cron-job label {
    display: flex;
    flex-direction: column;
    font-size: 13px;
    font-weight: 500;
    color: #444;
}

#dialog-cron-job input,
#dialog-cron-job select {
    margin-top: 6px;
    padding: 9px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.15s;
}

#dialog-cron-job input:focus,
#dialog-cron-job select:focus,
#dialog-cron-job textarea:focus {
    outline: none;
    border-color: #89b4fa;
}

#dialog-cron-job textarea {
    margin-top: 6px;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 13px;
    font-family: "JetBrains Mono", "Fira Code", monospace;
    resize: vertical;
    min-height: 120px;
    line-height: 1.5;
}

#dialog-cron-job .hint {
    font-size: 12px;
    color: #888;
    margin-top: -6px;
}

#dialog-cron-job .dialog-actions {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #eee;
}
