/* === Reset & Base === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg-main: #0d1117;
    --bg-sidebar: #161b22;
    --bg-surface: #1c2333;
    --bg-hover: #252d3f;
    --bg-input: #0d1117;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-amber: #d29922;
    --border: #30363d;
    --border-light: #21262d;
    --danger: #f85149;
    --success: #3fb950;
    --radius: 8px;
    --sidebar-width: 280px;
    --topbar-height: 48px;
    --app-height: 100dvh;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 15px;
    color: var(--text-primary);
    background: var(--bg-main);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    overscroll-behavior: none;
}

/* === App Layout === */
.app-container {
    display: flex;
    height: 100vh;
    height: var(--app-height);
    overflow: hidden;
}

/* === Sidebar === */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
    z-index: 100;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-amber);
}

.sidebar-section {
    padding: 12px;
}

.btn-new-chat {
    width: 100%;
    padding: 10px;
    font-size: 14px;
    font-weight: 500;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}

.btn-new-chat:hover {
    background: #79c0ff;
}

.sidebar-conversations {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding-top: 0;
}

.conv-item {
    padding: 10px 12px;
    cursor: pointer;
    border-radius: 6px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.12s;
}

.conv-item:hover {
    background: var(--bg-hover);
}

.conv-item.active {
    background: var(--bg-hover);
    border-left: 3px solid var(--accent);
}

.conv-title {
    font-size: 13px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.conv-rename-input {
    font-size: 13px;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: 4px;
    color: var(--text-primary);
    padding: 2px 6px;
    outline: none;
    width: 100%;
    font-family: var(--font);
}

.conv-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.12s;
}

.conv-item:hover .conv-delete {
    opacity: 1;
}

.conv-delete:hover {
    color: var(--danger);
}

.conv-loading {
    color: var(--text-muted);
    padding: 12px;
    text-align: center;
    font-size: 13px;
}

.sidebar-footer {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 3px;
    margin-top: auto;
    padding: 10px 12px 12px;
    border-top: 1px solid var(--border);
    background: rgba(13, 17, 23, 0.22);
}

.sidebar-link {
    border-radius: 6px;
    color: var(--text-secondary);
    display: block;
    font-size: 13px;
    line-height: 1.25;
    min-height: 32px;
    overflow: hidden;
    padding: 8px 10px;
    text-decoration: none;
    transition: color 0.12s;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-link:hover {
    background: var(--bg-hover);
    color: var(--accent);
}

/* === Main Content === */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
}

.top-bar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
}

.top-bar-persona-select {
    min-width: 90px;
    border: 1px solid var(--border);
    background: #0d1117;
    color: var(--text-primary);
    border-radius: 6px;
    padding: 4px 8px;
    height: 28px;
    font-size: 12px;
    font-family: var(--font);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.top-bar-title {
    font-weight: 500;
    font-size: 14px;
    color: var(--text-secondary);
}

.top-bar-tokens {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.top-bar-test-badge {
    font-size: 10px;
    font-weight: 600;
    color: var(--accent-amber);
    background: rgba(210, 153, 34, 0.15);
    padding: 1px 6px;
    border-radius: 4px;
    letter-spacing: 0.5px;
}

.top-bar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.compaction-bar-container {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 100px;
}

.compaction-bar {
    height: 6px;
    flex: 1;
    background: var(--bg-hover);
    border-radius: 3px;
    overflow: hidden;
}

.compaction-bar-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0;
}

.compaction-label {
    font-size: 10px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
}

/* === Status Bar === */
.status-bar {
    position: sticky;
    bottom: 0;
    z-index: 60;
    min-height: 28px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 16px;
    border-top: 1px solid var(--border);
    background: rgba(13, 17, 23, 0.96);
    color: var(--text-muted);
    font-size: 12px;
    flex-shrink: 0;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex: 0 0 auto;
}

.status-text {
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
}

.status-detail {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-notify-btn {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    flex: 0 0 auto;
    font-size: 11px;
    min-height: 22px;
    padding: 3px 8px;
}

.status-notify-btn:hover {
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.status-notify-btn:disabled {
    cursor: default;
    opacity: 0.62;
}

.status-bar[data-state="connected"] .status-dot {
    background: var(--success);
    box-shadow: 0 0 8px rgba(63, 185, 80, 0.55);
}

.status-bar[data-state="connecting"] .status-dot,
.status-bar[data-state="reconnecting"] .status-dot {
    background: var(--accent-amber);
    box-shadow: 0 0 8px rgba(210, 153, 34, 0.45);
}

.status-bar[data-state="offline"] .status-dot {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(248, 81, 73, 0.4);
}

/* === Chat Container === */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overscroll-behavior: contain;
    scroll-padding-bottom: 16px;
}

.welcome {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
}

.welcome p {
    font-size: 22px;
    color: var(--accent-amber);
    margin-bottom: 8px;
}

.welcome-sub {
    font-size: 14px !important;
    color: var(--text-muted) !important;
}

/* === Message Bubbles === */
.message {
    flex: 0 0 auto;
    min-width: 0;
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.5;
    font-size: 14px;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    align-self: flex-start;
    background: var(--bg-surface);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
    line-height: 1.6;
}

.assistant-turn {
    align-self: flex-start;
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    gap: 8px;
    max-width: 85%;
    min-width: 0;
    width: min(85%, 900px);
}

.assistant-turn > .message,
.assistant-turn > .thinking-block {
    align-self: stretch;
    box-sizing: border-box;
    max-width: none;
    width: 100%;
}

.assistant-turn > .thinking-block {
    margin: 0;
}

.message.assistant.tool-call-host {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px;
}

.tool-call-segment > :first-child {
    margin-top: 0;
}

.tool-call-segment > :last-child {
    margin-bottom: 0;
}

.message.assistant p { margin: 0 0 8px 0; }
.message.assistant p:last-child { margin-bottom: 0; }
.message.assistant br { display: block; content: ''; margin: 4px 0; }
.message.assistant h2, .message.assistant h3, .message.assistant h4 {
    margin: 12px 0 6px 0;
    color: var(--accent-amber);
}
.message.assistant h2 { font-size: 16px; }
.message.assistant h3 { font-size: 15px; }
.message.assistant h4 { font-size: 14px; }
.message.assistant strong { color: #fff; }
.message.assistant em { color: var(--text-secondary); }
.message.assistant code {
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 12px;
}
.message.assistant pre {
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    overflow-x: auto;
    margin: 8px 0;
}
.message.assistant pre code {
    background: none;
    padding: 0;
    font-size: 12px;
    line-height: 1.5;
}
.svg-render-block {
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin: 10px 0;
    overflow: hidden;
}

.svg-render-toolbar {
    align-items: center;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 6px;
    padding: 8px;
}

.svg-render-label {
    color: var(--accent-amber);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 700;
    margin-right: auto;
}

.svg-render-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font: 600 12px/1 var(--font);
    min-height: 30px;
    padding: 6px 10px;
}

.svg-render-btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-muted);
    color: var(--text-primary);
}

