@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500&family=Roboto:wght@400;500&family=Roboto+Mono&display=swap');

:root {
    --sidebar-bg: #f0f4f9;
    --main-bg: #ffffff;
    --text-primary: #1f1f1f;
    --text-secondary: #444746;
    --text-tertiary: #70757a;
    --accent-blue: #0b57d0;
    --selected-item: #d3e3fd;
    --border-color: #dee1e6;
    --hover-bg: #e1e5ea;
    --input-bg: #f0f4f9;
    --json-bg: #fdfdfd;
    --json-header: #f8f9fa;
    --modal-bg: #ffffff;
    --toast-bg: #323335;
}

body.dark-mode {
    --sidebar-bg: #1e1f20;
    --main-bg: #131314;
    --text-primary: #e3e3e3;
    --text-secondary: #c4c7c5;
    --text-tertiary: #9aa0a6;
    --accent-blue: #a8c7fa;
    --selected-item: #394457;
    --border-color: #444746;
    --hover-bg: #2d2f31;
    --input-bg: #1e1f20;
    --json-bg: #1e1f20;
    --json-header: #2d2f31;
    --modal-bg: #282a2c;
    --toast-bg: #e3e3e3;
}

* {
    margin: 0; padding: 0; box-sizing: border-box;
    transition: background-color 0.2s ease, border-color 0.2s ease;
}

body {
    font-family: 'Google Sans', Roboto, sans-serif;
    background-color: var(--main-bg); color: var(--text-primary);
    height: 100vh; width: 100vw; overflow: hidden;
}

.material-symbols-rounded {
    font-family: 'Material Symbols Rounded';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-feature-settings: 'liga';
    -webkit-font-smoothing: antialiased;
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 20;
}

.app-layout { display: flex; height: 100vh; width: 100vw; }

/* --- SIDEBAR --- */
.sidebar {
    width: 280px; min-width: 280px; background-color: var(--sidebar-bg);
    display: flex; flex-direction: column; transition: all 0.3s ease;
    z-index: 1000; border-right: 1px solid var(--border-color);
    overflow-x: hidden;
}
.sidebar.collapsed { width: 0; min-width: 0; overflow: hidden; border: none; }
.sidebar-header { padding: 1.5rem 1rem; }
.btn-new-chat {
    background: var(--hover-bg); border: none; border-radius: 12px; padding: 10px 16px;
    font-size: 0.9rem; font-weight: 500; cursor: pointer; display: flex; align-items: center;
    gap: 12px; color: var(--text-primary); width: calc(100% - 20px); margin: 0 10px;
}
.btn-new-chat:hover { background: var(--selected-item); }
.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0.5rem 0.75rem;
}
.sidebar-footer { padding: 1rem; border-top: 1px solid var(--border-color); }
.btn-nav {
    width: 100%; padding: 12px; border: none; background: none; border-radius: 12px;
    cursor: pointer; font-size: 0.9rem; display: flex; align-items: center; gap: 12px; color: var(--text-secondary);
}
.btn-nav:hover { background: var(--hover-bg); color: var(--text-primary); }

/* SCROLLBARS */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.2); border-radius: 10px; }
body.dark-mode ::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); }

/* --- HISTORIAL --- */
.history-group-header {
    padding: 1rem 12px 0.4rem;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05rem;
    opacity: 0.8;
    display: flex;
    align-items: center;
    gap: 8px;
}
/* Style for Pinned Header specifically */
.history-group-header:first-of-type {
    color: var(--accent-blue);
}
.history-item {
    position: relative;
    margin: 2px 0;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.2s;
    color: var(--text-secondary);
}
.history-item:hover { background-color: var(--hover-bg); color: var(--text-primary); }
.history-item.active { background-color: var(--selected-item); color: var(--accent-blue); font-weight: 500; }
.history-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.85rem;
}
.history-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.2s; }
.history-item:hover .history-actions { opacity: 1; }
.btn-history-action { background: none; border: none; padding: 4px; cursor: pointer; color: var(--text-tertiary); display: flex; align-items: center; justify-content: center; border-radius: 4px; }
.btn-history-action:hover { background-color: var(--hover-bg); color: var(--text-primary); }

