/* Captain Claw — Sessions Browser */

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-hover: #30363d;
    --border: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79c0ff;
    --green: #3fb950;
    --red: #f85149;
    --orange: #f78166;
    --purple: #bc8cff;
    --radius: 8px;
    --radius-sm: 6px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --mono: 'SF Mono', 'Cascadia Code', 'Fira Code', Consolas, monospace;
}

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

html, body {
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

/* ─── Header ─────────────────────────────────────────── */

.sess-header {
    display: flex;
    align-items: center;
    height: 48px;
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.sess-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.sess-logo-link {
    display: flex;
    align-items: center;
    border-radius: 6px;
}

.sess-logo-link img { border-radius: 5px; }

.sess-header-left h1 {
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
}

.sess-header-center { flex: 1; display: flex; justify-content: center; }

.sess-search {
    width: 100%;
    max-width: 360px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.sess-search:focus { border-color: var(--accent); }
.sess-search::placeholder { color: var(--text-muted); }

.sess-header-right { flex-shrink: 0; }

.sess-nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 13px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    transition: color 0.2s, background 0.2s;
}

.sess-nav-link:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* ─── Layout ─────────────────────────────────────────── */

.sess-layout {
    display: flex;
    height: calc(100vh - 48px);
}

/* ─── Session List (Left Panel) ──────────────────────── */

.sess-list-panel {
    width: 280px;
    min-width: 220px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-secondary);
}

.sess-list-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
}

.sess-select-all-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.sess-select-all-label input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.sess-bulk-delete-btn {
    margin-left: auto;
    padding: 3px 10px;
    background: transparent;
    border: 1px solid var(--red);
    border-radius: var(--radius-sm);
    color: var(--red);
    font-family: var(--font);
    font-size: 11px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    white-space: nowrap;
}

.sess-bulk-delete-btn:hover {
    background: var(--red);
    color: #fff;
}

.sess-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}

.sess-list::-webkit-scrollbar { width: 6px; }
.sess-list::-webkit-scrollbar-track { background: transparent; }
.sess-list::-webkit-scrollbar-thumb { background: var(--bg-hover); border-radius: 3px; }

.sess-loading {
    padding: 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

.sess-item {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
    margin-bottom: 2px;
}

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

.sess-item.active {
    background: var(--bg-hover);
    border-left: 3px solid var(--accent);
    padding-left: 9px;
}

.sess-item-checkbox {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    padding-top: 2px;
    cursor: pointer;
}

.sess-item-checkbox input[type="checkbox"] {
    accent-color: var(--accent);
    width: 14px;
    height: 14px;
    cursor: pointer;
}

.sess-item-content {
    flex: 1;
    min-width: 0;
}

.sess-item-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sess-item-desc {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.sess-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
}

/* ─── Detail Area (Right) ────────────────────────────── */

.sess-detail {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sess-detail-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}

.sess-detail-empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.5; }
.sess-detail-empty-text { font-size: 14px; }

/* ─── Actions Bar ────────────────────────────────────── */

.sess-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-shrink: 0;
}