.svg-preview-shell {
    align-items: center;
    background:
        linear-gradient(45deg, rgba(255,255,255,0.035) 25%, transparent 25%),
        linear-gradient(-45deg, rgba(255,255,255,0.035) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.035) 75%),
        linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.035) 75%),
        var(--bg-main);
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
    background-size: 16px 16px;
    border: 0;
    cursor: zoom-in;
    display: flex;
    justify-content: center;
    min-height: 180px;
    padding: 12px;
    width: 100%;
}

.svg-preview-img {
    display: block;
    height: auto;
    max-height: 460px;
    max-width: 100%;
    object-fit: contain;
}

.svg-source-panel {
    border: 0 !important;
    border-top: 1px solid var(--border) !important;
    border-radius: 0 !important;
    margin: 0 !important;
    max-height: 360px;
    white-space: pre-wrap;
}

.svg-lightbox {
    align-items: center;
    background: rgba(0, 0, 0, 0.82);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 24px;
    position: fixed;
    z-index: 2000;
}

.svg-lightbox[hidden] {
    display: none;
}

.svg-lightbox-img {
    background: transparent;
    display: block;
    max-height: 92vh;
    max-width: 96vw;
    object-fit: contain;
}

.svg-lightbox-close {
    background: rgba(13, 17, 23, 0.92);
    border: 1px solid rgba(255,255,255,0.22);
    border-radius: 6px;
    color: var(--text-primary);
    cursor: pointer;
    font: 600 13px/1 var(--font);
    padding: 9px 12px;
    position: fixed;
    right: 16px;
    top: 16px;
    z-index: 2001;
}

.svg-lightbox-close:hover {
    background: var(--bg-hover);
}

body.svg-lightbox-open {
    overflow: hidden;
}
.message.assistant blockquote {
    border-left: 3px solid var(--accent);
    margin: 8px 0;
    padding: 4px 12px;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-radius: 0 var(--radius) var(--radius) 0;
}
.message.assistant blockquote p {
    margin: 0 0 8px 0;
}
.message.assistant blockquote p:last-child {
    margin-bottom: 0;
}
.message.assistant ul, .message.assistant ol {
    margin: 6px 0;
    padding-left: 20px;
}
.message.assistant li { margin: 2px 0; }
.message.assistant hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 12px 0;
}
.message.assistant del { color: var(--text-muted); }
.translation-original-tail {
    color: var(--text-muted);
    opacity: 0.62;
}

@keyframes blink {
    50% { opacity: 0; }
}

.message.system {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    border: none;
    padding: 4px 8px;
}

