/* static/css/style.css */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Authentication Styles */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
}

.auth-card {
    background: var(--color-surface);
    border-radius: 16px;
    box-shadow: 0 25px 50px var(--color-overlay-dark);
    padding: 40px;
    width: 100%;
    max-width: 420px;
    backdrop-filter: blur(10px);
    border: 1px solid var(--color-overlay-light);
}

.auth-header {
    text-align: center;
    margin-bottom: 35px;
}

.auth-header h1 {
    color: var(--color-text-main);
    margin-bottom: 10px;
    font-size: 2.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-brand-main), var(--color-brand-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.auth-header p {
    color: var(--color-text-muted);
    font-size: 1.1rem;
    font-weight: 400;
}

.auth-form {
    margin-bottom: 25px;
}

.form-group {
    margin-bottom: 22px;
}

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

.form-row .form-group {
    flex: 1;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--color-text-main);
    font-weight: 600;
    font-size: 0.95rem;
}

.required-asterisk {
    color: var(--color-danger-main);
    font-weight: 700;
    margin-left: 2px;
}

.required-fields-legend {
    margin-bottom: 20px;
    padding: 10px 12px;
    background-color: var(--color-surface-soft);
    border-left: 4px solid var(--color-danger-main);
    border-radius: 4px;
}

.required-fields-legend p {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--color-border-main);
    border-radius: 10px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: var(--color-surface-soft);
    font-family: inherit;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-brand-main);
    background: var(--color-surface);
    box-shadow: 0 0 0 3px var(--color-overlay-dark);
    transform: translateY(-1px);
}

.form-input:hover {
    border-color: var(--color-border-hover);
}

.error-message {
    color: var(--color-danger-main);
    font-size: 0.875rem;
    margin-top: 6px;
    font-weight: 500;
}

.form-help {
    color: var(--color-text-muted);
    font-size: 0.875rem;
    margin-top: 6px;
}

.btn-full {
    width: 100%;
    padding: 14px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 10px;
    transition: all 0.3s ease;
    text-transform: none;
    letter-spacing: 0.5px;
    cursor: pointer;
}

.btn-full:focus,
.btn-full:focus-visible {
    outline: 3px solid var(--color-brand-bright);
    outline-offset: 2px;
}

.btn-full:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--color-overlay-dark);
}

.btn-full[aria-disabled="true"] {
    cursor: not-allowed;
    opacity: 0.6;
}

.btn-full[aria-disabled="true"]:focus,
.btn-full[aria-disabled="true"]:focus-visible {
    outline: 3px solid var(--color-brand-bright);
    outline-offset: 2px;
}

.auth-footer {
    text-align: center;
    padding-top: 25px;
    border-top: 1px solid var(--color-border-main);
}

.auth-footer p {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.auth-footer a {
    color: var(--color-brand-main);
    text-decoration: none;
    font-weight: 600;
    transition: color 0.3s ease;
}

.auth-footer a:hover {
    color: var(--color-brand-bright);
    text-decoration: underline;
}

/* (Design tokens now live in static/css/variables.css) */


/* CWRU Themed Authentication */
.auth-container.cwru-theme {
    background: var(--color-bg);
    position: relative;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    width: 100%;
    padding: 30px 20px;
}

.auth-card.cwru-card {
    background: var(--color-surface);
    border-radius: 16px;
    box-shadow: 0 4px 20px var(--color-overlay-dark);
    padding: 44px 40px;
    width: 100%;
    max-width: 480px;
    border: 1px solid var(--color-border-main);
    position: relative;
    z-index: 1;
}

.auth-card.cwru-card .auth-header {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 24px;
}

.cwru-logo {
    max-width: 260px;
    height: auto;
    display: inline-block;
}

html:not([data-theme="dark"]) .dark-logo { display: none !important; }
html[data-theme="dark"] .light-logo { display: none !important; }

.auth-card.cwru-card .auth-header h1 {
    color: var(--color-brand-main);
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.25;
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: var(--color-brand-main);
    background-clip: unset;
    margin-bottom: 6px;
    letter-spacing: -0.2px;
}

.auth-subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
    font-weight: 400;
}

/* Badges & Form Help Hints */
.auth-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-brand-main);
    background-color: var(--color-brand-alpha);
    border: 1px solid var(--color-border-soft);
    border-radius: 20px;
    margin-top: 10px;
}

.email-domain-badge {
    display: inline-block;
    padding: 1px 6px;
    font-size: 0.82rem;
    font-weight: 600;
    font-family: inherit;
    color: var(--color-brand-main);
    background: var(--color-brand-alpha);
    border-radius: 4px;
    letter-spacing: 0.2px;
}

.form-help-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin-top: 6px;
}

.form-help-box {
    background: var(--color-surface-soft);
    border: 1px solid var(--color-border-soft);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 18px;
    font-size: 0.88rem;
    color: var(--color-text-muted);
    line-height: 1.45;
}

/* CWRU Form Labels & Headers */
.auth-card.cwru-card .form-group label {
    color: var(--color-text-main);
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 6px;
    display: block;
}

.form-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.form-group-header label {
    margin-bottom: 0 !important;
}

.forgot-password-link {
    font-size: 0.85rem;
    color: var(--color-brand-main);
    font-weight: 500;
    text-decoration: none;
    border-radius: 4px;
    padding: 2px 4px;
    transition: color 0.2s ease, text-decoration 0.2s ease;
}

.forgot-password-link:hover {
    color: var(--color-brand-bright);
    text-decoration: underline;
}

.forgot-password-link:focus-visible {
    outline: 2px solid var(--color-brand-main);
    outline-offset: 2px;
}

/* CWRU Form Inputs & Wrappers */
.password-input-wrapper {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
}

.password-input-wrapper .form-input,
.password-input-wrapper .form-input.cwru-input {
    width: 100%;
    padding-right: 46px;
}

.password-toggle-btn {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 8px;
    min-width: 38px;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-subtle);
    border-radius: 8px;
    cursor: pointer;
    transition: color 0.2s ease, background-color 0.2s ease;
}

.password-toggle-btn:hover {
    color: var(--color-brand-main);
    background-color: var(--color-brand-alpha);
}

.password-toggle-btn:focus-visible {
    outline: 2px solid var(--color-brand-main);
    outline-offset: 1px;
    color: var(--color-brand-main);
}

.form-input.cwru-input {
    border: 1.5px solid var(--color-border-main);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 0.95rem;
    color: var(--color-text-main);
    background: var(--color-surface-soft);
    transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.form-input.cwru-input:focus {
    border-color: var(--color-brand-main);
    background: var(--color-surface);
    box-shadow: 0 0 0 3px var(--color-brand-alpha);
    outline: none;
}

.form-input.cwru-input:hover:not(:focus) {
    border-color: var(--color-border-hover);
}

.form-input.cwru-input::placeholder {
    color: var(--color-text-subtle);
    opacity: 0.8;
}

.form-input.cwru-input.error {
    border-color: var(--color-danger-main);
    background: var(--color-surface);
}

.form-input.cwru-input.error:focus {
    border-color: var(--color-danger-main);
    box-shadow: 0 0 0 3px var(--color-danger-border);
}

/* CWRU Button */
.btn-cwru {
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
    color: var(--color-text-inverse);
    box-shadow: 0 2px 8px var(--color-overlay-dark);
    border: none;
    padding: 13px 20px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.btn-cwru:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px var(--color-overlay-dark);
}

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

.btn-cwru:focus-visible {
    outline: 3px solid var(--color-brand-bright);
    outline-offset: 2px;
}

.btn-cwru.loading {
    opacity: 0.85;
    cursor: wait;
}

/* CWRU Auth Footer */
.auth-footer.cwru-footer {
    border-top: 1px solid var(--color-border-main);
    padding-top: 20px;
    margin-top: 20px;
    text-align: center;
}

.auth-footer.cwru-footer p {
    color: var(--color-text-muted);
    font-size: 0.9rem;
    margin-bottom: 6px;
}

.auth-footer.cwru-footer p:last-child {
    margin-bottom: 0;
}

.auth-footer.cwru-footer a {
    color: var(--color-brand-main);
    font-weight: 600;
    text-decoration: none;
    border-radius: 4px;
    padding: 2px 4px;
    transition: color 0.2s ease, text-decoration 0.2s ease;
}

.auth-footer.cwru-footer a:hover {
    color: var(--color-brand-bright);
    text-decoration: underline;
}

.auth-footer.cwru-footer a:focus-visible {
    outline: 2px solid var(--color-brand-main);
    outline-offset: 2px;
}

/* CWRU Profile Page Styles */
.profile-container.cwru-profile {
    background: var(--color-bg);
    min-height: 100vh;
    padding: 30px;
    width: 100%;
    max-width: none;
    overflow-y: auto;
    margin: 0;
    position: relative;
}

.profile-container.cwru-profile .profile-header,
.profile-container.cwru-profile .profile-content {
    position: relative;
    z-index: 1;
}

.profile-container.cwru-profile .profile-header h1 {
    color: var(--color-text-main);
}

.profile-container.cwru-profile .profile-header {
    max-width: 800px;
    margin: 0 auto 30px auto;
    border-bottom-color: var(--color-border-main);
}

.profile-container.cwru-profile .profile-content {
    max-width: 800px;
    margin: 0 auto;
}

.profile-container.cwru-profile .profile-header .btn-cwru {
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
}

.profile-container.cwru-profile .profile-header .btn-cwru:hover {
    background: var(--color-brand-light);
}

.cwru-card-style {
    border: 1px solid var(--color-border-main);
    box-shadow: 0 4px 12px var(--color-overlay-dark);
    background: var(--color-surface);
}

.cwru-card-style h3 {
    color: var(--color-brand-main);
}

.cwru-card-style .form-group label {
    color: var(--color-brand-main);
    font-weight: 600;
}

.profile-avatar.cwru-avatar {
    color: var(--color-brand-main);
}

.stat-item.cwru-stat {
    background: linear-gradient(135deg, var(--color-overlay-dark) 0%, var(--color-overlay-dark) 100%);
    border: 1px solid var(--color-overlay-dark);
}

.stat-item.cwru-stat .stat-value {
    color: var(--color-brand-main);
}

/* Auth and Profile page scrolling support */
body:has(.auth-container.cwru-theme),
body:has(.profile-container.cwru-profile),
body:has(.batch-container.cwru-profile) {
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
}

body:has(.auth-container.cwru-theme) .app-container,
body:has(.profile-container.cwru-profile) .app-container,
body:has(.batch-container.cwru-profile) .app-container {
    height: auto;
    min-height: 100vh;
    overflow-y: auto;
}

.auth-container.cwru-theme {
    overflow-y: auto;
    min-height: 100vh;
}

/* Alert Styles */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-weight: 500;
    font-size: 0.9rem;
}


.alert-success {
    background: var(--color-success-bg);
    color: var(--color-success-dark);
    border: 1px solid var(--color-success-border);
}

.alert-error {
    background: var(--color-danger-bg);
    color: var(--color-danger-dark);
    border: 1px solid var(--color-danger-border);
}

.alert-info {
    background: var(--color-info-bg);
    color: var(--color-info-dark);
    border: 1px solid var(--color-info-border);
}

/* User Info Styles */
.user-info {
    display: flex;
    align-items: center;
    margin-bottom: 25px;
    padding: 18px;
    background: linear-gradient(135deg, var(--color-surface-soft) 0%, var(--color-border-main) 100%);
    border-radius: 12px;
    position: relative;
    border: 1px solid var(--color-overlay-dark);
    transition: all 0.3s ease;
}

.user-info:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 25px var(--color-overlay-dark);
}

.user-avatar {
    font-size: 2.2rem;
    color: var(--color-brand-main);
    margin-right: 15px;
    filter: drop-shadow(0 2px 4px var(--color-overlay-dark));
}

.user-details {
    flex: 1;
}

.user-name {
    font-weight: 700;
    color: var(--color-text-main);
    font-size: 1rem;
    margin-bottom: 2px;
}

.user-username {
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 500;
}

.user-menu {
    position: relative;
}

.btn-icon {
    background: var(--color-overlay-dark);
    border: none;
    color: var(--color-brand-main);
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    transition: all 0.3s ease;
    font-size: 1rem;
}

.btn-icon:hover {
    background: var(--color-overlay-dark);
    transform: scale(1.05);
}

/* User Dropdown */
.user-dropdown {
    position: absolute;
    bottom: 100%;
    left: 10px;
    right: 10px;
    background: var(--color-surface);
    border-radius: 8px;
    box-shadow: 0 -4px 15px var(--color-overlay-dark);
    border: 1px solid var(--color-border-soft);
    display: none;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 10px;
    z-index: 1000;
}

.user-dropdown.show {
    display: flex;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-item {
    display: flex;
    align-items: center;
    padding: 12px 18px;
    color: var(--color-text-main);
    text-decoration: none;
    transition: all 0.3s ease;
    font-weight: 500;
    font-size: 0.9rem;
}

.dropdown-item:hover {
    background: linear-gradient(135deg, var(--color-surface-soft) 0%, var(--color-border-main) 100%);
    color: var(--color-brand-main);
    transform: translateX(2px);
}

.dropdown-item i {
    margin-right: 10px;
    width: 16px;
    font-size: 0.9rem;
}

/* A feature this account cannot open yet. It stays in the menu so the tool is
   discoverable and, more to the point, requestable — but it reads as shut,
   and the right-hand state says where the request has got to. */
.dropdown-item--locked {
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    font-family: inherit;
    font-size: 0.9rem;
    text-align: left;
    gap: 8px;
    padding-right: 12px;
    opacity: 0.72;
}

.dropdown-item--locked:hover:not(:disabled) {
    opacity: 1;
}

.dropdown-item--locked:disabled {
    cursor: default;
}

.dropdown-item__label {
    flex: 1;
    min-width: 0;
}

/* The state is an icon, not a word: the menu cannot grow past the sidebar,
   which clips its overflow, and a tool's name is worth more of that width
   than a label for it. The wording lives in the button's accessible name,
   so a screen reader still hears "locked" or "access requested". */
.dropdown-item__state {
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    margin-left: auto;
    color: var(--color-text-muted);
}

.dropdown-item__state i {
    margin-right: 0;
    width: auto;
    font-size: 0.8rem;
}

.dropdown-item--locked[data-status="declined"] .dropdown-item__state {
    color: var(--color-danger-main);
}

.dropdown-item--locked[data-status="requested"] .dropdown-item__state {
    color: var(--color-warning-main, var(--color-brand-main));
}

.sidebar-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.sidebar-actions h2 {
    margin-bottom: 0;
    color: var(--color-text-main);
    font-size: 1.3rem;
    font-weight: 700;
}

/* Profile Styles */
.profile-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 20px;
}

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--color-border-main);
}

