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

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #242837;
    --bg-hover: #2d3145;
    --text-primary: #e4e6eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --accent-subtle: rgba(59, 130, 246, 0.15);
    --border: #2d3145;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 4px 12px rgba(0,0,0,0.3);
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

/* === Login Page === */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container { width: 100%; max-width: 400px; padding: 1rem; }

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2.5rem 2rem;
    box-shadow: var(--shadow);
}

.login-title {
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    color: var(--accent);
}

.login-subtitle {
    text-align: center;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.form-group { margin-bottom: 1.25rem; }
.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.375rem;
}

.form-group input {
    width: 100%;
    padding: 0.625rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.9375rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus { border-color: var(--accent); }

.error-message {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    margin-bottom: 1rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.15s;
}

.btn-primary {
    width: 100%;
    background: var(--accent);
    color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

/* === App Layout === */
.app-layout {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    height: 48px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.top-bar-left { display: flex; align-items: center; gap: 0.75rem; }
.top-bar-brand { font-weight: 700; color: var(--accent); font-size: 1.1rem; }
.top-bar-right { display: flex; align-items: center; gap: 1rem; }
.top-bar-user { color: var(--text-secondary); font-size: 0.875rem; }

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
    border-radius: var(--radius-sm);
}

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

/* === Panels === */
.panels {
    display: flex;
    flex: 1;
    overflow: hidden;
}

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

.panel-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

/* === ClickUp Panel === */
.panel-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.panel-header h2 { font-size: 0.9375rem; font-weight: 600; }

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.filter-bar select {
    flex: 1 1 0;
    min-width: 0;
    padding: 0.25rem 0.375rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.75rem;
    font-family: var(--font);
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.board-header {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 0.75rem 0.75rem 0.25rem;
    margin-top: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.board-header:first-child { margin-top: 0; }

.board-header-collapsible {
    cursor: pointer;
    user-select: none;
    transition: color 0.1s;
}

.board-header-collapsible:hover { color: var(--text-primary); }

.board-header-fav {
    color: var(--warning);
}

.board-arrow {
    font-size: 0.625rem;
    display: inline-block;
    width: 0.75rem;
}

.star-btn {
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-muted);
    flex-shrink: 0;
    line-height: 1.2;
    transition: color 0.1s;
}

.star-btn:hover { color: var(--warning); }
.star-btn.starred { color: var(--warning); }

.task-item {
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 0.25rem;
    transition: background 0.1s;
}

.task-item:hover { background: var(--bg-hover); }
.task-item.active { background: var(--accent-subtle); border-color: var(--accent); }

.task-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.task-item-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.status-badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

/* === Task Detail Side Panel === */
.task-detail-panel {
    border-top: 2px solid var(--accent);
    display: flex;
    flex-direction: column;
    height: 66.6667%;
    min-height: 120px;
    overflow: hidden;
    flex-shrink: 0;
}

.task-detail-panel.hidden { display: none; }

/* Drag handle to resize task list vs detail panel */
.detail-resizer {
    height: 12px;
    cursor: row-resize;
    background: transparent;
    flex-shrink: 0;
    position: relative;
    transition: background 0.1s;
}

.detail-resizer::before {
    content: '';
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 64px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    transition: background 0.1s;
}

.detail-resizer:hover::before,
.detail-resizer.dragging::before { background: var(--accent); }
.detail-resizer.hidden { display: none; }

body.resizing-detail { cursor: row-resize; user-select: none; }

/* === Task Detail (inside panel) === */
.task-detail {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.task-detail-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.task-detail-title { font-size: 1rem; font-weight: 600; margin-bottom: 0.5rem; }

.task-detail-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.task-detail-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.task-detail-body * { max-width: 100%; }
.task-detail-body img { height: auto; }
.task-detail-body pre { overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
.task-detail-body code { word-break: break-word; }
.task-detail-body a { word-break: break-all; }
.task-detail-body table { display: block; overflow-x: auto; max-width: 100%; }

.task-description {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.comments-section h3 {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-secondary);
}

.comment {
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
}

.comment-author { font-size: 0.75rem; font-weight: 600; color: var(--accent); }
.comment-date { font-size: 0.6875rem; color: var(--text-muted); margin-left: 0.5rem; }
.comment-text {
    font-size: 0.875rem;
    margin-top: 0.375rem;
    color: var(--text-primary);
    word-break: break-word;
    overflow-wrap: anywhere;
}

.comment { min-width: 0; overflow: hidden; }

.comment-input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.comment-input-area textarea {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.875rem;
    resize: none;
    outline: none;
}

.comment-input-area textarea:focus { border-color: var(--accent); }

/* === Chat Panel === */
.chat-header {
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message { max-width: 85%; }
.message-user { align-self: flex-end; }
.message-assistant { align-self: flex-start; }

.message-bubble {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    line-height: 1.6;
    word-break: break-word;
}

.message-user .message-bubble {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: var(--radius-sm);
}

.message-assistant .message-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-bottom-left-radius: var(--radius-sm);
}

.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0;
    font-size: 0.8125rem;
}

.message-bubble th, .message-bubble td {
    padding: 0.375rem 0.625rem;
    border: 1px solid var(--border);
    text-align: left;
}

.message-bubble th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.message-bubble code {
    background: var(--bg-tertiary);
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.8125rem;
}

.message-bubble pre {
    background: var(--bg-tertiary);
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-bubble pre code { background: none; padding: 0; }
.message-bubble strong { font-weight: 600; }
.message-bubble ul, .message-bubble ol { padding-left: 1.5rem; margin: 0.5rem 0; }

.tool-activity {
    font-size: 0.8125rem;
    color: var(--text-muted);
    padding: 0.25rem 0;
    font-style: italic;
}

.tool-activity.active { color: var(--warning); }

.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 0.5rem 0;
}

.typing-indicator span {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

.chat-input-area {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 0.5rem;
    flex-shrink: 0;
}

.chat-input-area textarea {
    flex: 1;
    padding: 0.625rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9375rem;
    resize: none;
    outline: none;
    max-height: 120px;
}

.chat-input-area textarea:focus { border-color: var(--accent); }

.btn-send {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 0.5rem 1rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    align-self: flex-end;
}
.btn-send:hover { background: var(--accent-hover); }
.btn-send:disabled { opacity: 0.5; cursor: not-allowed; }

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

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 440px;
    margin: 1rem;
    display: flex;
    flex-direction: column;
}

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

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

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
}
.modal-close:hover { color: var(--text-primary); }

.modal-body {
    padding: 1.25rem;
    font-size: 0.9375rem;
    color: var(--text-secondary);
}

.modal-status { font-size: 0.875rem; }
.modal-status.success { color: var(--success); }
.modal-status.error { color: var(--danger); }

/* === Utility === */
.hidden { display: none !important; }

.loading-spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* === Scrollbars === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-tertiary); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border); }

/* === Responsive === */
@media (max-width: 1100px) {
    .panel-left { width: 100%; min-width: 0; border-right: none; }
    .panels { flex-direction: column; }
    .panel-right { border-top: 1px solid var(--border); }
}