.message.tool-call {
    align-self: center;
    background: var(--bg-hover);
    color: var(--accent-amber);
    font-size: 12px;
    padding: 4px 12px;
    border-radius: 12px;
    font-family: var(--font-mono);
}

.tool-call-block {
    flex: 0 0 auto;
    align-self: stretch;
    min-width: 0;
    max-width: none;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius);
    color: var(--text-primary);
    overflow: hidden;
}

.tool-call-host .tool-call-block {
    width: 100%;
}

.tool-call-block summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
    cursor: pointer;
    padding: 8px 12px;
    background: rgba(210, 153, 34, 0.08);
    color: var(--accent-amber);
    font-family: var(--font-mono);
    font-size: 12px;
    user-select: none;
}

.tool-call-block.success summary {
    background: rgba(99, 179, 129, 0.08);
    color: var(--success);
}

.tool-call-block.error summary {
    background: rgba(244, 114, 114, 0.08);
    color: var(--danger);
}

.tool-call-block.skipped summary {
    background: rgba(140, 140, 160, 0.08);
    color: var(--text-muted);
}

.tool-call-block.history summary {
    background: rgba(140, 140, 160, 0.08);
    color: var(--text-muted);
}

.tool-call-title {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: anywhere;
}

.tool-call-state {
    flex: 0 0 auto;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 10px;
}

.tool-call-body {
    display: flex;
    flex-direction: column;
    min-height: 0;
    max-height: min(420px, 48vh);
    overflow: hidden;
    padding: 10px 12px;
}

.tool-call-status {
    color: var(--text-secondary);
    font-size: 12px;
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

.stream-retry-notice {
    align-self: flex-start;
    background: rgba(255, 193, 7, 0.08);
    border: 1px solid rgba(255, 193, 7, 0.22);
    border-radius: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    margin: 6px 0;
    max-width: min(720px, 100%);
    padding: 7px 10px;
}

.tool-call-params {
    margin-bottom: 8px;
}

.tool-call-params summary {
    background: transparent;
    color: var(--text-muted);
    display: block;
    font-family: var(--font);
    font-size: 12px;
    gap: 0;
    justify-content: flex-start;
    padding: 0 0 4px;
}

.tool-call-params-json {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    max-height: 180px;
    overflow: auto;
    overflow-wrap: anywhere;
    padding: 8px;
    white-space: pre-wrap;
}

.tool-call-result {
    flex: 1 1 auto;
    min-height: 0;
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    max-height: min(320px, 36vh);
    overflow: auto;
    overflow-wrap: anywhere;
    padding: 8px;
    white-space: pre-wrap;
}

.compaction-event {
    flex: 0 0 auto;
    align-self: stretch;
    min-width: 0;
    max-width: none;
    background: var(--bg-surface);
    border: 1px solid var(--accent-amber);
    border-radius: var(--radius);
    color: var(--text-primary);
    overflow: hidden;
}

.memory-sweep-event {
    border-color: var(--accent);
}

.compaction-event summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    padding: 10px 12px;
    background: rgba(210, 153, 34, 0.1);
    color: var(--accent-amber);
    font-size: 13px;
    user-select: none;
}

.memory-sweep-event summary {
    background: rgba(88, 166, 255, 0.1);
    color: var(--accent);
}

.compaction-event-title {
    font-weight: 600;
}

.compaction-event-counts {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    text-align: right;
}

.compaction-event-body {
    padding: 12px;
}

.compaction-event-status {
    color: var(--text-secondary);
    font-size: 13px;
    margin-bottom: 8px;
}

.compaction-event-meta {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    margin-bottom: 10px;
    overflow-wrap: anywhere;
}

.compaction-event-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 10px;
}

.memory-sweep-event-grid {
    grid-template-columns: minmax(0, 1fr);
}

.compaction-event h3 {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 6px;
}

.compaction-event pre {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    min-height: 80px;
    max-height: 280px;
    overflow: auto;
    padding: 8px;
    white-space: pre-wrap;
}

/* Inline tool-call action blocks inside assistant messages —
   rendered like stage directions / action lines in fiction. */
.msg-tool-call {
    color: var(--accent-amber);
    font-family: var(--font-mono);
    font-size: 14px;
    font-style: italic;
    opacity: 0.7;
    padding: 2px 0;
    margin: 4px 0;
    line-height: 1.6;
    letter-spacing: 0.02em;
}

.msg-timestamp {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    font-family: var(--font-mono);
    opacity: 0.6;
}

/* Display timestamps from data attributes */
.message.user[data-timestamp]::after {
    content: attr(data-timestamp);
    display: block;
    font-size: 12px;
    color: #000000;
    background: rgba(255,255,255,0.35);
    font-family: var(--font-mono);
    margin-top: 4px;
    padding: 1px 4px;
    border-radius: 3px;
}

.message.assistant[data-timestamp]::after {
    content: attr(data-timestamp);
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    opacity: 0.75;
    margin-top: 4px;
}