.profile-header h1 {
    color: var(--color-text-main);
    margin: 0;
}

.profile-content {
    display: grid;
    gap: 30px;
}

.profile-card,
.profile-form-card,
.profile-stats-card {
    background: var(--color-surface);
    border-radius: 12px;
    box-shadow: 0 4px 12px var(--color-overlay-dark);
    padding: 25px;
}

.profile-info {
    display: flex;
    align-items: center;
}

.profile-avatar {
    font-size: 4rem;
    color: var(--color-brand-main);
    margin-right: 20px;
}

.profile-details h2 {
    color: var(--color-text-main);
    margin-bottom: 5px;
}

.profile-username {
    color: var(--color-text-muted);
    font-size: 1rem;
    margin-bottom: 5px;
}

.profile-email {
    color: var(--color-text-muted);
    margin-bottom: 5px;
}

.profile-joined {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

.profile-form-card h3,
.profile-stats-card h3 {
    color: var(--color-text-main);
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--color-border-main);
}

.profile-form {
    margin-top: 20px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
}

.stat-item {
    text-align: center;
    padding: 20px;
    background: var(--color-surface-soft);
    border-radius: 8px;
}

.stat-value {
    font-size: 2rem;
    font-weight: bold;
    color: var(--color-brand-main);
    margin-bottom: 5px;
}

.stat-label {
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* Enhanced Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: none;
    letter-spacing: 0.3px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
    color: var(--color-text-inverse);
    box-shadow: 0 4px 15px var(--color-overlay-dark);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--color-overlay-darker);
}

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

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

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

/* Loading States */
.btn.loading {
    position: relative;
    color: transparent;
}

.btn.loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Form Enhancements */
.form-input:invalid {
    border-color: var(--color-danger-main);
}

.form-input:valid {
    border-color: var(--color-success-main);
}

.form-input.error {
    border-color: var(--color-danger-main);
    background: var(--color-danger-bg);
    animation: shake 0.5s ease-in-out;
}

.form-input.valid {
    border-color: var(--color-success-main);
    background: var(--color-success-bg);
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-5px);
    }

    75% {
        transform: translateX(5px);
    }
}


/* Focus States - Global */
button:focus,
input:focus,
textarea:focus,
select:focus {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    box-shadow: 0 0 12px var(--color-overlay-dark);
}

/* Focus Visible for better UX */
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
a:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    box-shadow: 0 0 12px var(--color-overlay-dark);
}

/* Sidebar Elements Focus Styles */
.btn-new-chat:focus,
.model-item:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-brand-main), 0 0 12px var(--color-overlay-dark);
    background: var(--color-brand-alpha);
    border-radius: 6px;
}

.session-item:focus {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-brand-main), 0 0 12px var(--color-overlay-dark);
    background: var(--color-brand-alpha);
    border-radius: 8px;
}

.btn-rename:focus,
.btn-rename:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
    border-radius: 4px;
    transform: scale(1.2);
    box-shadow: 0 0 12px var(--color-overlay-dark);
}

.btn-delete:focus,
.btn-delete:focus-visible {
    outline: 3px solid var(--color-danger-main);
    outline-offset: 2px;
    background: var(--color-danger-main);
    color: var(--color-text-inverse);
    border-radius: 4px;
    transform: scale(1.2);
    box-shadow: 0 0 8px var(--color-danger-main);
}

.user-info:focus,
.user-info:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    background: var(--color-brand-alpha);
    border-radius: 8px;
    box-shadow: 0 0 12px var(--color-overlay-dark);
}

.dropdown-item:focus,
.dropdown-item:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    background: var(--color-brand-alpha);
    border-radius: 4px;
    box-shadow: 0 0 8px var(--color-overlay-dark);
}

/* Session Actions */
.session-actions {
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.session-item:hover .session-actions,
.session-item.active .session-actions,
.session-item:focus-within .session-actions {
    opacity: 1;
}

/* Show session actions when buttons are focused - using :has() for modern browsers */
.session-actions:has(.btn-rename:focus),
.session-actions:has(.btn-delete:focus),
.session-actions:has(.btn-rename:focus-visible),
.session-actions:has(.btn-delete:focus-visible) {
    opacity: 1;
}

/* Explicitly show focused buttons even if parent is hidden */
.btn-rename:focus,
.btn-rename:focus-visible,
.btn-delete:focus,
.btn-delete:focus-visible {
    opacity: 1 !important;
}

.btn-rename,
.btn-delete {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.3s ease;
    font-size: 0.85rem;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.9;
    visibility: visible;
}

.btn-rename:hover {
    background: var(--color-overlay-dark);
    color: var(--color-brand-main);
    transform: scale(1.1);
    opacity: 1;
}

.btn-delete:hover {
    background: var(--color-danger-bg);
    color: var(--color-danger-dark);
    transform: scale(1.1);
    opacity: 1;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-overlay-darker);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(5px);
}

.modal-content {
    background: var(--color-surface);
    border-radius: 12px;
    box-shadow: 0 20px 40px var(--color-overlay-dark);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(-20px) scale(0.95);
    }

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

.modal-header {
    padding: 20px 25px;
    border-bottom: 1px solid var(--color-border-main);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(135deg, var(--color-surface-soft) 0%, var(--color-border-main) 100%);
}

.modal-header h3 {
    margin: 0;
    color: var(--color-text-main);
    font-size: 1.2rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close:hover {
    background: var(--color-danger-bg);
    color: var(--color-danger-dark);
    transform: scale(1.1);
}

.btn-close:focus,
.btn-close:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-danger-border);
    background: var(--color-danger-bg);
    border-radius: 50%;
}

.btn:focus,
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-overlay-dark), 0 0 12px var(--color-overlay-dark);
    transform: translateY(-1px);
}

.btn-primary:focus,
.btn-primary:focus-visible {
    box-shadow: 0 0 0 3px var(--color-overlay-darker);
}

.btn-secondary:focus,
.btn-secondary:focus-visible {
    box-shadow: 0 0 0 3px var(--color-overlay-dark);
}

.btn-icon:focus,
.btn-icon:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-overlay-dark), 0 0 12px var(--color-overlay-dark);
    background: var(--color-brand-alpha);
    border-radius: 4px;
}

.modal-body {
    padding: 25px;
    overflow-y: auto;
    max-height: 70vh;
    /* Prevent modal from growing off-screen */
}

.modal-footer {
    padding: 20px 25px;
    border-top: 1px solid var(--color-border-main);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    background: var(--color-surface-soft);
}

/* Session Item Improvements */
.session-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    margin-bottom: 8px;
    border-radius: 8px;
    transition: all 0.3s ease;
    cursor: pointer;
    border: 1px solid transparent;
}

.session-item:hover {
    background: linear-gradient(135deg, var(--color-surface-soft) 0%, var(--color-border-main) 100%);
    border-color: var(--color-overlay-dark);
    transform: translateX(2px);
}

.session-item.active {
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
    border-color: var(--color-brand-main);
}

.session-item.active .session-title {
    color: var(--color-text-inverse);
}

.session-item.active .btn-rename,
.session-item.active .btn-delete {
    color: var(--color-text-inverse);
    opacity: 0.85;
}

.session-item.active .btn-rename:hover,
.session-item.active .btn-delete:hover {
    background: var(--color-overlay-light);
    color: var(--color-text-inverse);
    opacity: 1;
}

.session-title {
    flex: 1;
    font-weight: 500;
    color: var(--color-text-main);
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    height: 100vh;
    display: flex;
}

.chat-container {
    display: flex;
    width: 100%;
    height: 100vh;
    background: var(--color-surface);
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    overflow: auto;
}

/* Sidebar Styles */
.sidebar {
    width: 260px;
    background: var(--color-bg);
    /* Light grey/blue background */
    border-right: none;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
    position: relative;
    z-index: 100;
    overflow: hidden;
    max-height: 100vh;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border-strong) var(--color-bg);
}

/* Firefox scrollbar styling */
.sidebar::-webkit-scrollbar {
    width: 8px;
}

.sidebar::-webkit-scrollbar-track {
    background: var(--color-bg);
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 4px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-subtle);
}

.sidebar-header {
    padding: 20px;
    border-bottom: none;
    flex-shrink: 0;
}

.sidebar-logo-container {
    padding-bottom: 20px;
    text-align: left;
}

.sidebar-logo {
    width: auto;
    height: auto;
    display: inline-block;
}

.btn-new-chat {
    width: 100%;
    color: var(--color-brand-main);
    /* CWRU Blue */
    background: transparent;
    border: none;
    justify-content: flex-start;
    padding: 10px 0;
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-new-chat:hover {
    color: var(--color-brand-main);
    cursor: pointer;
}

.sidebar-section {
    padding: 0 20px 20px 20px;
}

.sidebar-section h2 {
    font-size: 0.9rem;
    text-transform: uppercase;
    color: var(--color-brand-main);
    margin-bottom: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
}

/* Models Section */
.sidebar-section.section-models {
    flex-shrink: 0;
    /* Don't shrink */
    padding-bottom: 20px;
}

/* Models List Container */
.models-list-container {
    max-height: 200px;
    /* Maximum height to allow scrolling within models */
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    /* CHANGED: Allow scrolling */
    border-bottom: 1px solid var(--color-border-soft);
    margin-bottom: 10px;
    padding-bottom: 5px;
    flex-shrink: 0;
}

.models-list {
    flex: 1;
    min-height: 0;
    /* Enable scrolling in nested flex */
    overflow-y: auto;
    padding-right: 5px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-item {
    padding: 8px 12px;
    font-size: 0.9rem;
    color: var(--color-brand-main);
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s ease;
    border-radius: 6px;
}

.model-item:hover {
    color: var(--color-brand-main);
    background: var(--color-overlay-dark);
    /* Subtle blue background */
    font-weight: 600;
}

.model-item.active {
    color: var(--color-text-inverse);
    background: var(--color-brand-main);
    font-weight: 700;
    box-shadow: 0 2px 4px var(--color-overlay-dark);
}

/* Custom scrollbar for models list */
.models-list::-webkit-scrollbar {
    width: 4px;
}

.models-list::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 4px;
}

.chat-sessions {
    flex-shrink: 0;
    /* Don't shrink */
    overflow-y: auto;
    padding-right: 5px;
    min-height: 0;
    max-height: 250px;
}

/* Custom scrollbar for sessions list */
.chat-sessions::-webkit-scrollbar {
    width: 4px;
}

.chat-sessions::-webkit-scrollbar-thumb {
    background: var(--color-border-strong);
    border-radius: 4px;
}

.btn {
    padding: 10px 15px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
    width: 100%;
}

.btn-primary:hover {
    background: var(--color-brand-light);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--color-text-muted);
    color: var(--color-text-inverse);
    width: 100%;
}

.btn-secondary:hover {
    background: var(--color-text-muted);
    transform: translateY(-1px);
}

/* Chats Section Container */
.sidebar-section.section-chats {
    flex: 1;
    /* Take the height left over, so the footer stays docked at the bottom */
    display: flex;
    flex-direction: column;
    min-height: 0;
    /* CRITICAL for nested flex scrolling */
    padding-bottom: 20px;
}

.chat-sessions {
    flex: 1;
    /* Fill the section-chats container */
    overflow-y: auto;
    /* Scroll internally */
    padding-right: 5px;
    min-height: 0;
}

.chat-sessions:not(:has(.session-item))::before {
    content: "No chats yet";
    display: block;
    padding: 8px 12px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}






/* Profile Section - Docked at bottom */
.sidebar-footer {
    flex-shrink: 0;
    padding: 15px 20px;
    /* Distinct background */
    border-top: 1px solid var(--color-border-soft);
    width: 100%;
    margin-top: auto;
}

.sidebar-footer .user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    background: var(--color-surface);
    box-shadow: none;
    transition: background 0.2s;
    width: 100%;
}

.sidebar-footer .user-info:hover {
    background: var(--color-surface-hover);
    transform: none;
    box-shadow: none;
}

.sidebar-footer .user-avatar {
    width: 36px;
    height: 36px;
    background: var(--color-surface);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--color-brand-main);
    font-size: 1rem;
    box-shadow: 0 2px 5px var(--color-overlay-dark);
}

.sidebar-footer .user-name {
    font-weight: 600;
    color: var(--color-brand-main);
    font-size: 0.95rem;
}

.sidebar-footer .full-link {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* ===================== SHARED SIDEBAR LAYOUT ========================
   Used by chat/sidebar_layout.html and the chat/_sidebar_*.html partials,
   so every sidebar page shares one header, nav style and user menu.
   =================================================================== */

/* The logo links back to chat on every page. */
a.sidebar-logo-container {
    display: block;
}

/* Scrollable middle of the sidebar, between the header and the footer. */
.sidebar-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 15px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--color-text-main);
    font-size: 0.9rem;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.sidebar-nav-item i {
    width: 16px;
    text-align: center;
    color: var(--color-brand-main);
}

