/* ═══════════════════════════════════════════════════════
   REGINA — Dark Theme Stylesheet
   Loyal Companion AI Agent
   ═══════════════════════════════════════════════════════ */

/* ── CSS Variables ── */
:root {
    --bg-primary: #0f0f14;
    --bg-secondary: #1a1a24;
    --bg-tertiary: #252532;
    --bg-elevated: #2d2d3d;
    --bg-input: #1e1e2a;

    --text-primary: #e8e8f0;
    --text-secondary: #a0a0b5;
    --text-muted: #6a6a80;

    --accent: #8b5cf6;
    --accent-hover: #a78bfa;
    --accent-glow: rgba(139, 92, 246, 0.15);

    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;

    --border: #33334a;
    --border-hover: #4a4a6a;

    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;

    --sidebar-width: 280px;
    --panel-width: 380px;

    --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', 'SF Pro Display', system-ui, -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ═══════════════════════════════════════════════════════
   LOGIN PAGE
   ═══════════════════════════════════════════════════════ */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    background: radial-gradient(ellipse at center, var(--bg-secondary) 0%, var(--bg-primary) 70%);
}

.login-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 48px 40px;
    width: 400px;
    max-width: 90vw;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px var(--accent-glow);
    text-align: center;
}

.login-avatar {
    font-size: 48px;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.login-header h1 {
    font-size: 28px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 32px;
}

.login-flash {
    margin-bottom: 20px;
}

.flash-error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--danger);
    color: #fca5a5;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 14px;
}

.login-form .form-group {
    margin-bottom: 16px;
}

.login-form input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 15px;
    transition: border var(--transition);
}

.login-form input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-btn {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

.login-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 24px var(--accent-glow);
}

.login-btn:active {
    transform: translateY(0);
}

.login-footer {
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ═══════════════════════════════════════════════════════
   APP LAYOUT
   ═══════════════════════════════════════════════════════ */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: margin-left var(--transition);
    z-index: 100;
}

.sidebar.collapsed {
    margin-left: calc(-1 * var(--sidebar-width));
}

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

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 18px;
    font-weight: 700;
}

.brand-icon { font-size: 22px; }

.new-chat-btn {
    margin: 12px;
    padding: 10px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    transition: all var(--transition);
    text-align: left;
}

.new-chat-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

.conversation-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px;
}

.conv-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    margin-bottom: 4px;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: background var(--transition);
}

.conv-item:hover {
    background: var(--bg-tertiary);
}

.conv-item.active {
    background: var(--accent-glow);
    border: 1px solid var(--accent);
}

.conv-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 14px;
}

.conv-delete {
    background: none;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--transition);
    padding: 2px 4px;
}

.conv-item:hover .conv-delete {
    opacity: 0.6;
}

.conv-delete:hover {
    opacity: 1 !important;
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 8px;
}

.sidebar-tab {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
}

.sidebar-tab:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.logout-tab:hover {
    color: var(--danger);
}

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

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.chat-title {
    flex: 1;
    font-size: 16px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    padding: 6px 8px;
    border-radius: var(--radius-xs);
    transition: all var(--transition);
}

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

.icon-btn.active {
    color: var(--accent);
    background: var(--accent-glow);
}

.menu-toggle { display: none; }

/* ── Messages ── */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.empty-icon {
    font-size: 56px;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

.empty-state h2 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-muted);
    font-size: 15px;
}

.message {
    max-width: 760px;
    margin: 0 auto 20px;
    display: flex;
    gap: 12px;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--bg-elevated);
}

.message.assistant .message-avatar {
    background: var(--accent-glow);
    border: 1px solid var(--accent);
}

.message-content {
    flex: 1;
    padding-top: 6px;
}

.message-role {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: capitalize;
}

.message-text {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-primary);
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-text em {
    color: var(--accent-hover);
    font-style: italic;
}

.prefill-badge {
    display: inline-block;
    background: var(--accent-glow);
    color: var(--accent-hover);
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    margin-bottom: 4px;
}

/* ── Typing Indicator ── */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

/* ── Input Area ── */
.input-area {
    padding: 12px 20px 20px;
    background: var(--bg-primary);
}

.prefill-input-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px 12px;
    background: var(--accent-glow);
    border: 1px dashed var(--accent);
    border-radius: var(--radius-sm);
}

.prefill-input-wrapper input {
    flex: 1;
    background: none;
    border: none;
    color: var(--accent-hover);
    font-size: 13px;
    font-style: italic;
}

.prefill-input-wrapper input:focus { outline: none; }
.prefill-input-wrapper input::placeholder { color: var(--text-muted); }

.icon-btn-small {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 6px;
    border-radius: 4px;
}

.icon-btn-small:hover { color: var(--danger); }

.chat-input-row {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px;
    transition: border var(--transition);
}

