﻿/*
 * Layout, components, and structure. Color tokens live in theme.css.
 */
body {
    background-color: var(--darker);
    color: var(--light);
    font-family: 'Inter', sans-serif;
}

/* Scroll + gutter only on main — navbar/footer stay full viewport width */
body.flex.flex-col.min-h-screen,
body > .flex.flex-col.min-h-screen {
    height: 100vh;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
}

body > .flex.flex-col.min-h-screen {
    display: flex;
    flex-direction: column;
    width: 100%;
}

#navbar-container,
site-footer {
    flex-shrink: 0;
}

main.page {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

/* Custom scrollbars (Firefox + WebKit); tokens in theme.css */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

*::-webkit-scrollbar {
    width: var(--scrollbar-size);
    height: var(--scrollbar-size);
}

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

*::-webkit-scrollbar-thumb {
    background-color: var(--scrollbar-thumb);
    border-radius: 9999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

*::-webkit-scrollbar-thumb:hover {
    background-color: var(--scrollbar-thumb-hover);
}

*::-webkit-scrollbar-corner {
    background: transparent;
}

/* ========================================================================== */
/* Shared Navigation                                                          */
/* ========================================================================== */
#navbar-container {
    min-height: 64px;
}

.site-nav {
    background-color: var(--surface-deep);
    border-bottom: 1px solid var(--dark);
    position: sticky;
    top: 0;
    z-index: 30;
}

#footer-container {
    margin-top: auto;
}

site-footer.footer-fixed {
    display: block;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
}

site-footer {
    display: block;
}

.site-footer {
    background-color: var(--surface-deep);
    border-top: 1px solid var(--dark);
}

.site-footer-inner {
    max-width: 72rem;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--text-muted);
}

@media (min-width: 640px) {
    .site-footer-inner {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}

.site-footer-brand {
    color: var(--text-dim);
}

.site-footer-version {
    font-variant-numeric: tabular-nums;
    color: var(--text-muted);
}

.site-footer-version [data-version] {
    display: inline-block;
    min-width: 4ch;
}
.nav-link {
    white-space: nowrap;
}

.nav-link:hover {
    background-color: var(--primary-tint-10);
}

.nav-link.active {
    border-bottom: 2px solid var(--primary);
}


.hamburger-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.375rem;
    border-radius: 0.375rem;
    color: var(--text-dim);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.125rem;
    transition: color 0.15s;
}

.hamburger-btn:hover {
    color: var(--text-on-accent);
}

.nav-mobile-menu {
    background-color: var(--surface-deep);
    border-top: 1px solid var(--dark);
    padding: 0.5rem 1rem 0.75rem;
    flex-wrap: wrap;
    gap: 0.25rem;
    align-items: center;
}

/* Tailwind .hidden must win; flex is applied only when menu is open */
.nav-mobile-menu:not(.hidden) {
    display: flex;
}

@media (min-width: 768px) {
    .nav-mobile-menu {
        display: none !important;
    }
}

.nav-mobile-link {
    display: flex;
    align-items: center;
    padding: 0.625rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-soft);
    transition: background-color 0.15s, color 0.15s;
}

.nav-mobile-link:hover {
    background-color: var(--primary-tint-10);
    color: var(--text-on-accent);
}

.nav-mobile-link.active {
    color: var(--text-on-accent);
    background-color: var(--primary-tint-15);
}

.nav-mobile-logout {
    margin-left: 0;
    align-self: flex-start;
}

.nav-user-wrap {
    min-width: 0;
    text-align: left;
    margin-left: 1.75rem;
    position: relative;
}

.nav-user-btn {
    width: 32px;
    height: 32px;
    border-radius: 9999px;
    border: 1px solid var(--surface-raised);
    background-color: var(--surface);
    overflow: visible;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: border-color 0.15s;
    position: relative;
}

.nav-user-btn:hover {
    border-color: var(--primary);
}

.nav-user-avatar {
    width: 100%;
    height: 100%;
    border-radius: 9999px;
    object-fit: cover;
    display: block;
}

.nav-user-badge {
    position: absolute;
    right: -0.25rem;
    bottom: -0.25rem;
    width: 0.95rem;
    height: 0.95rem;
    border-radius: 9999px;
    border: 1px solid var(--darker);
    background: var(--surface-mid);
    color: var(--text-on-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-ring-dark);
}

.nav-user-badge i {
    font-size: 0.5rem;
    line-height: 1;
}

.nav-user-badge.role-super_admin {
    background: var(--role-super-admin);
    color: var(--surface);
}

/* Admin: slightly darker green for better contrast with the white icon */
.nav-user-badge.role-admin {
    background: var(--role-admin);
    color: var(--text-on-accent);
}

/* Mod: blue chip + white icon */
.nav-user-badge.role-mod {
    background: var(--role-mod);
    color: var(--text-on-accent);
}

.nav-user-badge.role-guest {
    background: var(--surface-mid);
    color: var(--text-on-accent);
}

.nav-user-menu {
    position: absolute;
    right: 0;
    left: auto;
    top: calc(100% + 0.5rem);
    z-index: 60;
    min-width: 8.5rem;
    width: fit-content;
    max-width: min(22rem, calc(100vw - 1rem));
    padding: 0.35rem 10px;
    border-radius: 0.5rem;
    border: 1px solid var(--surface-raised);
    background-color: var(--surface-deep);
    box-shadow: var(--shadow-menu);
}

.nav-user-name {
    padding: 0.25rem 0.25rem 0.35rem;
    margin-bottom: 0;
    color: var(--light);
    font-size: 0.8125rem;
    font-weight: 700;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
}

.nav-user-divider {
    border: none;
    height: 1px;
    margin: 0.15rem 0.65rem 0.35rem;
    background-color: var(--surface-raised);
}

.nav-theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.5rem 0.75rem;
}

.nav-user-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    border-radius: 0.375rem;
    padding: 0.45rem 0.5rem;
    color: var(--text-dim);
    font-size: 0.8125rem;
    transition: background-color 0.15s, color 0.15s;
}

.nav-user-logout:hover {
    color: var(--text-on-accent);
    background-color: var(--primary-tint-14);
}

@media (max-width: 1100px) {
    .nav-desktop-links {
        margin-left: 1rem !important;
        gap: 0.35rem !important;
    }

    .nav-desktop-links .nav-link {
        padding: 0.45rem 0.55rem;
        font-size: 0.8125rem;
    }

    .nav-status-label,
    .nav-status-text {
        font-size: 0.8125rem;
    }
}

/* Progressive squeeze before switching to hamburger. */
@media (max-width: 1360px) {
    .nav-desktop-links {
        margin-left: 1.25rem !important;
        gap: 0.5rem !important;
    }

    .nav-desktop-links .nav-link {
        padding: 0.5rem 0.65rem;
    }

    .nav-user-wrap {
        margin-left: 1.1rem;
    }
}

@media (max-width: 1060px) {
    .nav-desktop-links {
        gap: 0.25rem !important;
    }

    .nav-desktop-links .nav-link {
        font-size: 0.78rem;
        padding: 0.45rem 0.5rem;
    }

    .nav-status-label,
    .nav-status-text {
        font-size: 0.68rem;
    }

    .nav-desktop-links .nav-link i {
        display: none;
    }
}

@media (max-width: 860px) {
    .nav-desktop-links {
        gap: 0.15rem !important;
    }

    .nav-desktop-links .nav-link {
        font-size: 0.72rem;
        padding: 0.4rem 0.42rem;
    }

    .nav-status-label,
    .nav-status-text {
        font-size: 0.62rem;
    }
}

@media (max-width: 767px) {
    .site-nav .nav-row {
        height: 3.5rem;
    }

    .site-nav .nav-left {
        min-width: 0;
        overflow: visible;
    }

    .site-nav .nav-right {
        gap: 0.5rem;
    }

    .nav-status-label,
    .nav-status-text {
        display: none;
    }

    .site-nav .status-indicator {
        width: 10px;
        height: 10px;
    }

    .nav-mobile-menu {
        flex-direction: column;
        align-items: stretch;
        gap: 0.2rem;
        padding: 0.5rem 0.75rem 0.7rem;
    }

    .nav-mobile-link {
        width: 100%;
        justify-content: flex-start;
        padding: 0.55rem 0.625rem;
        font-size: 0.8125rem;
    }

    .nav-mobile-logout {
        margin-left: 0;
    }
}

/* ========================================================================== */
/* Shared Status Indicators                                                   */
/* ========================================================================== */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
}

.status-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.status-active {
    background-color: var(--success);
    box-shadow: 0 0 10px var(--success);
}

.status-inactive {
    background-color: var(--danger-bright);
}

.status-starting {
    background-color: var(--warning);
    animation: pulse 2s infinite;
}

.status-stopping {
    background-color: var(--warning);
    animation: pulse 2s infinite;
}