.sidebar-nav-item:hover {
    background: linear-gradient(135deg, var(--color-surface-soft) 0%, var(--color-border-main) 100%);
    border-color: var(--color-overlay-dark);
    color: var(--color-text-main);
}

.sidebar-nav-item:focus-visible {
    outline: 2px solid var(--color-brand-main);
    outline-offset: 2px;
}

.sidebar-nav-item.active,
.sidebar-nav-item.active i {
    background: var(--color-brand-main);
    border-color: var(--color-brand-main);
    color: var(--color-text-inverse);
}

/* Current page in the user menu. */
.dropdown-item.active {
    color: var(--color-brand-main);
    font-weight: 700;
    background: var(--color-surface-soft);
}

/* Session-style list items that are links (e.g. recent pipelines). */
a.session-item {
    text-decoration: none;
    color: inherit;
}

.session-item__body {
    flex: 1;
    min-width: 0;
}

.session-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 4px;
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.session-meta__steps {
    font-size: 0.7rem;
    opacity: 0.8;
    margin-left: 2px;
}

.session-item.active .session-meta {
    color: var(--color-text-inverse);
}

.session-item.active .status-dot.pending {
    background: var(--color-text-inverse);
    opacity: 0.7;
}

.sidebar-empty {
    padding: 15px;
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.85rem;
}

/* Main area for non-chat sidebar pages. */
.chat-main.page-main {
    display: block;
    /* The top clears the fixed page bar (Back, Chat, trail) and the bell */
    padding: 84px 40px 40px;
}

/* ---------------------------------------------------------------------------
   Page bar: fixed at the top left of every page but the chat, mirroring the
   bell and theme toggle fixed at the top right. Back and Chat are always
   there; the trail says where the page sits and shrinks to the page itself
   when space runs short. Page actions stay in each page's own header.
   --------------------------------------------------------------------------- */
.page-nav {
    position: fixed;
    top: 16px;
    left: calc(260px + 24px);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: calc(100vw - 260px - 24px - 140px);
}

.page-nav__btn {
    flex: none;
    height: 42px;
    padding: 0 15px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 21px;
    border: 1px solid var(--color-border-main);
    background: var(--color-surface);
    color: var(--color-text-main);
    box-shadow: 0 2px 10px var(--color-overlay-dark);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: border-color .2s ease, background .2s ease;
}

.page-nav__btn i {
    color: var(--color-brand-main);
}

.page-nav__btn:hover {
    border-color: var(--color-brand-main);
    color: var(--color-text-main);
}

.page-nav__btn:focus-visible,
.page-nav__trail a:focus-visible {
    outline: 2px solid var(--color-brand-main);
    outline-offset: 2px;
}

.page-nav__trail {
    list-style: none;
    margin: 0 0 0 4px;
    padding: 0 16px;
    height: 42px;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 7px;
    overflow: hidden;
    border-radius: 21px;
    border: 1px solid var(--color-border-soft);
    background: var(--color-surface);
    box-shadow: 0 2px 10px var(--color-overlay-dark);
    font-size: 0.86rem;
    color: var(--color-text-muted);
}

.page-nav__trail li {
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.page-nav__trail li + li::before {
    content: '\203A';
    margin-right: 7px;
    color: var(--color-text-muted);
}

.page-nav__trail a {
    color: var(--color-text-muted);
    text-decoration: none;
}

.page-nav__trail a:hover {
    color: var(--color-text-main);
    text-decoration: underline;
}

.page-nav__trail [aria-current] {
    color: var(--color-text-main);
    font-weight: 700;
}

@media (max-width: 1100px) {
    .page-nav__trail li:not(:last-child) {
        display: none;
    }
}

@media (max-width: 768px) {
    /* Beside the sidebar toggle; the buttons keep their icons, the trail goes */
    .page-nav {
        left: 70px;
        max-width: calc(100vw - 70px - 130px);
    }

    .page-nav__btn {
        width: 42px;
        padding: 0;
        justify-content: center;
    }

    .page-nav__btn span,
    .page-nav__trail {
        display: none;
    }
}

/* Pages that paint and scroll their own full-height surface (account pages). */
.chat-main.page-main--flush {
    padding: 0;
}

.page-content {
    max-width: 1400px;
    margin: 0 auto;
}

@media (max-width: 768px) {
    /* Below 768px the sidebar is a slide-in drawer. Keep it full height so the
       user menu stays reachable, and leave a strip of overlay to tap to close.
       The extra .chat-container beats the later max-width:480px .sidebar rule
       that would otherwise shrink the drawer to 40vh. */
    .chat-container > .sidebar {
        width: min(300px, 85vw);
        height: 100vh;
        height: 100dvh;
        max-height: none;
    }

    /* Clear the fixed sidebar toggle in the top-left corner. */
    .chat-container > .sidebar .sidebar-header {
        padding-top: 70px;
    }

    .chat-main.page-main {
        padding: 70px 16px 24px;
    }

    .chat-main.page-main--flush {
        padding: 0;
    }
}



/* Prompts Section Styles */
.prompts-section {
    border-top: 1px solid var(--color-border-main);
    padding: 15px;
    flex-shrink: 0;
    overflow-y: auto;
    max-height: 40vh;
}

.prompts-header {
    margin-bottom: 15px;
}

.prompts-header h3 {
    color: var(--color-text-main);
    font-size: 1rem;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.prompts-header .btn {
    padding: 8px 12px;
    font-size: 0.85rem;
}

/* Prompts Tabs Styles */
.prompts-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
    border-bottom: 2px solid var(--color-border-main);
}

.prompt-tab {
    flex: 1;
    padding: 10px 16px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-bottom: -2px;
}

.prompt-tab:hover {
    color: var(--color-brand-main);
    background: var(--color-overlay-dark);
}

.prompt-tab.active {
    color: var(--color-brand-main);
    border-bottom-color: var(--color-brand-main);
    background: var(--color-overlay-dark);
}

.prompt-tab i {
    font-size: 0.8rem;
}

.add-prompt-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border-main);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    animation: slideDown 0.3s ease-out;
}

.add-prompt-form.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.prompt-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border-main);
    border-radius: 6px;
    margin-bottom: 10px;
    font-size: 0.9rem;
    transition: border-color 0.2s;
}

.prompt-input:focus {
    outline: none;
    border-color: var(--color-brand-main);
}

.prompt-textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--color-border-main);
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 80px;
    font-family: inherit;
    transition: border-color 0.2s;
    background: var(--color-surface);
    color: var(--color-text-main);
}

.prompt-textarea:focus {
    outline: none;
    border-color: var(--color-brand-main);
}

.prompt-form-actions {
    display: flex;
    gap: 10px;
}

.prompt-form-actions .btn {
    flex: 1;
    padding: 8px 12px;
    font-size: 0.85rem;
}

.prompts-list {
    max-height: 250px;
    overflow-y: auto;
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1101;
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
    color: var(--color-text-inverse);
    border: none;
    border-radius: 8px;
    padding: 12px;
    cursor: pointer;
    box-shadow: 0 4px 15px var(--color-overlay-dark);
    transition: all 0.3s ease;
}

.sidebar-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px var(--color-overlay-darker);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-overlay-darker);
    z-index: 1050;
    backdrop-filter: blur(2px);
}

.prompt-item {
    background: var(--color-surface);
    border: 1px solid var(--color-border-main);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.2s;
    animation: fadeIn 0.2s ease-out;
}

.prompt-item:hover {
    background: var(--color-surface-soft);
    transform: translateX(2px);
    border-color: var(--color-brand-main);
}

.prompt-item:focus,
.prompt-item:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-brand-main), 0 0 12px var(--color-overlay-dark);
    background: var(--color-brand-alpha);
    border-color: var(--color-brand-main);
}

.prompt-item-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
    gap: 8px;
}

.prompt-item-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-brand-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.prompt-item-content {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.prompt-item-actions {
    display: flex;
    justify-content: flex-end;
    gap: 5px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.2s;
}

.prompt-item:hover .prompt-item-actions,
.prompt-item:focus-within .prompt-item-actions,
.prompt-item:focus .prompt-item-actions,
.prompt-item-actions:has(button:focus),
.prompt-item-actions:has(button:focus-visible) {
    opacity: 1;
}

.prompt-item-actions button {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 0.75rem;
    transition: all 0.2s;
}

.prompt-item-actions button:hover {
    background: var(--color-surface-hover);
    color: var(--color-text-main);
}

.prompt-item-actions .btn-edit:hover {
    color: var(--color-brand-main);
}

.prompt-item-actions .btn-delete:hover {
    color: var(--color-danger-main);
}

/* Main Chat Area */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-bg);
    /* Light background for main area */
    height: 100vh;
    overflow: auto;
    padding: 20px;
}

/* Chat Area Wrapper Box */
.chat-area-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
    border-radius: 16px;
    box-shadow: 0 4px 20px var(--color-overlay-dark);
    overflow: auto;
    border: 1px solid var(--color-overlay-dark);
    position: relative;
}

.chat-area-wrapper.drag-over {
    border-color: var(--color-info-main);
    box-shadow: 0 0 0 3px var(--color-info-bg), 0 4px 20px var(--color-overlay-dark);
}

.chat-area-wrapper.drag-over::after {
    content: 'Drop files to attach';
    position: absolute;
    inset: 18px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--color-info-main);
    border-radius: 14px;
    background: var(--color-info-bg);
    color: var(--color-info-dark);
    font-weight: 700;
    pointer-events: none;
}

.welcome-message {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;
    padding: 20px;
}

.welcome-icon {
    font-size: 5rem;
    color: var(--color-brand-main);
    margin-bottom: 30px;
    background: var(--color-surface);
    width: 120px;
    height: 120px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid var(--color-brand-main);
}

#welcome-title,
.welcome-message h1 {
    color: var(--color-brand-main);
    font-size: 1.2rem;
    font-weight: 700;
    max-width: 650px;
    line-height: 1.5;
    margin-bottom: 12px;
}

.welcome-message p {
    color: var(--color-text-muted);
    font-size: 1rem;
    max-width: 600px;
}

/* Chat Messages Container */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    /* Top padding keeps the first message clear of the fixed bell/theme buttons */
    padding: 56px 20px 20px;
    display: flex;
    flex-direction: column;
    background: var(--color-surface);
}

/* Message Styles */
.message {
    display: flex;
    margin-bottom: 20px;
    max-width: 80%;
    animation: slideIn 0.3s ease-out;

}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    margin-left: auto;
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 12px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
}

.message.assistant .message-avatar {
    background: var(--color-surface-soft);
    color: var(--color-text-main);
}

.message-content {
    background: var(--color-surface);
    color: var(--color-text-main);
    padding: 15px 20px;
    border-radius: 18px;
    box-shadow: 0 2px 8px var(--color-overlay-dark);
    position: relative;
    word-wrap: break-word;
}

.message-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--color-border-soft);
}

.message-role {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: 0.9rem;
}

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

.toggle-view-btn {
    background: none;
    border: 1px solid var(--color-border-strong);
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.toggle-view-btn:hover {
    background: var(--color-surface-soft);
    border-color: var(--color-brand-main);
    color: var(--color-brand-main);
}

.toggle-view-btn.active {
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
    border-color: var(--color-brand-main);
}

.message-body {
    position: relative;
}

.raw-content {
    display: none;
    background: var(--color-surface-sunken);
    border: 1px solid var(--color-border-soft);
    border-radius: 6px;
    padding: 12px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.85rem;
    white-space: pre-wrap;
    overflow-x: auto;
    color: var(--color-text-main);
    line-height: 1.4;
    max-height: 400px;
    overflow-y: auto;
}

.raw-content::before {
    content: "Raw Output";
    display: block;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    margin-bottom: 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--color-border-main);
    font-weight: 600;
}

.raw-content.show {
    display: block;
}

.formatted-content {
    display: block;
}

.formatted-content.hide {
    display: none;
}

/* Markdown in messages */
.formatted-content > :first-child {
    margin-top: 0;
}

.formatted-content > :last-child {
    margin-bottom: 0;
}

.formatted-content p,
.formatted-content ul,
.formatted-content ol,
.formatted-content blockquote,
.formatted-content table {
    margin: 0 0 0.75em;
}

.formatted-content h1,
.formatted-content h2,
.formatted-content h3,
.formatted-content h4,
.formatted-content h5,
.formatted-content h6 {
    margin: 1em 0 0.5em;
    font-size: 1em;
    line-height: 1.3;
}

.formatted-content h1 {
    font-size: 1.4em;
}

.formatted-content h2 {
    font-size: 1.25em;
}

.formatted-content h3 {
    font-size: 1.1em;
}

.formatted-content ul,
.formatted-content ol {
    padding-left: 1.5em;
}

.formatted-content li + li {
    margin-top: 0.25em;
}

.formatted-content blockquote {
    padding: 0.25em 1em;
    border-left: 3px solid var(--color-border-strong);
    color: var(--color-text-muted);
}

.formatted-content table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    border-collapse: collapse;
}

.formatted-content th,
.formatted-content td {
    border: 1px solid var(--color-border-main);
    padding: 6px 10px;
    text-align: left;
}

.formatted-content th {
    background: var(--color-surface-soft);
}

.formatted-content hr {
    border: 0;
    border-top: 1px solid var(--color-border-main);
    margin: 1em 0;
}

.formatted-content a {
    color: var(--color-brand-light);
    text-decoration: underline;
}

.message.user .formatted-content a {
    color: inherit;
}

.message.user .formatted-content th {
    background: none;
}