/* === Memory Update Panel === */
.memory-update-panel {
    align-items: center;
    background: rgba(22, 27, 34, 0.96);
    border-top: 1px solid var(--border);
    display: flex;
    flex-shrink: 0;
    gap: 10px;
    min-height: 38px;
    padding: 7px 16px;
}

.memory-update-status {
    align-items: center;
    display: flex;
    flex: 1 1 auto;
    gap: 8px;
    min-width: 0;
}

.memory-update-label {
    color: var(--accent-amber);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.memory-update-state {
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.memory-update-state.running {
    color: var(--accent);
}

.memory-update-state.due {
    color: var(--accent-amber);
}

.memory-update-state.error {
    color: var(--danger);
}

.memory-update-state.warn {
    color: #e9bb00;
}

.memory-update-detail {
    color: var(--text-muted);
    flex: 1 1 auto;
    font-family: var(--font-mono);
    font-size: 11px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-memory-update {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--text-primary);
    min-height: 30px;
    padding: 6px 11px;
}

.btn-memory-update:hover:not(:disabled) {
    background: #30384b;
    border-color: var(--text-muted);
}

/* === Input Area === */
.input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    align-items: flex-end;
    flex-shrink: 0;
}

.input-area textarea {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    resize: none;
    outline: none;
    line-height: 1.4;
    min-height: 42px;
    max-height: 120px;
    transition: border-color 0.15s;
}

.input-area .btn,
.input-area .btn-send,
.input-area .btn-stop {
    min-height: 42px;
    display: flex;
    align-items: center;
}

.input-area textarea:focus {
    border-color: var(--accent);
}

.input-area textarea::placeholder {
    color: var(--text-muted);
}

.btn {
    padding: 10px 18px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-send {
    background: var(--accent);
    color: #fff;
}

.btn-send:hover:not(:disabled) {
    background: #79c0ff;
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    text-decoration: none;
}

.btn-link:hover {
    text-decoration: underline;
}

.load-more {
    text-align: center;
    padding: 4px 0;
}

/* === Message Actions === */
.msg-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
    margin-top: 4px;
    opacity: 1;
}

/* === Tool Logs Page === */
.tool-logs-page {
    padding: 24px;
    max-width: 900px;
    margin: 0 auto;
}

.tool-logs-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
}

.tool-logs-counter {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-left: auto;
}

.tool-logs-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tool-logs-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 0;
    font-size: 14px;
}

.tool-log-entry {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
}

.tool-log-entry.error {
    border-left: 3px solid var(--danger);
}

.tool-log-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

.tool-log-method {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    background: var(--bg-hover);
    padding: 1px 6px;
    border-radius: 4px;
}

.tool-log-path {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-primary);
    flex: 1;
}

.tool-log-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.tool-log-rerun {
    font-size: 11px;
    font-family: var(--font-mono);
    background: var(--bg-hover);
    border: 1px solid var(--border);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 4px;
    cursor: pointer;
    margin-left: auto;
}

.tool-log-rerun:hover {
    background: var(--accent);
    color: var(--bg-main);
}

.tool-log-rerun:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.tool-log-rerun-badge {
    font-family: var(--font-mono);
    font-size: 10px;
    color: var(--text-muted);
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    padding: 1px 6px;
    border-radius: 3px;
    display: inline-block;
    margin-bottom: 4px;
}

.tool-log-summary {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 2px 0 6px 0;
    cursor: pointer;
    user-select: none;
}

.tool-log-summary:hover {
    color: var(--text-primary);
}

.tool-log-body {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    padding: 6px 8px;
    margin: 4px 0;
    overflow-x: auto;
    max-height: 120px;
    white-space: pre-wrap;
    word-break: break-all;
}

.tool-log-body-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    display: block;
    margin-top: 6px;
    margin-bottom: 2px;
}

.tool-log-result {
    margin-top: 6px;
}

.tool-log-result-pre {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-primary);
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    max-height: 300px;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.tool-log-body {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-main);
    padding: 8px;
    border-radius: 4px;
    overflow-x: auto;
    max-height: 100px;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

@media (hover: hover) and (pointer: fine) {
    .msg-actions {
        opacity: 0;
        transition: opacity 0.15s;
    }
    .message.user:hover .msg-actions {
        opacity: 1;
    }
}

.btn-action {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 6px;
    line-height: 1;
    font-weight: 500;
    min-width: 32px;
    text-align: center;
}

.btn-action:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
    border-color: var(--text-muted);
}