.status-crashed {
    background-color: var(--warning);
    box-shadow: 0 0 10px var(--warning-glow);
}

@keyframes pulse {
    0% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }

    100% {
        opacity: 1;
    }
}

/* ========================================================================== */
/* Shared Disabled-State Styling                                              */
/* ========================================================================== */
input:disabled,
textarea:disabled {
    background-color: var(--surface-readonly);
    cursor: not-allowed;
    opacity: 0.5;
}

.input-readonly {
    background-color: var(--surface-readonly);
    cursor: not-allowed;
}

/* ========================================================================== */
/* Modal Surfaces                                                             */
/* ========================================================================== */
.modal {
    transition: opacity 0.3s ease;
}

.modal-content {
    max-height: 90vh;
}

/* ========================================================================== */
/* Character Editor                                                           */
/* ========================================================================== */
.model-rule {
    background-color: var(--surface-deep);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.mr-srv-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.375rem;
    padding: 0.625rem 0.75rem;
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-soft);
    cursor: pointer;
    transition: border-color 0.15s;
}

.mr-srv-btn:hover { border-color: var(--surface-mid); }

.mr-srv-dd {
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-dropdown-soft);
}

.mr-srv-dd label:hover {
    background-color: var(--surface-raised);
    border-radius: 0.25rem;
}

.model-rule-remove-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    margin-bottom: 0.125rem;
    border-radius: 0.5rem;
    border: 1px solid var(--surface-raised);
    background-color: var(--surface);
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.model-rule-remove-btn:hover {
    color: var(--danger-text);
    border-color: var(--danger-border);
    background-color: var(--danger-bg-soft);
}

.relative-inline-block {
    position: relative;
    display: inline-block;
}

#avatar-upload {
    color: var(--text-soft);
    background: transparent;
    font-size: 0.9rem;
    cursor: pointer;
}

#avatar-upload::file-selector-button {
    background: var(--surface-deep);
    color: var(--light);
    border: 1px solid var(--surface-raised);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    cursor: pointer;
}

#avatar-upload::file-selector-button:hover {
    background: var(--surface);
    border-color: var(--surface-mid);
}

#avatar-upload::file-selector-button:active {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
    color: var(--text-on-accent);
}

#avatar-canvas {
    cursor: grab;
    display: block;
    background: var(--dark);
    border-radius: 0.5rem;
}

#avatar-canvas:active {
    cursor: grabbing;
}

.slider-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.slider-row label {
    width: 90px;
    font-size: 0.8rem;
    color: var(--text-slate);
}

.slider-row input[type="range"] {
    flex: 1;
    accent-color: var(--primary);
}

.slider-row span {
    width: 40px;
    font-size: 0.8rem;
    color: var(--text-code);
    text-align: right;
}

#circle-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0.5rem;
    pointer-events: none;
    background: var(--gradient-editor-mask);
}

/* ========================================================================== */
/* Dashboard and Logs                                                         */
/* ========================================================================== */
.log-stream {
    font-family: 'Fira Code', monospace;
    background-color: var(--log-stream-bg);
    border: 1px solid var(--primary-tint-20);
}

.log-entry {
    border-bottom: 1px solid var(--primary-tint-10);
}

.log-entry:last-child {
    border-bottom: none;
}

.log-list-state {
    color: var(--text-muted);
    text-align: center;
    padding: 3rem 0;
}

.log-list-state.log-list-state-error {
    color: var(--danger-text);
}

.console-log-entry {
    border-bottom: 1px solid var(--primary-tint-10);
    padding: 0.5rem 0;
    font-size: 0.875rem;
}

.console-log-entry:last-child {
    border-bottom: none;
}

.console-log-time {
    color: var(--text-muted);
    margin-right: 0.5rem;
}

.console-log-message {
    color: var(--text-soft);
}

.server-list-state {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.server-list-state.server-list-state-error {
    color: var(--danger-bright);
}

.list-item {
    background-color: var(--surface);
    border-radius: 0.5rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background-color 0.15s;
}

.list-item:hover { background-color: var(--surface-raised); }
.list-item.active { background-color: var(--surface-raised); }

.server-list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.375rem 0;
}

.server-list-row-main {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
}

.server-list-icon {
    color: var(--text-muted);
    font-size: 0.75rem;
    flex-shrink: 0;
}

.server-list-name {
    color: var(--text-soft);
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.server-list-link {
    color: var(--primary-light);
    font-size: 0.75rem;
    transition: color 0.15s;
    white-space: nowrap;
    margin-left: 0.5rem;
}

.server-list-link:hover {
    color: var(--primary-lighter);
}

.character-grid-state {
    color: var(--text-dim);
    grid-column: 1 / -1;
}

.character-grid-state-error {
    color: var(--danger-bright);
}

.character-modal-shell {
    position: fixed;
    inset: 0;
    background-color: var(--overlay-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.character-modal-shell-top {
    z-index: 50;
}

.character-modal-shell-main {
    z-index: 40;
}

.character-card {
    position: relative;
    aspect-ratio: 1 / 1;
    background-color: var(--surface-deep);
    border-radius: 0.5rem;
    cursor: pointer;
    overflow: hidden;
    border: 1px solid var(--surface);
    box-shadow: var(--shadow-card);
    transition: transform 0.15s, border-color 0.15s;
}

.character-card:hover {
    transform: scale(1.05);
    border-color: var(--surface-mid);
}

.character-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.15s;
}

.character-card:hover .character-card-img {
    transform: scale(1.1);
}

.character-card-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: var(--gradient-card-footer);
}

.character-card-title {
    position: absolute;
    left: 0;
    bottom: 0;
    padding: 0.75rem;
    font-weight: 700;
    font-size: 1.125rem;
    line-height: 1.25;
    color: var(--text-on-accent);
}

.editor-preview-copy {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.625;
}

.editor-result-img {
    border-radius: 0.5rem;
    max-width: 20rem;
    border: 1px solid var(--surface-raised);
}

.scheduler-list-state {
    color: var(--text-muted);
    text-align: center;
    padding: 3rem 0;
}

.scheduler-list-state-icon {
    font-size: 1.875rem;
    margin-bottom: 0.75rem;
    display: block;
}

.scheduler-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1rem;
}

.scheduler-badge--status-done,
.scheduler-badge--mode-neutral {
    background-color: var(--surface);
    color: var(--text-dim);
}

.scheduler-badge--status-failed {
    background-color: var(--scheduler-failed-bg);
    color: var(--scheduler-failed-text);
}

.scheduler-task-card {
    background-color: var(--surface-deep);
    border: 1px solid var(--surface);
    border-radius: 0.5rem;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s;
}

.scheduler-task-card:hover {
    border-color: var(--surface-mid);
}

@media (min-width: 640px) {
    .scheduler-task-card {
        flex-direction: row;
        align-items: center;
    }
}

.scheduler-action-btn {
    font-size: 0.875rem;
}

.scheduler-combobox-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-size: 0.875rem;
}

.scheduler-combobox-item:hover {
    background-color: var(--surface-raised);
}

.scheduler-combobox-label {
    color: var(--text-on-accent);
}

.scheduler-combobox-sub {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-left: 0.5rem;
}

.servers-invite-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--primary-dark);
    color: var(--text-on-accent);
    font-weight: 700;
    padding: 0.5rem 1.25rem;
    border-radius: 0.5rem;
    transition: background-color 0.15s;
}

.servers-invite-link:hover {
    background-color: var(--primary-hover);
}

.power-btn {
    transition: all 0.3s ease;
    background-color: var(--surface);
    color: var(--text-on-accent);
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    display: flex;
    align-items: center;
    border: none;
    cursor: pointer;
}

.power-btn:hover {
    transform: scale(1.05);
    background-color: var(--surface-raised);
}

.power-btn.active {
    box-shadow: 0 0 20px var(--primary-glow);
}

.power-btn--active {
    background-color: var(--danger);
}

.power-btn--active:hover {
    background-color: var(--danger-dark);
}

.power-btn--inactive {
    background-color: var(--surface);
}

.power-btn--inactive:hover {
    background-color: var(--surface-raised);
}

.power-btn--crashed {
    background-color: var(--warning-hover);
}

.power-btn--crashed:hover {
    background-color: var(--warning-dark);
}

/* ========================================================================== */
/* Tabs                                                                       */
/* ========================================================================== */
.tab-active {
    color: var(--light);
}

/* ========================================================================== */
/* Generic Content                                                            */
/* ========================================================================== */
pre {
    white-space: pre-wrap;
    word-break: break-all;
}

