/* Alessia — Strategy Adviser Styles */

:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1b26;
    --bg-surface: #222436;
    --bg-message-user: #2a2d3e;
    --bg-message-assistant: #1e2030;
    --text-primary: #c8d3f5;
    --text-secondary: #828bb8;
    --text-muted: #545c7e;
    --accent: #7aa2f7;
    --accent-hover: #89b4fa;
    --border: #2f334d;
    --error: #f7768e;
    --encouraging: #9ece6a;
    --concerned: #e0af68;
    --font: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --radius: 12px;
    --radius-sm: 8px;
}

/* Light theme overrides */
:root[data-theme="light"] {
    --bg-primary: #f8f9fc;
    --bg-secondary: #eef0f5;
    --bg-surface: #ffffff;
    --bg-message-user: #e8ebf2;
    --bg-message-assistant: #f0f2f7;
    --text-primary: #1a1b26;
    --text-secondary: #4a5068;
    --text-muted: #7a7f96;
    --accent-hover: #5b8af0;
    --border: #d4d8e4;
    --error: #dc2626;
    --encouraging: #16a34a;
    --concerned: #d97706;
}

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

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

/* Layout */
.app-layout {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    gap: 1.25rem;
}

.sidebar-header {
    text-align: center;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.brand-sub {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
    letter-spacing: 0.03em;
}

#avatar-container {
    width: 100%;
    display: flex;
    justify-content: center;
}

#avatar-container video,
#expression-video {
    width: 100%;
    max-width: 240px;
    border-radius: var(--radius);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

/* Sidebar sections */
.sidebar-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
}

.sidebar-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.btn-icon {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
}

.btn-icon:hover {
    background: var(--bg-message-user);
    color: var(--text-primary);
}

/* Session list */
.session-list {
    list-style: none;
    overflow-y: auto;
    flex: 1;
    margin: 0;
    padding: 0;
}

.session-list::-webkit-scrollbar {
    width: 4px;
}

.session-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.6rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
    transition: background 0.1s ease;
}

.session-item:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

.session-item.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-left: 2px solid var(--accent);
}

.session-item.empty {
    color: var(--text-muted);
    font-style: italic;
    cursor: default;
}

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

.session-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1rem;
    padding: 0 0.25rem;
    opacity: 0;
    transition: opacity 0.1s;
}

.session-item:hover .session-delete {
    opacity: 1;
}

.session-delete:hover {
    color: var(--error);
}

/* Upload */
.upload-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 1.1rem;
    border-radius: var(--radius-sm);
    transition: background 0.1s;
    flex-shrink: 0;
}

.upload-btn:hover {
    background: var(--bg-surface);
}

.upload-feedback {
    padding: 0.5rem 1rem;
    font-size: 0.8rem;
    border-radius: var(--radius-sm);
    margin: 0 1.5rem;
}

.upload-feedback.success {
    background: rgba(45, 138, 110, 0.15);
    color: var(--encouraging);
    border: 1px solid rgba(45, 138, 110, 0.3);
}

.upload-feedback.error {
    background: rgba(247, 118, 142, 0.1);
    color: var(--error);
    border: 1px solid rgba(247, 118, 142, 0.3);
}

/* Chat header actions */
.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.75rem;
}

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
}

.btn-ghost:hover {
    background: var(--bg-surface);
    color: var(--text-primary);
}

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

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

/* Profile panel (modal) */
#modal-container:not(:empty) {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.profile-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    width: 360px;
    max-width: 90vw;
}

.profile-panel h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.profile-panel label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.profile-panel input,
.profile-panel select {
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.25rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.85rem;
}

.profile-panel button {
    margin-top: 0.5rem;
}

.profile-saved {
    color: var(--encouraging);
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem;
}

.sidebar-footer {
    margin-top: auto;
    text-align: center;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.user-name {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Buttons */
.btn {
    padding: 0.6rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease;
    width: 100%;
}

.btn-secondary {
    background: var(--bg-surface);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-message-user);
    color: var(--text-primary);
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.chat-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

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

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

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

.welcome-message {
    max-width: 600px;
    margin: auto;
    text-align: center;
    color: var(--text-secondary);
    line-height: 1.6;
}

.welcome-message p {
    margin-bottom: 0.75rem;
}

.message {
    display: flex;
    gap: 0.75rem;
    max-width: 85%;
    animation: fadeIn 0.2s ease;
}

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

.message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message.assistant {
    align-self: flex-start;
}

.message.error {
    align-self: center;
}

.message-avatar {
    font-size: 1.3rem;
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.message-body {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    line-height: 1.55;
    font-size: 0.9rem;
}

.message.user .message-body {
    background: var(--bg-message-user);
    border: 1px solid var(--border);
}

.message.assistant .message-body {
    background: var(--bg-message-assistant);
    border: 1px solid var(--border);
}

.message.error .message-body {
    background: rgba(247, 118, 142, 0.1);
    border: 1px solid var(--error);
    color: var(--error);
}

.message-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.35rem;
}

.message-body p {
    margin-bottom: 0.5rem;
}

.message-body p:last-child {
    margin-bottom: 0;
}

.message-body strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Markdown elements in messages */
.message-body h1,
.message-body h2,
.message-body h3,
.message-body h4 {
    color: var(--text-primary);
    margin: 0.8rem 0 0.4rem 0;
    line-height: 1.3;
}

.message-body h1 { font-size: 1.15rem; }
.message-body h2 { font-size: 1.05rem; }
.message-body h3 { font-size: 0.95rem; }
.message-body h4 { font-size: 0.9rem; }

.message-body ul,
.message-body ol {
    margin: 0.4rem 0;
    padding-left: 1.5rem;
}

.message-body li {
    margin-bottom: 0.25rem;
}

.message-body code {
    background: var(--bg-primary);
    padding: 0.15rem 0.35rem;
    border-radius: 4px;
    font-size: 0.82rem;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

.message-body pre {
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-body pre code {
    background: none;
    padding: 0;
    font-size: 0.82rem;
}

.message-body blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 0.75rem;
    margin: 0.5rem 0;
    color: var(--text-secondary);
}

.message-body a {
    color: var(--accent);
    text-decoration: none;
}

.message-body a:hover {
    text-decoration: underline;
}

.message-body hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.75rem 0;
}

/* Thinking indicator */
.htmx-indicator {
    display: none;
}

.htmx-indicator.htmx-request {
    display: flex;
}

.thinking-dots {
    display: flex;
    gap: 4px;
    padding: 0.25rem 0;
}

.thinking-dots span {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: pulse 1.2s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.thinking-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes pulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1); }
}