.chat-input-row:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

#chat-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
    resize: none;
    max-height: 160px;
    padding: 8px 4px;
    line-height: 1.5;
}

#chat-input:focus { outline: none; }

.send-btn {
    width: 40px;
    height: 40px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
}

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

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

/* ═══════════════════════════════════════════════════════
   PANELS (Config + Memory)
   ═══════════════════════════════════════════════════════ */
.config-panel, .memory-panel {
    width: var(--panel-width);
    min-width: var(--panel-width);
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    right: 0;
    top: 0;
    height: 100vh;
    transform: translateX(100%);
    transition: transform var(--transition);
    z-index: 200;
}

.config-panel.open, .memory-panel.open {
    transform: translateX(0);
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.3);
}

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

.panel-header h2 {
    font-size: 16px;
    font-weight: 600;
}

.panel-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
}

.panel-tab-btn {
    padding: 6px 12px;
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
}

.panel-tab-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-hover);
}

.panel-tab-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

.config-label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-weight: 500;
}

.config-editor {
    width: 100%;
    min-height: 360px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
    font-size: 13px;
    padding: 12px;
    resize: vertical;
    line-height: 1.6;
}

.config-editor:focus {
    outline: none;
    border-color: var(--accent);
}

.save-btn {
    margin-top: 12px;
    width: 100%;
    padding: 10px;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
}

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

/* ── LLM Form ── */
.llm-form { margin-bottom: 16px; }

.form-row {
    margin-bottom: 12px;
}

.form-row label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.form-row input,
.form-row select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-size: 13px;
}

.form-row input:focus,
.form-row select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-row.dual {
    display: flex;
    gap: 12px;
}

.form-row.dual > div { flex: 1; }

.form-row.dual input { padding: 8px 10px; }

/* ── Memory Panel ── */
.memory-controls {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

#memory-search {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-primary);
    font-size: 13px;
    margin-bottom: 8px;
}

#memory-search:focus { outline: none; border-color: var(--accent); }

.memory-filter {
    display: flex;
    gap: 4px;
}

.filter-btn {
    flex: 1;
    padding: 4px 8px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    color: var(--text-secondary);
    font-size: 11px;
    cursor: pointer;
    transition: all var(--transition);
}

.filter-btn:hover { color: var(--text-primary); }

.filter-btn.active {
    background: var(--accent-glow);
    border-color: var(--accent);
    color: var(--accent-hover);
}

.memory-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.memory-item {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 10px 12px;
    margin-bottom: 8px;
    transition: border var(--transition);
}

.memory-item:hover {
    border-color: var(--border-hover);
}

.memory-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.memory-type-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 600;
    text-transform: uppercase;
}

.memory-type-badge.factual { background: rgba(34, 197, 94, 0.2); color: #4ade80; }
.memory-type-badge.episodic { background: rgba(245, 158, 11, 0.2); color: #fbbf24; }
.memory-type-badge.self { background: rgba(139, 92, 246, 0.2); color: #c4b5fd; }

.memory-item-actions {
    display: flex;
    gap: 4px;
}

.memory-edit-btn, .memory-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.5;
    transition: opacity var(--transition);
}

.memory-item:hover .memory-edit-btn,
.memory-item:hover .memory-delete-btn { opacity: 1; }
.memory-delete-btn:hover { color: var(--danger); }

.memory-item-content {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.5;
}

.memory-item-content[contenteditable="true"] {
    background: var(--bg-input);
    padding: 4px 6px;
    border-radius: 4px;
    border: 1px solid var(--accent);
}

.memory-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
}

.danger-btn {
    width: 100%;
    padding: 8px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--danger);
    border-radius: var(--radius-xs);
    color: #fca5a5;
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
}

.danger-btn:hover {
    background: var(--danger);
    color: white;
}

/* ── Journal List ── */
.journal-list { margin-bottom: 16px; }

.journal-entry {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 10px 12px;
    margin-bottom: 8px;
}

.journal-entry-title {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 4px;
}

.journal-entry-content {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.journal-entry-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* ── Overlay ── */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition);
    z-index: 150;
}

.overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ── Toast ── */
.toast-container {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 20px;
    font-size: 14px;
    color: var(--text-primary);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    animation: toast-in 0.3s ease;
}

.toast.success { border-color: var(--success); color: #4ade80; }
.toast.error { border-color: var(--danger); color: #fca5a5; }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ═══════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ═══════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        margin-left: calc(-1 * var(--sidebar-width));
        z-index: 300;
    }

    .sidebar.mobile-open {
        margin-left: 0;
    }

    .menu-toggle { display: block; }

    .config-panel, .memory-panel {
        width: 100vw;
        min-width: 100vw;
    }

    .message {
        max-width: 100%;
    }

    .chat-input-row {
        max-width: 100%;
    }
}
