/* styles.css */
:root {
    /* --- Light Theme --- */
    --bg-app: #f8fafc;
    --bg-surface: #ffffff;
    --bg-sidebar: #f1f5f9;
    --bg-code: #1e293b;
    --bg-code-header: #0f172a;

    --border-subtle: #e2e8f0;
    --border-focus: #cbd5e1;

    --text-main: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --accent-primary: #7e9dcd;
    --accent-surface: #eff6ff;

    --thought-bg: #f8fafc;
    --thought-border: #e2e8f0;
    --thought-text: #475569;

    --hover-bg: rgba(0, 0, 0, 0.04);

    --scrollbar-track: #f1f1f1;
    --scrollbar-thumb: #c1c1c1;

    --sidebar-width: 280px;
    --header-height: 64px;
    --content-width: 800px; /* Default content width */
    --radius-sm: 6px;
    --radius-md: 10px;

    --font-sans: 'Inter', -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

[data-theme="dark"] {
    --bg-app: #1f1f1f;
    --bg-surface: #252525;
    --bg-sidebar: #1f1f1f;
    --bg-code: #1f1f1f;
    --bg-code-header: #2a2a2a;

    --border-subtle: #333333;
    --border-focus: #444444;

    --text-main: #e0e0e0;
    --text-muted: #a0a0a0;
    --text-faint: #666666;

    --accent-primary: #ababab;
    --accent-hover: #ffffff;
    --accent-surface: rgba(171, 171, 171, 0.1);

    --thought-bg: #222222;
    --thought-border: #333333;
    --thought-text: #888888;

    --hover-bg: rgba(255, 255, 255, 0.05);

    --scrollbar-track: #1f1f1f;
    --scrollbar-thumb: #333333;
}

* {
    box-sizing: border-box;
    outline: none;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg-app);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    width: 100%;
    overflow: hidden;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    transition: background-color 0.3s ease, color 0.3s ease;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 5px;
    border: 2px solid var(--scrollbar-track);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent-primary);
}

#sidebar {
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 20;
    transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
}

.sidebar-top {
    padding: 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.logo-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.brand-text h1 {
    font-size: 15px;
    font-weight: 600;
    margin: 0;
}

.version-link {
    font-size: 10px;
    color: var(--text-muted);
    background: var(--border-subtle);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
    text-decoration: none;
    transition: all 0.2s ease;
    margin-left: -3px;
}

.version-link:hover {
    color: var(--text-main);
    background: var(--hover-bg);
}

.search-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-input-wrapper {
    position: relative;
    color: var(--text-muted);
    flex-grow: 1;
}

.search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    pointer-events: none;
}

.search-input-wrapper input {
    width: 100%;
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    padding: 8px 10px 8px 34px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    transition: all 0.2s ease;
}

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