.msg-edit-area {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg-edit-input {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    resize: vertical;
    min-height: 60px;
    outline: none;
}

.msg-edit-actions {
    display: flex;
    gap: 6px;
}

.btn-small {
    padding: 4px 10px;
    font-size: 12px;
}

/* === Thinking Block === */
.thinking-block {
    align-self: flex-start;
    max-width: 85%;
    margin: 4px 0;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 4px 8px;
}

.thinking-block summary {
    cursor: pointer;
    color: var(--text-muted);
    font-size: 12px;
    padding: 2px 0;
    user-select: none;
}

.thinking-block summary:hover {
    color: var(--text-secondary);
}

.thinking-block .thinking-content {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-top: 4px;
    padding: 6px 8px;
    background: var(--bg-main);
    border-radius: 4px;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: var(--font-mono);
    font-size: 11px;
}

/* === Memory Page === */
.memory-page {
    padding: 16px 20px;
    max-width: 800px;
}

.memory-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
}

.memory-page .memory-update-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.memory-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.memory-section {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.memory-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}

.memory-section-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-amber);
}

.memory-section-actions {
    display: flex;
    gap: 4px;
}

.memory-section-body {
    padding: 12px 14px;
}

.memory-pre {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

.memory-textarea {
    width: 100%;
    min-height: 120px;
    font-family: var(--font-mono);
    font-size: 13px;
    resize: vertical;
}

.memory-edit-form {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.memory-edit-actions {
    display: flex;
    gap: 8px;
}

.memory-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
}

.page-subtitle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
}

.memory-instruct-form {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
}

.memory-instruct-label {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.btn-stop {
    background: var(--danger);
    color: #fff;
}

.btn-stop:hover {
    background: #ff6b62;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    transition: background 0.12s;
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-close {
    display: none;
}

/* === Files Page === */
.page-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.page-header h1 {
    font-size: 20px;
    font-weight: 600;
    margin-top: 4px;
}

.back-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
}

.back-link:hover {
    text-decoration: underline;
}

.file-browser {
    padding: 16px 20px;
}

.file-path {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding: 8px 12px;
    background: var(--bg-surface);
    border-radius: 6px;
    border: 1px solid var(--border);
}

.file-path a {
    color: var(--accent);
    text-decoration: none;
}

.file-path a:hover {
    text-decoration: underline;
}

.file-path span {
    margin: 0 2px;
}

.file-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.file-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    transition: background 0.12s;
}

.file-item:hover {
    background: var(--bg-hover);
}

.file-link {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    text-decoration: none;
    color: var(--text-primary);
    min-width: 0;
}

.file-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    color: var(--text-muted);
    font-size: 12px;
    font-family: var(--font-mono);
    text-align: right;
    min-width: 70px;
}

.file-date {
    color: var(--text-muted);
    font-size: 12px;
    min-width: 120px;
    text-align: right;
}

