* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #0f1117;
    color: #e0e0e0;
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* Header */
#header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: #1a1d27;
    border-bottom: 1px solid #2a2d3a;
}

#header h1 {
    font-size: 16px;
    font-weight: 600;
    color: #a0a8c0;
}

#session-info {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    color: #6b7280;
}

#new-session-btn {
    padding: 5px 12px;
    background: #1e2030;
    border: 1px solid #2a2d3a;
    border-radius: 6px;
    color: #9ca3af;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

#new-session-btn:hover {
    border-color: #4f46e5;
    color: #a5b4fc;
    background: #1a1c2e;
}

.badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge.phase-init { background: #3b3f5c; color: #818cf8; }
.badge.phase-interview { background: #1e3a5f; color: #60a5fa; }
.badge.phase-summary { background: #3b2f1e; color: #fbbf24; }
.badge.phase-curiosity { background: #1e3b2f; color: #34d399; }

.hidden { display: none !important; }

/* Main container */
#main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Chat panel */
#chat-panel {
    flex: 0 0 60%;
    display: flex;
    flex-direction: column;
    border-right: 1px solid #2a2d3a;
}

/* Disease selector */
#disease-selector {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    padding: 24px 40px;
    position: relative;
    overflow-y: auto;
}

#disease-selector h2 {
    font-size: 20px;
    font-weight: 500;
    margin-bottom: 24px;
    color: #9ca3af;
}

#disease-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 600px;
}

.disease-card {
    padding: 12px 14px;
    background: #1a1d27;
    border: 1px solid #2a2d3a;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.disease-card:hover {
    border-color: #4f46e5;
    background: #1e2030;
}

.disease-card.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.disease-card .name {
    font-size: 13px;
    font-weight: 500;
    color: #e0e0e0;
}

.disease-card .cui {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
}

/* Loading overlay over disease list */
#disease-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(15, 17, 23, 0.75);
    backdrop-filter: blur(4px);
    border-radius: 8px;
    gap: 12px;
    color: #6b7280;
    font-size: 14px;
}

/* Error banner under disease list */
.error-banner {
    margin-top: 12px;
    padding: 10px 16px;
    background: #2d1515;
    border: 1px solid #7f1d1d;
    border-radius: 8px;
    color: #f87171;
    font-size: 13px;
    text-align: center;
    max-width: 400px;
    width: 100%;
}

/* Session browser */
#session-browser {
    width: 100%;
    max-width: 400px;
    margin-bottom: 20px;
}

#session-browser h3 {
    font-size: 14px;
    font-weight: 500;
    color: #6b7280;
    margin-bottom: 10px;
}

#session-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.session-card {
    padding: 12px 16px;
    background: #1a1d27;
    border: 1px solid #2a2d3a;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
}

.session-card:hover {
    border-color: #34d399;
    background: #1e2030;
}

.session-disease {
    font-size: 14px;
    font-weight: 500;
    color: #e0e0e0;
}

.session-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.session-meta .badge {
    font-size: 10px;
    padding: 2px 8px;
}

.session-id-label {
    font-size: 11px;
    color: #4b5563;
    font-family: "JetBrains Mono", "Fira Code", monospace;
}

/* Chat area */
#chat-area {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.message.assistant {
    align-self: flex-start;
    background: #1e2030;
    border: 1px solid #2a2d3a;
    color: #d1d5db;
}

.message.user {
    align-self: flex-end;
    background: #3730a3;
    color: #e0e7ff;
}

.message.system {
    align-self: center;
    background: #1a2e1a;
    border: 1px solid #2a4a2a;
    color: #86efac;
    font-size: 13px;
    text-align: center;
}

/* Option buttons below assistant messages */
.message-options {
    align-self: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}

.message-options.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.option-btn {
    padding: 7px 16px;
    background: #1e2030;
    border: 1px solid #3730a3;
    border-radius: 20px;
    color: #a5b4fc;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.option-btn:hover {
    background: #2d2f4a;
    border-color: #4f46e5;
    color: #c7d2fe;
}