.search-toggle {
    font-size: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-toggle:hover, .search-toggle.active {
    color: var(--text-main);
}

.search-toggle.active {
    background-color: var(--accent-surface);
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0 12px;
}

.sidebar-mini-tabs {
    display: flex;
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: 8px;
    margin-top: 20px;
}

.mini-tab {
    flex: 1;
    background: none;
    border: none;
    padding: 6px 0;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.mini-tab.active {
    color: var(--text-main);
    border-bottom-color: var(--accent-primary);
}

.mini-tab:hover {
    color: var(--text-main);
}

.history-view {
    display: none;
}

.history-view.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

.recent-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 13px;
    font-family: inherit;
    margin-bottom: 2px;
}

.file-name-group {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow: hidden;
    white-space: nowrap;
}

.file-name-group i {
    color: var(--text-muted);
    font-size: 14px;
    flex-shrink: 0;
}

.file-text {
    overflow: hidden;
    text-overflow: ellipsis;
}

.recent-file-item:hover {
    background: var(--hover-bg);
}

.recent-file-item.active {
    background: var(--bg-surface);
    color: var(--accent-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    font-weight: 500;
}

[data-theme="dark"] .recent-file-item.active {
    background: var(--hover-bg);
    color: var(--text-main);
}

.pin-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 14px;
    opacity: 0;
    transition: all 0.2s;
    padding: 2px;
}

.recent-file-item:hover .pin-btn, .recent-file-item.active .pin-btn {
    opacity: 1;
}

.pin-btn:hover {
    color: var(--accent-primary);
    transform: scale(1.1);
}

.pin-btn.is-pinned {
    opacity: 1;
    color: var(--accent-primary);
}

.scrolling-pinned {
    max-height: 152px;
    overflow-y: auto;
    padding-right: 2px;
}

.scrolling-pinned::-webkit-scrollbar {
    width: 4px;
}

.scrolling-pinned::-webkit-scrollbar-thumb {
    border-radius: 2px;
    border: none;
    background: var(--border-focus);
}

.clear-history-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: transparent;
    border: 1px dashed var(--border-subtle);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    font-size: 11px;
    padding: 6px;
    margin-top: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.clear-history-btn:hover {
    border-color: var(--text-faint);
    color: var(--text-main);
    background: var(--hover-bg);
}

.separator {
    height: 1px;
    background: var(--border-subtle);
    margin: 16px 8px;
}

.sidebar-settings {
    display: grid;
    grid-template-columns: max-content 1fr;
    row-gap: 12px;
    column-gap: 36px;
    padding: 0 12px;
    margin-top: 10px;
    align-items: center;
}

.setting-title {
    font-weight: 500;
    font-size: 11px;
    color: var(--text-muted);
}

.styled-range {
    -webkit-appearance: none;
    width: 100%;
    height: 4px;
    background: var(--border-subtle);
    border-radius: 2px;
    outline: none;
    transition: background 0.2s;
}

.styled-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 12px;
    height: 12px;
    background: var(--accent-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 0 2px var(--bg-surface);
}

.styled-range:hover {
    background: var(--border-focus);
}

.mode-toggle-wrapper {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.toggle-label {
    font-size: 10px;
    color: var(--text-faint);
    white-space: nowrap;
}

.text-right {
    text-align: right;
}

.text-left {
    text-align: left;
}

.switch {
    position: relative;
    display: inline-block;
    width: 32px;
    height: 18px;
    justify-self: center;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--border-subtle);
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 12px;
    width: 12px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--accent-primary);
}

input:checked + .slider:before {
    transform: translateX(14px);
}

.slider.round {
    border-radius: 18px;
}

.slider.round:before {
    border-radius: 50%;
}

.custom-select-wrapper {
    position: relative;
    user-select: none;
    width: 100%;
}

.custom-select-trigger {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-main);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.custom-select-trigger:hover {
    border-color: var(--border-focus);
}

.custom-options {
    position: absolute;
    display: none;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 100;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 200px;
    overflow-y: auto;
    margin-top: 4px;
}

.custom-select-wrapper.open .custom-options {
    display: block;
    animation: fadeIn 0.1s ease;
}

.custom-option {
    padding: 8px 10px;
    font-size: 12px;
    color: var(--text-main);
    cursor: pointer;
    transition: background 0.1s;
}

.custom-option:hover {
    background: var(--hover-bg);
    color: var(--accent-primary);
}

.custom-option.selected {
    background: var(--bg-app);
    font-weight: 600;
    color: var(--accent-primary);
}

#theme-preview-container {
    position: absolute;
    z-index: 9999;
    width: 320px;
    height: auto;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: auto; /* Allow interaction */
    transition: opacity 0.2s;
    opacity: 0;
}

#theme-preview-container.visible {
    opacity: 1;
}

.nav-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-faint);
    letter-spacing: 0.05em;
    padding: 0 12px 8px;
    margin-top: 20px;
}

.mt-4 {
    margin-top: 24px;
}

.nav-item, .prompt-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    font-size: 13px;
    font-family: inherit;
}

.nav-item:hover, .prompt-item:hover {
    background: var(--hover-bg);
    color: var(--text-main);
}

.nav-item.active, .prompt-item.active {
    background: var(--bg-surface);
    color: var(--accent-primary);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    font-weight: 500;
}

[data-theme="dark"] .nav-item.active, [data-theme="dark"] .prompt-item.active {
    background: var(--hover-bg);
    color: var(--text-main);
}

.prompt-item {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-subtle);
    transition: border-color 0.3s ease;
}

.footer-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    transition: color 0.2s;
}

.footer-btn:hover {
    color: var(--text-main);
    background: var(--hover-bg);
}

#workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-app);
    position: relative;
    transition: background-color 0.3s ease;
    overflow: hidden;
}

.toolbar {
    height: var(--header-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    position: relative;
    z-index: 100;
}

.toolbar-left, .file-info {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 24px;
}

.filename {
    font-weight: 500;
    font-size: 14px;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.toolbar-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

#shareBtnWrapper {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    justify-content: center;
    height: 100%;
    align-items: center;
}

#shareBtn {
    cursor: not-allowed;
    opacity: 0.6;
    background: var(--bg-surface);
    border-color: var(--border-subtle);
    color: var(--text-main);
}