/* ========================================================================== */
/* Tooltips                                                                  */
/* ========================================================================== */
.tt {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.tt .tt-body {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    background: var(--dark);
    border: 1px solid var(--surface-raised);
    color: var(--text-tooltip);
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 11px;
    line-height: 1.5;
    white-space: normal;
    width: 230px;
    z-index: 100;
    transition: opacity 0.15s;
    pointer-events: none;
    font-weight: 400;
}

.tt:hover .tt-body {
    visibility: visible;
    opacity: 1;
}

.tt .tt-body.tt-right,
.tt .tt-body.tt-align-left {
    left: 0;
    transform: none;
}

.tt .tt-body.tt-align-right {
    left: auto;
    right: 0;
    transform: none;
}

.tt .tt-body.tt-bottom-left {
    bottom: auto;
    top: calc(100% + 8px);
    left: 0;
    transform: none;
}

.tt .tt-body.tt-bottom-right {
    bottom: auto;
    top: calc(100% + 8px);
    left: auto;
    right: 0;
    transform: none;
}

/* ========================================================================== */
/* Component Classes                                                          */
/* ========================================================================== */

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin-top: 1rem;
}

@media (min-width: 768px) {
    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    .form-grid.form-grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

.sim-sidebar .form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
}

.provider-card {
    background-color: var(--surface-deep);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    padding: 1rem;
}

.divider {
    border-top: 1px solid var(--surface-raised);
}

.card-dark {
    background-color: var(--surface-deep);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    border: 1px solid var(--dark);
}

.card-link {
    display: block;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s;
}

.card-link:hover {
    background-color: var(--primary-tint-04);
}

/* Compact card-dark rows (log list, etc.) */
.card-dark--row {
    padding: 1rem;
    box-shadow: none;
}

.card-dark--row-admin {
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.card-dark--clickable {
    cursor: pointer;
    transition: border-color 0.15s;
}

.card-dark--clickable:hover {
    border-color: var(--surface-mid);
}

/* Shared base for inputs and input-like selects */
:is(.input-field, .input-joined, .select-sm, .cb-dd-btn) {
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    color: var(--text-on-accent);
    border-radius: 0.5rem;
}

.input-field {
    font-size: 0.875rem;
    width: 100%;
    padding: 0.625rem;
    line-height: normal;
}

.input-field:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-focus-ring);
}

/* Allowed-models lists (core + multi providers) — same font and line height */
textarea.allowed-models-textarea {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
    font-size: 0.875rem;
    line-height: 1.5;
}

/* Shared base for block labels */
:is(.label-form, .label-muted) {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.label-form {
    color: var(--text-soft);
}

/* Shared base for solid color buttons */
:is(.btn-primary, .btn-primary-sm, .btn-gray, .btn-gray-sm, .btn-green, .btn-red) {
    border-radius: 0.5rem;
    transition: background-color 0.15s, transform 0.15s;
    color: var(--text-on-accent);
    border: none;
    cursor: pointer;
}

:is(.btn-primary, .btn-gray, .btn-green, .btn-red) {
    padding: 0.5rem 1rem;
}

:is(.btn-primary-sm, .btn-gray-sm) {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

.btn-primary {
    background-color: var(--primary-dark);
    font-weight: 500;
}

:is(.btn-primary, .btn-primary-sm):hover {
    background-color: var(--primary-hover);
    transform: scale(1.04);
}

body[data-page="ai-config"] :is(.btn-primary, .btn-primary-sm):hover {
    transform: none;
}

.btn-gray {
    background-color: var(--surface-raised);
}

:is(.btn-gray, .btn-gray-sm):hover {
    background-color: var(--surface-mid);
}

.toggle-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

/* Reusable toggle switch track for checkbox sliders */
.toggle-track {
    width: 2.75rem;
    height: 1.5rem;
    background-color: var(--surface-mid);
    border-radius: 9999px;
}

.peer:focus ~ .toggle-track {
    outline: none;
}

.toggle-track::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 1.25rem;
    height: 1.25rem;
    background-color: var(--text-on-accent);
    border: 1px solid var(--text-soft);
    border-radius: 9999px;
    transition: all 0.15s;
}

.peer:checked ~ .toggle-track {
    background-color: var(--toggle-track-on);
}

.peer:checked ~ .toggle-track::after {
    transform: translateX(100%);
    border-color: var(--toggle-knob);
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: var(--overlay-backdrop);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
    padding: 1rem;
    overflow-x: hidden;
    overflow-y: auto;
    box-sizing: border-box;
}

.modal-backdrop.top {
    align-items: flex-start;
    padding-top: 4rem;
}

.modal-backdrop-top-offset {
    padding-top: 12rem;
}

.modal-box-padded {
    padding: 1.5rem;
    box-sizing: border-box;
}

.modal-box-scroll {
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 0;
}

.modal-title-row {
    margin-bottom: 1.5rem;
}

.modal-footer-actions {
    display: flex;
    justify-content: flex-end;
    padding-top: 1.5rem;
}

.form-section-stack {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-fields-full {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 1rem;
}

.divider-section {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
}

.field-hint {
    margin-top: 0.5rem;
}

/* Server settings modal (overrides form) */
.server-config-modal {
    overflow-x: hidden;
    max-width: 100%;
    box-sizing: border-box;
    container-type: inline-size;
    container-name: server-config;
}

.server-config-header {
    gap: 0.75rem;
    min-width: 0;
    margin-bottom: 1rem;
}

.server-config-header-main {
    min-width: 0;
    flex: 1;
}

.server-config-fields {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 0;
    overflow-x: hidden;
    max-width: 100%;
}

.server-config-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.75rem;
    min-width: 0;
}

@media (min-width: 640px) {
    .server-config-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.server-config-grid > * {
    min-width: 0;
}

.server-config-modal .label-tt {
    flex-wrap: wrap;
    min-width: 0;
}

.server-config-modal .server-config-grid-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* Same 4-column tracks as row above — token limits align with Temperature / Max Tokens */
@container server-config (min-width: 30rem) {
    .server-config-modal .server-config-grid-4 {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .server-config-modal .server-config-prefill-cell {
        grid-column: span 2;
    }
}

@container server-config (max-width: 29.99rem) {
    .server-config-modal .server-config-prefill-cell {
        grid-column: 1 / -1;
    }
}

.server-config-prefill-cell {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-self: center;
    min-width: 0;
}

.server-config-prefill-cell > .label-tt {
    margin-bottom: 0.25rem;
}

.server-config-prefill-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: nowrap;
    gap: 0.5rem;
    min-height: 2.25rem;
    width: 100%;
}

.server-config-prefill-controls .btn-gray-sm {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 0.8125rem;
    padding: 0.375rem 0.5rem;
}

.server-config-modal .input-field {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

.server-config-modal .flex-between {
    min-width: 0;
}

.server-config-modal .flex-between > * {
    min-width: 0;
}

.fieldset-section {
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    padding: 1rem;
}

.label-xs {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-dim);
    margin-bottom: 0.25rem;
}

.heading-card {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-on-accent);
}

.heading-section {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-on-accent);
}

.label-tt {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-soft);
}

.btn-green {
    background-color: var(--success-solid);
    font-weight: 700;
}

.btn-green:hover {
    background-color: var(--success-hover);
}

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

.text-muted {
    font-size: 0.875rem;
    color: var(--text-muted);
}

:is(#control-status-text, #bot-status-text) {
    min-width: 48px;
    display: inline-block;
}

#control-status-text {
    margin-left: 0.5rem;
    color: var(--text-on-accent);
}

.btn-primary-sm {
    background-color: var(--primary-dark);
}

.btn-gray-sm {
    background-color: var(--surface-raised);
}

.badge-code {
    font-family: monospace;
    font-size: 0.75rem;
    color: var(--primary-light);
    background-color: var(--surface);
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
}

.btn-icon {
    color: var(--text-dim);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.15s;
}

.btn-icon:hover {
    color: var(--text-on-accent);
}

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

.btn-dashed {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: var(--surface);
    border: 1px dashed var(--surface-mid);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    color: var(--text-soft);
    transition: border-color 0.15s, color 0.15s;
    cursor: pointer;
}

.btn-dashed:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-dashed-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.75rem;
    gap: 0.25rem;
}

