/* Theme Variables */
:root {
    --bg: #0c0c0e;
    --surface: #141418;
    --surface-hover: #1c1c22;
    --surface-selected: #1a1a2e;
    --border: #232329;
    --text: #e0e0e6;
    --text-dim: #6e6e7a;
    --text-muted: #44444f;
    --accent: #7c6aef;
    --accent-dim: #5a4bb8;
    --green: #3dd68c;
    --green-bg: rgba(61, 214, 140, 0.08);
    --green-border: rgba(61, 214, 140, 0.15);
    --amber: #e8b931;
    --cyan: #5cc8d4;
    --danger: #e5484d;
    --red: #ef6b6b;
    --red-bg: rgba(239, 107, 107, 0.08);
    --red-border: rgba(239, 107, 107, 0.18);
    --blue: #5b9ef5;
    --blue-bg: rgba(91, 158, 245, 0.06);
    --blue-border: rgba(91, 158, 245, 0.12);
    --surface-2: #1a1a20;
    --border-subtle: #1c1c22;
    --code-bg: #18181e;
    --code-border: #282830;
    --spark: #7c6aef;
    --chip-active-bg: #7c6aef;
    --chip-active-text: #fff;
    --shadow-sm: none;
    --shadow-hover: none;
    --search-focus-ring: none;
    --thinking-bg: #16161e;
    --thinking-border: #2a2a3a;
    --thinking-text: #8888a0;
    --tool-bg: #141420;
    --tool-border: #252540;
    --tool-header: #9898b0;
    --user-bg: #141418;
    --assistant-bg: transparent;
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: #ffffff;
        --surface: #f3f3f5;
        --surface-hover: #ebebee;
        --surface-selected: #e8e8f3;
        --border: #dbdbe0;
        --text: #111111;
        --text-dim: #4e4e59;
        --text-muted: #858594;
        --accent: #5b4dc7;
        --accent-dim: #7b6fd4;
        --green: #18794e;
        --green-bg: rgba(24, 121, 78, 0.06);
        --green-border: rgba(24, 121, 78, 0.15);
        --amber: #8a6b14;
        --cyan: #0f6e6e;
        --danger: #cd2b31;
        --red: #c53030;
        --red-bg: rgba(197, 48, 48, 0.05);
        --red-border: rgba(197, 48, 48, 0.15);
        --blue: #2b6cb0;
        --blue-bg: rgba(43, 108, 176, 0.04);
        --blue-border: rgba(43, 108, 176, 0.12);
        --surface-2: #f0f0f3;
        --border-subtle: #eeeef0;
        --code-bg: #f4f4f6;
        --code-border: #e0e0e4;
        --spark: #5b4dc7;
        --chip-active-bg: #111111;
        --chip-active-text: #ffffff;
        --shadow-sm: none;
        --shadow-hover: 0 1px 4px rgba(0,0,0,0.05);
        --search-focus-ring: 0 0 0 3px rgba(91, 77, 199, 0.1);
        --thinking-bg: #f5f5f8;
        --thinking-border: #e0e0e8;
        --thinking-text: #707088;
        --tool-bg: #f4f4f9;
        --tool-border: #dddde8;
        --tool-header: #666680;
        --user-bg: #f7f7f8;
        --assistant-bg: transparent;
    }
}

/* Reset & Base */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { color-scheme: dark light; }
body {
    font-family: 'DM Sans', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Shared Utilities */
.loading {
    padding: 64px;
    font-size: 16px;
    text-align: center;
    color: var(--text-dim);
}

.meta-sep {
    color: var(--border);
    font-size: 10px;
    user-select: none;
}

/* Shared Components */
.branch-tag,
.meta-pill.branch {
    color: var(--green);
    background: var(--green-bg);
    border: 1px solid var(--green-border);
    border-radius: 3px;
    padding: 1px 6px;
}

.token-count,
.meta-pill.tokens {
    color: var(--amber);
}
.token-count {
    opacity: 0.8;
}

/* Session List — Layout */
.session-list-app {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
}

/* Session List — Header */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.header h1 {
    font-family: 'JetBrains Mono', monospace;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-dim);
    letter-spacing: 0.5px;
}
.header h1 span { color: var(--accent); }

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}
.session-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
}

/* Session List — Search */
.search-bar {
    position: relative;
    margin-bottom: 16px;
}
.search-bar input {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px 14px 10px 36px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--text);
    outline: none;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.search-bar input::placeholder { color: var(--text-muted); }
.search-bar input:focus {
    border-color: var(--accent-dim);
    box-shadow: var(--search-focus-ring);
}
.search-bar .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 13px;
    pointer-events: none;
}
.search-bar .kbd {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 2px 6px;
    pointer-events: none;
}