.custom-tooltip {
    opacity: 0;
    position: absolute;
    top: 100%;
    left: 50%;
    translate: -50% -16px;
    background: var(--bg-code);
    color: #fff;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    white-space: nowrap;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    pointer-events: auto;
    transition: opacity 0.3s, translate 0.3s;
}

.custom-tooltip a {
    color: var(--accent-primary);
    text-decoration: none;
}

.custom-tooltip a:hover {
    text-decoration: underline;
}

#shareBtnWrapper:hover .custom-tooltip {
    opacity: 1;
    translate: -50% -8px;
}

#shareBtnWrapper::after {
    content: '';
    position: absolute;
    bottom: -10px;
    width: 100%;
    height: 10px;
    left: 0;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
}

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

.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

[data-theme="dark"] .btn-primary {
    background: #ffffff;
    color: #000000;
}

.btn-secondary {
    background: var(--bg-surface);
    border-color: var(--border-subtle);
    color: var(--text-main);
}

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

.btn-sm {
    padding: 4px 12px;
    font-size: 12px;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

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

/* --- Explicit Button Group Styling (Classes Only) --- */
.btn-group {
    --icon-width: 48px;
    display: inline-flex;
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    position: relative; /* Context for popover */
}

.btn-group .btn, .btn-group .btn-label {
    border-radius: 0;
    border: none;
}

.btn-group .btn-left {
    border-top-left-radius: var(--radius-sm);
    border-bottom-left-radius: var(--radius-sm);
    border-right: 1px solid var(--border-subtle);
    min-width: var(--icon-width);
}

.btn-group .btn-right {
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    border-left: 1px solid var(--border-subtle);
}

.btn-group .btn-middle {
    /* Square */
}

.btn-group:has(.btn-secondary:hover) {
    background: var(--hover-bg);
}

/* Link Popover & GIF Tooltip */
#link-popover {
    position: absolute;
    top: calc(100% + 12px);
    left: calc(var(--icon-width) / 2);
    translate: -50%;
    width: 320px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    padding: 12px;
    animation: fadeIn 0.2s ease;
}

.popover-arrow {
    position: absolute;
    top: -6px;
    left: 50%;
    translate: -50%;
    width: 12px;
    height: 12px;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    border-top: 1px solid var(--border-subtle);
    transform: rotate(45deg);
}

.popover-content {
    display: flex;
    gap: 8px;
    position: relative;
    z-index: 2;
}

#driveLinkInput {
    flex: 1;
    background: var(--bg-app);
    border: 1px solid var(--border-subtle);
    color: var(--text-main);
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    font-family: inherit;
}

#driveLinkInput:focus {
    border-color: var(--accent-primary);
}

/* driveLoadBtn New Style */
#driveLoadBtn {
    height: 28px; /* Match input padding/font visual height */
    padding: 0 12px;
    background: var(--text-main);
    color: var(--bg-surface);
    border: 1px solid var(--text-main);
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    font-family: inherit;
}

#driveLoadBtn:hover {
    opacity: 0.9;
}

[data-theme="dark"] #driveLoadBtn {
    background: #ffffff;
    color: #000000;
    border-color: #ffffff;
}

.popover-footer {
    margin-top: 10px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    position: relative;
}

.help-container {
    position: relative;
    display: flex;
    align-items: center;
}

.help-trigger {
    font-size: 11px;
    color: var(--text-muted);
    cursor: help;
    display: flex;
    align-items: center;
    gap: 4px;
}

.help-trigger:hover {
    color: var(--accent-primary);
}

.gif-tooltip {
    position: absolute;
    top: 100%;
    right: 0;
    width: 280px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
    padding: 10px;
    z-index: 2000;
    display: none;
    margin-top: 8px;
}

.help-trigger:hover + .gif-tooltip, .gif-tooltip:hover {
    display: block;
    animation: fadeIn 0.2s ease;
}

.gif-tooltip img {
    width: 100%;
    border-radius: 4px;
    margin-bottom: 5px;
    border: 1px solid var(--border-subtle);
}

.gif-tooltip p {
    margin: 0;
    font-size: 11px;
    color: var(--text-muted);
    text-align: center;
}

.error-msg {
    margin-top: 8px;
    font-size: 11px;
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
    padding: 6px;
    border-radius: 4px;
    text-align: center;
}