.option-btn:disabled {
    cursor: not-allowed;
}

/* Implication note shown after selecting an option */
.option-implication {
    align-self: flex-end;
    max-width: 85%;
    padding: 6px 12px;
    font-size: 12px;
    line-height: 1.4;
    color: #9ca3af;
    background: #1a1d27;
    border-left: 2px solid #4f46e5;
    border-radius: 4px;
    margin-top: -4px;
}

/* Conversation History tab */
.history-entry {
    padding: 10px 14px;
    border-radius: 10px;
    margin-bottom: 8px;
    font-size: 13px;
    line-height: 1.5;
}

.history-user {
    background: #2a2654;
    border: 1px solid #3730a3;
    margin-left: 20%;
}

.history-user .history-message { color: #e0e7ff; }

.history-assistant {
    background: #1e2030;
    border: 1px solid #2a2d3a;
    margin-right: 10%;
}

.history-assistant .history-message { color: #d1d5db; }

.history-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.history-choices .option-btn {
    font-size: 11px;
    padding: 4px 10px;
    opacity: 0.6;
    cursor: default;
}

.history-meta {
    margin-top: 8px;
    font-size: 11px;
    color: #6b7280;
}

.history-trace { margin-top: 8px; }

.history-trace-toggle {
    font-size: 11px;
    color: #6b7280;
    cursor: pointer;
    user-select: none;
}

.history-trace-toggle:hover { color: #9ca3af; }

.history-trace-body {
    display: none;
    margin-top: 6px;
    padding-left: 8px;
    border-left: 1px solid #2a2d3a;
}

.history-trace-body.open { display: block; }

.history-trace-step {
    padding: 4px 0;
    font-size: 11px;
    color: #9ca3af;
}

.history-trace-step .trace-agent-name {
    font-size: 11px;
}

.history-trace-output {
    color: #6b7280;
    font-size: 11px;
    margin-top: 2px;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 80px;
    overflow: hidden;
}

/* Input area */
#input-area {
    display: flex;
    gap: 8px;
    padding: 16px 20px;
    background: #1a1d27;
    border-top: 1px solid #2a2d3a;
}

#user-input {
    flex: 1;
    padding: 10px 14px;
    background: #0f1117;
    border: 1px solid #2a2d3a;
    border-radius: 8px;
    color: #e0e0e0;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
}

#user-input:focus {
    border-color: #4f46e5;
}

#send-btn {
    padding: 10px 20px;
    background: #4f46e5;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

#send-btn:hover { background: #4338ca; }
#send-btn:disabled { background: #374151; color: #6b7280; cursor: not-allowed; }

/* Debug panel */
#debug-panel {
    flex: 0 0 40%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#debug-tabs {
    display: flex;
    background: #1a1d27;
    border-bottom: 1px solid #2a2d3a;
    padding: 0 8px;
    overflow-x: auto;
}

.tab-btn {
    padding: 10px 14px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: #6b7280;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s;
}