.copy-btn {
    background: none;
    border: 1px solid var(--color-border-strong);
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.copy-btn:hover {
    background: var(--color-surface-soft);
    border-color: var(--color-success-main);
    color: var(--color-success-main);
}

.copy-btn.copied {
    background: var(--color-success-main);
    color: var(--color-text-inverse);
    border-color: var(--color-success-main);
}

.message.user .message-content {
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
    border-bottom-right-radius: 4px;
}

.message.user .message-header {
    border-bottom-color: var(--color-overlay-light);
}

.message.assistant .message-content {
    border-bottom-left-radius: 4px;
    border: 1px solid var(--color-border-main);
    /* Fill the row so the absolutely positioned code-block toolbar fits even on short replies */
    flex: 1;
    min-width: 0;
}

/* Hide message actions for user messages */
.message.user .message-actions {
    display: none;
}

/* Adjust spacing for user messages without header */
.message.user .message-content .message-body {
    margin-top: 0;
}

.message-time {
    font-size: 0.75rem;
    margin-top: 8px;
    text-align: right;
    color: var(--color-text-inverse);
    opacity: 0.85;
}

.message.assistant .message-time {
    text-align: left;
    color: var(--color-text-muted);
    opacity: 1;
}

/* Plain-language error shown in place of a reply */
.message.chat-error .message-avatar {
    background: var(--color-danger-bg);
    color: var(--color-danger-dark);
}

.message.chat-error .message-content {
    background: var(--color-danger-bg);
    color: var(--color-danger-dark);
    border: 1px solid var(--color-danger-border);
}

/* Chat Input */
.chat-input-container {
    padding: 0;
    border-top: none;
    background: transparent;
    max-width: 800px;
    margin: 0 auto 40px auto;
    width: 90%;
}

.chat-input-container.card-style {
    background: var(--color-surface);
    padding: 25px;
    border-radius: 24px;
    box-shadow: 0 4px 25px var(--color-overlay-dark);
}

.input-label {
    font-size: 0.9rem;
    color: var(--color-brand-main);
    margin-bottom: 15px;
    font-weight: 600;
}

.prompt-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 20px;
    justify-content: center;
}

/* Prompt chips start a chat; once it has messages they only take up room */
.chat-area-wrapper:not(:has(.welcome-message)) .prompt-chips {
    display: none;
}

.chip {
    background: var(--color-surface-hover);
    border: none;
    padding: 10px 18px;
    border-radius: 20px;
    color: var(--color-brand-main);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.chip:hover {
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
}

.chip:focus,
.chip:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-brand-main), 0 0 12px var(--color-overlay-dark);
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
    transform: scale(1.05);
}

.library-content {
    padding: 15px;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.library-content:hover {
    background: var(--color-overlay-dark);
    border-left: 3px solid var(--color-brand-main);
}

.library-content:focus,
.library-content:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px var(--color-brand-main), 0 0 12px var(--color-overlay-dark);
    background: var(--color-brand-alpha);
    border-radius: 8px;
}

.form-input:focus,
.form-input:focus-visible,
.form-textarea:focus,
.form-textarea:focus-visible {
    outline: none;
    border-color: var(--color-brand-main);
    box-shadow: 0 0 0 3px var(--color-overlay-dark), 0 0 8px var(--color-overlay-dark);
    background: var(--color-surface);
}

.input-wrapper {
    background: var(--color-surface);
    /* Or transparent if the card is white */
}

.input-controls textarea {
    border: none;
    box-shadow: none;
    background: transparent;
    padding: 0;
    font-size: 1rem;
    min-height: 24px;
    color: var(--color-brand-main);
    font-weight: 500;
}

.input-controls textarea:focus {
    outline: none;
    box-shadow: none;
}

.input-controls textarea::placeholder {
    color: var(--color-brand-main);
    font-weight: 600;
    opacity: 1;
}

.input-controls {
    display: flex;
    align-items: center;
    gap: 15px;
    background: transparent;
    padding: 0;
    border: none;
}

.attach-btn,
.send-btn {
    color: var(--color-brand-main);
    background: transparent;
    padding: 5px;
    font-size: 1.2rem;
}

.send-btn:hover,
.attach-btn:hover {
    background: var(--color-surface-hover);
    color: var(--color-brand-main);
    border-radius: 50%;
}

.send-btn:focus,
.send-btn:focus-visible,
.attach-btn:focus,
.attach-btn:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    background: var(--color-brand-alpha);
    border-radius: 50%;
    box-shadow: 0 0 12px var(--color-overlay-dark);
}

/* File Upload Styles */
.file-upload-area {
    margin-bottom: 15px;
}

.file-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.file-item {
    display: flex;
    align-items: center;
    background: var(--color-surface-soft);
    border: 1px solid var(--color-border-main);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    animation: fadeIn 0.2s ease-out;
}

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

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

.file-item i {
    margin-right: 8px;
    color: var(--color-brand-main);
}

.file-item .file-thumb {
    width: 24px;
    height: 24px;
    object-fit: cover;
    border-radius: 4px;
    margin-right: 8px;
    flex-shrink: 0;
}

.file-item .file-name {
    margin-right: 8px;
}

.file-item .file-size {
    color: var(--color-text-muted);
    font-size: 0.8rem;
    margin-right: 8px;
}

.file-item .file-status {
    color: var(--color-info-dark);
    background: var(--color-info-bg);
    border: 1px solid var(--color-info-border);
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
    padding: 4px 7px;
    margin-right: 8px;
}

.file-item .remove-file {
    background: none;
    border: none;
    color: var(--color-danger-main);
    cursor: pointer;
    padding: 2px;
    border-radius: 3px;
    transition: background 0.2s;
}

.file-item .remove-file:hover {
    background: var(--color-danger-main);
    color: var(--color-text-inverse);
}

.input-wrapper {
    background: var(--color-surface);
    border-radius: 25px;
    padding: 15px 20px;
    border: 2px solid var(--color-border-main);
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px var(--color-overlay-dark);
    position: relative;
}

.input-wrapper.drag-over {
    border-color: var(--color-info-main);
    background: var(--color-info-bg);
    box-shadow: 0 0 0 3px var(--color-info-bg);
}

.input-wrapper.is-generating {
    border-color: var(--color-border-strong);
}

.input-controls {
    display: flex;
    align-items: flex-end;
    gap: 15px;
    width: 100%;
}

.attach-btn {
    background: var(--color-overlay-dark);
    border: none;
    color: var(--color-brand-main);
    cursor: pointer;
    padding: 10px;
    border-radius: 50%;
    transition: all 0.3s ease;
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.attach-btn:hover {
    background: var(--color-overlay-dark);
    transform: scale(1.1);
    box-shadow: 0 4px 15px var(--color-overlay-dark);
}

.input-wrapper:focus-within {
    border-color: var(--color-brand-main);
    box-shadow: 0 0 0 3px var(--color-overlay-dark);
    transform: translateY(-1px);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    outline: none;
    font-size: 1rem;
    line-height: 1.6;
    min-height: 26px;
    max-height: 120px;
    font-family: inherit;
    color: var(--color-text-main);
}

#message-input:focus,
#message-input:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    background: var(--color-brand-alpha);
    border-radius: 4px;
    box-shadow: 0 0 8px var(--color-overlay-dark);
}

#message-input::placeholder {
    color: var(--color-text-subtle);
    font-style: italic;
}

.send-btn {
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
    color: var(--color-text-inverse);
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    font-size: 1.1rem;
    box-shadow: 0 4px 15px var(--color-overlay-dark);
}

.send-btn:hover:not(:disabled) {
    transform: scale(1.1);
    box-shadow: 0 6px 20px var(--color-overlay-darker);
}

.send-btn:focus,
.send-btn:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px var(--color-brand-main), 0 0 12px var(--color-overlay-dark);
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
}

.send-btn:disabled {
    background: var(--color-text-subtle);
    cursor: not-allowed;
    transform: none;
}

.stop-generating-btn {
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 14px;
    border: 1px solid var(--color-danger-bg);
    border-radius: 8px;
    background: var(--color-danger-bg);
    color: var(--color-danger-dark);
    cursor: pointer;
    display: inline-flex;
    flex-shrink: 0;
    font-size: 0.92rem;
    font-weight: 700;
    line-height: 1;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.stop-generating-btn:hover:not(:disabled),
.stop-generating-btn:focus-visible {
    background: var(--color-danger-border);
    border-color: var(--color-danger-main);
    box-shadow: 0 0 0 3px var(--color-danger-bg);
}

.stop-generating-btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.fullscreen-input-btn {
    align-items: center;
    background: var(--color-overlay-dark);
    border: none;
    border-radius: 50%;
    color: var(--color-brand-main);
    cursor: pointer;
    display: flex;
    flex-shrink: 0;
    font-size: 1.05rem;
    height: 42px;
    justify-content: center;
    padding: 10px;
    transition: all 0.3s ease;
    width: 42px;
}

.fullscreen-input-btn:hover:not(:disabled) {
    background: var(--color-overlay-dark);
    box-shadow: 0 4px 15px var(--color-overlay-dark);
    transform: scale(1.1);
}

.fullscreen-input-btn:focus,
.fullscreen-input-btn:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    background: var(--color-brand-alpha);
    box-shadow: 0 0 12px var(--color-overlay-dark);
}

.fullscreen-input-btn:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

body.fullscreen-input-open {
    overflow: hidden;
}

.fullscreen-input-modal {
    align-items: stretch;
    background: var(--color-overlay-darker);
    backdrop-filter: blur(5px);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: clamp(12px, 3vw, 28px);
    position: fixed;
    z-index: 2600;
}

.fullscreen-input-panel {
    background: var(--color-surface);
    border: 1px solid var(--color-brand-alpha);
    border-radius: 16px;
    box-shadow: 0 24px 60px var(--color-overlay-dark);
    display: flex;
    flex-direction: column;
    max-height: 100%;
    max-width: 1040px;
    min-height: 0;
    overflow: hidden;
    width: 100%;
}

.fullscreen-input-modal.drag-over .fullscreen-input-panel,
.fullscreen-input-panel.drag-over {
    border-color: var(--color-info-main);
    box-shadow: 0 0 0 4px var(--color-info-bg), 0 24px 60px var(--color-overlay-dark);
}

.fullscreen-input-panel.is-generating {
    border-color: var(--color-border-strong);
}

.fullscreen-input-header {
    align-items: center;
    background: linear-gradient(135deg, var(--color-surface-soft) 0%, var(--color-surface-hover) 100%);
    border-bottom: 1px solid var(--color-border-main);
    display: flex;
    gap: 16px;
    justify-content: space-between;
    padding: 18px 22px;
}

.fullscreen-input-header h2 {
    color: var(--color-text-main);
    font-size: 1.1rem;
    font-weight: 700;
    margin: 0;
}

.fullscreen-close-btn {
    align-items: center;
    background: var(--color-overlay-dark);
    border: none;
    border-radius: 50%;
    color: var(--color-brand-main);
    cursor: pointer;
    display: flex;
    flex-shrink: 0;
    height: 36px;
    justify-content: center;
    transition: all 0.2s ease;
    width: 36px;
}

.fullscreen-close-btn:hover {
    background: var(--color-overlay-dark);
    transform: scale(1.05);
}

.fullscreen-close-btn:focus,
.fullscreen-close-btn:focus-visible {
    outline: 3px solid var(--color-brand-main);
    outline-offset: 2px;
    box-shadow: 0 0 12px var(--color-overlay-dark);
}

.fullscreen-input-body {
    display: flex;
    flex: 1;
    min-height: 0;
    padding: 18px;
}

#fullscreen-message-input {
    background: var(--color-surface);
    border: 2px solid var(--color-border-main);
    border-radius: 12px;
    color: var(--color-text-main);
    flex: 1;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.6;
    min-height: 320px;
    outline: none;
    padding: 16px;
    resize: none;
    width: 100%;
}

#fullscreen-message-input:focus,
#fullscreen-message-input:focus-visible {
    border-color: var(--color-brand-main);
    box-shadow: 0 0 0 3px var(--color-brand-alpha);
}

#fullscreen-message-input::placeholder {
    color: var(--color-text-muted);
    font-style: italic;
}

.fullscreen-file-upload-area {
    display: none;
    padding: 0 18px 12px;
}

.fullscreen-file-list {
    max-height: 132px;
    overflow-y: auto;
    padding: 2px;
}

.fullscreen-input-actions {
    align-items: center;
    background: var(--color-surface-soft);
    border-top: 1px solid var(--color-border-main);
    display: flex;
    gap: 12px;
    padding: 16px 18px;
}

.fullscreen-action-spacer {
    flex: 1;
}

.fullscreen-action-btn {
    margin-right: 0;
}

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
    padding: 0 10px;
}

.streaming-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
}

.streaming-toggle label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.streaming-toggle input[type="checkbox"] {
    appearance: none;
    width: 40px;
    height: 20px;
    background: var(--color-text-subtle);
    border-radius: 20px;
    position: relative;
    cursor: pointer;
    transition: background 0.2s;
}

.streaming-toggle input[type="checkbox"]:checked {
    background: var(--color-brand-main);
}

.streaming-toggle input[type="checkbox"]:before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: var(--color-surface);
    border-radius: 50%;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}

.streaming-toggle input[type="checkbox"]:checked:before {
    transform: translateX(20px);
}

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

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--color-overlay-darker);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 3500;
}

.loading-overlay.hidden {
    display: none;
}

.loading-spinner {
    background: var(--color-surface);
    padding: 30px;
    border-radius: 12px;
    text-align: center;
}

.loading-spinner i {
    font-size: 2rem;
    color: var(--color-brand-main);
    margin-bottom: 15px;
}