.btn-ghost {
    background: transparent;
    border: 1px solid var(--surface-mid);
    color: var(--text-dim);
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn-ghost:hover {
    background-color: var(--surface-raised);
    border-color: var(--text-muted);
    color: var(--text-on-accent);
}

.btn-danger {
    background: transparent;
    border: 1px solid var(--surface-mid);
    color: var(--text-dim);
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn-danger:hover {
    background-color: var(--danger);
    border-color: var(--danger);
    color: var(--text-on-accent);
}

/* ========================================================================== */
/* Role Badges                                                                 */
/* ========================================================================== */
.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.55rem;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
/* Users list: soft pills (avatar chips stay solid in .nav-user-badge) */
.role-badge.role-super_admin { background: var(--role-super-admin-tint); color: var(--role-super-admin-text); }
.role-badge.role-admin       { background: var(--role-admin-tint); color: var(--role-admin-text); }
.role-badge.role-mod         { background: var(--role-mod-tint); color: var(--role-mod-text); }
.role-badge.role-guest       { background: var(--role-guest-tint); color: var(--text-dim); }
.role-badge.role-pending     { background: var(--role-pending-tint); color: var(--role-super-admin-text); }
.role-badge.role-rejected    { background: var(--role-rejected-tint); color: var(--danger-text); }

.legend-section {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--light);
    padding: 0 0.5rem;
}

/* ========================================================================== */
/* Filter Panels                                                               */
/* ========================================================================== */
.filter-panel {
    background-color: var(--surface-deep);
    border: 1px solid var(--surface);
    border-radius: 0.5rem;
    padding: 1rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    --filter-control-fs: 0.875rem;
    --filter-control-lh: 1.5rem;
    --filter-control-pad-y: 0.5rem;
    --filter-control-pad-x: 0.75rem;
    --filter-control-h: 2.5rem;
}

/* One height for inputs, selects, dropdowns, date pickers in filter bars */
.filter-panel :is(
    .input-field,
    .field,
    .cb-dd-btn,
    .date-picker-control,
    .custom-select-btn
) {
    box-sizing: border-box;
    font-size: var(--filter-control-fs);
    line-height: var(--filter-control-lh);
    min-height: var(--filter-control-h);
    padding: var(--filter-control-pad-y) var(--filter-control-pad-x);
}

.filter-panel :is(.cb-dd-btn, .date-picker-control, .custom-select-btn) {
    display: flex;
    align-items: center;
}

.filter-panel .date-picker-segments {
    line-height: var(--filter-control-lh);
}

.filter-panel .input-field.pr-8 {
    padding-right: 2rem;
}

.filter-panel .select-wrap.custom-select-enhanced:has(.icon-clear-btn) .custom-select-btn {
    padding-right: 3.5rem;
}

.filter-panel .custom-select-btn {
    padding-right: 2rem;
}

.filter-panel-wrap {
    position: relative;
}

.filter-panel-col {
    position: relative;
}

.filter-panel-col--xs {
    width: 7rem;
}

.filter-panel-col--sm {
    width: 9rem;
}

.filter-panel-col--md {
    width: 10rem;
}

.filter-panel-col--action {
    width: 20rem;
    min-width: 12rem;
}

.filter-panel-col--xs :is(.cb-dd-btn, .cb-dd),
.filter-panel-col--sm :is(.cb-dd-btn, .cb-dd),
.filter-panel-col--md :is(.input-field, .cb-dd),
.filter-panel-col--action :is(.input-field, .cb-dd) {
    width: 100%;
}

.filter-panel-input--sm {
    width: 9rem;
}

.filter-panel-input--md {
    width: 10rem;
}

.filter-panel-input--lg {
    width: 12rem;
}

.filter-panel-input--auto {
    width: auto;
    min-width: 6rem;
}

/* Requests tab: keep Role/Type slots in layout so the row aligns like Users/Sessions */
body[data-page="users"] #users-filters.filter-panel--requests #users-filter-role,
body[data-page="users"] #users-filters.filter-panel--requests #users-filter-type {
    visibility: hidden;
    pointer-events: none;
}

.btn-clear-filter {
    margin-left: auto;
    align-self: flex-end;
    color: var(--text-dim);
    font-size: 0.875rem;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.15s;
}

.btn-clear-filter:hover {
    color: var(--text-on-accent);
}

/* Native date: hidden browser calendar icon; × + custom calendar as flex siblings */
.date-filter-wrap {
    display: inline-flex;
    align-items: center;
    gap: 0.1rem;
    max-width: 100%;
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    padding-right: 0.15rem;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.date-filter-wrap:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-focus-ring);
}

/* Clip native date field so reserved year slot is not visible */
.date-filter-clip {
    flex: 0 0 auto;
    width: 4.35rem;
    overflow: hidden;
}

.date-filter-wrap input.date-filter-md {
    display: block;
    width: 7.25rem;
    min-width: 7.25rem;
    max-width: none;
    margin-right: -3.1rem;
    border: none;
    background: transparent;
    box-shadow: none;
    padding: 0.625rem 0 0.625rem 0.625rem;
}

.date-filter-wrap input.date-filter-md:focus {
    outline: none;
    border-color: transparent;
    box-shadow: none;
}

input.date-filter-md::-webkit-datetime-edit-year-field {
    display: none;
}

input.date-filter-md::-webkit-datetime-edit-month-field,
input.date-filter-md::-webkit-datetime-edit-day-field {
    padding: 0;
}

input.date-filter-md::-webkit-datetime-edit-text {
    padding: 0 0.05rem;
}

input.date-filter-md::-webkit-calendar-picker-indicator {
    display: none;
    -webkit-appearance: none;
    appearance: none;
}

input.date-filter-md::-webkit-clear-button {
    display: none;
}

.date-filter-clear,
.date-filter-picker {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.15rem;
    min-width: 1.35rem;
    min-height: 1.75rem;
    font-size: 0.8rem;
    line-height: 1;
    transition: color 0.15s;
}

.date-filter-clear:hover,
.date-filter-picker:hover {
    color: var(--text-soft);
}

/* Custom date picker (replaces native calendar UI) */
.date-picker-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    max-width: 100%;
}

.date-picker-wrap--field {
    min-width: 6.5rem;
}

.date-picker-wrap--input {
    min-width: 6.25rem;
}

.date-picker-native,
.datetime-picker-native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.date-picker-control {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    min-width: 0;
    box-sizing: border-box;
    font-family: inherit;
    font-weight: inherit;
}

/* Same look as scheduler filter From/To (field + custom picker) everywhere */
.date-picker-wrap--field {
    width: auto;
    max-width: 100%;
}

.date-picker-wrap--field .date-picker-control.field {
    width: 100%;
    min-height: 2.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.5rem;
}

.date-picker-wrap--field .date-picker-segments {
    line-height: 1.5rem;
}

.filter-panel .date-picker-wrap--field {
    width: 100%;
}

.date-picker-segments {
    display: inline-flex;
    align-items: center;
    flex: 1 1 auto;
    min-width: 0;
    font-variant-numeric: tabular-nums;
}

.date-picker-control.is-empty .date-picker-seg::placeholder {
    color: var(--text-muted);
}

.date-picker-seg {
    border: none;
    background: transparent;
    color: inherit;
    font: inherit;
    font-variant-numeric: tabular-nums;
    padding: 0;
    outline: none;
    text-align: center;
    field-sizing: content;
}

.date-picker-seg[data-seg="d"],
.date-picker-seg[data-seg="m"] {
    width: 1.4rem;
}

.date-picker-seg[data-seg="y"] {
    width: 2.65rem;
}

.date-picker-sep {
    color: var(--text-muted);
    user-select: none;
    pointer-events: none;
    flex-shrink: 0;
}

.date-picker-trail {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    flex-shrink: 0;
}

.date-picker-open {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: color 0.15s;
}

.date-picker-open:hover {
    color: var(--text-soft);
}

.date-picker-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.1rem;
    font-size: 0.8rem;
    line-height: 1;
    transition: color 0.15s;
}

.date-picker-clear.hidden {
    display: none;
}

.date-picker-clear:hover {
    color: var(--text-soft);
}

/* Native date input + custom popup only (scheduler filters) */
.date-picker-popup-host {
    position: relative;
}

.date-picker-popup-host > input[type="date"].field {
    padding-right: 28px;
}

.date-picker-popup-host > input[type="date"].date-picker-has-popup::-webkit-calendar-picker-indicator {
    display: none;
    -webkit-appearance: none;
    appearance: none;
}

.date-picker-popup-host .icon-clear-btn {
    right: calc(1.1rem + 2px);
}

.date-picker-popup-host .date-picker-open-native {
    position: absolute;
    right: calc(0.4rem + 2px);
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: none;
    padding: 0;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-muted);
    transition: color 0.15s;
}

.date-picker-popup-host .date-picker-open-native:hover {
    color: var(--text-soft);
}

.date-picker-popup-host > .date-picker-popup {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
}

.date-picker-popup {
    position: absolute;
    top: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 60;
    width: 16.25rem;
    padding: 0.65rem;
    background-color: var(--surface-deep);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-menu);
}

.date-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.date-picker-title {
    flex: 1 1 auto;
    text-align: center;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--light);
}

.date-picker-nav {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border: none;
    border-radius: 0.375rem;
    background: none;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s;
}

.date-picker-nav:hover {
    color: var(--light);
    background-color: var(--surface);
}

.date-picker-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 0.25rem;
}

.date-picker-weekday {
    text-align: center;
    font-size: 0.625rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    padding: 0.15rem 0;
}