/* Session List — Filter Chips */
.filters {
    display: flex;
    gap: 6px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.chip {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-dim);
    cursor: pointer;
    transition: all 0.12s;
}
.chip:hover { border-color: var(--accent-dim); color: var(--text); }
.chip.active {
    background: var(--chip-active-bg);
    border-color: var(--chip-active-bg);
    color: var(--chip-active-text);
}

/* Session List — Rows */
.session-list {
    display: flex;
    flex-direction: column;
}

.session-row {
    display: grid;
    grid-template-columns: 140px 1fr auto;
    gap: 16px;
    align-items: baseline;
    padding: 10px 12px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.1s, box-shadow 0.15s;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
}
.session-row:last-child { border-bottom: none; }
.session-row:hover {
    background: var(--surface-hover);
    box-shadow: var(--shadow-hover);
}

/* Session List — Project Column */
.session-project {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    font-weight: 500;
    color: var(--cyan);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Session List — Content */
.session-content {
    min-width: 0;
}
.session-summary {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.4;
}
.session-summary.empty {
    color: var(--text-muted);
    font-style: italic;
    font-weight: 400;
}
.session-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 4px;
}
.meta-item {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 3px;
}
.branch-tag {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
}
.token-count {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
}

/* Session List — Sparkline */
.sparkline {
    display: flex;
    gap: 1px;
    align-items: flex-end;
    height: 12px;
    margin-left: 2px;
}
.sparkline .bar {
    width: 2.5px;
    border-radius: 0.5px;
    background: var(--spark);
    opacity: 0.5;
    min-height: 1px;
    transition: opacity 0.15s;
}
.session-row:hover .sparkline .bar {
    opacity: 0.85;
}

/* Session List — Time Column */
.session-right {
    text-align: right;
    white-space: nowrap;
    min-width: 70px;
}
.session-time {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-dim);
}

/* Session List — Date Separators */
.date-separator {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 12px 12px 6px;
    margin-top: 4px;
}

/* Session List — Search Highlights */
.search-highlights {
    margin-top: 2px;
    margin-bottom: 4px;
    padding: 4px 8px;
    background: var(--surface);
    border-radius: 4px;
    font-size: 11px;
}
.search-highlight {
    line-height: 1.5;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.search-highlight:last-child {
    margin-bottom: 0;
}
.highlight-field {
    color: var(--text-muted);
    font-weight: 600;
    margin-right: 4px;
}
.highlight-snippet {
    color: var(--text);
}
.highlight-snippet b {
    color: var(--accent);
    font-weight: 700;
    background: rgba(124, 106, 239, 0.1);
    padding: 0 3px;
    border-radius: 2px;
}

/* Session Detail — Layout */
.app {
    max-width: 820px;
    margin: 0 auto;
    padding: 24px 20px 80px;
}

/* Session Detail — Top Bar */
.top-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.back-link {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--text-muted);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: 4px;
    transition: background 0.1s, color 0.1s;
}
.back-link:hover {
    background: var(--surface-hover);
    color: var(--text-dim);
}

.top-bar-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--text-dim);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.top-bar-title .project-name {
    color: var(--cyan);
}

/* Session Detail — Header */
.session-header {
    margin-bottom: 28px;
}

.session-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.4;
    margin-bottom: 10px;
}

.session-meta-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.meta-pill {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-muted);
}

/* Session Detail — Messages */
.messages {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.message {
    padding: 14px 16px;
    border-radius: 6px;
    position: relative;
    animation: msgIn 0.2s ease both;
}

.message + .message {
    margin-top: 2px;
}

.role-label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.role-label .timestamp {
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0;
    text-transform: none;
}

.message.user {
    background: var(--user-bg);
    border: 1px solid var(--border-subtle);
}
.message.user .role-label {
    color: var(--cyan);
}

.message.assistant {
    background: var(--assistant-bg);
}
.message.assistant .role-label {
    color: var(--accent);
}

/* Session Detail — Message Text */
.msg-text {
    font-size: 13.5px;
    color: var(--text);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}

.msg-text code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 3px;
    padding: 1px 5px;
}
.msg-text pre {
    background: var(--code-bg);
    border: 1px solid var(--code-border);
    border-radius: 5px;
    padding: 10px 12px;
    margin: 8px 0;
    overflow-x: auto;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-dim);
}
.msg-text pre code {
    background: none;
    border: none;
    padding: 0;
}

/* Session Detail — Thinking Blocks */
.thinking-block {
    background: var(--thinking-bg);
    border: 1px solid var(--thinking-border);
    border-radius: 5px;
    margin: 8px 0;
    overflow: hidden;
}

