/* Gordon Memoir Interview UI v2 — Dark Theme, Warm Amber Accent, Split-Screen Layout */

:root {
    --color-bg: #0f0f0f;
    --color-surface: #1a1a1a;
    --color-surface-2: #242424;
    --color-border: #333;
    --color-text: #e8e8e8;
    --color-text-dim: #999;
    --color-accent: #d4a574;
    --color-accent-hover: #e0b88a;
    --color-warm: #d4a574;
    --color-green: #4caf50;
    --color-red: #e57373;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

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

body {
    background: var(--color-bg);
    color: var(--color-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Inter", sans-serif;
    min-height: 100vh;
    overflow-x: hidden;
}

/* === Login Screen === */

#login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.login-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 40px;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: var(--shadow);
}

.login-card h1 {
    font-size: 1.5em;
    font-weight: 600;
    margin-bottom: 8px;
    letter-spacing: -0.02em;
    color: var(--color-accent);
}

.login-card p {
    color: var(--color-text-dim);
    font-size: 0.9em;
    margin-bottom: 24px;
}

.login-card input {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 12px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.95em;
    outline: none;
    transition: border-color 0.2s;
}

.login-card input:focus {
    border-color: var(--color-accent);
}

.login-card button {
    width: 100%;
    padding: 12px;
    background: var(--color-accent);
    color: #1a1a1a;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.login-card button:hover {
    background: var(--color-accent-hover);
}

.google-btn {
    width: 100%;
    padding: 12px;
    background: #fff;
    color: #3c4043;
    border: 1px solid #dadce0;
    border-radius: var(--radius-sm);
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: background 0.2s, box-shadow 0.2s;
}

.google-btn:hover {
    background: #f7f8f8;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

.apple-btn {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    background: #000;
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: background 0.2s;
}

.apple-btn:hover {
    background: #1a1a1a;
}

.login-divider {
    display: flex;
    align-items: center;
    margin: 16px 0;
    color: var(--color-text-dim);
    font-size: 0.8em;
}

.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--color-border);
}

.login-divider span {
    padding: 0 12px;
}

.login-error {
    color: var(--color-red);
    font-size: 0.85em;
    margin-top: 8px;
    min-height: 20px;
}

/* === Main App === */

#app-screen {
    display: none;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.app-header h1 {
    font-size: 1.15em;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--color-accent);
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-btn {
    padding: 6px 14px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.85em;
    cursor: pointer;
    transition: all 0.2s;
}

.header-btn:hover {
    background: var(--color-border);
}

.header-btn.primary {
    background: var(--color-accent);
    border-color: var(--color-accent);
    color: #1a1a1a;
}

.header-btn.primary:hover {
    background: var(--color-accent-hover);
}

.header-btn.danger {
    color: var(--color-red);
}

/* Session Title */

.session-title-input {
    background: transparent;
    border: 1px dashed transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 1em;
    font-weight: 500;
    padding: 4px 10px;
    outline: none;
    max-width: 300px;
    transition: border-color 0.2s;
}

.session-title-input:hover {
    border-color: var(--color-border);
}

.session-title-input:focus {
    border-color: var(--color-accent);
    border-style: solid;
}

/* === Split-Screen Layout (v2) === */

.app-main {
    display: grid;
    grid-template-columns: minmax(280px, 35%) 4px 1fr;
    flex: 1;
    overflow: hidden;
}

.app-main.outline-collapsed {
    grid-template-columns: 40px 0px 1fr;
}

/* Outline Panel */

.outline-panel {
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
    overflow: hidden;
    transition: min-width 0.2s;
}

.app-main.outline-collapsed .outline-panel {
    min-width: 40px;
    max-width: 40px;
}

.app-main.outline-collapsed .outline-tree,
.app-main.outline-collapsed .outline-stats,
.app-main.outline-collapsed .outline-header h2 {
    display: none;
}

.app-main.outline-collapsed .outline-collapse-btn {
    transform: rotate(180deg);
}

.outline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.outline-header h2 {
    font-size: 0.95em;
    font-weight: 600;
    color: var(--color-text);
}