.date-picker-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.date-picker-day {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 1.75rem;
    border: none;
    border-radius: 0.375rem;
    background: none;
    color: var(--text-soft);
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
    cursor: pointer;
    transition: background-color 0.12s, color 0.12s;
}

.date-picker-day:hover {
    background-color: var(--surface);
    color: var(--light);
}

.date-picker-day.is-outside {
    color: var(--text-muted);
    opacity: 0.55;
}

.date-picker-day.is-today {
    box-shadow: inset 0 0 0 1px var(--primary-light);
}

.date-picker-day.is-selected {
    background-color: var(--primary-dark);
    color: var(--text-on-accent);
}

.date-picker-day.is-selected:hover {
    background-color: var(--primary);
}

.icon-clear-btn {
    position: absolute;
    right: 0.45rem;
    top: 50%;
    transform: translateY(-50%);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0 2px;
    min-width: 1.75rem;
    min-height: 1.75rem;
    transition: color 0.15s;
    z-index: 2;
}

.icon-clear-btn i {
    font-size: 1em;
    line-height: 1;
}

.icon-clear-btn:hover {
    color: var(--text-soft);
}

/* Select with custom chevron + clearable X */
.select-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.select-wrap select.field {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 2rem;
    cursor: pointer;
}

.select-wrap::after {
    content: '\f078';
    font-family: 'Font Awesome 6 Free';
    font-weight: 900;
    font-size: 0.75rem;
    color: var(--text-dim);
    position: absolute;
    right: 0.55rem;
    pointer-events: none;
    transition: opacity 0.15s;
}

.select-wrap.has-value::after {
    opacity: 0;
}

.select-wrap .icon-clear-btn {
    right: 0.45rem;
}

.select-wrap.custom-select-enhanced .icon-clear-btn {
    right: 1.55rem;
}

.select-wrap.custom-select-enhanced:has(.custom-select-btn.select-sm) .icon-clear-btn {
    right: 1.35rem;
}

/* ========================================================================== */
/* Dropdown (cb-dd) Styling                                                    */
/* ========================================================================== */
.cb-dd-chevron {
    font-size: 0.75rem;
    color: var(--text-dim);
    margin-left: auto;
}

.cb-dd-chevron--btn {
    margin-left: 0;
}

.cb-dd-btn {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    position: relative;
}

#af-action-search {
    padding-right: 2.75rem;
}

/* Admin logs Action: search input + trailing strip for list / clear */
.af-action-dd-trigger {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1;
    min-width: 2.75rem;
    padding: 0 0.45rem;
    justify-content: center;
    gap: 0.35rem;
    border: none;
    border-left: 1px solid var(--surface-raised);
    border-radius: 0 0.5rem 0.5rem 0;
    background-color: var(--surface);
    font-size: 0.875rem;
    line-height: 1.5rem;
}

.af-action-dd-trigger:focus {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--primary-tint-35);
}

.cb-dd-clear {
    flex-shrink: 0;
    font-size: 1rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px;
    line-height: 1;
    transition: color 0.15s;
}

.cb-dd-clear:hover {
    color: var(--text-soft);
}

.cb-dd {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.25rem;
    z-index: 30;
    background-color: var(--surface-deep);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-dropdown);
    padding: 0.25rem 0;
}

.cb-dd-scrollable {
    max-height: min(20rem, 50vh);
    overflow-y: auto;
    overflow-x: hidden;
}

.cb-dd.cb-dd-searchable {
    padding: 0;
    display: flex;
    flex-direction: column;
    max-height: min(28rem, 55vh);
}

/* Ensure Tailwind's `hidden` always wins for dropdowns. */
.cb-dd.hidden {
    display: none !important;
}

.cb-dd-search-wrap {
    flex-shrink: 0;
    padding: 0.5rem;
    border-bottom: 1px solid var(--surface-raised);
}

.cb-dd-search-list {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    padding: 0.25rem 0;
}

.cb-dd-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--text-on-accent);
    transition: background-color 0.15s;
}

.cb-dd-item:hover {
    background-color: var(--surface);
}

.custom-cb {
    appearance: none;
    -webkit-appearance: none;
    width: 1rem;
    height: 1rem;
    margin: 0;
    flex-shrink: 0;
    border: 1.5px solid var(--surface-mid);
    border-radius: 0.25rem;
    background-color: var(--surface);
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, box-shadow 0.15s;
    display: grid;
    place-content: center;
}

.custom-cb::before {
    content: '';
    width: 0.5rem;
    height: 0.25rem;
    border-left: 2px solid var(--text-on-accent);
    border-bottom: 2px solid var(--text-on-accent);
    transform: rotate(-45deg) scale(0);
    transform-origin: center;
    margin-top: -0.125rem;
    transition: transform 0.12s ease;
}

.custom-cb:checked {
    background-color: var(--primary);
    border-color: var(--primary);
}

.custom-cb:checked::before {
    transform: rotate(-45deg) scale(1);
}

.custom-cb:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-tint-35);
}

.custom-cb:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ========================================================================== */
/* Custom single-select (replaces native <select> UI)                          */
/* ========================================================================== */
select.custom-select-native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.select-wrap.custom-select-enhanced {
    display: inline-flex;
    max-width: 100%;
    flex-shrink: 0;
}

.custom-select-sizer {
    position: absolute;
    visibility: hidden;
    height: 0;
    overflow: hidden;
    white-space: nowrap;
    pointer-events: none;
}

.select-wrap.custom-select-enhanced::after {
    display: none;
}

.custom-select-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    text-align: left;
    cursor: pointer;
    border: 1px solid var(--surface-raised);
    background-color: var(--surface);
    color: var(--light);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.5rem;
    padding: 0.5rem 0.75rem;
    padding-right: 2rem;
    position: relative;
}

.select-wrap.custom-select-enhanced:has(.icon-clear-btn) .custom-select-btn {
    padding-right: 3.5rem;
}

.custom-select-btn.select-sm {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    padding-right: 1.75rem;
    line-height: 1.25rem;
}

.select-wrap.custom-select-enhanced:has(.icon-clear-btn) .custom-select-btn.select-sm {
    padding-right: 3rem;
}

.custom-select-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.custom-select-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.custom-select-chevron {
    position: absolute;
    right: 0.55rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.75rem;
    color: var(--text-dim);
    pointer-events: none;
}

.custom-select-dd {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 0.25rem;
    z-index: 40;
    background-color: var(--surface-deep);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-dropdown);
    padding: 0.25rem 0;
    max-height: min(16rem, 50vh);
    overflow-y: auto;
}

.custom-select-dd.hidden {
    display: none !important;
}

.custom-select-option {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--light);
    cursor: pointer;
    transition: background-color 0.15s;
}

.custom-select-option.is-selected {
    color: var(--primary-light);
    font-weight: 500;
}

.custom-select-option.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.custom-select-option:hover:not(.is-disabled) {
    background-color: var(--surface);
}

/* Users / Sessions filters: short option lists — no scroll clip */
body[data-page="users"] #users-filter-role .custom-select-dd,
body[data-page="users"] #users-filter-type .custom-select-dd,
body[data-page="users"] #sessions-filters .custom-select-dd {
    max-height: none;
    overflow-y: visible;
}

/* ========================================================================== */
/* Tabs                                                                        */
/* ========================================================================== */
body[data-page="logs"] .tabs-bar,
body[data-page="users"] .tabs-bar,
body[data-page="stats"] .tabs-bar {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 0;
    border-bottom: 1px solid var(--surface);
}

body[data-page="logs"] .tab-btn,
body[data-page="users"] .tab-btn,
body[data-page="stats"] .tab-btn {
    min-height: 2.5rem;
    padding: 0.625rem 0.125rem 0.7rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-dim);
    background: transparent;
    border: none;
    border-radius: 0;
    cursor: pointer;
    position: relative;
    transition: color 0.15s ease;
}

body[data-page="logs"] .tab-btn::after,
body[data-page="users"] .tab-btn::after,
body[data-page="stats"] .tab-btn::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: -1px;
    height: 2px;
    border-radius: 9999px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    transform: scaleX(0);
    transform-origin: center;
    transition: transform 0.18s ease;
}

body[data-page="logs"] .tab-btn:hover,
body[data-page="users"] .tab-btn:hover,
body[data-page="stats"] .tab-btn:hover {
    color: var(--text-soft);
}

body[data-page="logs"] .tab-btn.tab-active,
body[data-page="users"] .tab-btn.tab-active,
body[data-page="stats"] .tab-btn.tab-active {
    color: var(--light);
}

body[data-page="logs"] .tab-btn.tab-active::after,
body[data-page="users"] .tab-btn.tab-active::after,
body[data-page="stats"] .tab-btn.tab-active::after {
    transform: scaleX(1);
}

body[data-page="logs"] .tab-btn.tab-locked,
body[data-page="logs"] .tab-btn.tab-locked:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