.file-empty {
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

/* === File View Page === */
.file-view-content {
    padding: 16px 20px;
}

.file-meta {
    display: flex;
    gap: 20px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 16px;
}

.file-source {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* === Settings Page === */
.settings-container {
    padding: 16px 20px;
    max-width: 1240px;
}

.settings-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.settings-section h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 600;
}

.split-page {
    display: grid;
    gap: 18px;
    grid-template-columns: 180px minmax(0, 1fr);
    margin: 0 auto;
    max-width: 1240px;
    padding: 16px 20px;
    width: 100%;
}

.split-nav {
    align-self: start;
    border-right: 1px solid var(--border);
    display: grid;
    gap: 4px;
    padding-right: 12px;
    position: sticky;
    top: 16px;
}

.split-nav button {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    padding: 9px 10px;
    text-align: left;
}

.split-nav button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.split-nav button.active {
    background: var(--bg-surface);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.split-content {
    min-width: 0;
}

.settings-panel,
.testing-panel {
    display: none;
}

.settings-panel.active,
.testing-panel.active {
    display: grid;
    gap: 16px;
}

.settings-panel-header {
    align-items: center;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 12px;
    justify-content: space-between;
    min-width: 0;
    padding-bottom: 12px;
}

.settings-panel-header h2 {
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.settings-panel-subtitle {
    color: var(--text-muted);
    display: block;
    font-family: var(--font-mono);
    font-size: 12px;
    margin-top: 4px;
}

.settings-field-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-time-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.settings-inline-check {
    min-height: 40px;
}

.settings-autonomy-stats {
    margin-bottom: 2px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-input {
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.15s;
}

.form-input:focus {
    border-color: var(--accent);
}

.form-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    align-self: flex-start;
}

.btn-primary:hover {
    background: #79c0ff;
}

.settings-info {
    margin-top: 24px;
    padding: 16px;
    background: var(--bg-surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.settings-info ul {
    margin: 8px 0 0 16px;
}

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

.settings-notification-row {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.settings-notification-status {
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 12px;
    padding: 4px 10px;
}

.settings-notification-status.allowed {
    border-color: rgba(63, 185, 80, 0.55);
    color: var(--success);
}

.settings-notification-status.blocked {
    border-color: rgba(248, 81, 73, 0.45);
    color: var(--danger);
}

.settings-notification-status.waiting {
    border-color: rgba(210, 153, 34, 0.45);
    color: var(--accent-amber);
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-success {
    background: rgba(63, 185, 80, 0.12);
    color: var(--success);
    border: 1px solid rgba(63, 185, 80, 0.3);
}

.alert-error {
    background: rgba(248, 81, 73, 0.12);
    color: var(--danger);
    border: 1px solid rgba(248, 81, 73, 0.3);
}

/* === Compaction Page === */
.compaction-page {
    padding: 16px 20px;
    max-width: 1180px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.testing-page {
    max-width: 1240px;
}

.compaction-panel,
.compaction-results {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}

.compaction-controls {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto auto;
    gap: 12px;
    align-items: end;
}

.compaction-conversation-field {
    min-width: 0;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
}

.checkbox-label input {
    accent-color: var(--accent);
}

.compaction-checkbox {
    min-height: 40px;
}

.compaction-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.compaction-status {
    margin-top: 12px;
    min-height: 18px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 12px;
}

.compaction-summary-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.compaction-stat {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 10px 12px;
    min-width: 0;
}

.compaction-stat-label {
    display: block;
    color: var(--text-muted);
    font-size: 11px;
    margin-bottom: 4px;
}

.compaction-stat strong {
    display: block;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.compaction-detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(320px, 1fr);
    gap: 16px;
    margin-bottom: 16px;
}

.compaction-results h2 {
    color: var(--accent-amber);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 10px;
}

.compaction-details {
    display: grid;
    grid-template-columns: 100px minmax(0, 1fr);
    gap: 8px 12px;
    font-size: 13px;
}

.compaction-details dt {
    color: var(--text-muted);
}

.compaction-details dd {
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.compaction-summary-preview,
.compaction-json pre {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    margin: 0;
    max-height: 320px;
    overflow: auto;
    padding: 10px;
    white-space: pre-wrap;
}

.compaction-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-light);
    border-radius: 6px;
    margin-bottom: 12px;
}

.compaction-table {
    width: 100%;
    min-width: 680px;
    border-collapse: collapse;
    font-size: 12px;
}

.compaction-table th,
.compaction-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-light);
    text-align: left;
}

.compaction-table th {
    color: var(--text-muted);
    font-weight: 600;
    background: var(--bg-sidebar);
}

.compaction-table td {
    color: var(--text-secondary);
}

.compaction-table code {
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.compaction-empty-cell {
    text-align: center !important;
    color: var(--text-muted) !important;
}

.compaction-json summary {
    cursor: pointer;
    color: var(--accent);
    font-size: 13px;
    margin-bottom: 8px;
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Toast Notifications === */
.toast {
    position: fixed;
    top: 12px;
    right: 12px;
    background: var(--bg-surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text-primary);
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    cursor: pointer;
    animation: toastIn 0.3s ease;
    max-width: 400px;
}

.toast-hide {
    animation: toastOut 0.3s ease forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateY(0); }
    to { opacity: 0; transform: translateY(-10px); }
}

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-close {
        display: block;
    }

    .message {
        max-width: 90%;
    }

    .split-page {
        grid-template-columns: 1fr;
        padding: 12px;
    }

    .split-nav {
        border-bottom: 1px solid var(--border);
        border-right: 0;
        display: flex;
        gap: 6px;
        overflow-x: auto;
        padding: 0 0 10px;
        position: static;
    }

    .split-nav button {
        flex: 0 0 auto;
        white-space: nowrap;
    }

    .settings-field-grid {
        grid-template-columns: 1fr;
    }

    .settings-panel-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .memory-update-panel {
        align-items: stretch;
        flex-direction: column;
        gap: 6px;
        padding: 8px 12px;
    }

    .memory-update-status {
        align-items: flex-start;
        flex-wrap: wrap;
        gap: 5px 8px;
    }

    .memory-update-detail {
        flex-basis: 100%;
        white-space: normal;
    }

    .btn-memory-update {
        width: 100%;
    }

    .svg-render-toolbar {
        flex-wrap: wrap;
    }

    .svg-render-label {
        flex-basis: 100%;
    }

    .svg-render-btn {
        flex: 1 1 90px;
    }

    .svg-preview-shell {
        min-height: 130px;
        padding: 8px;
    }

    .svg-preview-img {
        max-height: 320px;
    }

    .svg-lightbox {
        padding: 12px;
    }

    .svg-lightbox-close {
        right: 10px;
        top: 10px;
    }

    .file-size, .file-date {
        display: none;
    }

    .compaction-page {
        padding: 12px;
    }

    .compaction-controls,
    .compaction-summary-row,
    .compaction-detail-grid {
        grid-template-columns: 1fr;
    }

    .compaction-actions {
        justify-content: flex-start;
    }

    .compaction-actions .btn {
        flex: 1 1 140px;
    }

    .compaction-details {
        grid-template-columns: 1fr;
        gap: 4px;
    }

    .compaction-event summary {
        align-items: flex-start;
        flex-direction: column;
    }

    .compaction-event-counts {
        text-align: left;
    }

    .compaction-event-grid {
        grid-template-columns: 1fr;
    }
}

/* === KaiTimer === */
.timer-page {
    padding: 18px;
    width: 100%;
    max-width: 1180px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.timer-panel {
    border: 1px solid var(--border);
    background: var(--bg-surface);
    border-radius: var(--radius);
    padding: 18px;
    min-width: 0;
}

.timer-hero {
    max-width: none;
}

.timer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

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

.timer-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-top: 3px;
}

.timer-status {
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 12px;
    padding: 3px 9px;
    text-transform: uppercase;
}

.timer-status.running {
    color: var(--success);
    border-color: rgba(63, 185, 80, 0.55);
}

.timer-display {
    font-family: var(--font-mono);
    font-size: 48px;
    line-height: 1.1;
    margin-top: 24px;
    overflow-wrap: anywhere;
}

.timer-meta {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 13px;
    margin-top: 8px;
}

.timer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 22px;
}

.timer-message {
    color: var(--success);
    font-size: 13px;
    min-height: 18px;
    margin-top: 14px;
}

.timer-message.error {
    color: var(--danger);
}

.timer-dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    gap: 14px;
}

.timer-section-header {
    align-items: center;
    display: flex;
    gap: 10px;
    justify-content: space-between;
    margin-bottom: 12px;
}

.timer-section-header h2 {
    color: var(--accent-amber);
    font-size: 15px;
    font-weight: 600;
}

.timer-inline-form {
    align-items: stretch;
    display: flex;
    gap: 8px;
    margin-top: 12px;
    min-width: 0;
}

.timer-stack-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.timer-flex-input {
    flex: 1 1 auto;
    min-width: 0;
}

.timer-number-input {
    flex: 0 0 96px;
    min-width: 0;
}

.timer-textarea {
    min-height: 74px;
    resize: vertical;
}

.timer-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.timer-row {
    align-items: center;
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    display: flex;
    gap: 8px;
    min-width: 0;
    padding: 8px;
}

.timer-row-stack {
    align-items: stretch;
    flex-direction: column;
}

.timer-row-top,
.timer-row-actions {
    align-items: center;
    display: flex;
    gap: 8px;
    min-width: 0;
}

.timer-row-text {
    flex: 1 1 auto;
    min-height: 44px;
    min-width: 0;
    resize: vertical;
}

.timer-row-weight {
    flex: 0 0 74px;
}

.timer-check {
    align-items: center;
    color: var(--text-secondary);
    display: inline-flex;
    flex: 0 0 auto;
    font-size: 12px;
    gap: 5px;
    white-space: nowrap;
}

.timer-check input {
    accent-color: var(--accent);
}

.timer-pill {
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    flex: 0 0 auto;
    font-size: 11px;
    padding: 3px 8px;
    white-space: nowrap;
}

.timer-counter-value {
    color: var(--text-primary);
    flex: 0 0 auto;
    font-family: var(--font-mono);
    font-size: 16px;
    min-width: 38px;
    text-align: right;
}

.timer-meta-inline {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 12px;
    margin-right: auto;
}

.timer-empty {
    color: var(--text-muted);
    font-size: 13px;
    padding: 14px 0;
}

.timer-wheel-wrap {
    align-items: center;
    display: flex;
    justify-content: center;
    min-height: 250px;
    position: relative;
}

.timer-wheel {
    aspect-ratio: 1;
    background: var(--bg-main);
    border: 1px solid var(--border);
    border-radius: 50%;
    box-shadow: inset 0 0 0 18px rgba(13, 17, 23, 0.18);
    max-width: 280px;
    transition: transform 1.2s cubic-bezier(.16, .78, .23, 1);
    width: min(70vw, 280px);
}

.timer-wheel::after {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 50%;
    content: "";
    height: 54px;
    left: 50%;
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 54px;
}

.timer-wheel-pointer {
    border-left: 12px solid transparent;
    border-right: 12px solid transparent;
    border-top: 24px solid var(--accent-amber);
    left: 50%;
    position: absolute;
    top: 6px;
    transform: translateX(-50%);
    z-index: 2;
}

.timer-result {
    color: var(--accent-amber);
    font-size: 13px;
    min-height: 20px;
    text-align: center;
}

.timer-event {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 8px 10px;
}

.timer-event span {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

.timer-event strong {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}

.autonomy-page {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin: 0 auto;
    max-width: 1180px;
    padding: 18px;
    width: 100%;
}

.autonomy-hero {
    gap: 16px;
}

.autonomy-stats {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.autonomy-stats div,
.autonomy-meta {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: 10px;
}

.autonomy-stats span,
.autonomy-meta span,
.autonomy-settings label > span {
    color: var(--text-muted);
    font-size: 12px;
}

.autonomy-stats strong,
.autonomy-meta strong {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.autonomy-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.timer-settings-row {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.autonomy-persona-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.autonomy-persona-card {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    display: grid;
    gap: 10px;
    padding: 12px;
}

.autonomy-persona-card.disabled {
    opacity: 0.75;
}

.autonomy-persona-header {
    align-items: center;
    display: flex;
    gap: 8px;
    justify-content: space-between;
}

.autonomy-persona-name {
    color: var(--text-primary);
    font-weight: 600;
}

.autonomy-persona-meta {
    color: var(--text-secondary);
    display: grid;
    gap: 6px;
    line-height: 1.35;
    font-size: 12px;
    min-width: 0;
    word-wrap: break-word;
}

.autonomy-persona-meta span {
    overflow-wrap: anywhere;
}

.autonomy-persona-meta strong {
    color: var(--text-primary);
}

.timer-pill.enabled {
    background: rgba(63, 185, 80, 0.18);
    border-color: rgba(63, 185, 80, 0.45);
    color: var(--success);
}

.timer-pill.disabled {
    background: rgba(248, 81, 73, 0.17);
    border-color: rgba(248, 81, 73, 0.4);
    color: var(--danger);
}

.timer-pill.testing {
    background: rgba(210, 153, 34, 0.18);
    border-color: rgba(210, 153, 34, 0.45);
    color: var(--accent-amber);
}

.autonomy-wide {
    grid-column: 1 / -1;
}

.autonomy-settings {
    display: grid;
    gap: 12px;
}

.autonomy-settings label:not(.timer-check) {
    display: grid;
    gap: 6px;
}

.autonomy-world {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    margin: 0;
    max-height: 360px;
    overflow: auto;
    padding: 12px;
    white-space: pre-wrap;
}

.autonomy-current-run {
    color: var(--text-secondary);
    display: grid;
    gap: 10px;
}

.autonomy-current-run p {
    margin: 0;
}

.autonomy-current-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.autonomy-guidance-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.autonomy-guidance-grid h3 {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    margin: 0 0 8px;
}

.autonomy-pending-guidance {
    display: grid;
    gap: 10px;
}

.autonomy-proposal-meta {
    color: var(--text-secondary);
    display: grid;
    gap: 6px;
}

.autonomy-proposal-meta p {
    margin: 0;
}

.autonomy-file {
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 12px;
    overflow-wrap: anywhere;
}

.autonomy-intention {
    align-items: start;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr) auto;
}

.autonomy-intention strong {
    color: var(--text-primary);
    display: block;
    font-size: 13px;
    margin-bottom: 4px;
}

.autonomy-intention p {
    color: var(--text-secondary);
    margin: 0 0 4px;
}

.autonomy-intention span,
.autonomy-intention code {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
}

.autonomy-intention.completed,
.autonomy-intention.dropped {
    opacity: 0.68;
}

.autonomy-log {
    background: var(--bg-main);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    overflow: hidden;
}

.autonomy-log summary {
    align-items: center;
    cursor: pointer;
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(160px, 0.7fr) minmax(0, 1fr) auto;
    list-style: none;
    padding: 10px 12px;
}

.autonomy-log summary::-webkit-details-marker {
    display: none;
}

.autonomy-log summary span,
.autonomy-log summary em {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    font-style: normal;
}

.autonomy-log summary strong {
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}

.autonomy-log-body {
    border-top: 1px solid var(--border-light);
    color: var(--text-secondary);
    display: grid;
    gap: 8px;
    padding: 10px 12px 12px;
}

.autonomy-log-body p {
    margin: 0;
}

.autonomy-log-body ul {
    margin: 0;
    padding-left: 18px;
}

.autonomy-log-body pre {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.45;
    margin: 0;
    max-height: 240px;
    overflow: auto;
    padding: 10px;
    white-space: pre-wrap;
}

@media (max-width: 620px) {
    .timer-page {
        padding: 12px;
    }

    .autonomy-page {
        padding: 12px;
    }

    .timer-display {
        font-size: 34px;
    }

    .timer-dashboard-grid,
    .autonomy-grid,
    .autonomy-guidance-grid,
    .autonomy-stats {
        grid-template-columns: 1fr;
    }

    .timer-inline-form,
    .timer-row,
    .timer-row-top,
    .timer-row-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .timer-number-input,
    .timer-row-weight {
        flex-basis: auto;
        width: 100%;
    }

    .timer-check,
    .timer-pill,
    .timer-meta-inline {
        align-self: flex-start;
    }

    .timer-wheel-wrap {
        min-height: 210px;
    }

    .autonomy-log summary {
        align-items: flex-start;
        grid-template-columns: 1fr;
    }
}

@media (min-width: 769px) {
    .sidebar-close {
        display: none;
    }
}