/* --- CONTEXT MENU --- */
.history-menu {
    position: fixed; /* Fixed to avoid container clipping */
    background-color: var(--modal-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 10000;
    min-width: 160px;
    padding: 6px 0;
    display: none;
    pointer-events: auto;
}
.history-menu.show { display: block; }
.history-menu-item {
    padding: 10px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.85rem;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all 0.2s;
}
.history-menu-item:hover { background-color: var(--hover-bg); color: var(--text-primary); }
.history-menu-item span.material-symbols-rounded { font-size: 20px; }
.history-menu-item.delete:hover { color: #d93025; background-color: #fce8e6; }
body.dark-mode .history-menu-item.delete:hover { background-color: #3c2626; color: #f28b82; }

/* Remove old animation as it conflicts with fixed positioning calc */
.history-menu.show { animation: none; }

/* --- MAIN --- */
.main-content { flex: 1; display: flex; flex-direction: column; min-width: 0; background-color: var(--main-bg); }
.top-bar { height: 64px; display: flex; align-items: center; padding: 0 1rem; gap: 1rem; border-bottom: 1px solid var(--border-color); }
.btn-menu { background: none; border: none; cursor: pointer; padding: 8px; border-radius: 50%; color: var(--text-secondary); display: flex; align-items: center; }
.btn-menu:hover { background: var(--hover-bg); }

.chat-viewport { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.chat-inner { max-width: 850px; width: 100%; margin: 0 auto; padding: 1.5rem 1.5rem; }

/* --- MESSAGES --- */
.message { margin-bottom: 1rem; display: flex; gap: 1.5rem; width: 100%; }
.message.user { flex-direction: row-reverse; }
.message-content {
    max-width: 85%;
    font-size: 1rem;
    line-height: 1.4;
    color: var(--text-primary);
    font-family: 'Google Sans', Roboto, sans-serif;
    overflow-wrap: break-word;
}

.message-content p,
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6,
.message-content ul,
.message-content ol,
.message-content li {
    margin-top: 0;
    margin-bottom: 0;
}

.message-content li { margin-left: 1em; }

.message-content p + p,
.message-content h1 + p,
.message-content h2 + p,
.message-content h3 + p,
.message-content h4 + p,
.message-content h5 + p,
.message-content h6 + p,
.message-content ul + p,
.message-content ol + p {
    margin-top: 0.4em;
}

.message-content h1, .message-content h2, .message-content h3, .message-content h4, .message-content h5, .message-content h6 {
    margin-top: 0.5em;
    margin-bottom: 0.2em;
}

.message-content ul, .message-content ol {
    margin-top: 0.2em;
    margin-bottom: 0.2em;
}

/* --- CODE STYLES --- */
.message-content code {
    max-width: 100%;
    overflow: hidden; /* Prevent horizontal scroll on inline code */
    background-color: var(--input-bg);
    padding: 0.1em 0.3em;
    border-radius: 0.3em;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.9em;
}

.message-content pre {
    max-width: 100%;
    overflow-x: auto; /* Allow horizontal scroll ONLY inside code blocks */
    background-color: var(--input-bg);
    padding: 0.8em;
    border-radius: 0.5em;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.9em;
    margin-top: 0.5em;
    margin-bottom: 0.5em;
}

.message.user .message-content { background-color: var(--input-bg); padding: 8px 16px; border-radius: 20px; }
.message.bot .message-content { width: 100%; }

/* --- FEEDBACK --- */
.message-actions { display: flex; gap: 8px; margin-top: 4px; opacity: 0.6; transition: opacity 0.2s; }
.message:hover .message-actions { opacity: 1; }
.btn-feedback {
    background: none; border: 1px solid var(--border-color); border-radius: 8px;
    padding: 4px 8px; cursor: pointer; color: var(--text-tertiary); display: flex;
    align-items: center; gap: 4px; transition: all 0.2s;
}
.btn-feedback:hover { background: var(--hover-bg); color: var(--accent-blue); border-color: var(--accent-blue); }
.btn-feedback.active { background: var(--selected-item); color: var(--accent-blue); border-color: var(--accent-blue); }
.btn-feedback .material-symbols-rounded { font-size: 18px; }

/* --- JSON BOX --- */
.json-box-container {
    background: var(--modal-bg); border: 1px solid var(--border-color); border-radius: 12px;
    margin: 1.5rem 0 1rem; box-shadow: 0 4px 12px rgba(0,0,0,0.1); overflow: visible; width: 100%;
}

.json-tree-view {
    width: 100%;
    max-height: 500px;
    overflow: auto;
    background: var(--json-bg);
    padding: 10px;
    border-radius: 0 0 12px 12px;
}

/* Specific reset for JSON box pre to avoid double spacing and overflow */
.json-tree-view pre {
    margin: 0 !important;
    padding: 0 !important;
    background: transparent !important;
    font-family: 'Roboto Mono', monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    max-width: 100%;
    overflow: visible; /* Scroll handled by .json-tree-view parent */
}

/* Syntax Highlighting (WCAG AA Compliant) */
.json-key { color: #b71c1c; font-weight: 500; }
.json-string { color: #0d652d; }
.json-number { color: #1a73e8; }
.json-boolean { color: #c5221f; }
.json-null { color: #5f6368; }

body.dark-mode .json-key { color: #f28b82; font-weight: 500; }
body.dark-mode .json-string { color: #81c995; }
body.dark-mode .json-number { color: #8ab4f8; }
body.dark-mode .json-boolean { color: #f28b82; }
body.dark-mode .json-null { color: #9aa0a6; }

.json-box-header {
    background: var(--json-header); border-bottom: 1px solid var(--border-color); padding: 10px 16px;
    display: flex; justify-content: space-between; align-items: center; border-radius: 12px 12px 0 0;
}
.json-box-actions { display: flex; gap: 8px; align-items: center; }
.btn-action-small {
    width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-color);
    background: var(--modal-bg); cursor: pointer; color: var(--accent-blue);
    display: flex; align-items: center; justify-content: center; transition: all 0.2s;
}
.btn-action-small:hover {
    background-color: var(--hover-bg);
    border-color: var(--accent-blue);
}

.status-active {
    color: #1e8e3e; /* Google Success Green */
    font-weight: 500;
}

body.dark-mode .status-active {
    color: #81c995; /* Lighter Green for Dark Mode */
}

/* --- INPUT AREA --- */
.input-area { padding: 1rem 1.5rem 2.5rem; display: flex; flex-direction: column; align-items: center; background: var(--main-bg); }
.input-wrapper {
    max-width: 800px; width: 100%; background-color: var(--input-bg); border-radius: 32px;
    display: flex; align-items: center; padding: 0.6rem 1.5rem; margin: 0 auto;
}
.input-area textarea {
    flex: 1; border: none; background: transparent; padding: 6px 8px;
    font-size: 1rem; outline: none; resize: none; max-height: 200px; color: var(--text-primary);
}
.btn-round { background: none; border: none; color: var(--accent-blue); cursor: pointer; padding: 8px; border-radius: 50%; display: flex; align-items: center; }

/* --- MODALS --- */
.modal { display: none; position: fixed; z-index: 2000; left: 0; top: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.modal-content {
    background: var(--modal-bg); margin: 5vh auto; width: 90%; max-width: 450px; border-radius: 24px;
    overflow: hidden; display: flex; flex-direction: column; box-shadow: 0 20px 40px rgba(0,0,0,0.3); border: 1px solid var(--border-color);
}
.modal-content.large { max-width: 900px; height: 90vh; }
.modal-header { padding: 1.5rem; border-bottom: 1px solid var(--border-color); display: flex; justify-content: space-between; align-items: center; }
.modal-header h2 { font-size: 1.2rem; font-weight: 500; color: var(--text-primary); }
.modal-body { padding: 1.5rem; flex: 1; display: flex; flex-direction: column; gap: 1.2rem; overflow-y: auto; }
.modal-footer { padding: 1rem 1.5rem; background: var(--json-header); display: flex; justify-content: flex-end; gap: 12px; border-top: 1px solid var(--border-color); }
.btn-modal { padding: 10px 24px; border-radius: 100px; cursor: pointer; font-size: 0.9rem; font-weight: 500; border: none; display: flex; align-items: center; justify-content: center; width: auto; }
.btn-modal-primary { background: var(--accent-blue); color: white; }
.btn-modal-secondary { background: var(--modal-bg); color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-modal-danger { background: #d93025; color: white; }

.form-group { display: flex; flex-direction: column; gap: 0.5rem; }
.form-group label { font-size: 0.85rem; font-weight: 500; color: var(--text-secondary); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 12px; border-radius: 12px; border: 1px solid var(--border-color); background: var(--main-bg); color: var(--text-primary); font-size: 0.95rem; outline: none;
}

/* --- TOASTS --- */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 9999; }
.toast {
    padding: 12px 20px; border-radius: 8px; background: #323335; color: white;
    font-size: 0.9rem; box-shadow: 0 4px 12px rgba(0,0,0,0.3); display: flex;
    align-items: center; gap: 10px; animation: toastSlideIn 0.3s ease forwards;
}
.toast.error { background: #d93025; }

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

@keyframes toastFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

.toast.fade-out { animation: toastFadeOut 0.3s ease forwards; }

@media (max-width: 768px) {
    .sidebar { position: fixed; height: 100%; left: 0; top: 0; box-shadow: 4px 0 15px rgba(0,0,0,0.1); }
    .sidebar.collapsed { transform: translateX(-100%); width: 280px; }
}