.thinking-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--thinking-text);
    list-style: none;
    transition: color 0.1s;
}
.thinking-toggle:hover {
    color: var(--text-dim);
}
.thinking-toggle::-webkit-details-marker {
    display: none;
}
.thinking-toggle .arrow {
    font-size: 9px;
    transition: transform 0.15s;
    display: inline-block;
}
.thinking-block[open] .thinking-toggle .arrow {
    transform: rotate(90deg);
}

.thinking-content {
    padding: 0 12px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11.5px;
    line-height: 1.6;
    color: var(--thinking-text);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

/* Session Detail — Tool Use Blocks */
.tool-use-block {
    background: var(--tool-bg);
    border: 1px solid var(--tool-border);
    border-radius: 5px;
    margin: 8px 0;
    overflow: hidden;
}

.tool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
}

.tool-icon {
    font-size: 12px;
    width: 18px;
    text-align: center;
}

.tool-name {
    font-weight: 600;
    color: var(--blue);
}

.tool-desc {
    color: var(--tool-header);
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Session Detail — Tool Input */
.tool-input-section {
    margin: 0;
}

.tool-input-toggle {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 12px 8px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-muted);
    list-style: none;
}
.tool-input-toggle:hover {
    color: var(--text-dim);
}
.tool-input-toggle::-webkit-details-marker {
    display: none;
}
.tool-input-toggle .arrow {
    font-size: 8px;
    transition: transform 0.15s;
    display: inline-block;
}
.tool-input-section[open] .tool-input-toggle .arrow {
    transform: rotate(90deg);
}

.tool-input-content {
    padding: 0 12px 10px;
    border-top: 1px solid var(--tool-border);
    padding-top: 8px;
    margin: 0 12px;
}
.tool-input-content pre {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-muted);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
    margin: 0;
}

/* Session Detail — Tool Results */
.tool-result-block {
    background: var(--tool-bg);
    border: 1px solid var(--tool-border);
    border-radius: 5px;
    margin: 8px 0;
    overflow: hidden;
}
.tool-result-block.error {
    background: var(--red-bg);
    border-color: var(--red-border);
}

.result-header {
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    list-style: none;
}
.result-header:hover {
    opacity: 0.85;
}
.result-header::-webkit-details-marker {
    display: none;
}

.result-icon {
    font-size: 11px;
    width: 18px;
    text-align: center;
}

.result-label {
    color: var(--tool-header);
    font-weight: 500;
}
.tool-result-block.error .result-label {
    color: var(--red);
}

.result-arrow {
    font-size: 8px;
    color: var(--text-muted);
    margin-left: auto;
    transition: transform 0.15s;
    display: inline-block;
}
.tool-result-block[open] .result-arrow {
    transform: rotate(90deg);
}

.result-content {
    padding: 0 12px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-dim);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    border-top: 1px solid var(--tool-border);
    padding-top: 8px;
    margin: 0 12px;
}
.tool-result-block.error .result-content {
    color: var(--red);
    border-top-color: var(--red-border);
}

/* Session Detail — Tool Groups & Stacks */
.tool-group {
    margin: 8px 0;
    border: 1px solid var(--tool-border);
    border-radius: 5px;
    background: var(--tool-bg);
    overflow: hidden;
}
.tool-group .tool-use-block,
.tool-group .tool-result-block {
    border: none;
    border-radius: 0;
    margin: 0;
    background: transparent;
}
.tool-group .tool-result-block {
    border-top: 1px dashed var(--tool-border);
}
.tool-group .tool-result-block.error {
    background: var(--red-bg);
}

.tool-call-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 8px 0;
}

/* Session Detail — Images & Misc */
.image-block .content-image {
    max-width: 100%;
    border-radius: 6px;
}

.unknown-block {
    color: var(--text-dim);
    font-style: italic;
}

.error-callout {
    background: var(--red-bg);
    border: 1px solid var(--red-border);
    border-radius: 6px;
    padding: 12px 16px;
    color: var(--red);
    font-size: 13px;
    margin-top: 12px;
}

/* Animations */
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}
.session-row {
    animation: fadeSlideIn 0.2s ease both;
}
.session-row:nth-child(2) { animation-delay: 0.02s; }
.session-row:nth-child(3) { animation-delay: 0.04s; }
.session-row:nth-child(4) { animation-delay: 0.06s; }
.session-row:nth-child(5) { animation-delay: 0.08s; }
.session-row:nth-child(6) { animation-delay: 0.10s; }
.session-row:nth-child(7) { animation-delay: 0.12s; }

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

/* Responsive */
@media (max-width: 640px) {
    .session-row {
        grid-template-columns: 1fr auto;
    }
    .session-project {
        grid-column: 1 / -1;
    }
    .sparkline { display: none; }

    .app {
        padding: 16px 12px 60px;
    }
    .message {
        padding: 10px 12px;
    }
    .session-meta-bar {
        gap: 6px;
    }
}