body[data-page="logs"] .tab-btn.tab-locked:hover,
body[data-page="logs"] .tab-btn.tab-locked:disabled:hover {
    color: var(--text-dim);
}

body[data-page="logs"] .tab-lock-wrap {
    display: inline-block;
    cursor: not-allowed;
}

.tab-count-badge {
    min-width: 0.8125rem;
    height: 0.8125rem;
    padding: 0 0.22rem;
    border-radius: 9999px;
    font-size: 0.5rem;
    font-weight: 600;
    line-height: 0.8125rem;
    text-align: center;
    background-color: var(--danger);
    color: var(--text-on-accent);
}


@media (max-width: 640px) {
    body[data-page="users"] .users-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    body[data-page="users"] #new-user-btn {
        width: 100%;
        justify-content: center;
    }

    body[data-page="users"] .users-tabs {
        gap: 0.85rem;
    }

    /* On small screens keep requests badge as compact dot. */
    body[data-page="users"] .tab-count-badge {
        min-width: 0.375rem;
        width: 0.375rem;
        height: 0.375rem;
        padding: 0;
        font-size: 0;
        line-height: 0;
        border-radius: 9999px;
        color: transparent;
    }

    body[data-page="users"] .role-badge {
        padding-left: 0.45rem;
        padding-right: 0.45rem;
    }

    body[data-page="users"] .role-badge-label {
        display: none;
    }

    body[data-page="users"] #users-filters > div,
    body[data-page="users"] #sessions-filters > div {
        width: 100%;
    }

    body[data-page="users"] #users-filters .input-field,
    body[data-page="users"] #sessions-filters .input-field {
        width: 100%;
    }

    body[data-page="users"] #clear-filters-btn,
    body[data-page="users"] #clear-session-filters-btn {
        width: 100%;
        margin-left: 0;
        text-align: center;
    }

    body[data-page="users"] .users-name {
        font-size: 0.8125rem !important;
    }

    body[data-page="users"] .users-date {
        display: none;
    }
}

@media (max-width: 420px) {
    body[data-page="users"] .users-name {
        font-size: 0.75rem !important;
    }
}

/* ========================================================================== */
/* Pagination                                                                  */
/* ========================================================================== */
.btn-page {
    padding: 0.375rem 0.75rem;
    background-color: var(--surface);
    border-radius: 0.5rem;
    color: inherit;
    border: none;
    cursor: pointer;
    transition: background-color 0.15s;
}

.btn-page:hover {
    background-color: var(--surface-raised);
}

.btn-page:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.select-sm {
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}

/* ========================================================================== */
/* Modal Boxes                                                                 */
/* ========================================================================== */
.modal-box {
    position: relative;
    background-color: var(--surface-deep);
    border-radius: 0.75rem;
    border: 1px solid var(--surface);
    box-shadow: var(--shadow-modal);
    box-sizing: border-box;
    max-width: 100%;
}

.btn-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
}

.modal-sm { width: 100%; max-width: 24rem; }
.modal-md {
    width: 100%;
    max-width: min(42rem, calc(100vw - 2rem));
}
.modal-lg { width: 100%; max-width: 52rem; }

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem;
    border-bottom: 1px solid var(--surface);
    background-color: var(--surface-deep);
}

.modal-header--sticky {
    position: sticky;
    top: 0;
    z-index: 10;
}

/* ========================================================================== */
/* Detail Rows                                                                 */
/* ========================================================================== */
.detail-row {
    display: flex;
    justify-content: space-between;
    color: var(--text-dim);
}

/* ========================================================================== */
/* Log Detail                                                                  */
/* ========================================================================== */
.metadata-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.375rem 1.25rem;
    align-items: baseline;
}

@media (min-width: 480px) {
    .metadata-grid {
        grid-template-columns: max-content 1fr max-content 1fr;
    }
    .metadata-full-value {
        grid-column: span 3;
    }
}

body[data-page="logs"] #detail-modal .modal-box {
    max-width: 46rem;
}

.metadata-label {
    color: var(--text-dim);
    white-space: nowrap;
}

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

.log-section {
    padding-top: 0.5rem;
    border-top: 1px solid var(--surface);
}

.log-section-label {
    color: var(--text-dim);
    margin-bottom: 0.25rem;
}

.log-pre {
    background-color: var(--surface);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font-size: 0.75rem;
    color: var(--log-pre-text);
    white-space: pre-wrap;
    word-break: break-word;
    font-family: monospace;
}

.log-pre-error {
    background-color: var(--danger-log-bg);
    border: 1px solid var(--danger-log-border);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font-size: 0.75rem;
    color: var(--danger-text-light);
    white-space: pre-wrap;
    font-family: monospace;
}

.detail-content {
    font-size: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.log-json-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}

.log-json-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.btn-copy {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.15s;
}

.btn-copy:hover {
    color: var(--text-on-accent);
}

.log-prettier-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}

.log-json {
    background-color: var(--surface);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-dim);
    max-height: 24rem;
    overflow-y: auto;
    white-space: pre-wrap;
    font-family: monospace;
}

/* ========================================================================== */
/* Inline Label (no block/margin)                                             */
/* ========================================================================== */
.label-inline {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-soft);
}

/* ========================================================================== */
/* Password Eye Toggle                                                        */
/* ========================================================================== */
.btn-eye {
    position: absolute;
    inset-block: 0;
    right: 0;
    padding: 0 0.75rem;
    display: flex;
    align-items: center;
    color: var(--text-dim);
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.15s;
}

.btn-eye:hover {
    color: var(--text-on-accent);
}

/* ========================================================================== */
/* Red Action Button                                                          */
/* ========================================================================== */
.btn-red {
    background-color: var(--danger-dark);
    font-weight: 700;
}

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

/* ========================================================================== */
/* Code / Pre Block                                                           */
/* ========================================================================== */
.code-block {
    background-color: var(--surface);
    color: var(--text-soft);
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-family: monospace;
    font-size: 0.75rem;
    overflow-x: auto;
    line-height: 1.625;
}

.text-secondary {
    color: var(--text-soft);
}

.code-inline {
    color: var(--text-dim);
}

.icon-info {
    color: var(--text-muted);
    cursor: help;
    transition: color 0.15s;
}

.icon-info:hover {
    color: var(--text-soft);
}

.icon-info-indigo {
    color: var(--surface-mid);
    cursor: help;
    font-size: 0.75rem;
    transition: color 0.15s;
}

.icon-info-indigo:hover {
    color: var(--primary-light);
}

.avatar-img {
    border-radius: 0.5rem;
    object-fit: cover;
    background-color: var(--surface);
    flex-shrink: 0;
}

.avatar-preview-wrap {
    position: relative;
    flex-shrink: 0;
}

.avatar-preview-wrap .avatar-img.is-loading {
    opacity: 0;
    visibility: hidden;
}

.avatar-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
    background-color: var(--surface);
    z-index: 1;
}

.avatar-loader.hidden {
    display: none;
}

.loader-spinner {
    display: block;
    width: 1.75rem;
    height: 1.75rem;
    border: 2px solid var(--surface-raised);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: loader-spin 0.75s linear infinite;
}

.loader-spinner-sm {
    display: inline-block;
    width: 0.875rem;
    height: 0.875rem;
    border: 2px solid var(--surface-raised);
    border-top-color: var(--primary-light);
    border-radius: 50%;
    animation: loader-spin 0.75s linear infinite;
    vertical-align: middle;
}

.panel-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem 1rem;
    color: var(--text-dim);
    font-size: 0.875rem;
}

.panel-loader.is-full-width,
.grid-full-width {
    grid-column: 1 / -1;
}

.panel-loader-label {
    color: var(--text-dim);
}

.list-load-error {
    color: var(--danger-text);
    text-align: center;
}

.list-empty-state {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.875rem;
}

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

.tooltip-popup {
    position: absolute;
    left: 0;
    bottom: 1.5rem;
    width: 16rem;
    background-color: var(--surface-deep);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font-size: 0.75rem;
    color: var(--text-soft);
    z-index: 50;
    box-shadow: var(--shadow-dropdown);
}

.tooltip-title {
    display: block;
    font-weight: 600;
    color: var(--text-on-accent);
    margin-bottom: 0.25rem;
}

.tooltip-text {
    color: var(--text-dim);
}

.text-dim {
    color: var(--text-dim);
}

.label-filter {
    font-size: 0.875rem;
    color: var(--text-dim);
    white-space: nowrap;
}

.link-indigo-sm {
    font-size: 0.75rem;
    color: var(--primary-light);
    white-space: nowrap;
    transition: color 0.15s;
}

.link-indigo-sm:hover {
    color: var(--primary-lighter);
}