/* Chat Input */
#chat-input-area {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.input-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
}

#chat-textarea {
    flex: 1;
    padding: 0.75rem 1rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.9rem;
    resize: none;
    outline: none;
    transition: border-color 0.15s ease;
    line-height: 1.4;
}

#chat-textarea:focus {
    border-color: var(--accent);
}

#chat-textarea::placeholder {
    color: var(--text-muted);
}

.send-btn {
    padding: 0.75rem 1.25rem;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
    white-space: nowrap;
}

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

.send-btn:active {
    transform: scale(0.98);
}

/* Visualisation panels */
.vis-panel {
    margin-top: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--bg-primary);
}

.vis-panel-header {
    padding: 0.6rem 1rem;
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.vis-panel-header::marker,
.vis-panel-header::-webkit-details-marker {
    display: none;
}

.vis-panel-header::before {
    content: "▶";
    font-size: 0.6rem;
    transition: transform 0.15s ease;
    color: var(--text-muted);
}

.vis-panel[open] > .vis-panel-header::before {
    transform: rotate(90deg);
}

.vis-panel-content {
    padding: 1rem;
    overflow-x: auto;
}

/* Tables */
.vis-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.vis-table th {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.vis-table td {
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}

.vis-table tbody tr:hover {
    background: var(--bg-surface);
}

.vis-table td:nth-child(n+2) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Chart canvas */
.vis-panel canvas {
    max-height: 320px;
}

/* Mermaid diagrams */
.vis-panel .mermaid {
    display: flex;
    justify-content: center;
    padding: 0.5rem 0;
}

.vis-panel .mermaid svg {
    max-width: 100%;
}

.vis-error {
    color: var(--error);
    font-size: 0.85rem;
    font-style: italic;
}

/* Theme toggle */
.theme-toggle {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.4rem 0.6rem;
    transition: background 0.15s ease, color 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}

.theme-toggle:hover {
    background: var(--bg-message-user);
    color: var(--text-primary);
}

.sidebar-footer-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
}

/* History panel — slide-out overlay */
.history-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.history-overlay.open {
    opacity: 1;
    visibility: visible;
}

.history-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 420px;
    max-width: 90vw;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    z-index: 201;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
}

.history-overlay.open .history-panel {
    transform: translateX(0);
}

.history-panel-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-panel-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}

.history-close:hover {
    color: var(--text-primary);
}

.history-search {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.history-search input {
    width: 100%;
    padding: 0.6rem 0.9rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 0.85rem;
    outline: none;
    transition: border-color 0.15s ease;
}

.history-search input:focus {
    border-color: var(--accent);
}

.history-search input::placeholder {
    color: var(--text-muted);
}

.history-results {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

.history-results::-webkit-scrollbar {
    width: 4px;
}

.history-results::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* History table */
.history-table {
    width: 100%;
    border-collapse: collapse;
}

.history-th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 2px solid var(--border);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.history-th:hover {
    color: var(--text-primary);
}

.sort-arrow {
    font-size: 0.65rem;
    margin-left: 0.25rem;
}

.history-row {
    cursor: pointer;
    transition: background 0.1s ease;
}

.history-row:hover {
    background: var(--bg-surface);
}

.history-row td {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.history-title {
    font-size: 0.84rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.history-summary {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-width: 280px;
}

.history-row:hover .history-summary {
    color: var(--text-secondary);
}

.history-cell-date {
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.history-cell-msgs {
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-align: right !important;
    font-variant-numeric: tabular-nums;
}

.history-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 2rem 1rem;
}

/* Responsive: collapse sidebar on small screens */
@media (max-width: 768px) {
    .sidebar {
        width: 80px;
        min-width: 80px;
        padding: 1rem 0.5rem;
    }

    .brand-sub,
    .sidebar-footer,
    .sidebar-controls .btn {
        display: none;
    }

    .brand {
        font-size: 0.9rem;
    }

    #avatar-container video {
        max-width: 60px;
    }

    .message {
        max-width: 95%;
    }
}