.sess-actions-left {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.sess-active-name {
    font-size: 15px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sess-active-meta {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

.sess-actions-right {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.sess-action-btn {
    padding: 5px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 12px;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
    white-space: nowrap;
}

.sess-action-btn:hover {
    border-color: var(--accent);
    color: var(--text-primary);
}

.sess-action-btn.danger:hover {
    border-color: var(--red);
    color: var(--red);
}

.sess-action-btn.secondary { background: transparent; }

.sess-action-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ─── Chat + Monitor Split ───────────────────────────── */

.sess-panels {
    flex: 1;
    display: flex;
    min-height: 0;
}

.sess-chat-panel,
.sess-monitor-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.sess-monitor-panel {
    border-left: 1px solid var(--border);
}

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

.sess-panel-title {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.sess-panel-count {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 1px 8px;
    border-radius: 10px;
}

.sess-resize-handle {
    width: 4px;
    cursor: col-resize;
    background: var(--border);
    transition: background 0.2s;
    flex-shrink: 0;
}

.sess-resize-handle:hover,
.sess-resize-handle.dragging {
    background: var(--accent);
}

/* ─── Chat Messages ──────────────────────────────────── */

.sess-chat-messages,
.sess-monitor-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.sess-chat-messages::-webkit-scrollbar,
.sess-monitor-messages::-webkit-scrollbar {
    width: 6px;
}

.sess-chat-messages::-webkit-scrollbar-track,
.sess-monitor-messages::-webkit-scrollbar-track {
    background: transparent;
}

.sess-chat-messages::-webkit-scrollbar-thumb,
.sess-monitor-messages::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 3px;
}

.sess-msg {
    margin-bottom: 12px;
    max-width: 85%;
    animation: msgFadeIn 0.15s ease-out;
}

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

.sess-msg.user {
    margin-left: auto;
}

.sess-msg.system {
    max-width: 100%;
    margin-bottom: 8px;
}

.sess-msg-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 3px;
    padding: 0 2px;
}

.sess-msg.user .sess-msg-label { text-align: right; }

.sess-msg-bubble {
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.sess-msg.user .sess-msg-bubble {
    background: #1f3a5c;
    border: 1px solid #264a78;
    color: var(--text-primary);
}

.sess-msg.assistant .sess-msg-bubble {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    color: var(--text-primary);
}

.sess-msg.system .sess-msg-bubble {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    font-style: italic;
    font-size: 12px;
}

.sess-msg-bubble pre {
    background: var(--bg-primary);
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 6px 0;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.4;
}

.sess-msg-bubble code {
    font-family: var(--mono);
    font-size: 12px;
    background: var(--bg-tertiary);
    padding: 1px 4px;
    border-radius: 3px;
}

.sess-msg-bubble pre code {
    background: none;
    padding: 0;
}

.sess-msg-bubble p { margin: 4px 0; }
.sess-msg-bubble h2 { font-size: 15px; margin: 8px 0 4px; }
.sess-msg-bubble h3 { font-size: 14px; margin: 6px 0 4px; }
.sess-msg-bubble ul, .sess-msg-bubble ol { padding-left: 20px; margin: 4px 0; }
.sess-msg-bubble li { margin: 2px 0; }
.sess-msg-bubble strong { color: var(--text-primary); }

.sess-msg-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 3px;
    padding: 0 2px;
}

.sess-msg.user .sess-msg-time { text-align: right; }

/* ─── Monitor Entries ────────────────────────────────── */

.sess-monitor-entry {
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    animation: msgFadeIn 0.15s ease-out;
}

.sess-monitor-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-secondary);
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}

.sess-monitor-header:hover { background: var(--bg-tertiary); }

.sess-monitor-toggle {
    font-size: 10px;
    color: var(--text-muted);
    flex-shrink: 0;
    width: 12px;
}

.sess-monitor-tool {
    font-size: 12px;
    font-weight: 600;
    color: var(--purple);
    white-space: nowrap;
}

.sess-monitor-args {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

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

.sess-monitor-body {
    display: none;
    padding: 8px 10px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.4;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 400px;
    overflow-y: auto;
}

.sess-monitor-body.open { display: block; }

/* ─── Modals ─────────────────────────────────────────── */

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

.sess-modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    min-width: 360px;
    max-width: 500px;
}

.sess-modal h3 {
    font-size: 15px;
    margin-bottom: 12px;
}

.sess-modal-input,
.sess-modal-textarea {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s;
}

.sess-modal-input:focus,
.sess-modal-textarea:focus {
    border-color: var(--accent);
}

.sess-modal-textarea { resize: vertical; min-height: 80px; }

.sess-modal-buttons {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    justify-content: flex-end;
}

/* ─── Utility ────────────────────────────────────────── */

.hidden { display: none !important; }

/* ─── Toast ──────────────────────────────────────────── */

.sess-toast {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 10px 18px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    z-index: 200;
    animation: toastIn 0.3s ease-out;
}

.sess-toast.error { border-color: var(--red); color: var(--red); }
.sess-toast.success { border-color: var(--green); color: var(--green); }

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

/* ─── Responsive ─────────────────────────────────────── */

@media (max-width: 900px) {
    .sess-layout { flex-direction: column; }
    .sess-list-panel {
        width: 100%;
        max-width: 100%;
        height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sess-panels { flex-direction: column; }
    .sess-monitor-panel { border-left: none; border-top: 1px solid var(--border); }
    .sess-resize-handle { display: none; }
}

@media (max-width: 600px) {
    .sess-header-center { display: none; }
    .sess-actions { flex-direction: column; align-items: flex-start; }
    .sess-actions-right { flex-wrap: wrap; }
}