/* ========================================================================== */
/* Segmented / Tab Buttons                                                   */
/* ========================================================================== */
.mode-tab, .mode-btn {
    padding: 0.125rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
    transition: background-color 0.15s, color 0.15s;
    cursor: pointer;
    border: none;
}

.mode-tab-group {
    display: flex;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid var(--surface-raised);
    font-size: 0.75rem;
}

.mode-tab-group--segmented {
    gap: 0.25rem;
    padding: 0.125rem;
    overflow: visible;
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
}

.mode-tab-group--segmented .mode-tab,
.mode-tab-group--segmented .mode-btn {
    border-radius: 0.375rem;
}

.mode-tab {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 0;
    cursor: pointer;
    border: none;
}

.mode-tab-on {
    background-color: var(--primary-dark);
    color: var(--text-on-accent);
}

.mode-tab-off {
    background-color: var(--surface);
    color: var(--text-dim);
}

.mode-tab-off:hover {
    color: var(--text-on-accent);
}

.type-btn, .ttype-btn {
    padding: 0.5rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
    cursor: pointer;
}

.day-pill {
    padding: 0.375rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: 1px solid transparent;
    transition: background-color 0.15s, border-color 0.15s, color 0.15s;
    cursor: pointer;
}

.tab-indigo-on {
    background-color: var(--primary-dark);
    border-color: var(--primary);
    color: var(--text-on-accent);
}

.tab-amber-on {
    background-color: var(--warning-hover);
    border-color: var(--warning);
    color: var(--text-on-accent);
}

.tab-off {
    background-color: var(--surface);
    border-color: var(--surface-raised);
    color: var(--text-dim);
}

.tab-off:hover {
    border-color: var(--primary);
    color: var(--text-on-accent);
}

/* ========================================================================== */
/* History Toggle Button                                                     */
/* ========================================================================== */
#history-toggle {
    position: relative;
    width: 3rem;
    height: 1.5rem;
    border-radius: 9999px;
    background-color: var(--surface-mid);
    transition: background-color 0.15s;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
}

#history-toggle:focus {
    outline: none;
}

#history-toggle.is-on {
    background-color: var(--primary-dark);
}

#history-thumb {
    position: absolute;
    top: 0.125rem;
    left: 0.125rem;
    width: 1.25rem;
    height: 1.25rem;
    border-radius: 9999px;
    background-color: var(--text-on-accent);
    transition: transform 0.15s;
    pointer-events: none;
}

#history-thumb.is-on {
    transform: translateX(1.5rem);
}

/* ========================================================================== */
/* Picker Dropdown (channel / DM combobox)                                   */
/* ========================================================================== */
.picker-dd {
    position: absolute;
    z-index: 10;
    width: 100%;
    margin-top: 0.25rem;
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-dropdown);
    max-height: 12rem;
    overflow-y: auto;
}

/* ========================================================================== */
/* Sidebar Scrollable List                                                   */
/* ========================================================================== */
.sidebar-list {
    overflow-y: auto;
}

.sidebar-list > * + * {
    margin-top: 0.5rem;
}

#character-form {
    padding: 1.5rem;
}

#character-form > * + * {
    margin-top: 1.5rem;
}

/* ========================================================================== */
/* Delete Link Button                                                         */
/* ========================================================================== */
.icon-accent {
    color: var(--primary-light);
}

.preview-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-soft);
}

.instructions-display {
    color: var(--text-soft);
    white-space: pre-wrap;
    word-break: break-word;
    background-color: var(--surface);
    border-radius: 0.5rem;
    padding: 0.75rem;
    font-size: 0.75rem;
}

.btn-delete {
    color: var(--danger-text);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    background: none;
    border: none;
    cursor: pointer;
    transition: color 0.15s;
}

.btn-delete:hover {
    color: var(--danger-text-light);
}

/* ========================================================================== */
/* Modal Body                                                                 */
/* ========================================================================== */
.modal-body {
    padding: 1.25rem;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-body--sm {
    font-size: 0.875rem;
}

.form-error {
    font-size: 0.75rem;
    color: var(--danger-text);
}

.text-error {
    color: var(--danger-text);
}

/* ========================================================================== */
/* Modal Footer                                                               */
/* ========================================================================== */
.modal-footer {
    border-top: 1px solid var(--surface);
    padding: 1.25rem;
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
}

.modal-footer--split {
    justify-content: space-between;
    align-items: center;
}

/* ========================================================================== */
/* Unit Annotation Span                                                       */
/* ========================================================================== */
.text-unit {
    color: var(--text-muted);
    font-weight: 400;
}

/* ========================================================================== */
/* Sidebar / Section Heading                                                  */
/* ========================================================================== */
.heading-sidebar {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.75rem;
}

/* ========================================================================== */
/* Discord Brand Button                                                       */
/* ========================================================================== */
.btn-discord {
    background-color: var(--discord);
    color: var(--text-on-accent);
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.375rem 1rem;
    border-radius: 0.375rem;
    border: none;
    cursor: pointer;
    transition: background-color 0.15s;
}

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

/* ========================================================================== */
/* Config Panel Wrapper                                                       */
/* ========================================================================== */
.config-panel {
    background-color: var(--surface-deep);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-panel);
    border: 1px solid var(--surface);
}

/* ========================================================================== */
/* Shared List Cards (refactor-style)                                         */
/* ========================================================================== */
.list-card {
    background-color: var(--surface-deep);
    border: 1px solid var(--surface);
    border-radius: 0.5rem;
    padding: 1rem;
    transition: border-color 0.15s;
}

.list-card:hover {
    border-color: var(--surface-mid);
}

/* ========================================================================== */
/* Toggle Row (label + toggle inline)                                        */
/* ========================================================================== */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    padding: 0.625rem 0.75rem;
}

/* ========================================================================== */
/* Inline Select (small select inside a row)                                 */
/* ========================================================================== */
.select-inline {
    background-color: var(--surface-raised);
    border: 1px solid var(--surface-mid);
    color: var(--text-on-accent);
    font-size: 0.875rem;
    border-radius: 0.5rem;
    padding: 0.25rem 0.5rem;
}

/* ========================================================================== */
/* Modal Heading (large h3 inside modals)                                    */
/* ========================================================================== */
.modal-heading {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-on-accent);
    margin-bottom: 1rem;
}

/* ========================================================================== */
/* Autocomplete Dropdown                                                      */
/* ========================================================================== */
.autocomplete-dd {
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 0.25rem;
    z-index: 30;
    background-color: var(--surface-deep);
    border: 1px solid var(--surface-raised);
    border-radius: 0.5rem;
    box-shadow: var(--shadow-dropdown);
    max-height: 12rem;
    overflow-y: auto;
    min-width: 100%;
}

.combobox-item:hover { background-color: var(--surface-raised); }

/* ========================================================================== */
/* Pagination Bar                                                             */
/* ========================================================================== */
.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 1.5rem;
    font-size: 0.875rem;
    color: var(--text-dim);
}

/* ========================================================================== */
/* Editor: File Input Label                                                  */
/* ========================================================================== */
.file-label {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    cursor: pointer;
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    color: var(--text-soft);
    font-size: 0.875rem;
    border-radius: 0.5rem;
    padding: 0.625rem;
    transition: border-color 0.15s, color 0.15s;
}

.file-label:hover {
    border-color: var(--primary);
    color: var(--text-on-accent);
}

/* ========================================================================== */
/* Joined Input + Button Group                                               */
/* ========================================================================== */
.input-joined {
    font-size: 0.875rem;
    border-radius: 0.5rem 0 0 0.5rem;
    display: block;
    width: 100%;
    padding: 0.625rem;
}

.input-joined:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-focus-ring);
}

.btn-joined {
    background-color: var(--surface-raised);
    color: var(--text-on-accent);
    padding: 0 0.75rem;
    border-radius: 0 0.5rem 0.5rem 0;
    border: none;
    cursor: pointer;
    transition: background-color 0.15s;
}

.btn-joined:hover {
    background-color: var(--surface-mid);
}

/* ========================================================================== */
/* Editor: CDN URL Input                                                     */
/* ========================================================================== */
.input-cdn {
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    color: var(--primary-lighter);
    font-size: 0.75rem;
    border-radius: 0.5rem;
    flex-grow: 1;
    padding: 0.5rem;
    cursor: pointer;
}

/* ========================================================================== */
/* Brand Header (logo + name above cards)                                     */
/* ========================================================================== */
.brand-header {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1.5rem;
    /* Optical correction: logo shifts visual center right, nudge left to compensate */
    transform: translateX(-0.6rem);
}

.brand-header img {
    height: 2.5rem;
    width: auto;
    margin-right: 0.5rem;
}

.brand-header span {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-on-accent);
}

/* ========================================================================== */
/* Error Pages                                                                 */
/* ========================================================================== */

.error-page-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}