/* Error Modal */
#error-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(2px);
    z-index: 3000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.error-dialog {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.3);
    width: 400px;
    overflow: hidden;
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.error-header {
    background: #ef4444;
    color: white;
    padding: 12px 16px;
    font-weight: 600;
    font-size: 13px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.error-body {
    padding: 20px;
    font-size: 13px;
    color: var(--text-main);
    line-height: 1.5;
}

#error-body p {
    margin: 0;
}

#error-gif-container {
    margin-top: 16px;
    border-top: 1px solid var(--border-subtle);
    padding-top: 16px;
}

#error-gif-container img {
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

#error-gif-container p {
    margin: 8px 0 0 0;
    font-size: 11px;
    text-align: center;
    color: var(--text-muted);
}

.error-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: flex-end;
    background: var(--bg-app);
}

@keyframes popIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

#scroll-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 0 32px 32px 32px;
    scroll-behavior: smooth;
    position: relative;
}

.content-wrapper {
    max-width: var(--content-width); /* Dynamic Width */
    margin: 0 auto;
    width: 100%;
    padding-bottom: 50px;
    transition: max-width 0.2s ease;
}

/* Make first child (Metadata Panel) touch the header */
.content-wrapper > :first-child {
    margin-top: 32px;
}

.panel {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
    margin-bottom: 32px;
    overflow: hidden;
    transition: background-color 0.3s ease, border-color 0.3s ease;
}

.panel.hidden {
    display: none;
}

.tabs-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-app);
    transition: background-color 0.3s ease;
    cursor: pointer;
}

.tabs-container {
    display: flex;
    overflow-x: auto;
}

.tab-btn {
    background: none;
    border: none;
    padding: 12px 20px;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.tab-btn.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
    background: var(--bg-surface);
}

.collapse-btn {
    background: none;
    border: none;
    padding: 0 15px;
    cursor: pointer;
    color: var(--text-muted);
}

.panel-body {
    padding: 20px;
    font-size: 13px;
    line-height: 1.6;
    color: var(--text-main);
    overflow-x: auto;
    display: block;
}

.panel-body.collapsed {
    display: none;
}

.tab-pane {
    display: none;
}

.tab-pane.active {
    display: block;
    animation: fadeIn 0.2s ease;
}

/* Metadata List Styles */
.meta-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-subtle);
}

.meta-key {
    color: var(--text-muted);
    font-weight: 500;
}

.meta-value {
    font-family: var(--font-mono);
    color: var(--text-main);
    text-align: right;
    max-width: 60%;
    word-break: break-all;
}

/* Safety Grid Styles */
.safety-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
    margin-top: 10px;
}

.safety-card {
    background: var(--bg-app);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.safety-category {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}

.safety-badge {
    align-self: flex-start;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    background: var(--border-subtle);
    color: var(--text-main);
}

.safety-badge.off {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    opacity: 0.7;
}

.safety-badge.block-none {
    background: #dcfce7;
    color: #166534;
}

.safety-badge.block-low {
    background: #fef9c3;
    color: #854d0e;
}

.safety-badge.block-med {
    background: #ffedd5;
    color: #9a3412;
}

.safety-badge.block-high {
    background: #fee2e2;
    color: #991b1b;
}

[data-theme="dark"] .safety-badge.block-none {
    background: #052e16;
    color: #86efac;
}

[data-theme="dark"] .safety-badge.block-low {
    background: #422006;
    color: #fde047;
}

[data-theme="dark"] .safety-badge.block-med {
    background: #431407;
    color: #fdba74;
}

[data-theme="dark"] .safety-badge.block-high {
    background: #450a0a;
    color: #fca5a5;
}

#chat-stream {
    padding-bottom: 60px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message {
    display: flex;
    flex-direction: column;
    width: 100%;
    scroll-margin-top: 20px;
    position: relative;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-muted);
}