.outline-collapse-btn {
    background: none;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    color: var(--color-text-dim);
    font-size: 0.85em;
    cursor: pointer;
    padding: 2px 6px;
    transition: all 0.2s;
}

.outline-collapse-btn:hover {
    border-color: var(--color-accent);
    color: var(--color-text);
}

.outline-tree {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.outline-tree::-webkit-scrollbar {
    width: 5px;
}

.outline-tree::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

/* Outline Node Styles */

.outline-act {
    margin-bottom: 4px;
}

.outline-node {
    padding: 5px 12px 5px 8px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88em;
    line-height: 1.4;
    transition: background 0.15s;
    user-select: none;
}

.outline-node:hover {
    background: var(--color-surface-2);
}

.outline-node.depth-0 {
    font-weight: 600;
    font-size: 0.92em;
    padding-left: 8px;
    color: var(--color-accent);
}

.outline-node.depth-1 {
    padding-left: 24px;
    font-weight: 500;
}

.outline-node.depth-2 {
    padding-left: 44px;
    font-size: 0.82em;
    color: var(--color-text-dim);
}

.outline-toggle {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    color: var(--color-text-dim);
    flex-shrink: 0;
    transition: transform 0.15s;
}

.outline-toggle.expanded {
    transform: rotate(90deg);
}

.outline-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.outline-dot.covered {
    background: var(--color-green);
}

.outline-dot.partial {
    background: var(--color-accent);
}

.outline-dot.unexplored {
    background: var(--color-border);
}

.outline-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.outline-count {
    font-size: 0.7em;
    color: var(--color-text-dim);
    flex-shrink: 0;
    background: var(--color-surface-2);
    padding: 1px 5px;
    border-radius: 8px;
}

.outline-children {
    overflow: hidden;
    transition: max-height 0.2s ease-out;
}

.outline-children.collapsed {
    max-height: 0 !important;
}

/* Outline Stats */

.outline-stats {
    padding: 10px 16px;
    border-top: 1px solid var(--color-border);
    font-size: 0.78em;
    color: var(--color-text-dim);
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
}

.outline-stats .stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.outline-stats .stat-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}

/* Panel Divider */

.panel-divider {
    background: var(--color-border);
    cursor: col-resize;
    transition: background 0.15s;
}

.panel-divider:hover {
    background: var(--color-accent);
}

/* Chat Panel */

.chat-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px 20px;
    gap: 16px;
}

/* Avatar Canvas */

.avatar-container {
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.avatar-canvas-wrapper {
    width: 100%;
    max-width: 480px;
    aspect-ratio: 4/3;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    position: relative;
}

.avatar-canvas-wrapper > #avatar-canvas {
    width: 100%;
    height: 100%;
    display: block;
}

.avatar-loading {
    position: absolute;
    bottom: 8px;
    left: 8px;
    padding: 3px 8px;
    background: rgba(0,0,0,0.6);
    border-radius: 4px;
    color: var(--color-text-dim);
    font-size: 0.8em;
    pointer-events: none;
    z-index: 2;
}

.avatar-loading.hidden {
    display: none;
}

.avatar-status {
    position: absolute;
    bottom: 8px;
    right: 8px;
    padding: 3px 8px;
    background: rgba(0,0,0,0.6);
    border-radius: 4px;
    font-size: 0.75em;
    color: var(--color-text-dim);
}

/* Chat Transcript */

.chat-container {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 3px;
}

.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.92em;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.chat-msg.assistant {
    align-self: flex-start;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--color-accent);
    color: #1a1a1a;
}

.chat-msg .voice-badge {
    font-size: 0.75em;
    opacity: 0.7;
    margin-left: 6px;
}

/* Input Area */

.input-area {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    padding-top: 4px;
}

.input-area input[type="text"] {
    flex: 1;
    padding: 12px 16px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-size: 0.95em;
    outline: none;
    transition: border-color 0.2s;
}

.input-area input[type="text"]:focus {
    border-color: var(--color-accent);
}

.input-area input[type="text"]::placeholder {
    color: var(--color-text-dim);
}