.error-page-card {
    background-color: var(--surface-deep);
    border: 1px solid var(--surface);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-modal);
    padding: 2.5rem 2rem;
    max-width: 22rem;
    width: 100%;
    text-align: center;
}

.error-page-brand {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.error-page-icon-wrap {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 4rem;
    height: 4rem;
    border-radius: 9999px;
    margin-bottom: 1.25rem;
    font-size: 1.5rem;
}

.error-page-code {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 0.5rem;
}

.error-page-title {
    font-size: 1.375rem;
    font-weight: 700;
    color: var(--light);
    margin-bottom: 0.625rem;
}

.error-page-msg {
    font-size: 0.875rem;
    color: var(--text-dim);
    line-height: 1.6;
    margin-bottom: 1.75rem;
}

.error-page-msg-sm {
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.6;
    margin-bottom: 0.25rem;
}

.error-page-countdown {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1.75rem;
}

.error-page-actions {
    display: flex;
    gap: 0.625rem;
    justify-content: center;
    flex-wrap: wrap;
}

.error-icon-indigo { background-color: var(--icon-tint-primary); color: var(--primary-light); }
.error-icon-red    { background-color: var(--icon-tint-danger); color: var(--danger-text); }
.error-icon-amber  { background-color: var(--icon-tint-warning); color: var(--role-super-admin-text); }
.error-icon-orange { background-color: var(--icon-tint-orange); color: var(--accent-orange); }

.error-code-indigo { color: var(--primary-light); }
.error-code-red    { color: var(--danger-text); }
.error-code-amber  { color: var(--role-super-admin-text); }
.error-code-orange { color: var(--accent-orange); }

/* ========================================================================== */
/* Stats Page                                                                  */
/* ========================================================================== */
.range-btn {
    padding: 0.3rem 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    border-radius: 0.375rem;
    border: 1px solid var(--surface-raised);
    background-color: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}

.range-btn:hover {
    color: var(--light);
    border-color: var(--surface-mid);
    background-color: var(--surface);
}

.range-btn-active {
    background-color: var(--primary);
    border-color: var(--primary);
    color: var(--text-on-accent);
}

.range-btn-active:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
}

.stats-activity-panel {
    min-height: 13rem;
}

.stats-activity-empty {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.875rem;
}

.stats-activity-chart {
    position: relative;
    height: 13rem;
}

.stats-bar-track {
    height: 0.375rem;
    border-radius: 9999px;
    background-color: var(--surface);
    overflow: hidden;
}

.stats-bar-fill {
    height: 100%;
    border-radius: 9999px;
    background-color: var(--primary);
    transition: width 0.3s ease;
}

.stats-err-badge {
    display: inline-block;
    margin-left: 0.4rem;
    font-size: 0.7rem;
    color: var(--danger-text);
    font-weight: 500;
}

.log-source-chat      { background: #14532d; color: #86efac; }
.log-source-test      { background: #1f2937; color: #d1d5db; }
.log-source-scheduler { background: #312e81; color: #a5b4fc; }

.sched-badge-reminder  { background: #78350f; color: #fcd34d; }


.main-content {
    width: 100%;
    max-width: 72rem;
    margin: 0 auto;
}

.page {
    display: flex;
    padding: 1.5rem 1rem;
}

@media (min-width: 640px) {
    .page {
        padding-left: 1.5rem;
        padding-right: 1.5rem;
    }
}

@media (min-width: 1024px) {
    .page {
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

.page-heading {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-on-accent);
    margin-bottom: 0.5rem;
}

.page-subtitle {
    font-size: 1rem;
    color: var(--text-dim);
}

.field {
    background-color: var(--surface);
    border: 1px solid var(--surface-raised);
    color: var(--text-on-accent);
    border-radius: 0.5rem;
    line-height: 1.5rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
}

.date-picker-control.field,
.date-picker-control.input-field {
    display: inline-flex;
    align-items: center;
}

.filter-panel .date-picker-wrap {
    display: flex;
    width: 100%;
}

.fieldset-section .field:not(.date-picker-control) {
    width: 100%;
}

/* ========================================================================== */
/* Login Page                                                                 */
/* ========================================================================== */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-shell {
    width: 100%;
    max-width: 24rem;
}

.login-brand {
    display: flex;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.login-brand-logo {
    height: 3rem;
    width: auto;
    margin-right: 0.75rem;
}

.login-brand-name {
    color: var(--text-on-accent);
    font-weight: 700;
    font-size: 1.5rem;
    align-self: center;
}

.login-hint {
    margin-top: 0.75rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-align: center;
}

.login-error {
    margin-top: 1rem;
    color: var(--danger-text);
    font-size: 0.875rem;
    text-align: center;
}

/* ========================================================================== */
/* Chat Simulator (/test)                                                     */
/* ========================================================================== */
.sim-readonly-banner {
    margin-top: 0.75rem;
    padding: 0.625rem 0.875rem;
    border-radius: 0.375rem;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.35);
    color: #c7d2fe;
    font-size: 0.875rem;
}

.sim-page.sim-readonly .autocomplete-dd {
    display: none !important;
}

.sim-page .sim-layout {
    display: grid;
    grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
    gap: 1rem;
    min-height: calc(100vh - 12rem);
}

@media (max-width: 960px) {
    .sim-page .sim-layout {
        grid-template-columns: 1fr;
    }
}

.sim-sidebar {
    align-self: start;
    max-height: calc(100vh - 10rem);
    overflow-y: auto;
}

.sim-chat-wrap {
    display: flex;
    flex-direction: column;
    min-height: 520px;
    max-height: calc(100vh - 10rem);
    background-color: #313338;
    border-radius: 0.5rem;
    border: 1px solid #1e1f22;
    overflow: hidden;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.35);
}

.sim-chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background-color: #2b2d31;
    border-bottom: 1px solid #1e1f22;
    flex-shrink: 0;
}

.sim-chat-header-icon {
    width: 2rem;
    height: 2rem;
    border-radius: 9999px;
    background-color: #404249;
    color: #b5bac1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
}

.sim-chat-header-title {
    font-weight: 600;
    color: #f2f3f5;
    text-transform: lowercase;
}

.sim-chat-header-sub {
    font-size: 0.75rem;
    color: #949ba4;
}

.sim-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.sim-chat-empty {
    margin: auto;
    text-align: center;
    color: #949ba4;
    max-width: 18rem;
    padding: 2rem 1rem;
}

.sim-chat-empty-icon {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    opacity: 0.5;
}

.sim-msg {
    display: flex;
    gap: 1rem;
    padding: 0.125rem 0.5rem 0.125rem 4rem;
    position: relative;
    border-radius: 0.25rem;
}

.sim-msg:hover {
    background-color: rgba(0, 0, 0, 0.06);
}

.sim-msg-avatar {
    position: absolute;
    left: 1rem;
    top: 0.125rem;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 9999px;
    object-fit: cover;
    background-color: #5865f2;
}

.sim-msg-head {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    line-height: 1.375rem;
}

.sim-msg-author {
    font-weight: 600;
    color: #f2f3f5;
    font-size: 1rem;
}

.sim-msg--bot .sim-msg-author {
    color: #5865f2;
}

.sim-msg-time {
    font-size: 0.6875rem;
    color: #949ba4;
    font-weight: 500;
}

.sim-msg-content {
    color: #dbdee1;
    font-size: 1rem;
    line-height: 1.375rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.sim-inline-code {
    background-color: #1e1f22;
    padding: 0.125rem 0.25rem;
    border-radius: 0.25rem;
    font-size: 0.875em;
    font-family: ui-monospace, monospace;
}

.sim-msg-meta {
    margin-top: 0.25rem;
    font-size: 0.6875rem;
    color: #72767d;
}

.sim-typing-dots {
    display: flex;
    gap: 0.25rem;
    padding: 0.25rem 0;
}

.sim-typing-dots span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 9999px;
    background-color: #949ba4;
    animation: sim-typing-bounce 1.2s infinite ease-in-out;
}

.sim-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.sim-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes sim-typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.sim-chat-meta {
    padding: 0.375rem 1rem;
    font-size: 0.6875rem;
    color: #949ba4;
    background-color: #2b2d31;
    border-top: 1px solid #1e1f22;
    flex-shrink: 0;
}

.sim-chat-compose {
    padding: 0 1rem 1rem;
    background-color: #313338;
    flex-shrink: 0;
}

.sim-compose-inner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: #383a40;
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
}

.sim-compose-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: #dbdee1;
    font-size: 1rem;
    line-height: 1.375rem;
}

.sim-compose-input::placeholder {
    color: #6d6f78;
}

.sim-compose-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sim-send-btn {
    padding: 0.5rem 0.75rem;
    flex-shrink: 0;
}

.sim-user-row {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.sim-user-avatar-preview {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 9999px;
    object-fit: cover;
    flex-shrink: 0;
    background-color: var(--surface-raised);
}