.message-bubble {
    border-radius: var(--radius-md);
    padding: 16px 24px;
    font-size: 15px;
    line-height: 1.6;
    position: relative;
    max-width: 100%;
    color: var(--text-main);
    transition: background-color 0.3s ease, border-color 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.role-user {
    align-items: flex-end;
}

.role-user .message-header {
    flex-direction: row-reverse;
}

/* User Content Wrapper: Holds all message parts on the right */
.user-content-wrapper {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 85%;
    align-items: flex-end; /* Align bubbles to right by default */
}

/* Align Drive Document Card to the left of the user wrapper */
.user-content-wrapper .drive-document-card {
    align-self: flex-start;
}

/* Standard user text bubbles remain right-aligned within wrapper (or full width of wrapper) */
.user-content-wrapper .message-bubble {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-top-right-radius: 2px;
    width: 100%;
}

.role-model {
    align-items: flex-start;
}

.role-model .message-bubble {
    padding-left: 0;
    background: transparent;
    width: 100%;
}

.role-model .message-header i {
    color: var(--accent-primary);
    font-size: 16px;
}

.thought-message .message-bubble {
    background: var(--thought-bg);
    border: 1px dashed var(--thought-border);
    color: var(--thought-text);
    padding: 16px;
    font-style: italic;
}

.thought-message .message-header {
    cursor: pointer;
    user-select: none;
}

.thought-message .message-header:hover {
    opacity: 0.8;
}

.thought-icon-rotate {
    transition: transform 0.2s;
    display: inline-block;
}

.thought-message.collapsed .message-bubble {
    display: none;
}

.thought-message.collapsed {
    margin-bottom: 0;
    opacity: 0.7;
}

.inline-img {
    max-width: 400px;
    width: 100%;
    height: auto;
    border-radius: var(--radius-sm);
    cursor: zoom-in;
    border: 1px solid var(--border-subtle);
    transition: transform 0.2s;
}

.inline-img:hover {
    transform: scale(1.01);
}

.message-bubble a {
    color: var(--accent-primary);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.message-bubble a:hover {
    color: var(--text-main);
}

.message-tooltip {
    position: absolute;
    top: 32px;
    right: 8px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    display: flex;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 10;
}

.thought-message.collapsed .message-tooltip {
    top: 50%;
    transform: translateY(-50%);
}

.message-tooltip::after {
    content: '';
    position: absolute;
    top: -10px;
    bottom: -10px;
    left: -10px;
    right: -10px;
    z-index: -1;
}

.message:hover .message-tooltip, .message-tooltip:hover {
    opacity: 1;
    pointer-events: auto;
}

.tooltip-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    padding: 6px 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.tooltip-btn:hover {
    background: var(--hover-bg);
    color: var(--text-main);
}

.tooltip-btn:first-child {
    border-top-left-radius: var(--radius-sm);
    border-bottom-left-radius: var(--radius-sm);
}

.tooltip-btn:last-child {
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
}

/* --- Drive Document/Image Card --- */
.drive-document-card {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    width: fit-content; /* Only take necessary width */
    max-width: 100%;
}

.drive-doc-icon {
    font-size: 24px;
    color: var(--text-muted);
    background: var(--bg-app);
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.drive-doc-info {
    flex-grow: 1;
    min-width: 0;
}

.drive-doc-title {
    font-weight: 600;
    color: var(--text-main);
    display: block;
}

.drive-doc-meta {
    font-size: 12px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
}

.drive-doc-actions {
    display: flex;
    gap: 8px;
}

/* --- Code Blocks Architecture --- */
.code-block-wrapper {
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    margin: 16px 0;
    position: relative;
    max-width: 100%;
}

.code-header {
    background: var(--bg-app);
    padding: 8px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-subtle);
    position: sticky;
    top: 0;
    z-index: 20;
    border-top-left-radius: var(--radius-md);
    border-top-right-radius: var(--radius-md);
    transition: border-radius 0.2s;
}

/* Flatten top corners when sticky */
.code-header.is-sticky {
    border-top-left-radius: 0;
    border-top-right-radius: 0;
    border-bottom: 1px solid var(--border-subtle);
}

pre {
    margin: 0 !important;
    border: none !important;
    border-radius: 0 !important;
    overflow-x: auto;
    background: transparent !important;
    border-bottom-left-radius: var(--radius-md);
    border-bottom-right-radius: var(--radius-md);
}

/* Sticky Sentinel - Placed absolutely at top of wrapper */
.sticky-sentinel {
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 1px;
    pointer-events: none;
}

/* Scrollable Code Logic */
body.scrollable-codeblocks pre {
    max-height: 400px;
}

/* Wrap Code Logic */
body.wrap-codeblocks pre {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.code-block-wrapper.collapsed pre {
    display: none;
}

.code-block-wrapper.collapsed {
    border-bottom: 1px solid var(--border-subtle);
}

.code-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.collapse-code-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    transition: all 0.2s;
}

.collapse-code-btn i {
    transition: transform 0.2s;
}

.code-block-wrapper.collapsed .collapse-code-btn i {
    transform: rotate(-90deg);
}

.collapse-code-btn:hover {
    color: white;
}

.lang-tag {
    color: #94a3b8;
    font-family: var(--font-mono);
    font-size: 11px;
    text-transform: uppercase;
}

.copy-btn {
    background: transparent;
    border: 1px solid #aebed5;
    color: #6c839f;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn:hover {
    background: #c9d0d9;
    color: white;
}

[data-theme="dark"] .copy-btn {
    border: 1px solid #636973;
    color: #cbd5e1;
}

[data-theme="dark"] .copy-btn:hover {
    background: #30373f;
}

pre code {
    font-family: var(--font-mono) !important;
    font-size: 13px !important;
    padding: 16px !important;
    color: #e2e8f0;
    display: block;
}

#nav-widget {
    position: fixed;
    bottom: 30px;
    right: 30px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 50;
}

#nav-widget button {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.2s;
}