.btn-record {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: 2px solid var(--color-border);
    background: var(--color-surface);
    color: var(--color-text);
    font-size: 1.2em;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-record:hover {
    border-color: var(--color-accent);
}

.btn-record.recording {
    border-color: var(--color-red);
    background: rgba(229, 115, 115, 0.15);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(229,115,115,0.3); }
    50% { box-shadow: 0 0 0 8px rgba(229,115,115,0); }
}

.btn-send {
    padding: 12px 20px;
    background: var(--color-accent);
    border: none;
    border-radius: var(--radius-sm);
    color: #1a1a1a;
    font-size: 0.95em;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.btn-send:hover {
    background: var(--color-accent-hover);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Usage Stats Bar */

.usage-bar {
    text-align: center;
    font-size: 0.78em;
    color: var(--color-text-dim);
    padding: 4px 0;
    flex-shrink: 0;
}

/* === Sessions Panel === */

.sessions-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
}

.sessions-overlay.open {
    display: flex;
}

.sessions-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
}

.sessions-panel {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 360px;
    max-width: 90vw;
    background: var(--color-surface);
    border-left: 1px solid var(--color-border);
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    z-index: 1;
}

.sessions-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--color-border);
}

.sessions-header h2 {
    font-size: 1.1em;
    font-weight: 600;
}

.sessions-close {
    background: none;
    border: none;
    color: var(--color-text-dim);
    font-size: 1.5em;
    cursor: pointer;
    padding: 0 4px;
}

.sessions-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.session-card {
    padding: 12px 14px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.session-card:hover {
    border-color: var(--color-accent);
    background: var(--color-surface-2);
}

.session-card.active {
    border-color: var(--color-accent);
    background: rgba(212,165,116,0.1);
}

.session-card-title {
    font-weight: 500;
    font-size: 0.92em;
    margin-bottom: 4px;
}

.session-card-meta {
    font-size: 0.78em;
    color: var(--color-text-dim);
    display: flex;
    justify-content: space-between;
}

.session-card-status {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.75em;
    font-weight: 500;
}

.session-card-status.active { background: rgba(76,175,80,0.2); color: var(--color-green); }
.session-card-status.ended { background: rgba(153,153,153,0.2); color: var(--color-text-dim); }

.session-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

.session-card-actions button {
    padding: 4px 10px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: transparent;
    color: var(--color-text-dim);
    font-size: 0.78em;
    cursor: pointer;
    transition: all 0.15s;
}

.session-card-actions button:hover {
    border-color: var(--color-accent);
    color: var(--color-text);
}

.session-card-actions button.delete-btn:hover {
    border-color: var(--color-red);
    color: var(--color-red);
}

/* === Harvest Indicator === */

.usage-bar.harvest-active {
    color: var(--color-green);
    animation: harvest-pulse 1.5s ease-in-out infinite;
}

@keyframes harvest-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* === Coverage Legend (bottom of outline) === */

.coverage-legend {
    display: flex;
    gap: 12px;
    padding: 6px 16px;
    font-size: 0.72em;
    color: var(--color-text-dim);
    border-top: 1px solid var(--color-border);
}

.coverage-legend span {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* === Panel Sections (Nuggets, Characters, Timeline) === */

.panel-section {
    border-top: 1px solid var(--color-border);
}

.panel-section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.panel-section-header:hover {
    background: var(--color-surface-2);
}

.panel-section-header h3 {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--color-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    flex: 1;
}

.panel-section-toggle {
    font-size: 0.7em;
    color: var(--color-text-dim);
    transition: transform 0.15s;
    display: inline-block;
}

.panel-section-toggle.expanded {
    transform: rotate(90deg);
}

.panel-section-count {
    font-size: 0.72em;
    color: var(--color-text-dim);
    background: var(--color-surface-2);
    padding: 1px 6px;
    border-radius: 8px;
}

.panel-section-body {
    padding: 0 12px 8px;
    max-height: 250px;
    overflow-y: auto;
}

.panel-empty {
    font-size: 0.8em;
    color: var(--color-text-dim);
    padding: 8px 4px;
    font-style: italic;
}

/* Nugget Cards */

.nugget-card {
    padding: 8px 10px;
    margin-bottom: 6px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--color-accent);
}

.nugget-content {
    font-size: 0.82em;
    line-height: 1.4;
    color: var(--color-text);
}

.nugget-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}

