/* Casknition — Dark Amber Theme */

:root {
    --accent: #c0965c;
    --accent-hover: #d4a96e;
    --accent-dim: rgba(192, 150, 92, 0.15);
    --coral: #D93A5B;
    --green: #34d399;
    --purple: #a78bfa;
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #242837;
    --bg-surface: #2e3348;
    --text-primary: #e4e4e7;
    --text-secondary: #c4c4c8;
    --text-muted: #9ca3af;
    --border-color: #2e3348;
    --border-light: #3d4460;
    --sidebar-width: 280px;
    --sidebar-collapsed-width: 60px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: row;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* Page Wrapper */
.page-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-left: var(--sidebar-width);
    transition: margin-left 0.3s ease;
}

body:has(.chat-sidebar.collapsed) .page-wrapper {
    margin-left: var(--sidebar-collapsed-width);
}

/* Sidebar */
.chat-sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    transition: width 0.3s ease;
    position: fixed;
    top: 0;
    left: 0;
    z-index: 100;
}

.chat-sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

.sidebar-logo-section {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    flex-shrink: 0;
}

.sidebar-brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent);
    white-space: nowrap;
    overflow: hidden;
}

.chat-sidebar.collapsed .sidebar-brand { display: none; }

.sidebar-toggle-button {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.4rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.sidebar-toggle-button:hover {
    background: var(--bg-tertiary);
    border-color: var(--border-light);
    color: var(--text-primary);
}

.chat-sidebar.collapsed .sidebar-toggle-button { margin: 0 auto; }

/* New Chat Button */
.sidebar-header {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.new-chat-button {
    width: 100%;
    padding: 0.625rem 1rem;
    background: var(--accent);
    color: var(--bg-primary);
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: center;
    transition: all 0.2s ease;
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
}

.new-chat-button:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(192, 150, 92, 0.3);
}

.new-chat-button:active { transform: translateY(0); }

.chat-sidebar.collapsed .new-chat-button {
    padding: 0;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 50%;
    margin: 0 auto;
}

.chat-sidebar.collapsed .new-chat-button .new-chat-label { display: none; }

/* Sidebar Content */
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.chat-sidebar.collapsed .sidebar-content { display: none; }

.sidebar-content::-webkit-scrollbar { width: 6px; }
.sidebar-content::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 3px;
}

/* Conversation Sections */
.conversation-section { margin-bottom: 0.5rem; }

.section-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 0.75rem 1rem 0.25rem;
}

.conversation-list { display: flex; flex-direction: column; }

.no-conversations {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 2rem 1rem;
}

/* Conversation Items */
.conversation-item {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0.625rem 1rem;
    border-left: 3px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    border-bottom: 1px solid var(--border-color);
}

.conversation-item:hover { background: var(--bg-tertiary); }
.conversation-item.active {
    background: var(--bg-surface);
    border-left-color: var(--accent);
}
.conversation-item.pinned { border-left-color: var(--accent-hover); }

.conversation-content { flex: 1; min-width: 0; margin-right: 0.5rem; }

.conversation-title {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.125rem;
}

/* Conversation Actions */
.conversation-actions { position: relative; }

.conversation-menu-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: all 0.2s ease;
}

.conversation-item:hover .conversation-menu-btn { opacity: 1; }
.conversation-menu-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.conversation-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    z-index: 10002;
    min-width: 120px;
    display: none;
    overflow: hidden;
}

.conversation-dropdown.show { display: block; }

.conversation-dropdown button {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: none;
    background: transparent;
    text-align: left;
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.conversation-dropdown button:hover { background: var(--bg-tertiary); }
.conversation-dropdown button.delete-option { color: var(--coral); }
.conversation-dropdown button.delete-option:hover { background: rgba(217, 58, 91, 0.15); }

/* Nav links for editions/entities */
.nav-links {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border-color);
}

.nav-links a {
    padding: 0.5rem 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.nav-links a:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-links a.active { color: var(--accent); background: var(--accent-dim); }

/* Loading Indicators */
.htmx-indicator { display: none; }

.conversations-loading { text-align: center; padding: 1rem; }

.messages-loading {
    display: none;
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
}

.messages-loading.htmx-request { display: flex; }

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slideIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Rename Modal */
.rename-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 10003;
}
.rename-modal-overlay.show { display: block; }

.rename-modal {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: 12px;
    padding: 1.5rem;
    z-index: 10004;
    min-width: 400px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}
.rename-modal.show { display: block; }
.rename-modal h3 { margin-bottom: 1rem; color: var(--text-primary); }

.rename-input {
    width: 100%;
    padding: 0.625rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}
.rename-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(192, 150, 92, 0.2);
}

.rename-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

.btn-cancel {
    padding: 0.5rem 1rem;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
}
.btn-cancel:hover { background: var(--bg-tertiary); }

.btn-confirm {
    padding: 0.5rem 1rem;
    background: var(--accent);
    border: none;
    border-radius: 6px;
    color: var(--bg-primary);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
}
.btn-confirm:hover { background: var(--accent-hover); }

/* Container for editions/entities pages */
.container {
    max-width: 1000px;
    margin: 0 auto;
    padding: 2rem;
}

.page-title { font-size: 1.5rem; margin-bottom: 1rem; }

.search-input {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 0.9rem;
    outline: none;
}
.search-input:focus { border-color: var(--accent); }

.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem 1.25rem;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-sidebar { width: var(--sidebar-collapsed-width); }
    .page-wrapper { margin-left: var(--sidebar-collapsed-width); }
    .rename-modal { min-width: auto; width: calc(100% - 2rem); }
}