#nav-widget button:hover {
    background: var(--accent-primary);
    color: var(--bg-surface);
    border-color: var(--accent-primary);
}

#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 15px;
    color: white;
    font-weight: 500;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Modals */
#image-modal, #text-viewer-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 40px;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}

/* Image Viewer Content */
.image-viewer-content {
    background: var(--bg-code);
    border-radius: var(--radius-md);
    width: auto;
    height: auto;
    max-width: 95%;
    max-height: 95%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.image-wrapper {
    flex-grow: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    background: url('data:image/svg+xml;utf8, <svg width="20" height="20" xmlns="http://www.w3.org/2000/svg"><rect width="10" height="10" fill="%23333" opacity="0.1"/><rect x="10" y="10" width="10" height="10" fill="%23333" opacity="0.1"/></svg>');
}

#modal-img {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    display: block;
}

/* Text Viewer */
.text-viewer-content {
    background: var(--bg-code);
    border-radius: var(--radius-md);
    width: 100%;
    height: 100%;
    max-width: 1000px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.text-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: var(--bg-code-header);
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 12px;
    flex-shrink: 0;
}

.viewer-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.viewer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.viewer-lang-tag {
    background: var(--border-subtle);
    color: var(--text-muted);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 10px;
    text-transform: uppercase;
}

.text-viewer-header .icon-btn {
    color: var(--text-muted);
}

.text-viewer-header .icon-btn:hover {
    color: var(--text-main);
}

#text-viewer-modal pre {
    flex-grow: 1;
    overflow: auto;
    margin: 0 !important;
    padding: 0 !important;
    max-height: none !important; /* Override preference */
}

#text-viewer-modal code {
    padding: 16px !important;
}

body.wrap-codeblocks #text-viewer-modal pre {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.hidden {
    display: none !important;
}

.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--text-main);
    color: var(--bg-surface);
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
    z-index: 100;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.empty-state-hero {
    text-align: center;
    margin-top: 80px;
    color: var(--text-muted);
    padding: 0 20px;
}

.hero-icon {
    width: 64px;
    height: 64px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 20px;
    font-size: 32px;
    color: var(--text-main);
}

.empty-state-sidebar {
    padding: 20px;
    text-align: center;
    font-size: 12px;
    font-style: italic;
    color: var(--text-faint);
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

/* Responsive */
.mobile-only {
    display: none;
}

#sidebar-toggle-btn {
    display: none;
}

#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 15;
    opacity: 0;
    transition: opacity 0.3s;
}

@media (max-width: 768px) {
    #sidebar {
        position: fixed;
        height: 100%;
        transform: translateX(-100%);
    }

    #sidebar.open {
        transform: translateX(0);
    }

    #sidebar-overlay.open {
        display: block;
        opacity: 1;
    }

    #sidebar-toggle-btn {
        display: block;
    }

    .mobile-only {
        display: flex;
    }

    .desktop-only {
        display: none;
    }

    .toolbar {
        padding: 0 16px;
    }

    #scroll-container {
        padding: 0 16px 16px 16px;
    }

    .role-user .message-bubble {
        max-width: 100%;
    }

    .user-content-wrapper {
        max-width: 100%;
    }

    #nav-widget {
        bottom: 20px;
        right: 20px;
    }

    #shareBtnWrapper {
        display: none;
    }

    #link-popover {
        left: 0;
        width: 100%;
        transform: none;
    }

    .popover-arrow {
        left: 20px;
        right: auto;
    }

    #theme-preview-container {
        display: none !important;
    }
}