.tab-btn:hover { color: #9ca3af; }
.tab-btn.active { color: #818cf8; border-bottom-color: #818cf8; }

#debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.placeholder {
    color: #4b5563;
    font-style: italic;
    text-align: center;
    padding: 40px 20px;
}

.md-viewer {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #c9d1d9;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Agent trace */
.trace-step {
    margin-bottom: 12px;
    border: 1px solid #2a2d3a;
    border-radius: 8px;
    overflow: hidden;
}

.trace-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: #1a1d27;
    cursor: pointer;
    user-select: none;
}

.trace-header:hover { background: #1e2030; }

.trace-agent-name {
    font-size: 13px;
    font-weight: 600;
    color: #818cf8;
}

.trace-toggle {
    font-size: 11px;
    color: #6b7280;
}

.trace-body {
    padding: 10px 12px;
    font-size: 12px;
    line-height: 1.5;
    display: none;
}

.trace-body.open { display: block; }

.trace-body .label {
    font-weight: 600;
    color: #9ca3af;
    margin-top: 6px;
}

.trace-body .value {
    color: #c9d1d9;
    margin-bottom: 4px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.state-change {
    display: inline-block;
    padding: 2px 8px;
    background: #1e3a5f;
    color: #60a5fa;
    border-radius: 4px;
    font-size: 11px;
    margin: 2px;
}

/* Turn separator in trace */
.trace-turn-separator {
    text-align: center;
    color: #4b5563;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1px;
    padding: 8px 0;
    margin: 12px 0;
    border-top: 1px solid #2a2d3a;
}

/* Turn usage summary banner */
.trace-usage-summary {
    padding: 6px 12px;
    margin-bottom: 10px;
    background: #1a1d27;
    border: 1px solid #2a2d3a;
    border-radius: 6px;
    font-size: 12px;
    color: #9ca3af;
}

.trace-usage-summary .usage-label {
    font-weight: 600;
    color: #6b7280;
}

.trace-usage-summary .usage-in { color: #60a5fa; }
.trace-usage-summary .usage-out { color: #34d399; }
.trace-usage-summary .usage-total { color: #fbbf24; font-weight: 600; }

/* Per-step token count (inline in header) */
.trace-token-count {
    margin-left: 8px;
    font-size: 11px;
    font-weight: 400;
    color: #6b7280;
}

/* Model badge in header */
.trace-model {
    margin-left: 8px;
    font-size: 10px;
    font-weight: 500;
    color: #9ca3af;
    background: #2a2d3a;
    padding: 1px 6px;
    border-radius: 3px;
}

/* Duration in header */
.trace-duration {
    margin-left: 8px;
    font-size: 11px;
    color: #9ca3af;
}

/* Cost in header */
.trace-cost {
    margin-left: 8px;
    font-size: 11px;
    font-weight: 500;
    color: #34d399;
}

/* Tool call entries */
.tool-call-entry {
    margin: 4px 0 4px 8px;
    padding: 4px 8px;
    border-left: 2px solid #818cf8;
    background: #13151d;
    border-radius: 0 4px 4px 0;
}

.tool-call-entry.tool-response {
    border-left-color: #34d399;
}

.tool-call-name {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 12px;
    font-weight: 600;
    color: #c084fc;
}

.tool-call-args {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 11px;
    color: #9ca3af;
    white-space: pre-wrap;
    word-break: break-all;
    margin-top: 2px;
}

.tool-call-args a {
    color: #60a5fa;
    text-decoration: none;
    font-size: 10px;
}

.tool-call-args a:hover { text-decoration: underline; }

/* State change entry with key + value */
.state-change-entry {
    margin: 4px 0;
    padding: 2px 0;
}

.state-change-key {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 11px;
    font-weight: 600;
    color: #60a5fa;
    background: #1e3a5f;
    padding: 1px 6px;
    border-radius: 3px;
}

.state-change-value {
    font-family: "JetBrains Mono", "Fira Code", monospace;
    font-size: 11px;
    color: #9ca3af;
    white-space: pre-wrap;
    word-break: break-all;
    margin-top: 2px;
    padding-left: 4px;
}

.state-change-value a {
    color: #60a5fa;
    text-decoration: none;
    font-size: 10px;
}

.state-change-value a:hover { text-decoration: underline; }

.dimmed { color: #4b5563; font-style: italic; }

/* Turn usage cost and duration */
.trace-usage-summary .usage-cost { color: #34d399; font-weight: 600; }
.trace-usage-summary .usage-duration { color: #9ca3af; }

/* Loading indicator */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #2a2d3a;
    border-top: 2px solid #818cf8;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 8px auto;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Streaming trace step entrance animation */
.trace-step.streaming {
    animation: traceSlideIn 0.3s ease-out;
}

@keyframes traceSlideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #374151; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4b5563; }