.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 15px 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border-main);
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px var(--color-overlay-dark);
    max-width: 70%;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-brand-main);
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes typing {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Code Syntax Highlighting */
pre {
    background: var(--color-surface-sunken);
    color: var(--color-text-main);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    border: 1px solid var(--color-border-main);
    margin: 12px 0;
    position: relative;
    box-shadow: inset 0 1px 0 var(--color-overlay-light);
}

pre::before {
    content: attr(data-language);
    position: absolute;
    top: 10px;
    left: 14px;
    right: auto;
    font-size: 0.72rem;
    color: var(--color-text-muted);
    letter-spacing: 0;
    text-transform: uppercase;
    font-weight: 700;
}

pre code {
    background: transparent;
    border: none;
    color: inherit;
    padding: 0;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}

code {
    background: var(--color-surface-hover);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9em;
    color: var(--color-danger-dark);
    border: 1px solid var(--color-border-soft);
}

/* Keep generated code blocks consistent across languages. */
pre code.language-html,
pre code.language-css,
pre code.language-javascript,
pre code.language-js,
pre code.language-python {
    color: inherit;
}

/* Better code block styling */
pre {
    max-height: 500px;
    overflow-y: auto;
}

pre:hover {
    box-shadow: inset 0 1px 0 var(--color-overlay-light), 0 8px 24px var(--color-overlay-dark);
}

/* Mobile Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: 280px;
    }

    .prompts-section {
        max-height: 35vh;
    }

    .prompts-list {
        max-height: 200px;
    }
}

@media (max-width: 768px) {
    .chat-container {
        margin: 5px;
        border-radius: 8px;
    }

    .sidebar {
        width: 280px;
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1100;
        transform: translateX(-100%);
        box-shadow: 2px 0 10px var(--color-overlay-dark);
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .sidebar-toggle {
        display: block;
    }

    .chat-main {
        width: 100%;
    }

    .message {
        max-width: 90%;
    }

    .input-wrapper {
        padding: 10px 15px;
    }

    .input-controls {
        flex-wrap: wrap;
        gap: 10px;
    }

    #message-input {
        min-width: 120px;
    }

    .fullscreen-input-btn,
    .attach-btn,
    .send-btn {
        height: 40px;
        width: 40px;
    }

    .stop-generating-btn {
        width: 100%;
    }

    .chat-sessions {
        max-height: 40vh;
        flex: 0 0 auto;
    }

    .prompts-section {
        padding: 12px;
        max-height: 30vh;
        flex: 0 0 auto;
    }

    .prompts-header h3 {
        font-size: 0.9rem;
    }

    .prompts-header .btn {
        padding: 6px 10px;
        font-size: 0.8rem;
    }

    .prompt-tab {
        padding: 8px 12px;
        font-size: 0.8rem;
    }

    .prompts-list {
        max-height: 180px;
    }
}

@media (max-width: 640px) {
    .chat-container {
        margin: 0;
        border-radius: 0;
    }

    .sidebar {
        width: 260px;
    }

    .sidebar-header {
        padding: 15px;
    }

    .user-info {
        padding: 12px;
    }

    .user-avatar {
        font-size: 1.8rem;
        margin-right: 10px;
    }

    .user-name {
        font-size: 0.9rem;
    }

    .user-username {
        font-size: 0.75rem;
    }

    .sidebar-actions h2 {
        font-size: 1.1rem;
    }

    .chat-sessions {
        max-height: 35vh;
        flex: 0 0 auto;
    }

    .prompts-section {
        padding: 10px;
        max-height: 25vh;
        flex: 0 0 auto;
    }

    .prompts-header h3 {
        font-size: 0.85rem;
    }

    .prompts-header .btn {
        padding: 5px 8px;
        font-size: 0.75rem;
    }

    .prompt-tab {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    .prompt-tab i {
        font-size: 0.7rem;
    }

    .prompts-list {
        max-height: 150px;
    }

    .prompt-item {
        padding: 10px;
    }

    .prompt-item-title {
        font-size: 0.85rem;
    }

    .prompt-item-content {
        font-size: 0.75rem;
    }
}

@media (max-width: 480px) {
    .sidebar {
        width: 100%;
    }

    .chat-sessions {
        max-height: 40vh;
        flex: 0 0 auto;
    }

    .prompts-section {
        max-height: 30vh;
        padding: 8px;
        flex: 0 0 auto;
    }

    .prompts-list {
        max-height: 200px;
    }

    .sidebar-toggle {
        top: 10px;
        left: 10px;
        padding: 10px;
    }
}

/* Notification Styles */
.notification-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    max-width: 400px;
}

.notification {
    background: var(--color-surface);
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 10px;
    box-shadow: 0 4px 12px var(--color-overlay-dark);
    border-left: 4px solid var(--color-brand-main);
    animation: slideInRight 0.3s ease-out;
    display: flex;
    align-items: center;
    gap: 10px;
}

.notification.success {
    border-left-color: var(--color-success-main);
}

.notification.error {
    border-left-color: var(--color-danger-main);
}

.notification.info {
    border-left-color: var(--color-info-main);
}

.notification-icon {
    font-size: 1.2rem;
}

.notification.success .notification-icon {
    color: var(--color-success-main);
}

.notification.error .notification-icon {
    color: var(--color-danger-main);
}

.notification.info .notification-icon {
    color: var(--color-info-main);
}

.notification-message {
    flex: 1;
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.notification-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.notification-close:hover {
    background: var(--color-surface-soft);
    color: var(--color-text-muted);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }

    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOutRight {
    from {
        opacity: 1;
        transform: translateX(0);
    }

    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.notification.hiding {
    animation: slideOutRight 0.3s ease-out forwards;
}

/* Attached Files Display Styles */
.attached-files-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--color-border-main);
}

.attached-file-card {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--color-surface-soft);
    border: 1px solid var(--color-border-main);
    border-radius: 8px;
    padding: 10px 12px;
    transition: all 0.2s ease;
    cursor: pointer;
    min-width: 200px;
    max-width: 300px;
}

.attached-file-card:hover {
    background: var(--color-border-main);
    border-color: var(--color-brand-main);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px var(--color-overlay-dark);
}

.file-card-icon {
    font-size: 1.5rem;
    color: var(--color-brand-main);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: var(--color-overlay-dark);
    border-radius: 6px;
    flex-shrink: 0;
}

.file-card-info {
    flex: 1;
    min-width: 0;
}

.file-card-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.file-card-size {
    font-size: 0.75rem;
    color: var(--color-text-muted);
}

.file-card-menu-btn {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-card-menu-btn:hover {
    background: var(--color-overlay-dark);
    color: var(--color-brand-main);
}

/* File Action Menu */
.file-action-menu {
    background: var(--color-surface);
    border: 1px solid var(--color-border-main);
    border-radius: 8px;
    box-shadow: 0 10px 30px var(--color-overlay-dark);
    padding: 8px 0;
    z-index: 3000;
    animation: fadeIn 0.2s ease-out;
    min-width: 160px;
}

.file-action-btn {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 16px;
    background: none;
    border: none;
    color: var(--color-text-main);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.file-action-btn:hover {
    background: var(--color-surface-soft);
    color: var(--color-brand-main);
}

.file-action-btn i {
    width: 16px;
    text-align: center;
    color: var(--color-brand-main);
}

.file-action-btn.preview-file-btn {
    background: linear-gradient(135deg, var(--color-overlay-dark) 0%, var(--color-overlay-dark) 100%);
    font-weight: 600;
}

.file-action-btn.preview-file-btn:hover {
    background: linear-gradient(135deg, var(--color-overlay-dark) 0%, var(--color-overlay-dark) 100%);
}

.file-action-btn.preview-file-btn i {
    color: var(--color-brand-main);
}

/* Download menu — two named choices rather than one unexplained button, so
   the difference between the editable source and the tagged PDF is readable
   before the click rather than after the download. */
.download-action-menu {
    min-width: 290px;
    max-width: min(340px, calc(100vw - 24px));
}

.download-action-menu .file-action-btn {
    align-items: flex-start;
    padding: 11px 16px;
}

.download-action-menu .file-action-btn i {
    margin-top: 2px;
}

.download-option {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.download-option-name {
    font-weight: 600;
}

.download-option-hint {
    font-size: 0.78rem;
    font-weight: 400;
    color: var(--color-text-muted);
    white-space: normal;
}

.download-action-menu .file-action-btn:hover .download-option-hint {
    color: inherit;
}

/* File View Modal */
.file-view-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--color-overlay-darker);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2500;
    backdrop-filter: blur(5px);
    animation: fadeIn 0.3s ease-out;
}

.file-view-content {
    background: var(--color-surface);
    border-radius: 12px;
    box-shadow: 0 20px 40px var(--color-overlay-darker);
    width: 90%;
    max-width: 780px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalSlideIn 0.3s ease-out;
}

.file-view-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 22px;
    border-bottom: 1px solid var(--color-border-main);
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
    flex-shrink: 0;
}

.file-view-header h3 {
    margin: 0;
    color: var(--color-text-inverse);
    font-size: 1.15rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    padding-right: 15px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.close-modal-btn {
    background: var(--color-overlay-light);
    border: none;
    color: var(--color-text-inverse);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.close-modal-btn:hover {
    background: var(--color-overlay-medium);
    transform: scale(1.1);
}

.file-view-body {
    padding: 20px 24px;
    max-height: calc(85vh - 130px);
    overflow-y: auto;
    flex: 1;
}

.file-view-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    padding: 14px 24px;
    border-top: 1px solid var(--color-border-main);
    background: var(--color-surface-soft);
    flex-shrink: 0;
}

.file-view-preview {
    margin-bottom: 16px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--color-surface-soft);
    border: 1px solid var(--color-border-main);
}

.file-view-preview.image-preview {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
    background: var(--color-overlay-dark);
}

/* The file viewer (chat.js, createFileViewModal): the file itself, with Download beside it. */
.file-preview-dialog {
    max-width: 920px;
}

.file-preview-dialog.is-large {
    width: min(1180px, 96vw);
    max-width: none;
    height: 92vh;
    max-height: 92vh;
}

.file-preview-dialog .file-view-header h3 {
    display: flex;
    align-items: baseline;
    gap: 10px;
    min-width: 0;
}

.file-preview-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-preview-meta {
    flex: none;
    font-size: 0.78rem;
    font-weight: 500;
    /* The header is the brand colour; a muted grey would vanish on it. */
    color: inherit;
    opacity: 0.8;
}

.file-preview-body {
    display: flex;
    flex-direction: column;
    padding: 0;
    max-height: none;
    min-height: 240px;
    background: var(--color-surface-soft);
}

.file-preview-dialog.is-large .file-preview-body {
    flex: 1;
    min-height: 0;
}

.file-preview-frame {
    flex: 1;
    width: 100%;
    min-height: 60vh;
    border: 0;
    background: #fff;
}

.file-preview-dialog.is-large .file-preview-frame {
    min-height: 0;
    height: 100%;
}

.file-preview-image {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow: auto;
}

.file-preview-image img {
    max-width: 100%;
    max-height: 72vh;
    object-fit: contain;
    border-radius: 6px;
    background: #fff;
}

.file-preview-text,
.file-preview-view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: auto;
}

.file-preview-view[hidden] {
    display: none;
}

.file-preview-text .file-code-preview {
    margin: 0;
    padding: 16px 20px;
    max-height: none;
    flex: 1;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.85rem;
    line-height: 1.5;
}

.file-preview-loading,
.file-preview-empty,
.file-preview-error {
    margin: auto;
    padding: 32px 24px;
    text-align: center;
    color: var(--color-text-muted);
}

.file-preview-empty i {
    display: block;
    font-size: 2rem;
    margin-bottom: 10px;
}

.file-preview-error {
    color: var(--color-danger-dark);
}

.file-preview-tabs {
    display: flex;
    gap: 4px;
    padding: 8px 24px 0;
    border-bottom: 1px solid var(--color-border-main);
}

.file-preview-tab {
    border: 1px solid transparent;
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    background: none;
    padding: 6px 14px;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    cursor: pointer;
}

.file-preview-tab.active {
    background: var(--color-surface-soft);
    border-color: var(--color-border-main);
    color: var(--color-text-main);
    font-weight: 600;
    margin-bottom: -1px;
}

.file-preview-table-wrap {
    overflow: auto;
    flex: 1;
    padding: 12px 16px;
}

.file-preview-table {
    border-collapse: collapse;
    font-size: 0.85rem;
    background: var(--color-surface);
}

.file-preview-table th,
.file-preview-table td {
    border: 1px solid var(--color-border-main);
    padding: 4px 10px;
    text-align: left;
    vertical-align: top;
    white-space: pre-wrap;
}

.file-preview-table th {
    position: sticky;
    top: 0;
    background: var(--color-surface-soft);
    font-weight: 600;
}

.file-preview-note-inline {
    margin: 0;
    padding: 0 16px 12px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.file-preview-note {
    margin-right: auto;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.file-preview-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    border-radius: 6px;
    border: 1px solid var(--color-border-main);
    background: var(--color-surface-soft);
    color: var(--color-text-main);
    cursor: pointer;
}

.file-preview-btn.primary {
    background: var(--color-brand-main);
    border-color: var(--color-brand-main);
    color: var(--color-text-inverse, #fff);
}

.file-preview-btn[hidden] {
    display: none;
}

@media (max-width: 640px) {
    .file-preview-dialog.is-large {
        width: 100vw;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0;
    }

    .file-preview-dialog .file-view-footer {
        flex-wrap: wrap;
    }
}

.file-view-preview.code-preview {
    display: flex;
    flex-direction: column;
}

.file-view-preview .code-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: var(--color-overlay-dark);
    border-bottom: 1px solid var(--color-border-main);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--color-text-muted);
}

.file-code-preview {
    margin: 0;
    padding: 14px;
    max-height: 380px;
    overflow: auto;
    font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.85rem;
    line-height: 1.45;
    color: var(--color-text-main);
    white-space: pre-wrap;
    word-break: break-word;
}

.file-info-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.file-info-icon {
    margin-bottom: 20px;
    color: var(--color-brand-main);
}

.file-info-details {
    width: 100%;
    background: var(--color-surface-soft);
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 0;
}

.file-info-details p {
    margin: 8px 0;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    text-align: left;
}

.file-info-details strong {
    color: var(--color-text-main);
    margin-right: 8px;
}