.nugget-tag {
    font-size: 0.68em;
    padding: 1px 5px;
    background: rgba(212,165,116,0.2);
    color: var(--color-accent);
    border-radius: 4px;
}

.nugget-mood, .nugget-source {
    font-size: 0.68em;
    color: var(--color-text-dim);
}

.nugget-delete {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--color-text-dim);
    cursor: pointer;
    font-size: 1em;
    padding: 0 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.nugget-card:hover .nugget-delete {
    opacity: 1;
}

.nugget-delete:hover {
    color: var(--color-red);
}

/* Character Cards */

.character-card {
    padding: 8px 10px;
    margin-bottom: 6px;
    background: var(--color-surface-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    position: relative;
}

.character-card.confirmed {
    border-left: 3px solid var(--color-green);
}

.character-card.suggested {
    border-left: 3px solid var(--color-text-dim);
    opacity: 0.8;
}

.character-name {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--color-text);
}

.character-rel {
    font-size: 0.72em;
    color: var(--color-accent);
    margin-top: 1px;
}

.character-desc {
    font-size: 0.78em;
    color: var(--color-text-dim);
    margin-top: 3px;
    line-height: 1.3;
}

.character-actions {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.character-actions button {
    padding: 2px 8px;
    border: 1px solid var(--color-border);
    border-radius: 4px;
    background: transparent;
    color: var(--color-text-dim);
    font-size: 0.72em;
    cursor: pointer;
    transition: all 0.15s;
}

.character-actions button:first-child:hover {
    border-color: var(--color-green);
    color: var(--color-green);
}

.character-actions button:last-child:hover {
    border-color: var(--color-red);
    color: var(--color-red);
}

.character-delete {
    position: absolute;
    top: 6px;
    right: 6px;
    background: none;
    border: none;
    color: var(--color-text-dim);
    cursor: pointer;
    font-size: 0.9em;
    opacity: 0;
    transition: opacity 0.15s;
}

.character-card:hover .character-delete {
    opacity: 1;
}

.character-delete:hover {
    color: var(--color-red);
}

.characters-suggested-label {
    font-size: 0.72em;
    color: var(--color-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 8px 0 4px;
}

/* Timeline */

.timeline-track {
    position: relative;
    padding-left: 16px;
}

.timeline-track::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--color-border);
}

.timeline-event {
    position: relative;
    padding: 6px 0 12px 14px;
}

.timeline-dot {
    position: absolute;
    left: -13px;
    top: 10px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-accent);
    border: 2px solid var(--color-surface);
}

.timeline-period {
    font-size: 0.68em;
    color: var(--color-accent);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.timeline-title {
    font-size: 0.82em;
    font-weight: 500;
    color: var(--color-text);
    margin-top: 1px;
}

.timeline-desc {
    font-size: 0.75em;
    color: var(--color-text-dim);
    margin-top: 2px;
    line-height: 1.3;
}

/* === Responsive === */

@media (max-width: 900px) {
    .app-main {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }

    .outline-panel {
        max-height: 35vh;
        border-right: none;
        border-bottom: 1px solid var(--color-border);
    }

    .panel-divider {
        display: none;
    }

    .app-main.outline-collapsed .outline-panel {
        max-height: 40px;
        min-width: unset;
        max-width: unset;
    }

    .app-main.outline-collapsed {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 640px) {
    .app-header {
        padding: 10px 12px;
    }

    .app-header h1 {
        font-size: 1em;
    }

    .chat-panel {
        padding: 10px 12px;
        gap: 10px;
    }

    .avatar-canvas-wrapper {
        max-width: 100%;
        aspect-ratio: 16/10;
    }

    .input-area input[type="text"] {
        font-size: 16px; /* Prevent iOS zoom */
    }

    .sessions-panel {
        width: 100%;
        max-width: 100vw;
    }

    .session-title-input {
        max-width: 160px;
        font-size: 0.9em;
    }

    .outline-node.depth-1 {
        padding-left: 16px;
    }

    .outline-node.depth-2 {
        padding-left: 32px;
    }
}
