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

:root {
    --bg: #0d1117;
    --surface: #161b22;
    --surface2: #1c2333;
    --border: #30363d;
    --text: #e6edf3;
    --text-dim: #8b949e;
    --accent: #58a6ff;
    --green: #3fb950;
    --yellow: #d29922;
    --red: #f85149;
    --purple: #bc8cff;
}

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

/* Layout */
.app {
    display: flex;
    height: 100vh;
    position: relative;
}
.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: margin-left 0.25s ease, opacity 0.25s ease;
    margin-left: -320px; /* collapsed by default */
    position: relative;
    z-index: 20;
}
.sidebar.open {
    margin-left: 0;
}
.sidebar-overlay {
    display: none;
}
.sidebar-close {
    display: none;
}
.sidebar-toggle {
    font-size: 18px;
    padding: 4px 8px;
}
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

/* Header */
.header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.header h1 {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}
.stats {
    display: flex;
    gap: 16px;
    font-size: 13px;
    color: var(--text-dim);
}
.stats .num { font-weight: 600; }
.stats .num.green { color: var(--green); }
.stats .num.yellow { color: var(--yellow); }
.stats .num.red { color: var(--red); }

/* Sidebar */
.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.session-item {
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    margin-bottom: 4px;
    transition: background 0.15s;
}
.session-item:hover {
    background: var(--surface2);
}
.session-item.active {
    background: var(--surface2);
    border-color: var(--accent);
}
.session-item .name {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 4px;
}
.session-item .meta {
    font-size: 12px;
    color: var(--text-dim);
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge.idle { background: #30363d; color: var(--text-dim); }
.badge.running { background: #1b3a2d; color: var(--green); }
.badge.paused { background: #3d2e00; color: var(--yellow); }
.badge.pending { background: #1c2333; color: var(--accent); }
.badge.completed { background: #1b3a2d; color: var(--green); }
.badge.failed { background: #3d1418; color: var(--red); }

/* Main content */
.main-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: var(--text-dim);
    font-size: 15px;
}
.task-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.task-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.task-header h2 {
    font-size: 16px;
    font-weight: 600;
}
.session-actions {
    display: flex;
    gap: 8px;
}

/* Task input */
.task-input-area {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}
.task-input-row {
    display: flex;
    gap: 8px;
}
.task-input-row textarea {
    flex: 1;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    padding: 10px 14px;
    font-family: inherit;
    font-size: 14px;
    resize: vertical;
    min-height: 42px;
    max-height: 200px;
}
.task-input-row textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.task-input-row textarea::placeholder {
    color: var(--text-dim);
}

/* Task list */
.task-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    padding: 12px 20px;
}
.task-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin-bottom: 10px;
}
.task-item-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}
.task-prompt {
    font-size: 14px;
    font-weight: 500;
    word-break: break-word;
}
.task-time {
    font-size: 11px;
    color: var(--text-dim);
    white-space: nowrap;
}
.task-result {
    background: var(--bg);
    border-radius: 6px;
    padding: 12px;
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 60vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    margin-top: 8px;
    color: var(--text-dim);
}
.task-result.error {
    border-left: 3px solid var(--red);
    color: var(--red);
}
.task-actions {
    margin-top: 8px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--surface2); }
.btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.9; }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: #3d1418; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon {
    padding: 6px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    border-radius: 6px;
}
.btn-icon:hover { background: var(--surface2); color: var(--text); }

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    width: 90%;
    max-width: 480px;
}
.modal h3 {
    font-size: 16px;
    margin-bottom: 16px;
}
.modal label {
    display: block;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 4px;
    margin-top: 12px;
}
.modal input, .modal select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
}
.modal input:focus, .modal select:focus {
    outline: none;
    border-color: var(--accent);
}
.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

/* Goal banner */
.goal-banner {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: rgba(188, 140, 255, 0.06);
    border-left: 3px solid var(--purple);
}
.goal-banner-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}
.goal-banner-header .goal-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--purple);
}
.goal-banner .goal-condition {
    font-size: 13px;
    color: var(--text);
    margin-bottom: 6px;
    word-break: break-word;
}
.goal-banner .goal-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    font-size: 12px;
    color: var(--text-dim);
    flex-wrap: wrap;
}
.goal-banner .goal-assessment {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 6px;
    font-style: italic;
}
.goal-set-btn {
    padding: 8px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
}
.badge.active-goal { background: rgba(188, 140, 255, 0.15); color: var(--purple); }
.badge.paused-goal { background: #3d2e00; color: var(--yellow); }

/* Goal log modal */
.goal-log {
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 12px;
}
.goal-log-item {
    background: var(--bg);
    border-radius: 6px;
    padding: 12px;
    margin-bottom: 8px;
    font-size: 13px;
}
.goal-log-item .iter-num {
    font-weight: 600;
    color: var(--purple);
    margin-bottom: 4px;
}
.goal-log-item .iter-prompt {
    color: var(--accent);
    margin-bottom: 4px;
    word-break: break-word;
}
.goal-log-item .iter-assessment {
    color: var(--text-dim);
    font-style: italic;
}
.goal-log-item .iter-tokens {
    font-size: 11px;
    color: var(--text-dim);
    margin-top: 4px;
}
.modal textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 8px 12px;
    font-size: 14px;
    font-family: inherit;
    resize: vertical;
    min-height: 60px;
}
.modal textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.stats .num.purple { color: var(--purple); }

/* Spinner */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 300px;
        min-width: 300px;
        margin-left: -300px;
        z-index: 200;
        border-right: 1px solid var(--border);
        box-shadow: 4px 0 24px rgba(0,0,0,0.5);
    }
    .sidebar.open {
        margin-left: 0;
    }
    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 150;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.25s ease;
    }
    .sidebar-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }
    .sidebar-close {
        display: inline-flex;
        font-size: 18px;
    }
    .main {
        flex: 1;
        overflow: visible;
        min-height: 0;
    }
    .task-panel {
        overflow: visible;
    }
    .task-list {
        overflow-y: visible;
        max-height: none;
    }
    .task-result {
        max-height: none;
    }
    .header h1 { font-size: 14px; }
}

/* Desktop: hide stats on narrow screens */
@media (max-width: 900px) {
    .stats { display: none; }
}