.file-view-notice {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 15px;
    background: var(--color-overlay-dark);
    border: 1px solid var(--color-overlay-dark);
    border-radius: 8px;
    color: var(--color-text-muted);
}

.file-view-notice i {
    color: var(--color-brand-main);
    font-size: 1.2rem;
}

.file-view-notice p {
    margin: 0;
    font-size: 0.9rem;
}

/* Mobile responsiveness for file cards */
@media (max-width: 768px) {
    .attached-files-container {
        gap: 8px;
    }

    .attached-file-card {
        min-width: 100%;
        max-width: 100%;
    }

    .file-view-content {
        width: 95%;
        max-height: 90vh;
    }

    .file-view-body {
        padding: 20px;
    }
}

/* Interactive Code Block Styles */
.interactive-code-block {
    position: relative;
    padding-top: 45px !important;
}

.code-block-actions {
    position: absolute;
    top: 8px;
    right: 10px;
    display: flex;
    gap: 6px;
    z-index: 10;
}

.code-action-btn {
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    color: var(--color-text-main);
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 3px var(--color-overlay-dark);
}

.code-action-btn:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-brand-main);
    color: var(--color-brand-main);
    transform: translateY(-1px);
    box-shadow: 0 2px 8px var(--color-overlay-dark);
}

.code-action-btn.copied {
    background: var(--color-success-bg);
    border-color: var(--color-success-main);
    color: var(--color-success-main);
}

.code-action-btn i {
    font-size: 0.9rem;
}

/* Code View Modal */
.code-view-modal .file-view-content {
    max-width: 900px;
}

.code-view-pre {
    background: var(--color-surface-sunken);
    border: 1px solid var(--color-border-main);
    border-radius: 8px;
    padding: 20px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    overflow-x: auto;
    color: var(--color-text-main);
    line-height: 1.6;
    max-height: 60vh;
    overflow-y: auto;
    margin: 0;
}

.code-view-pre code {
    background: none;
    padding: 0;
    border: none;
    color: inherit;
    font-size: inherit;
}

/* Enhance existing pre tags */
pre {
    position: relative;
}

pre::before {
    z-index: 5;
}

/* HTML Preview Modal Styles */
.html-preview-modal {
    z-index: 2600;
}

.html-preview-content {
    max-width: 90vw;
    max-height: 90vh;
    width: 1200px;
    height: 85vh;
    display: flex;
    flex-direction: column;
}

.html-preview-content.fullscreen {
    max-width: 100vw;
    max-height: 100vh;
    width: 100vw;
    height: 100vh;
    border-radius: 0;
    animation: expandFullscreen 0.3s ease-out;
}

@keyframes expandFullscreen {
    from {
        max-width: 90vw;
        max-height: 90vh;
    }

    to {
        max-width: 100vw;
        max-height: 100vh;
    }
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.preview-control-btn {
    background: var(--color-overlay-light);
    border: none;
    color: var(--color-text-inverse);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.3s ease;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.preview-control-btn:hover {
    background: var(--color-overlay-medium);
    transform: scale(1.1);
}

/* The Review marks switch: labelled, since what it does is not obvious from an icon. */
.preview-control-btn.preview-marks-toggle {
    width: auto;
    gap: 6px;
    padding: 0 12px;
    border-radius: 16px;
    font-size: 0.8rem;
    font-weight: 600;
}

.preview-control-btn.preview-marks-toggle:hover {
    transform: none;
}

.preview-control-btn.preview-marks-toggle.active {
    background: #fff3bf;
    color: #5c3d00;
    box-shadow: inset 0 0 0 2px #d62828;
}

.preview-control-btn.preview-marks-toggle:disabled {
    opacity: 0.6;
    cursor: progress;
}

.html-preview-body {
    flex: 1;
    padding: 0 !important;
    max-height: none !important;
    overflow: hidden !important;
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
    background: #ffffff;
}

.html-preview-host {
    width: 100%;
    height: 100%;
    flex: 1;
    border: none;
    display: block;
}

.file-view-header h3 {
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-view-header h3 i {
    font-size: 1.1rem;
}

/* Preview Button Special Styling */
.preview-btn {
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
    color: var(--color-text-inverse) !important;
    border-color: transparent;
    font-weight: 600;
}

.preview-btn:hover {
    background: linear-gradient(135deg, var(--color-brand-light) 0%, var(--color-brand-main) 100%);
    color: var(--color-text-inverse) !important;
    box-shadow: 0 4px 12px var(--color-overlay-darker);
    transform: translateY(-2px);
}

.preview-btn i,
.preview-btn:hover i {
    color: var(--color-text-inverse) !important;
}

/* Push to Canvas — sits beside Preview, styled as its secondary companion */
.push-canvas-btn {
    background: var(--color-surface);
    border-color: var(--color-brand-main);
    color: var(--color-brand-main);
    font-weight: 600;
}

.push-canvas-btn:hover {
    background: linear-gradient(135deg, var(--color-brand-main) 0%, var(--color-brand-light) 100%);
    color: var(--color-text-inverse) !important;
    border-color: transparent;
    box-shadow: 0 4px 12px var(--color-overlay-darker);
    transform: translateY(-2px);
}

.push-canvas-btn i {
    color: inherit !important;
}

.push-canvas-btn .code-action-label {
    margin-left: 2px;
}

/* Loading indicator for preview */
.html-preview-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--color-brand-main);
    font-size: 2rem;
    animation: spin 1s linear infinite;
}

/* Mobile responsiveness for code blocks */
@media (max-width: 768px) {
    .code-block-actions {
        top: 5px;
        right: 5px;
        gap: 4px;
    }

    .code-action-btn {
        padding: 5px 8px;
        font-size: 0.8rem;
    }

    .push-canvas-btn .code-action-label {
        display: none;
    }

    .interactive-code-block {
        padding-top: 40px !important;
    }

    .code-view-modal .file-view-content {
        max-width: 100%;
    }

    .code-view-pre {
        font-size: 0.8rem;
        padding: 15px;
    }

    .html-preview-content {
        width: 95vw;
        height: 80vh;
    }

    .preview-controls {
        gap: 6px;
    }

    .preview-control-btn {
        width: 28px;
        height: 28px;
        padding: 6px;
    }
}

/* Prompt Library Styles */
.library-item {
    background: var(--color-surface);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--color-border-soft);
    margin-bottom: 10px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.library-item:hover {
    border-color: var(--color-brand-main);
    box-shadow: 0 4px 6px var(--color-overlay-dark);
    background: var(--color-surface-soft);
}

.library-content {
    flex: 1;
}

.library-actions {
    flex: 0 0 auto;
    display: flex;
    gap: 5px;
    margin-left: 10px;
}

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

.library-item h4 {
    margin: 0;
    color: var(--color-brand-main);
    font-size: 1rem;
    font-weight: 600;
}

.library-item p {
    margin: 0;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    line-height: 1.4;
}

/* Center Layout for Empty Chat (Welcome State) */
.chat-main:has(.welcome-message) .chat-messages {
    flex: 0 0 auto;
    margin-top: auto;
    /* Push down from header */
    width: 100%;
}

.chat-main:has(.welcome-message) .welcome-message {
    height: auto;
    /* Allow auto height to fit content */
    padding-bottom: 10px;
}

.chat-main:has(.welcome-message) .chat-input-container {
    margin-top: 20px;
    margin-bottom: auto;
    /* Push up from bottom */
    /* Ensure horizontal centering */
    margin-left: auto;
    margin-right: auto;
}

/* Password Strength Container & Bar */
.password-strength-container {
    margin-top: 10px;
    display: none;
}

.password-strength-container.visible {
    display: block;
    animation: fadeIn 0.2s ease;
}

.password-strength-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
    font-size: 0.8rem;
    font-weight: 500;
}

.password-strength-label {
    color: var(--color-text-muted);
}

.password-strength-text {
    font-weight: 600;
}

.password-strength-text.strength-text-weak { color: var(--color-danger-main); }
.password-strength-text.strength-text-fair { color: var(--color-warning-main); }
.password-strength-text.strength-text-good { color: var(--color-info-main); }
.password-strength-text.strength-text-strong { color: var(--color-success-main); }

.password-strength-meter {
    height: 4px;
    width: 100%;
    background: var(--color-border-main);
    border-radius: 2px;
    overflow: hidden;
}

.password-strength-bar {
    height: 100%;
    transition: width 0.3s ease, background-color 0.3s ease;
    border-radius: 2px;
}

.password-strength-bar.strength-weak {
    width: 25%;
    background-color: var(--color-danger-main);
}

.password-strength-bar.strength-fair {
    width: 50%;
    background-color: var(--color-warning-main);
}

.password-strength-bar.strength-good {
    width: 75%;
    background-color: var(--color-info-main);
}

.password-strength-bar.strength-strong {
    width: 100%;
    background-color: var(--color-success-main);
}

/* Password Match Status */
.password-match-status {
    margin-top: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    display: none;
}

.password-match-status.visible {
    display: block;
}

.password-match-status.match-success {
    color: var(--color-success-main);
}

.password-match-status.match-error {
    color: var(--color-danger-main);
}

/* Password Requirements Checklist - Minimal & Clean */
.password-requirements {
    margin-top: 10px;
    font-size: 0.82rem;
    color: var(--color-text-muted);
    background: var(--color-surface-soft);
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--color-border-soft);
    display: none;
    transition: all 0.2s ease;
}

.password-requirements.visible {
    display: block;
    animation: fadeIn 0.2s ease;
}

.requirement-title {
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--color-text-main);
    font-size: 0.82rem;
}

.requirement-item {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 3px;
    font-size: 0.8rem;
    transition: color 0.2s ease;
}

.requirement-item:last-child {
    margin-bottom: 0;
}

.requirement-item .req-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-subtle);
    display: inline-block;
    flex-shrink: 0;
    transition: background-color 0.2s ease, transform 0.2s ease;
}

.requirement-item.valid {
    color: var(--color-success-main);
    font-weight: 500;
}

.requirement-item.valid .req-indicator {
    background-color: var(--color-success-main);
    transform: scale(1.2);
}

.requirement-item.invalid {
    color: var(--color-text-muted);
}

.requirement-item.pending {
    color: var(--color-text-muted);
}

/* Mobile optimizations for prompt chips */
@media (max-width: 768px) {
    .prompt-chips {
        max-height: 80px;
        overflow-y: auto;
        justify-content: flex-start;
        /* Align chips to start for better scrolling experience */
        scrollbar-width: thin;
        /* Firefox */
    }

    .prompt-chips::-webkit-scrollbar {
        width: 6px;
    }

    .prompt-chips::-webkit-scrollbar-track {
        background: var(--color-surface-soft);
        border-radius: 4px;
    }

    .prompt-chips::-webkit-scrollbar-thumb {
        background: var(--color-text-subtle);
        border-radius: 4px;
    }

    .prompt-chips::-webkit-scrollbar-thumb:hover {
        background: var(--color-text-subtle);
    }
}

/* Reasoning Blocks Styles */
.reasoning-block {
    margin: 12px 0;
    background-color: var(--color-surface-soft);
    border: 1px solid var(--color-border-soft);
    border-radius: 8px;
    overflow: hidden;
}

.reasoning-block summary {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    font-weight: 600;
    list-style: none;
    display: flex;
    align-items: center;
    background-color: var(--color-surface-soft);
    user-select: none;
    transition: background-color 0.2s;
}

.reasoning-block summary:hover {
    background-color: var(--color-border-soft);
}

.reasoning-block summary::-webkit-details-marker {
    display: none;
}

.reasoning-block summary::before {
    content: "\\f0eb";
    font-family: "Font Awesome 5 Free";
    font-weight: 900;
    margin-right: 8px;
    color: var(--color-text-muted);
}

.reasoning-block[open] summary {
    border-bottom: 1px solid var(--color-border-soft);
}

.reasoning-content {
    padding: 15px;
    font-size: 0.9rem;
    color: var(--color-text-muted);
    line-height: 1.5;
    white-space: pre-wrap;
    font-family: inherit;
    background-color: var(--color-surface);
}

/* Kimi K2 Thought Process */
.reasoning-block-kimi {
    background-color: var(--color-warning-bg);
    border-color: var(--color-warning-border);
}

.reasoning-block-kimi summary {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-dark);
}

.reasoning-block-kimi summary:hover {
    background-color: var(--color-warning-border);
}

.reasoning-block-kimi summary::before {
    content: "\f5dc";
    color: var(--color-warning-dark);
}

.reasoning-block-kimi[open] summary {
    border-bottom-color: var(--color-warning-border);
}

.reasoning-block-kimi .reasoning-content {
    background-color: var(--color-warning-bg);
    color: var(--color-warning-dark);
}

/* GPT Thought Process */
.reasoning-block-gpt {
    background-color: var(--color-info-bg);
    border-color: var(--color-info-border);
}

.reasoning-block-gpt summary {
    background-color: var(--color-info-bg);
    color: var(--color-success-dark);
}

.reasoning-block-gpt summary:hover {
    background-color: var(--color-info-border);
}

.reasoning-block-gpt summary::before {
    content: "\f0eb";
    color: var(--color-success-main);
}

.reasoning-block-gpt[open] summary {
    border-bottom-color: var(--color-info-border);
}

.reasoning-block-gpt .reasoning-content {
    background-color: var(--color-info-bg);
    color: var(--color-info-dark);
}

/* Zoom and Responsive Design Fixes */
/* Standard mobile landscape and small screens */
@media (max-width: 600px) {

    .auth-card,
    .auth-card.cwru-card {
        max-width: 100%;
        padding: 30px 20px;
        margin: 0 auto;
    }

    .auth-container {
        padding: 10px;
    }

    .auth-container.cwru-theme {
        padding: 10px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row .form-group {
        margin-bottom: 22px;
    }

    .cwru-logo {
        max-width: 200px;
    }

    .auth-header h1 {
        font-size: 1.5rem;
    }
}

/* Medium screens and zoom at 150% */
@media (max-width: 800px) {

    .auth-card,
    .auth-card.cwru-card {
        max-width: calc(100vw - 40px);
        padding: 35px 25px;
    }

    .form-input,
    .form-input.cwru-input {
        padding: 12px 14px;
        font-size: 16px;
    }

    .btn-full {
        padding: 12px;
        font-size: 0.95rem;
    }

    .password-requirements {
        max-height: 300px;
        overflow-y: auto;
    }
}

/* High zoom levels (150%+) and small viewport support */
@media (max-width: 500px) {

    body,
    html {
        overflow-x: hidden;
    }

    .auth-card,
    .auth-card.cwru-card {
        max-width: 100%;
        padding: 25px 15px;
        border-radius: 12px;
        box-shadow: 0 15px 35px var(--color-overlay-dark);
    }

    .auth-container {
        padding: 5px;
        min-height: auto;
        align-items: flex-start;
        padding-top: 10px;
    }

    .auth-container.cwru-theme {
        padding: 5px;
        padding-top: 10px;
    }

    .form-group label {
        font-size: 0.9rem;
        margin-bottom: 6px;
    }

    .form-input {
        width: 100%;
        padding: 12px 12px;
        font-size: 16px;
    }

    .auth-header h1 {
        font-size: 1.3rem;
        margin-bottom: 5px;
    }

    .auth-header p {
        font-size: 0.95rem;
    }

    .cwru-logo {
        max-width: 150px;
    }

    .btn-full {
        padding: 11px;
        font-size: 0.9rem;
    }

    .password-requirements {
        font-size: 0.85rem;
        max-height: 280px;
    }

    .requirement-item {
        padding: 6px 0;
    }

    .requirement-title {
        font-size: 0.85rem;
        margin-bottom: 8px;
    }

    .form-row {
        flex-direction: column;
        gap: 0;
    }

    .form-row .form-group {
        margin-bottom: 20px;
    }

    .error-message {
        font-size: 0.8rem;
    }
}

/* Zoom-specific adjustments for 150%+ zoom and tablets */
@media (max-width: 1024px) {
    .chat-container {
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: 240px;
    }

    .chat-main {
        height: auto;
        min-height: 100vh;
    }

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

/* Extra small screens and high zoom (200%+) */
@media (max-width: 480px) {
    .chat-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }

    .sidebar {
        width: 100%;
        height: auto;
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid var(--color-border-soft);
    }

    .chat-main {
        height: auto;
        min-height: 60vh;
        padding: 10px;
    }

    .chat-area-wrapper {
        border-radius: 12px;
        padding: 10px;
    }

    .message {
        max-width: 100%;
        margin-bottom: 15px;
    }

    .message-avatar {
        width: 35px;
        height: 35px;
        margin: 0 8px;
    }

    .message-content {
        padding: 12px;
        font-size: 0.95rem;
    }

    .sidebar-logo {
        max-width: 180px;
    }

    .sidebar-section {
        padding: 0 15px 15px 15px;
    }

    .models-list-container {
        height: auto;
        max-height: 25vh;
        min-height: 150px;
    }

    .chat-messages {
        padding: 56px 10px 10px;
    }

    .welcome-icon {
        font-size: 3rem;
        width: 80px;
        height: 80px;
        margin-bottom: 20px;
    }

    #welcome-title,
    .welcome-message h1 {
        font-size: 1.1rem;
    }

    .welcome-message p {
        font-size: 0.9rem;
    }
}

/* Modal zoom fixes */
@media (max-width: 700px) {
    .modal-content {
        width: 95%;
        max-width: 100%;
        max-height: 85vh;
        border-radius: 10px;
    }

    .modal-header {
        padding: 15px 20px;
    }

    .modal-header h3 {
        font-size: 1.1rem;
    }

    .modal-body {
        padding: 20px;
        max-height: 65vh;
    }

    .modal-footer {
        padding: 15px 20px;
        flex-direction: column;
        gap: 10px;
    }

    .btn-close {
        width: 28px;
        height: 28px;
    }
}

/* File view modal zoom fixes */
@media (max-width: 700px) {
    .file-view-modal {
        width: 95%;
        max-width: 100%;
        max-height: 85vh;
    }

    .file-view-content {
        max-height: 70vh;
    }
}

/* HTML preview modal zoom fixes */
@media (max-width: 700px) {
    .html-preview-modal {
        width: 95%;
        max-width: 100%;
        max-height: 85vh;
    }
}

@media (max-width: 700px) {
    .fullscreen-input-modal {
        padding: 0;
    }

    .fullscreen-input-panel {
        border-radius: 0;
        border-width: 0;
        height: 100%;
        max-height: none;
    }

    .fullscreen-input-header {
        padding: 14px 16px;
    }

    .fullscreen-input-body {
        padding: 12px;
    }

    #fullscreen-message-input {
        border-radius: 10px;
        font-size: 16px;
        min-height: 0;
        padding: 14px;
    }

    .fullscreen-file-upload-area {
        padding: 0 12px 10px;
    }

    .fullscreen-input-actions {
        padding: 12px;
    }

    .fullscreen-file-list .file-item {
        max-width: 100%;
    }
}

/* ===== Gemini "Thinking" panel ===== */
.thinking-panel {
    margin: 0 0 12px 0;
    border: 1px solid var(--color-brand-alpha);
    border-radius: 10px;
    background: linear-gradient(135deg, var(--color-brand-alpha), var(--color-brand-alpha));
    overflow: hidden;
    transition: background 0.2s ease;
}

.thinking-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 8px 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    font: inherit;
    color: var(--color-brand-main, var(--color-brand-main));
}

.thinking-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    letter-spacing: 0.2px;
}

.thinking-label .fa-brain {
    color: var(--color-brand-light, var(--color-brand-light));
}

/* Animated dots while the model is still thinking */
.thinking-dots span {
    animation: thinkingBlink 1.4s infinite both;
}

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

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

@keyframes thinkingBlink {

    0%,
    80%,
    100% {
        opacity: 0.2;
    }

    40% {
        opacity: 1;
    }
}

/* Subtle shimmer on the label while actively thinking */
.thinking-panel:not(.done) .thinking-title {
    background: linear-gradient(90deg, var(--color-brand-main, var(--color-brand-main)) 25%, var(--color-brand-light, var(--color-brand-light)) 50%, var(--color-brand-main, var(--color-brand-main)) 75%);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: thinkingShimmer 2.2s linear infinite;
}

@keyframes thinkingShimmer {
    to {
        background-position: 200% center;
    }
}

.thinking-chevron {
    font-size: 0.75rem;
    transition: transform 0.2s ease;
    color: var(--color-text-muted, var(--color-text-muted));
}

.thinking-panel.expanded .thinking-chevron {
    transform: rotate(180deg);
}

.thinking-content {
    max-height: 0;
    opacity: 0;
    padding: 0 14px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--color-text-muted);
    border-top: 1px solid transparent;
    overflow-y: auto;
    transition: max-height 0.25s ease, opacity 0.2s ease, padding 0.2s ease;
}

.thinking-panel.expanded .thinking-content {
    max-height: 320px;
    opacity: 1;
    padding: 10px 14px;
    border-top-color: var(--color-brand-alpha);
}

.thinking-content p {
    margin: 0 0 8px 0;
}

.thinking-content p:last-child {
    margin-bottom: 0;
}

.message.assistant .message-body .thinking-content {
    background: transparent;
}

/* Token Metrics Toggle Button */
.token-toggle-btn {
    background: var(--color-surface-soft);
    color: var(--color-text-main);
    border: 1px solid var(--color-border-main);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.725rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
    transition: all 0.2s ease-in-out;
    outline: none;
    margin-top: 5px;
}

.token-toggle-btn:hover {
    background: var(--color-overlay-dark);
    border-color: var(--color-overlay-dark);
}

.scroll-to-bottom-btn {
    position: absolute;
    bottom: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background-color: var(--color-brand-main);
    /* CWRU Blue */
    color: var(--color-text-inverse);
    border: none;
    box-shadow: 0 4px 12px var(--color-overlay-darker);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    /* Ensure it's on top */
    transition: all 0.2s ease-in-out;
    opacity: 1;
    transform: translateY(0);
}

.scroll-to-bottom-btn i {
    font-size: 1.2rem;
}

.scroll-to-bottom-btn:hover {
    background-color: var(--color-surface-sunken);
    color: var(--color-brand-main);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--color-overlay-darker);
}

.scroll-to-bottom-btn.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
}


/* =====================================================================
   Theme toggle button (light / dark mode)
   ===================================================================== */
.theme-toggle-btn {
    position: fixed;
    top: 16px;
    right: 18px;
    z-index: 100;
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
    border: 1px solid var(--color-border-main);
    background: var(--color-surface);
    color: var(--color-text-main);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 10px var(--color-overlay-dark);
    transition: background .2s ease, color .2s ease, border-color .2s ease;
}

.theme-toggle-btn:hover {
    background: var(--color-surface-hover);
    border-color: var(--color-border-hover);
}

.theme-toggle-btn:focus-visible {
    outline: 2px solid var(--color-brand-main);
    outline-offset: 2px;
}

/* =====================================================================
   Global Badge System (Accessible WCAG AAA)
   ===================================================================== */
.badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1.3;
}
.badge-info {
    background: var(--color-info-bg);
    color: var(--color-info-dark);
    border: 1px solid var(--color-info-border);
}
.badge-success,
.badge-succeeded {
    background: var(--color-success-bg);
    color: var(--color-success-dark);
    border: 1px solid var(--color-success-border);
}
.badge-danger,
.badge-failed {
    background: var(--color-danger-bg);
    color: var(--color-danger-dark);
    border: 1px solid var(--color-danger-border);
}
.badge-warning,
.badge-paused {
    background: var(--color-warning-bg);
    color: var(--color-warning-dark);
    border: 1px solid var(--color-warning-border);
}
.badge-pending {
    background: var(--color-surface-soft);
    color: var(--color-text-main);
    border: 1px solid var(--color-border-main);
}
.badge-running,
.badge-processing {
    background: var(--color-info-bg);
    color: var(--color-info-dark);
    border: 1px solid var(--color-info-border);
}

/* =====================================================================
   Missing text utility classes for contrast alignment
   ===================================================================== */
.text-danger { color: var(--color-danger-main) !important; }
.text-success { color: var(--color-success-main) !important; }
.text-warning { color: var(--color-warning-dark) !important; }
.text-info { color: var(--color-info-dark) !important; }
.text-primary { color: var(--color-brand-main) !important; }
.text-muted { color: var(--color-text-muted) !important; }
.text-secondary { color: var(--color-text-subtle) !important; }

/* Input text color (theme-agnostic: dark text on light, light text on dark) */
.form-input,
.form-textarea,
textarea.prompt-textarea {
    color: var(--color-text-main);
}
.form-input::placeholder,
.form-textarea::placeholder,
textarea.prompt-textarea::placeholder,
.input-controls textarea::placeholder {
    color: var(--color-text-subtle);
}

/* Legacy/secondary chat textarea: use semantic text color instead of brand blue */
.input-controls textarea {
    color: var(--color-text-main);
}

/* .form-textarea had no base rule; provide background/border/color for dark */
.form-textarea {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--color-border-main);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-surface-soft);
    color: var(--color-text-main);
    resize: vertical;
    transition: all 0.3s ease;
}
.form-textarea:focus,
.form-textarea:focus-visible {
    outline: none;
    border-color: var(--color-brand-main);
    background: var(--color-surface);
    box-shadow: 0 0 0 3px var(--color-overlay-dark);
}
/* Reasoning controls inside the composer (adaptive thinking + effort levels) */
.reasoning-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--color-border-soft);
}

/* display:flex would otherwise defeat the hidden attribute */
.reasoning-controls[hidden] {
    display: none;
}

.reasoning-title {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--color-text-muted);
}

.reasoning-value {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--color-brand-main);
    /* Reserve room for the longest label ("Extra high") so the slider next
       to it doesn't shift horizontally as the level (and label width) changes. */
    display: inline-block;
    min-width: 10ch;
    flex-shrink: 0;
}

/* Dotted pill track with a knob per effort level */
.effort-slider-wrap {
    position: relative;
    width: 104px;
    height: 18px;
    display: flex;
    align-items: center;
    border-radius: 999px;
}

.effort-slider-wrap::before {
    content: '';
    position: absolute;
    inset: 3px 0;
    border-radius: 999px;
    background: var(--color-brand-main);
    opacity: 0.85;
}

.effort-slider-wrap:focus-within {
    box-shadow: 0 0 0 3px var(--color-brand-alpha);
}

.effort-ticks {
    position: absolute;
    inset: 0 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
}

.effort-ticks span {
    width: 3px;
    height: 3px;
    border-radius: 50%;
    background: var(--color-surface);
    opacity: 0.6;
}

.effort-slider {
    position: relative;
    width: 100%;
    height: 18px;
    margin: 0;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    cursor: pointer;
}

.effort-slider:focus {
    outline: none;
}

.effort-slider::-webkit-slider-runnable-track {
    height: 18px;
    background: transparent;
}

.effort-slider::-moz-range-track {
    height: 18px;
    background: transparent;
}

.effort-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    margin-top: 2px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    box-shadow: 0 1px 4px var(--color-overlay-dark);
}

.effort-slider::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--color-surface);
    border: 1px solid var(--color-border-strong);
    box-shadow: 0 1px 4px var(--color-overlay-dark);
}

/* Selected model, shown under the composer; chosen in the sidebar */
.composer-model {
    display: block;
    margin-top: 6px;
    font-size: 0.72rem;
    color: var(--color-text-muted);
}

.composer-model::before {
    content: "Model: ";
}

.composer-model:empty {
    display: none;
}

.reasoning-check {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: auto;
    font-size: 0.72rem;
    color: var(--color-text-muted);
    cursor: pointer;
}

.reasoning-check input {
    width: 13px;
    height: 13px;
    margin: 0;
    cursor: pointer;
    accent-color: var(--color-brand-main);
}

@media (max-width: 600px) {
    .reasoning-check {
        margin-left: 0;
    }
}

/* "Request Max" access affordance, shown next to the effort slider when
   the 'max' level is locked for the current user. States are driven by
   data-state, set in chat.js's updateMaxEffortAccessUI(). */
.max-effort-request-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 10px;
    border-radius: 999px;
    border: 1px solid var(--color-border-strong);
    background: var(--color-surface);
    color: var(--color-text-muted);
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.4;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease;
}

.max-effort-request-btn i {
    font-size: 0.68rem;
}

.max-effort-request-btn:hover:not(:disabled) {
    border-color: var(--color-brand-main);
    color: var(--color-brand-main);
    background: var(--color-brand-alpha);
}

.max-effort-request-btn:focus-visible {
    outline: 2px solid var(--color-brand-main);
    outline-offset: 2px;
}

.max-effort-request-btn:disabled {
    cursor: default;
}

.max-effort-request-btn[data-state="requested"] {
    border-color: var(--color-warning-border);
    color: var(--color-warning-dark);
    background: var(--color-warning-bg);
}

.max-effort-request-btn[data-state="declined"] {
    border-color: var(--color-danger-border);
    color: var(--color-danger-dark);
    background: var(--color-danger-bg);
}

@media (max-width: 600px) {
    .max-effort-request-btn span {
        display: none;
    }
}

/* --- Transcription confidence (transcription_review.js) -------------------
   One score for the answer, one per doubtful place, and a side-by-side view
   of the original page for any place under 100%. The band colour is never
   the only signal: every score is also written as a number. */
.review-panel {
    margin-top: 12px;
    border: 1px solid var(--color-border-main);
    border-radius: 10px;
    background: var(--color-surface-soft);
    color: var(--color-text-main);
    font-size: 0.88rem;
}

.review-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    flex-wrap: wrap;
}

.review-head > span:not(.review-score):not(.review-title) {
    flex: 1;
}

.review-title {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 180px;
}

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

.review-score {
    font-size: 1.15rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 8px;
    min-width: 3.4em;
    text-align: center;
}

.review-panel button,
.review-dialog button {
    font: inherit;
    cursor: pointer;
}

.review-run,
.review-toggle {
    background: var(--color-surface);
    color: var(--color-text-main);
    border: 1px solid var(--color-border-main);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 0.8rem;
}

.review-run:hover,
.review-toggle:hover,
.review-run:focus-visible,
.review-toggle:focus-visible {
    border-color: var(--color-info-dark);
}

.review-panel.idle {
    border: none;
    background: none;
}

.review-panel.idle .review-head {
    padding: 0;
}

.review-start {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.85rem;
}

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

.review-body {
    padding: 0 12px 10px;
}

.review-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.review-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    text-align: left;
    background: var(--color-surface);
    color: var(--color-text-main);
    border: 1px solid var(--color-border-soft);
    border-left-width: 4px;
    border-radius: 8px;
    padding: 7px 10px;
}

.review-item:hover,
.review-item:focus-visible {
    border-color: var(--color-info-dark);
}

.review-item-score {
    font-weight: 700;
    min-width: 2.8em;
}

.review-item-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.review-item-quote {
    overflow-wrap: anywhere;
}

.review-item-reading {
    color: var(--color-text-muted);
}

.review-item-reason {
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

.review-settled {
    margin-top: 8px;
    color: var(--color-text-muted);
    font-size: 0.8rem;
}

.review-settled summary {
    cursor: pointer;
}

.review-evidence {
    margin: 8px 0 0 18px;
    padding: 0;
    color: var(--color-text-muted);
    font-size: 0.78rem;
}

.band-verified { background: var(--color-success-bg); color: var(--color-success-dark); }
.band-high { background: var(--color-success-bg); color: var(--color-success-dark); }
.band-medium { background: var(--color-warning-bg); color: var(--color-warning-dark); }
.band-low { background: var(--color-danger-bg); color: var(--color-danger-dark); }
.band-unknown { background: var(--color-surface); color: var(--color-text-muted); }
.review-item.band-high, .review-item.band-verified { background: var(--color-surface); color: var(--color-text-main); border-left-color: var(--color-success-dark); }
.review-item.band-medium { background: var(--color-surface); color: var(--color-text-main); border-left-color: var(--color-warning-dark); }
.review-item.band-low { background: var(--color-surface); color: var(--color-text-main); border-left-color: var(--color-danger-dark); }
.review-item.band-high .review-item-score { color: var(--color-success-dark); }
.review-item.band-medium .review-item-score { color: var(--color-warning-dark); }
.review-item.band-low .review-item-score { color: var(--color-danger-dark); }

.review-dialog {
    width: min(1440px, 97vw);
    height: 94vh;
    max-height: 94vh;
    padding: 0;
    border: 1px solid var(--color-border-main);
    border-radius: 10px;
    background: var(--color-surface);
    color: var(--color-text-main);
}

/* Only when open: a closed dialog has to keep the browser's display: none. */
.review-dialog[open] {
    display: flex;
    flex-direction: column;
}

.review-dialog::backdrop {
    background: var(--color-overlay-darker);
}

/* Several of these set display, which would otherwise beat the hidden attribute. */
.review-dialog [hidden] {
    display: none !important;
}

.review-dialog-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--color-border-main);
    flex: none;
}

.review-dialog-sub {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin-top: 3px;
}

.review-close {
    background: transparent;
    color: var(--color-text-main);
    border: 1px solid var(--color-border-main);
    border-radius: 6px;
    padding: 4px 10px;
}

/* The two documents, side by side and the same size, each with the place marked. */
.review-panes {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    padding: 12px 18px 12px;
}

.review-pane {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.review-pane-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    flex: none;
}

.review-pane-head h3 {
    font-size: 0.95rem;
    margin: 0;
}

.review-pane-sub {
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.review-page-nav {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--color-text-muted);
}

.review-page-nav button {
    background: var(--color-surface-soft);
    color: var(--color-text-main);
    border: 1px solid var(--color-border-main);
    border-radius: 6px;
    padding: 2px 8px;
}

.review-page-nav button:disabled {
    opacity: 0.4;
    cursor: default;
}

/* Pictures of documents, so they keep a light surface in either theme. */
.review-page,
.review-frame {
    flex: 1 1 auto;
    min-height: 0;
    border: 1px solid var(--color-border-soft);
    border-radius: 6px;
    background: #ffffff;
}

.review-page {
    overflow: auto;
}

.review-frame {
    width: 100%;
}

.review-sheet {
    position: relative;
}

.review-sheet img {
    display: block;
    width: 100%;
    height: auto;
}

/* The same yellow and red as the highlight in the transcription, so the two
   read as one place. */
.review-box {
    position: absolute;
    border: 3px solid #d62828;
    border-radius: 3px;
    background: rgba(255, 224, 102, 0.35);
    pointer-events: none;
    animation: review-pulse 1.2s ease-in-out 3;
}

@keyframes review-pulse {
    50% { border-color: #ffb703; }
}

@media (prefers-reduced-motion: reduce) {
    .review-box { animation: none; }
}

/* Every other flagged place on the page: faint, and opens on a click. */
.review-box.faint {
    border-width: 2px;
    border-color: rgba(214, 40, 40, 0.45);
    background: rgba(255, 224, 102, 0.18);
    animation: none;
    pointer-events: auto;
    cursor: pointer;
}

.review-box.faint:hover,
.review-box.faint:focus-visible {
    background: rgba(255, 224, 102, 0.4);
    outline: 2px solid var(--color-primary, #0a3161);
    outline-offset: 1px;
}

.review-box.faint.done {
    border-color: rgba(46, 125, 50, 0.45);
    background: rgba(46, 125, 50, 0.08);
}

/* In the original, missing from the transcription: blue, as the marker in the transcription. */
.review-box-missing { border-color: #1565c0; background: rgba(21, 101, 192, 0.14); }
.review-box-missing.faint { border-color: rgba(21, 101, 192, 0.5); background: rgba(21, 101, 192, 0.08); }

/* Not in the original: where it would be, dashed purple, as its highlight in the transcription. */
.review-box-insertion { border-style: dashed; border-color: #8e24aa; background: rgba(142, 36, 170, 0.08); }
.review-box-insertion.faint { border-color: rgba(142, 36, 170, 0.5); background: rgba(142, 36, 170, 0.05); }

@keyframes review-pulse-missing { 50% { border-color: #64b5f6; } }
@keyframes review-pulse-insertion { 50% { border-color: #ce93d8; } }
.review-box-missing.current { animation-name: review-pulse-missing; }
.review-box-insertion.current { animation-name: review-pulse-insertion; }

/* The gap a missing word would fill, at the end of the words it follows. */
.review-caret {
    position: absolute;
    top: -6px;
    bottom: -6px;
    right: -6px;
    width: 4px;
    border-radius: 2px;
    background: #8e24aa;
}

.review-box-label {
    position: absolute;
    left: -3px;
    bottom: calc(100% + 4px);
    white-space: nowrap;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 1px 7px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.5;
    color: #fff;
    background: #d62828;
}

.review-box-label.below { bottom: auto; top: calc(100% + 4px); }
.review-box-label.beside { left: calc(100% + 12px); top: 50%; bottom: auto; transform: translateY(-50%); }
.review-box-missing .review-box-label { background: #1565c0; }
.review-box-insertion .review-box-label { background: #8e24aa; }

.review-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    margin: 0;
    padding: 6px 18px;
    list-style: none;
    font-size: 0.76rem;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border-main);
}

.review-legend li { display: inline-flex; align-items: center; gap: 6px; }

.review-key {
    display: inline-block;
    width: 18px;
    height: 12px;
    border-radius: 3px;
    border: 2px solid #d62828;
    background: rgba(255, 224, 102, 0.6);
}

.review-key.key-other { border-color: rgba(214, 40, 40, 0.45); background: rgba(255, 224, 102, 0.2); }
.review-key.key-missing { border-color: #1565c0; background: rgba(21, 101, 192, 0.14); }
.review-key.key-extra { border: 2px dashed #8e24aa; background: rgba(142, 36, 170, 0.1); }

.review-trans-note {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin: 0 0 6px;
}

.review-tag {
    display: inline-block;
    margin-right: 6px;
    padding: 0 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.6;
    vertical-align: 1px;
}

.review-tag-missing { background: #e3f2fd; color: #0d47a1; }
.review-tag-extra { background: #f3e5f5; color: #6a1b9a; }
.review-tag-figure { background: var(--color-surface-soft); color: var(--color-text-main); border: 1px solid var(--color-border-main); }

.review-render-note {
    font-size: 0.82rem;
    color: var(--color-warning-dark);
    margin: 0 0 6px;
}

/* The verdict and the correction, under both documents. */
.review-controls {
    flex: none;
    display: grid;
    grid-template-columns: 2fr 3fr;
    gap: 18px;
    padding: 12px 18px 14px;
    border-top: 1px solid var(--color-border-main);
    max-height: 40vh;
    overflow: auto;
}

@media (max-width: 860px) {
    .review-dialog[open] {
        overflow: auto;
    }

    .review-panes,
    .review-controls {
        grid-template-columns: 1fr;
    }

    .review-pane {
        height: 60vh;
    }

    .review-controls {
        max-height: none;
    }
}

.review-loading,
.review-error {
    padding: 24px;
    color: var(--color-text-muted);
}

.review-error {
    color: var(--color-danger-dark);
}

.review-note {
    font-size: 0.82rem;
    color: var(--color-text-muted);
    margin: 0 0 8px;
}

.review-confidence {
    display: inline-block;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 8px;
    margin-bottom: 8px;
}

.review-reason {
    margin: 0 0 6px;
}

.review-evidence-list {
    margin: 0 0 12px 18px;
    padding: 0;
    font-size: 0.82rem;
    color: var(--color-text-muted);
}

.review-label {
    display: block;
    font-weight: 700;
    font-size: 0.85rem;
    margin-bottom: 5px;
}

.review-text {
    width: 100%;
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid var(--color-border-main);
    background: var(--color-surface);
    color: var(--color-text-main);
    font: inherit;
    resize: vertical;
}

.review-hint {
    font-size: 0.78rem;
    color: var(--color-text-muted);
    margin: 4px 0 10px;
}

.review-suggestion {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--color-info-bg);
    color: var(--color-info-dark);
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.review-use {
    background: var(--color-surface);
    color: var(--color-info-dark);
    border: 1px solid var(--color-info-dark);
    border-radius: 6px;
    padding: 3px 10px;
}

.review-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.review-confirm,
.review-save,
.review-remove,
.review-insert-figure {
    border-radius: 6px;
    padding: 7px 12px;
    border: 1px solid var(--color-border-main);
}

.review-remove {
    background: var(--color-surface);
    color: #6a1b9a;
    border-color: #8e24aa;
}

.review-insert-figure {
    background: var(--color-surface);
    color: #0d47a1;
    border-color: #1565c0;
}

.review-actions button[hidden] {
    display: none;
}

html[data-theme="dark"] .review-remove { color: #e1bee7; border-color: #ce93d8; }
html[data-theme="dark"] .review-insert-figure { color: #bbdefb; border-color: #90caf9; }

.review-confirm {
    background: var(--color-success-bg);
    color: var(--color-success-dark);
    border-color: var(--color-success-dark);
}

.review-save {
    background: var(--color-brand-main);
    color: var(--color-text-inverse);
    border-color: var(--color-brand-main);
}

.review-actions button:disabled {
    opacity: 0.5;
    cursor: default;
}

.review-status {
    min-height: 1.2em;
    margin: 10px 0 0;
    font-size: 0.85rem;
}
