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

:root {
    --teal: #00a884;
    --teal-dark: #008069;
    --teal-light: #d9fdd3;
    --bg-app: #f0f2f5;
    --bg-sidebar: #ffffff;
    --bg-chat: #eee9e2;
    --bg-header: #f0f2f5;
    --bg-input: #ffffff;
    --bg-bubble-in: #ffffff;
    --chat-pattern: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23c8bfb6' fill-opacity='0.3'%3E%3Cpath d='M30 0l4 8H26zM60 30l-8 4V26zM30 60l-4-8h8zM0 30l8-4v8z'/%3E%3C/g%3E%3C/svg%3E");
    --chat-pattern-size: 60px 60px;
    --bg-hover: #f5f6f6;
    --bg-selected: #e9edef;
    --text-1: #111b21;
    --text-2: #52636d;
    --text-3: #667781;
    --border: #dde4e8;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --font-sans: "Microsoft YaHei UI", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", "Source Han Sans SC", "Segoe UI", system-ui, -apple-system, sans-serif;
    --font-mono: "Cascadia Mono", "JetBrains Mono", "Fira Mono", "Courier New", monospace;
    --fs-2xs: 0.6875rem;
    --fs-xs: 0.75rem;
    --fs-sm: 0.8125rem;
    --fs-control: 0.875rem;
    --fs-body: 0.9375rem;
    --fs-title: 1rem;
    --fs-lg: 1.125rem;
    --fs-xl: 1.25rem;
    --lh-tight: 1.35;
    --lh-control: 1.45;
    --lh-body: 1.62;
    --line-measure: 68ch;
}

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: var(--bg-app);
    font-family: var(--font-sans);
    font-size: 100%;
    text-size-adjust: 100%;
    letter-spacing: 0;
}

* {
    scrollbar-width: thin;
    scrollbar-color: rgba(82, 99, 109, 0.35) transparent;
}

*::-webkit-scrollbar {
    width: 7px;
    height: 7px;
}

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

*::-webkit-scrollbar-thumb {
    border-radius: 999px;
    background: rgba(82, 99, 109, 0.28);
}

*::-webkit-scrollbar-thumb:hover {
    background: rgba(82, 99, 109, 0.46);
}

body {
    color: var(--text-1);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    text-align: left;
    text-rendering: optimizeLegibility;
}

body.sidebar-open {
    overflow: hidden;
    overscroll-behavior: none;
}

button,
input,
select,
textarea {
    font: inherit;
    letter-spacing: 0;
}

.app {
    display: flex;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.sidebar {
    width: 340px;
    min-width: 340px;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: transform 0.25s ease;
    z-index: 10;
}

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

.avatar {
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-weight: 700;
}

.avatar.has-room-logo {
    background: rgba(17, 27, 33, 0.05);
    box-shadow: inset 0 0 0 1px rgba(17, 27, 33, 0.04);
}

.is-logo-echo {
    color: var(--teal);
}

.is-logo-chat {
    color: #2087c8;
}

.is-logo-ai {
    color: #5f5bd8;
}

.is-logo-app {
    color: #00a884;
}

.av-room.is-logo-echo {
    background: var(--teal);
    color: #fff;
}

.av-room.is-logo-chat {
    background: #2087c8;
    color: #fff;
}

.av-room.is-logo-ai {
    background: #5f5bd8;
    color: #fff;
}

.av-room.is-logo-app {
    background: #00a884;
    color: #fff;
}

.av-side.is-logo-echo,
.av-bot.is-logo-echo {
    background: var(--teal);
    color: #fff;
}

.av-side.is-logo-chat,
.av-bot.is-logo-chat {
    background: #2087c8;
    color: #fff;
}

.av-side.is-logo-ai,
.av-bot.is-logo-ai {
    background: #5f5bd8;
    color: #fff;
}

.av-side.is-logo-app,
.av-bot.is-logo-app {
    background: #00a884;
    color: #fff;
}

.logo-mark {
    position: relative;
    z-index: 1;
    width: 64%;
    height: 64%;
    display: block;
}

.logo-thread {
    fill: none;
    stroke: currentColor;
    stroke-width: 4.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.logo-under {
    opacity: 0.46;
    stroke-width: 3.8;
}

.av-user {
    width: 42px;
    height: 42px;
    background: #5b6ad4;
    color: #fff;
    font-size: var(--fs-lg);
}

.av-room {
    width: 50px;
    height: 50px;
    background: var(--teal);
    color: #fff;
    font-size: var(--fs-title);
}

.av-bot {
    width: 40px;
    height: 40px;
    background: var(--teal);
    color: #fff;
    font-size: var(--fs-control);
}

.av-side {
    width: 28px;
    height: 28px;
    background: var(--teal);
    color: #fff;
    font-size: var(--fs-2xs);
    font-family: var(--font-mono);
}

.av-side .logo-mark {
    width: 68%;
    height: 68%;
}

.av-side .logo-thread {
    stroke-width: 4.8;
}

.av-side .logo-under {
    stroke-width: 4.3;
}

.av-self {
    width: 28px;
    height: 28px;
    background: #5b6ad4;
    color: #fff;
    font-size: var(--fs-sm);
}

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

.user-name-row {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.user-name {
    flex: 1;
    min-width: 0;
    font-size: var(--fs-title);
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-name-edit {
    width: 28px;
    height: 28px;
    border: 1px solid transparent;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
    flex-shrink: 0;
}

.user-name-edit svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.85;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.user-name-edit:hover {
    background: rgba(0, 128, 105, 0.08);
    border-color: rgba(0, 128, 105, 0.18);
    color: var(--teal-dark);
}

.auth-btns {
    display: flex;
    gap: 6px;
}

.btn-auth {
    padding: 5px 12px;
    border-radius: 20px;
    border: 1px solid var(--teal);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.btn-login {
    background: transparent;
    color: var(--teal);
}

.btn-login:hover {
    background: #e8f5e9;
}

.btn-register {
    background: var(--teal);
    color: #fff;
}

.btn-register:hover {
    background: var(--teal-dark);
}

.btn-logout {
    background: #f44336;
    color: #fff;
    border-color: #f44336;
}

.btn-logout:hover {
    background: #d32f2f;
    border-color: #d32f2f;
}

.search-wrap {
    padding: 12px 14px 10px;
    border-bottom: 1px solid var(--border);
}

.search-box {
    width: 100%;
    min-height: 38px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: var(--bg-header);
    color: var(--text-2);
    font-size: var(--fs-control);
    line-height: 18px;
    outline: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease;
}

.search-box:focus {
    border-color: rgba(0, 128, 105, 0.35);
    background: #ffffff;
    box-shadow: 0 1px 5px rgba(17, 27, 33, 0.08);
}

.search-box:empty::before {
    content: attr(data-placeholder);
    color: var(--text-3);
    pointer-events: none;
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 6px 8px 10px;
}

.chat-item {
    width: 100%;
    padding: 14px 10px;
    border: none;
    border-radius: 12px;
    background: transparent;
    display: flex;
    align-items: center;
    gap: 14px;
    text-align: left;
    cursor: pointer;
    transition: background 0.12s, box-shadow 0.12s;
}

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

.chat-item.is-filtered-out,
.ai-session-panel.is-filtered-out,
.ai-session-item.is-filtered-out {
    display: none;
}

.chat-item.active {
    background: rgba(0, 168, 132, 0.08);
    box-shadow: inset 2px 0 0 rgba(0, 128, 105, 0.72);
}

.chat-meta {
    flex: 1;
    min-width: 0;
}

.chat-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.chat-name {
    font-size: var(--fs-title);
    font-weight: 600;
    line-height: var(--lh-tight);
}

.chat-preview {
    font-size: var(--fs-control);
    line-height: var(--lh-control);
    color: var(--text-2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-empty {
    display: none;
    padding: 16px;
    color: var(--text-3);
    font-size: var(--fs-control);
    text-align: center;
}

.search-empty.show {
    display: block;
}

.ai-session-panel {
    padding: 10px 12px 12px 28px;
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.72);
}

.ai-session-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 700;
}

.ai-session-head button {
    width: 24px;
    height: 24px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #ffffff;
    color: var(--teal-dark);
    cursor: pointer;
    line-height: 1;
}

.ai-session-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ai-session-item {
    width: 100%;
    min-height: 34px;
    padding: 2px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-2);
    display: flex;
    align-items: center;
    gap: 4px;
    text-align: left;
    cursor: pointer;
    content-visibility: auto;
    contain-intrinsic-size: 40px;
    transition: background-color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, color 0.14s ease;
}

.ai-session-item:hover {
    border-color: rgba(0, 128, 105, 0.12);
    background: rgba(0, 128, 105, 0.025);
    box-shadow: 0 1px 4px rgba(17, 27, 33, 0.045);
    color: var(--text-1);
}

.ai-session-item.active {
    border-color: rgba(0, 128, 105, 0.22);
    background: #f0fffb;
    color: var(--text-1);
    box-shadow: inset 3px 0 0 var(--teal);
}

.ai-session-main {
    flex: 1;
    min-width: 0;
    min-height: 30px;
    padding: 4px 6px;
    border: none;
    background: transparent;
    color: inherit;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    text-align: left;
    cursor: pointer;
}

.ai-session-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--fs-control);
}

.ai-session-time {
    flex-shrink: 0;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-family: var(--font-mono);
    transition: color 0.14s ease;
}

.ai-session-item:hover .ai-session-time,
.ai-session-item.active .ai-session-time {
    color: var(--text-2);
}

.ai-session-spinner {
    width: 18px;
    height: 18px;
    display: inline-block;
    box-sizing: border-box;
    flex-shrink: 0;
    border-radius: 50%;
    border: 2px solid rgba(26, 140, 255, 0.18);
    border-top-color: #1a8cff;
    transform: translateZ(0);
    will-change: transform;
    animation: ai-session-spin 0.82s linear infinite;
}

.ai-session-spinner::after {
    content: none;
}

.ai-session-item.active .ai-session-spinner {
    border-color: rgba(10, 132, 255, 0.22);
    border-top-color: #0a84ff;
}

.ai-session-item.is-pending .ai-session-title {
    color: var(--text-1);
}

@keyframes ai-session-spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.ai-session-delete {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.14s ease, color 0.14s ease, opacity 0.14s ease;
}

.ai-session-delete:hover {
    background: rgba(180, 35, 24, 0.08);
    color: #b42318;
}

.ai-session-delete svg {
    width: 16px;
    height: 16px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar-footer {
    min-height: 46px;
    padding: 9px 16px;
    border-top: 1px solid var(--border);
    font-size: var(--fs-xs);
    color: var(--text-3);
    text-align: center;
    font-family: var(--font-mono);
    font-weight: 700;
}

.main {
    position: relative;
    flex: 1;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
}

.main::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: var(--chat-pattern);
    background-size: var(--chat-pattern-size);
    background-attachment: fixed;
    pointer-events: none;
}

.notif-bar {
    position: fixed;
    left: 50%;
    bottom: 76px;
    z-index: 2000;
    max-width: min(520px, calc(100% - 36px));
    min-height: 36px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border: 1px solid rgba(17, 27, 33, 0.08);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 8px 28px rgba(17, 27, 33, 0.14);
    color: var(--text-2);
    font-size: var(--fs-control);
    line-height: var(--lh-control);
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    backdrop-filter: blur(8px);
}

.notif-bar.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0);
}

.notif-bar.is-success {
    border-color: rgba(0, 128, 105, 0.16);
    color: #0f5132;
}

.notif-bar.is-warning {
    border-color: rgba(190, 112, 0, 0.2);
    color: #7a4a00;
}

.notif-bar.is-error {
    border-color: rgba(180, 35, 24, 0.16);
    color: #9f1f17;
}

.notif-bar svg {
    flex: 0 0 auto;
    width: 15px;
    height: 15px;
}

.notif-bar span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notif-close {
    width: 20px;
    height: 20px;
    margin-left: 2px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: currentColor;
    font-size: var(--fs-body);
    line-height: 1;
    opacity: 0.56;
    cursor: pointer;
}

.notif-close:hover {
    background: rgba(17, 27, 33, 0.06);
    opacity: 0.9;
}

.chat-header {
    position: relative;
    z-index: 2;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 22px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    font-size: var(--fs-title);
    font-weight: 600;
    line-height: var(--lh-tight);
}

.chat-header-status {
    margin-top: 2px;
    display: block;
    color: var(--text-2);
    font-size: var(--fs-sm);
    line-height: var(--lh-control);
}

.chat-header-right {
    display: none;
}

.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    min-width: 0;
}

.header-new-ai-btn {
    display: none;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    color: var(--teal-dark);
    font-size: var(--fs-control);
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
}

.header-new-ai-btn.show {
    display: inline-flex;
}

.header-new-ai-btn:hover {
    border-color: rgba(0, 128, 105, 0.35);
    background: #f0fffb;
}

.ai-settings-bar {
    position: relative;
    z-index: 3;
    display: none;
    align-items: center;
    justify-content: flex-start;
    padding: 8px 22px;
    background-color: var(--bg-chat);
    background-image: var(--chat-pattern);
    background-size: var(--chat-pattern-size);
    background-attachment: fixed;
    border-bottom: none;
}

.ai-settings-bar.show {
    display: flex;
}

.ai-selector-group {
    flex: 0 1 520px;
    min-width: 0;
    display: flex;
    align-items: center;
}

.ai-provider-select,
.ai-model-select,
.ai-config-panel select,
.ai-config-panel input,
.ai-config-panel textarea {
    min-height: 36px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text-1);
    font-size: var(--fs-control);
    min-width: 0;
    outline: none;
}

.ai-provider-select {
    display: none;
}

.ai-settings-bar .ai-model-select {
    display: none;
}

.ai-model-switcher {
    position: relative;
    width: min(520px, 100%);
    min-width: min(280px, 100%);
}

.ai-model-switcher-button {
    width: 100%;
    min-height: 38px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text-1);
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: var(--fs-control);
    text-align: left;
    cursor: pointer;
    outline: none;
    transition: border-color 0.14s ease, box-shadow 0.14s ease, background-color 0.14s ease;
}

.ai-model-switcher-button:hover,
.ai-model-switcher.open .ai-model-switcher-button {
    border-color: rgba(0, 128, 105, 0.35);
    box-shadow: 0 5px 18px rgba(17, 27, 33, 0.08);
}

.ai-model-switcher-icon {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.ai-model-switcher-icon .ai-provider-logo {
    margin: 0;
}

.ai-model-switcher-copy {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.ai-model-switcher-main,
.ai-model-switcher-sub {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-model-switcher-main {
    flex: 0 1 auto;
    color: var(--text-1);
    font-size: var(--fs-control);
    font-weight: 750;
}

.ai-model-switcher-sub {
    flex: 1 1 auto;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 650;
}

.ai-model-switcher-sub::before {
    content: "·";
    margin-right: 8px;
    color: var(--text-3);
}

.ai-model-switcher-caret {
    flex-shrink: 0;
    color: var(--text-3);
}

.ai-model-switcher-menu {
    position: absolute;
    left: auto;
    right: 0;
    top: calc(100% + 6px);
    z-index: 25;
    display: none;
    width: 100%;
    max-width: 100%;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 12px 30px rgba(17, 27, 33, 0.14);
}

.ai-model-switcher.open .ai-model-switcher-menu {
    display: block;
}

.ai-model-switcher-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-model-switcher-search {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    height: 34px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-1);
    font-size: var(--fs-control);
    outline: none;
}

.ai-model-switcher-search:focus {
    border-color: var(--teal);
}

.ai-model-switcher-options {
    max-height: min(360px, 50vh);
    margin-top: 10px;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.ai-model-switcher-group {
    padding: 8px 0;
    border-top: 1px solid rgba(17, 27, 33, 0.06);
}

.ai-model-switcher-group:first-child {
    border-top: none;
    padding-top: 0;
}

.ai-model-switcher-provider {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 3px 4px 7px;
}

.ai-model-switcher-provider-copy {
    min-width: 0;
    display: grid;
    gap: 1px;
}

.ai-model-switcher-provider-name,
.ai-model-switcher-provider-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-model-switcher-provider-name {
    color: var(--text-1);
    font-size: var(--fs-control);
    font-weight: 750;
}

.ai-model-switcher-provider-meta {
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 650;
}

.ai-model-switcher-models {
    display: grid;
    gap: 2px;
}

.ai-model-switcher-option {
    width: 100%;
    min-height: 36px;
    padding: 7px 9px 7px 40px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: var(--fs-control);
    line-height: var(--lh-control);
    text-align: left;
    cursor: pointer;
}

.ai-model-switcher-option:hover {
    background: var(--bg-hover);
}

.ai-model-switcher-option.active {
    background: #f0fffb;
    color: var(--teal-dark);
    font-weight: 700;
}

.ai-model-switcher-option-name,
.ai-model-switcher-option-meta {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-model-switcher-option-name {
    font-weight: 720;
}

.ai-model-switcher-option-meta {
    flex: 0 1 auto;
    max-width: 34%;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 650;
}

.ai-model-switcher-provider-empty {
    padding: 8px 9px 8px 40px;
    color: var(--text-3);
    font-size: var(--fs-control);
}

.ai-model-empty {
    padding: 12px 8px;
    color: var(--text-3);
    font-size: var(--fs-control);
    text-align: center;
}

.ai-switcher-action {
    flex: 0 0 auto;
    min-height: 32px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text-2);
    font-size: var(--fs-control);
    font-weight: 700;
    cursor: pointer;
}

.ai-switcher-action:hover {
    border-color: rgba(0, 128, 105, 0.3);
    background: var(--bg-hover);
}

.ai-provider-select:focus,
.ai-model-select:focus,
.ai-config-panel select:focus,
.ai-config-panel input:focus,
.ai-config-panel textarea:focus {
    border-color: var(--teal);
}

.ai-save-btn,
.ai-clear-btn {
    min-height: 36px;
    padding: 0 12px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: var(--fs-control);
    cursor: pointer;
    white-space: nowrap;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text-2);
}

.ai-save-btn {
    border: none;
    background: var(--teal);
    color: #fff;
}

.ai-save-btn:hover {
    background: var(--teal-dark);
}

.ai-clear-btn {
    background: transparent;
    color: var(--text-2);
}

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

.ai-config-panel {
    position: fixed;
    inset: 0;
    z-index: 115;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 22px;
    background: rgba(17, 27, 33, 0.34);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.ai-config-panel.show {
    display: flex;
}

.ai-config-panel.show .ai-config-dialog {
    animation: modalEnter 0.14s ease-out;
}

.ai-config-dialog {
    width: min(840px, 100%);
    max-height: min(660px, calc(100dvh - 44px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(17, 27, 33, 0.09);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 18px 46px rgba(17, 27, 33, 0.18);
}

.ai-config-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 54px;
    padding: 10px 14px 10px 16px;
    border-bottom: 1px solid #e7ecef;
    background: #fbfcfc;
}

.ai-config-title {
    font-size: var(--fs-title);
    font-weight: 700;
}

.ai-config-sub {
    margin-top: 2px;
    color: var(--text-3);
    font-size: var(--fs-sm);
    line-height: var(--lh-control);
    max-width: 58ch;
}

.ai-panel-close {
    width: 34px;
    height: 34px;
    border: 1px solid transparent;
    border-radius: 50%;
    background: transparent;
    color: var(--text-2);
    font-size: var(--fs-xl);
    cursor: pointer;
    line-height: 1;
}

.ai-panel-close:hover {
    border-color: #dde5e9;
    background: #f6f8f8;
    color: var(--text-1);
}

.ai-config-body {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 0;
    min-height: 0;
    overflow: hidden;
}

.ai-provider-rail {
    min-width: 0;
    padding: 12px;
    border-right: 1px solid #e7ecef;
    background: #f7f9f9;
}

.ai-provider-rail-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 34px;
    margin-bottom: 8px;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 700;
}

.ai-rail-add-btn {
    width: 28px;
    height: 28px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: #ffffff;
    color: var(--teal-dark);
    font-size: var(--fs-lg);
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.ai-rail-add-btn:hover {
    border-color: rgba(0, 128, 105, 0.35);
    background: #f0fffb;
}

.ai-provider-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: min(520px, calc(100dvh - 178px));
    overflow-y: auto;
}

.ai-provider-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 42px;
    padding: 0 10px 0 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--text-1);
    text-align: left;
    cursor: pointer;
    position: relative;
    transition: background-color 0.14s ease, border-color 0.14s ease, box-shadow 0.14s ease, opacity 0.14s ease;
}

.ai-provider-card:hover {
    background: rgba(255, 255, 255, 0.72);
    border-color: rgba(17, 27, 33, 0.06);
}

.ai-provider-card.is-dragging {
    opacity: 0.62;
    transform: scale(0.985);
}

.ai-provider-card.is-drag-placeholder {
    border-style: dashed;
    border-color: #cfe1dc;
    background: rgba(0, 128, 105, 0.05);
    box-shadow: none;
}

.ai-provider-card.is-drag-placeholder .ai-provider-main,
.ai-provider-card.is-drag-placeholder .ai-provider-meta {
    opacity: 0.18;
}

.ai-provider-card.active {
    border-color: rgba(0, 128, 105, 0.12);
    background: #ffffff;
    box-shadow: 0 3px 10px rgba(17, 27, 33, 0.05);
}

.ai-provider-card.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 7px;
    bottom: 7px;
    width: 4px;
    border-radius: 999px;
    background: var(--teal);
}

.ai-provider-card .ai-provider-name {
    font-size: var(--fs-control);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-provider-card.active .ai-provider-name {
    color: var(--teal-dark);
    font-weight: 700;
}

.ai-provider-card.no-key .ai-provider-name {
    color: #35464e;
}

.ai-provider-card.is-drop-before::after,
.ai-provider-card.is-drop-after::after {
    content: "";
    position: absolute;
    left: 14px;
    right: 14px;
    height: 2px;
    border-radius: 999px;
    background: rgba(0, 128, 105, 0.7);
}

.ai-provider-card.is-drop-before::after {
    top: -3px;
}

.ai-provider-card.is-drop-after::after {
    bottom: -3px;
}

.ai-provider-main {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    min-width: 0;
    flex: 1 1 auto;
}

.ai-provider-handle {
    flex: 0 0 auto;
    color: #b5c0c7;
    font-size: 12px;
    letter-spacing: -1px;
    line-height: 1;
    cursor: grab;
    user-select: none;
    opacity: 0.42;
    transition: opacity 0.16s ease, color 0.16s ease;
}

.ai-provider-card:hover .ai-provider-handle,
.ai-provider-card.active .ai-provider-handle {
    color: #8ea0aa;
    opacity: 0.86;
}

.ai-provider-drag-ghost {
    position: fixed;
    z-index: 1200;
    pointer-events: none;
    margin: 0;
    box-shadow: 0 14px 36px rgba(17, 27, 33, 0.18);
    transform: scale(1.01);
}

body.ai-provider-dragging {
    user-select: none;
}

.ai-provider-card:active .ai-provider-handle {
    cursor: grabbing;
}

.ai-provider-logo {
    width: 22px;
    height: 22px;
    border: 1px solid #e1e7eb;
    border-radius: 7px;
    background: #f7f9fa;
    color: #31414a;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    flex: 0 0 auto;
}

.ai-provider-logo.is-compact {
    width: 18px;
    height: 18px;
    border-radius: 5px;
    font-size: 9px;
}

.ai-provider-logo.is-openai {
    border-color: #cfe9df;
    background: #effaf5;
    color: #0d8f6a;
}

.ai-provider-logo.is-google {
    border-color: #d9e3fb;
    background: linear-gradient(135deg, #eef4ff 0%, #fff5e8 100%);
    color: #3773e0;
}

.ai-provider-logo.is-anthropic {
    border-color: #ece5da;
    background: #faf6ef;
    color: #6c4c2e;
}

.ai-provider-logo.is-deepseek {
    border-color: #dce7ff;
    background: #f1f5ff;
    color: #3b63d1;
}

.ai-provider-logo.is-custom {
    border-color: #e4e8ee;
    background: #f7f9fb;
    color: #5b6871;
}

.ai-provider-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 4px;
    flex: 0 0 auto;
    color: var(--text-3);
    font-size: var(--fs-xs);
}

.ai-provider-status-dot {
    flex: 0 0 auto;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #b8c2c8;
    box-shadow: 0 0 0 2px rgba(184, 194, 200, 0.18);
}

.ai-provider-status-dot.is-saved {
    background: #16a34a;
    box-shadow: 0 0 0 2px #edf9f2;
}

.ai-provider-status-dot.is-missing {
    background: #b8c2c8;
    box-shadow: 0 0 0 2px rgba(184, 194, 200, 0.18);
}

.ai-provider-form {
    min-width: 0;
    padding: 14px 16px 16px;
    overflow: auto;
    scrollbar-gutter: stable;
}

.ai-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 13px;
}

.ai-form-grid > label,
.ai-form-grid > .ai-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    color: var(--text-2);
    font-size: var(--fs-sm);
}

.ai-form-grid > label > span,
.ai-field-title > span:first-child,
.ai-model-list-head > span {
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 700;
}

.ai-field-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
}

.ai-field-title {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: 0;
}

.ai-field-title > span:first-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-form-grid input,
.ai-form-grid select,
.ai-form-grid textarea {
    width: 100%;
    min-height: 40px;
    padding: 0 10px;
    border-color: #e4eaee;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text-1);
    font-size: var(--fs-control);
    transition: border-color 0.14s ease, box-shadow 0.14s ease, background-color 0.14s ease;
}

.ai-form-grid textarea {
    height: 112px;
    padding: 8px 10px;
    resize: vertical;
}

.ai-key-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #c4ccd2;
}

.ai-key-dot.is-saved {
    background: #16a34a;
}

.ai-key-status-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    min-height: 58px;
    padding: 10px 12px;
    border: 1px solid #e8edf0;
    border-radius: 8px;
    background: #f8fafb;
}

.ai-key-status-main,
.ai-key-status-actions,
.ai-key-editor-foot {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    justify-content: space-between;
    flex-wrap: wrap;
}

.ai-key-status-main {
    flex: 1 1 auto;
    column-gap: 12px;
}

.ai-key-state-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    min-height: 0;
    padding: 0;
    border-radius: 0;
    background: transparent;
    color: var(--text-2);
    font-size: var(--fs-sm);
    font-weight: 600;
}

.ai-key-status-text {
    color: var(--text-2);
    font-size: var(--fs-sm);
    font-weight: 600;
}

.ai-key-count-text {
    color: var(--text-3);
    font-size: var(--fs-xs);
}

.ai-key-status-actions {
    flex: 0 0 auto;
    gap: 14px;
    min-height: 22px;
}

.ai-key-status-actions .hidden {
    display: inline-flex !important;
    visibility: hidden;
    pointer-events: none;
}

.ai-key-status-actions .ai-link-btn {
    padding: 0;
    color: var(--text-2);
    font-weight: 500;
}

#ai-test-connection-btn {
    color: var(--teal-dark);
    font-weight: 600;
}

#ai-test-connection-btn.is-loading {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--teal-dark);
    opacity: 1;
}

#ai-test-connection-btn.is-loading::before {
    content: "";
    width: 12px;
    height: 12px;
    box-sizing: border-box;
    border: 2px solid rgba(0, 128, 105, 0.18);
    border-top-color: var(--teal-dark);
    border-radius: 50%;
    animation: ai-session-spin 0.82s linear infinite;
}

.ai-link-btn.ai-link-danger {
    color: #b42318;
}

.ai-link-btn.ai-link-danger:hover {
    color: #912018;
}

.ai-key-editor.hidden {
    display: flex !important;
    max-height: 0;
    min-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
}

.ai-key-test-status.hidden {
    display: block !important;
    visibility: hidden;
    opacity: 0;
}

.ai-key-test-status {
    min-height: 32px;
    padding: 8px 10px;
    border: none;
    border-radius: 8px;
    background: #f5f7f8;
    color: var(--text-2);
    font-size: var(--fs-xs);
    line-height: 1.45;
    transition: opacity 0.14s ease, background-color 0.14s ease, color 0.14s ease;
}

.ai-key-test-status.is-success {
    box-shadow: inset 3px 0 0 #7cc795;
    background: #eef9f2;
    color: #18794e;
}

.ai-key-test-status.is-pending {
    box-shadow: inset 3px 0 0 rgba(0, 128, 105, 0.42);
    background: #f5faf8;
    color: var(--teal-dark);
}

.ai-key-test-status.is-error {
    box-shadow: inset 3px 0 0 #e09a90;
    background: #fef3f1;
    color: #b42318;
}

.ai-key-strategy-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 2px;
}

.ai-key-strategy-row.hidden {
    display: none;
}

.ai-key-strategy-row span {
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 600;
}

.ai-key-strategy-row select {
    width: auto;
    min-width: 132px;
    min-height: 34px;
}

.ai-key-list-panel {
    border: 1px solid #e8edf0;
    border-radius: 8px;
    background: #f9fbfb;
    padding: 8px;
    min-height: 58px;
}

.ai-key-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-key-empty {
    padding: 4px 2px;
    color: var(--text-3);
    font-size: var(--fs-sm);
}

.ai-key-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-height: 38px;
    padding: 7px 10px;
    border: 1px solid #e8edf0;
    border-radius: 8px;
    background: #ffffff;
}

.ai-key-item.is-active {
    border-color: rgba(0, 128, 105, 0.22);
    background: #f4fbf8;
}

.ai-key-item-main {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    width: 100%;
    min-width: 0;
    flex: 1 1 auto;
}

.ai-key-item-main input[type="radio"] {
    margin: 0;
    width: 16px;
    height: 16px;
    accent-color: var(--teal);
    flex: 0 0 auto;
}

.ai-key-item-body {
    min-width: 0;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 10px;
    flex: 1 1 auto;
}

.ai-key-item-title {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.ai-key-item-label {
    color: var(--text-1);
    font-size: var(--fs-sm);
    font-weight: 600;
}

.ai-key-item-badge {
    color: var(--teal-dark);
    font-size: var(--fs-xs);
}

.ai-key-item-meta {
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.ai-key-row-btn {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #9aa6ae;
    cursor: pointer;
    line-height: 1;
    flex: 0 0 auto;
}

.ai-key-row-btn:hover {
    background: #f1f4f6;
    color: var(--text-1);
}

.ai-key-editor {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 170px;
    min-height: 0;
    padding: 10px;
    border: 1px solid #e8edf0;
    border-radius: 8px;
    background: #ffffff;
    opacity: 1;
    visibility: visible;
    overflow: hidden;
    transition: max-height 0.16s ease, opacity 0.14s ease, padding 0.16s ease, border-width 0.16s ease;
}

.ai-key-editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 160px) minmax(0, 1fr);
    gap: 8px;
}

.ai-secret-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.ai-secret-input-wrap input {
    padding-right: 76px;
}

.ai-input-icon-btn {
    position: absolute;
    top: 50%;
    width: 28px;
    height: 28px;
    transform: translateY(-50%);
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-3);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.ai-input-icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-1);
}

.ai-input-icon-btn:disabled {
    cursor: default;
    opacity: 0.35;
}

.ai-input-icon-btn:disabled:hover {
    background: transparent;
    color: var(--text-3);
}

.ai-input-icon-btn svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

#ai-key-visibility-btn {
    right: 38px;
}

#ai-clear-key-btn {
    right: 7px;
    font-size: var(--fs-lg);
    line-height: 1;
}

.ai-key-editor-note {
    color: var(--text-3);
    font-size: var(--fs-xs);
}

.ai-key-editor-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-provider-type-row.hidden,
.ai-custom-only.hidden,
.ai-base-url-row.hidden {
    display: none;
}

.ai-api-key-field,
.ai-model-tags-field,
.ai-base-url-row {
    grid-column: 1 / -1;
}

.ai-api-key-field {
    min-height: 232px;
}

.ai-model-tags-field {
    min-height: 220px;
}

.ai-model-manager {
    padding: 8px;
    border: 1px solid #e4eaee;
    border-radius: 8px;
    background: #ffffff;
    transition: border-color 0.14s ease, background-color 0.14s ease;
}

.ai-model-manager:focus-within {
    border-color: var(--teal);
}

.ai-enabled-model-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 180px;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.ai-enabled-model-row {
    min-height: 34px;
    padding: 6px 6px 6px 10px;
    border-radius: 7px;
    background: #f7f8fa;
    color: var(--text-1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: var(--fs-control);
    font-weight: 700;
}

.ai-enabled-model-row > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-enabled-model-empty {
    padding: 10px 8px;
    border-radius: 7px;
    background: #f8fafb;
    color: var(--text-3);
    font-size: var(--fs-control);
    text-align: center;
}

.ai-model-add-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.ai-model-add-row input {
    flex: 1 1 auto;
    min-width: 0;
    height: 34px;
    min-height: 34px;
    padding: 0 10px;
    border: 1px solid #e4eaee;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text-1);
    font-size: var(--fs-control);
    outline: none;
}

.ai-model-add-row input:focus {
    border-color: var(--teal);
}

.ai-model-catalog {
    margin-top: 10px;
    padding: 10px;
    border: 1px solid #e4eaee;
    border-radius: 8px;
    background: #fbfcfd;
}

.ai-model-catalog.hidden {
    display: none;
}

.ai-model-catalog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
    color: var(--text-2);
    font-size: var(--fs-control);
    font-weight: 750;
}

.ai-model-catalog-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-model-catalog-search {
    width: 100%;
    min-height: 34px;
    margin-bottom: 8px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text-1);
    font-size: var(--fs-control);
    outline: none;
}

.ai-model-catalog-search:focus {
    border-color: var(--teal);
}

.ai-model-catalog-list {
    display: grid;
    gap: 4px;
    max-height: 260px;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.ai-model-catalog-row {
    width: 100%;
    min-height: 38px;
    padding: 6px 8px;
    border: none;
    border-radius: 7px;
    background: transparent;
    color: var(--text-1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: var(--fs-control);
    text-align: left;
    cursor: pointer;
}

.ai-model-catalog-row:hover {
    background: var(--bg-hover);
}

.ai-model-catalog-row.is-enabled {
    background: #f0fffb;
    color: var(--teal-dark);
    font-weight: 700;
}

.ai-model-catalog-row > span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ai-model-catalog-row > small {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #eef3f6;
    color: var(--text-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 800;
    line-height: 1;
}

.ai-model-catalog-row.is-enabled > small {
    background: #e5f8f3;
    color: var(--teal-dark);
}

.ai-model-catalog-empty {
    padding: 10px 8px;
    color: var(--text-3);
    font-size: var(--fs-control);
    text-align: center;
}

.ai-model-row-action {
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #a0abb3;
    cursor: pointer;
    line-height: 1;
}

.ai-model-row-action:hover {
    background: #e8edf0;
    color: var(--text-1);
}

#ai-model-tag-input {
    border-style: solid;
}

.ai-config-actions {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    gap: 8px;
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.ai-config-action-spacer {
    flex: 1 1 auto;
    min-width: 0;
}

.ai-danger-btn {
    min-height: 36px;
    padding: 0 12px;
    border: 1px solid #f3b4aa;
    border-radius: 8px;
    background: #fff5f2;
    color: #b42318;
    font-size: var(--fs-control);
    cursor: pointer;
}

.ai-danger-btn:hover {
    background: #fff1f0;
}

.ai-danger-btn.hidden {
    display: none;
}

.ai-model-list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ai-link-btn {
    border: none;
    background: transparent;
    color: var(--text-2);
    font-size: var(--fs-sm);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.ai-link-btn:hover {
    color: var(--teal-dark);
}

.ai-link-btn:disabled {
    color: var(--text-3);
    cursor: default;
    opacity: 0.55;
}

.ai-link-btn:disabled:hover {
    color: var(--text-3);
}

.ai-model-list-head .ai-link-btn {
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid #e4ebee;
    border-radius: 999px;
    background: #f8fafb;
    color: var(--teal-dark);
    font-weight: 600;
}

.ai-model-list-head .ai-link-btn:hover {
    border-color: rgba(0, 128, 105, 0.2);
    background: #f3faf7;
    color: var(--teal-dark);
}

.ai-model-list-head .ai-link-btn:disabled,
.ai-model-list-head .ai-link-btn:disabled:hover {
    border-color: #e8edf0;
    background: #f8fafb;
    color: var(--text-3);
}

.ai-config-actions .ai-clear-btn {
    border-color: #e7ecef;
    color: var(--text-3);
}

.ai-config-actions .ai-clear-btn:hover {
    background: #f7f9fa;
    color: var(--text-2);
}


.reasoning-box {
    margin-bottom: 8px;
    padding: 0 12px 10px;
    border-left: 3px solid #008069;
    border-radius: 8px;
    background: rgba(0, 128, 105, 0.1);
    color: #3e515a;
    font-size: var(--fs-sm);
    line-height: var(--lh-control);
    text-align: left;
}

.reasoning-box summary {
    position: sticky;
    top: 8px;
    z-index: 1;
    margin: 0 -12px 8px;
    padding: 10px 12px;
    border-radius: 6px;
    background: rgba(231, 245, 241, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    cursor: pointer;
    color: var(--teal-dark);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.reasoning-summary-title {
    flex-shrink: 0;
}

.reasoning-summary-time {
    min-width: 0;
    color: #4f636b;
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    font-weight: 600;
}

.reasoning-summary-action {
    margin-left: auto;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 600;
}

.reasoning-box:not([open]) {
    padding-bottom: 0;
}

.reasoning-box:not([open]) summary {
    margin-bottom: 0;
}

.reasoning-content {
    overflow-wrap: anywhere;
}

.reasoning-collapse-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 7px 10px;
    border: 1px solid rgba(0, 128, 105, 0.18);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.58);
    color: var(--teal-dark);
    font-size: var(--fs-sm);
    font-weight: 700;
    cursor: pointer;
}

.reasoning-collapse-btn:hover {
    background: rgba(255, 255, 255, 0.82);
}

.md-p {
    margin: 0 0 0.55em;
}

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

.md-render-block {
    contain: layout style;
}

.md-render-block + .md-render-block {
    margin-top: 0.35em;
}

.md-heading {
    margin: 0.55em 0 0.42em;
    line-height: var(--lh-tight);
    font-weight: 700;
    color: var(--text-1);
}

.md-heading:first-child {
    margin-top: 0;
}

.md-heading-1 {
    font-size: var(--fs-xl);
    padding-bottom: 0.18em;
    border-bottom: 1px solid rgba(17, 27, 33, 0.1);
}

.md-heading-2 {
    font-size: var(--fs-lg);
}

.md-heading-3 {
    font-size: var(--fs-title);
}

.md-heading-4,
.md-heading-5,
.md-heading-6 {
    font-size: var(--fs-body);
}

.md-heading-5,
.md-heading-6 {
    color: var(--text-2);
}

.md-list {
    margin: 0.35em 0 0.65em 1.35em;
}

.md-list li {
    margin: 0.25em 0;
    padding-left: 0.05em;
}

.md-blockquote {
    margin: 0.55em 0;
    padding: 6px 12px;
    border-left: 3px solid rgba(0, 128, 105, 0.5);
    color: var(--text-2);
    background: rgba(0, 128, 105, 0.06);
    border-radius: 0 8px 8px 0;
}

.md-table-wrap {
    max-width: 100%;
    margin: 0.65em 0;
    overflow-x: auto;
}

.md-table {
    width: max-content;
    min-width: min(100%, 420px);
    border-collapse: collapse;
    font-size: var(--fs-sm);
    line-height: var(--lh-control);
}

.md-table th,
.md-table td {
    padding: 7px 10px;
    border: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

.md-table th {
    background: rgba(17, 27, 33, 0.05);
    color: var(--text-1);
    font-weight: 700;
}

.md-inline-code {
    padding: 1px 5px;
    border-radius: 4px;
    border: 1px solid rgba(17, 27, 33, 0.08);
    background: rgba(17, 27, 33, 0.06);
    color: #0b3b4a;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    line-height: 1.45;
    white-space: break-spaces;
}

.md-math-inline {
    display: inline;
}

.md-math-inline.is-fallback {
    padding: 0 2px;
    font-family: "Cambria Math", "Times New Roman", serif;
    font-style: italic;
}

.md-math-block {
    max-width: 100%;
    margin: 8px 0;
    overflow-x: auto;
    overflow-y: hidden;
}

.md-math-block.is-fallback {
    padding: 8px 10px;
    border-radius: 8px;
    background: rgba(17, 27, 33, 0.05);
    font-family: "Cambria Math", "Times New Roman", serif;
    font-size: var(--fs-title);
    text-align: center;
}

.math-frac {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 1.2em;
    margin: 0 2px;
    vertical-align: middle;
    line-height: 1.05;
    font-size: 0.92em;
}

.math-frac span:first-child {
    padding: 0 2px 1px;
    border-bottom: 1px solid currentColor;
}

.math-frac span:last-child {
    padding: 1px 2px 0;
}

.bubble mjx-container {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
}

.bubble mjx-container[jax="CHTML"][display="true"] {
    margin: 0.45em 0;
}

.md-code-wrap {
    position: relative;
    margin: 8px 0;
    overflow: hidden;
    border-radius: 8px;
    background: #111b21;
    color: #e9edef;
}

.md-code-head {
    min-height: 32px;
    padding: 5px 44px 5px 12px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    border-bottom: 1px solid rgba(233, 237, 239, 0.14);
    color: rgba(233, 237, 239, 0.72);
    font-family: var(--font-mono);
    font-size: var(--fs-xs);
    line-height: var(--lh-control);
}

.code-copy-btn,
.msg-action-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: var(--text-2);
    cursor: pointer;
    line-height: 1;
}

.code-copy-btn svg,
.msg-action-btn svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
    pointer-events: none;
}

.code-copy-btn {
    position: absolute;
    top: 4px;
    right: 8px;
    background: rgba(233, 237, 239, 0.1);
    color: #e9edef;
}

.code-copy-btn:hover,
.msg-action-btn:hover {
    background: rgba(17, 27, 33, 0.06);
    border-color: rgba(0, 128, 105, 0.36);
    color: var(--teal-dark);
}

.code-copy-btn:hover {
    background: rgba(233, 237, 239, 0.18);
    color: #ffffff;
}

.msg-action-btn.active {
    background: rgba(0, 128, 105, 0.12);
    color: var(--teal-dark);
}

.msg-action-btn.is-done {
    background: rgba(0, 128, 105, 0.12);
    border-color: rgba(0, 128, 105, 0.28);
    color: var(--teal-dark);
}

.msg-action-btn.is-error {
    background: rgba(180, 35, 24, 0.08);
    border-color: rgba(180, 35, 24, 0.25);
    color: #b42318;
}

.msg-action-btn.is-danger:hover {
    background: rgba(180, 35, 24, 0.08);
    border-color: rgba(180, 35, 24, 0.25);
    color: #b42318;
}

.md-code-block {
    margin: 0;
    padding: 10px 12px;
    overflow-x: auto;
    background: transparent;
    color: inherit;
    font-family: var(--font-mono);
    font-size: var(--fs-sm);
    line-height: var(--lh-control);
}

.hamburger {
    display: none;
    border: none;
    background: none;
    color: var(--text-2);
    cursor: pointer;
}

.msgs {
    position: relative;
    z-index: 1;
    flex: 1;
    overflow-y: auto;
    overflow-anchor: none;
    padding: 22px clamp(20px, 4vw, 48px) 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#msg-list {
    width: min(100%, 1080px);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.load-earlier-chat {
    display: none;
    align-self: center;
    width: min(100%, 1080px);
    border: 1px solid rgba(17, 27, 33, 0.12);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.86);
    color: var(--text-2);
    padding: 8px 12px;
    font-size: var(--fs-sm);
    cursor: pointer;
}

.load-earlier-chat.show {
    display: block;
}

.load-earlier-chat:disabled {
    cursor: default;
    opacity: 0.68;
}

.plus-menu-wrap {
    position: relative;
    flex-shrink: 0;
}

.plus-menu-wrap.hidden {
    display: none;
}

.plus-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: #ffffff;
    color: var(--text-2);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.15s ease, background 0.15s ease;
}

.plus-btn:hover {
    color: var(--teal-dark);
    background: #f8fffd;
}

.plus-menu {
    display: none;
    position: absolute;
    bottom: 44px;
    left: 0;
    background: #fff;
    border: 1px solid rgba(17, 27, 33, 0.12);
    border-radius: 10px;
    box-shadow: 0 2px 12px rgba(17, 27, 33, 0.12);
    min-width: 150px;
    padding: 4px;
    z-index: 20;
}

.plus-menu.show {
    display: block;
}

.plus-menu button {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-1);
    font-size: var(--fs-base);
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
}

.plus-menu button.hidden {
    display: none;
}

.plus-menu button svg {
    flex-shrink: 0;
    color: var(--text-2);
}

.plus-menu button:hover {
    background: rgba(17, 27, 33, 0.06);
}

.plus-menu button.active {
    color: var(--teal-dark);
    background: #f1fbf8;
}

.plus-toggle-state {
    margin-left: auto;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-weight: 700;
}

.modal-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(17, 27, 33, 0.12);
    border-radius: 8px;
    font-size: var(--fs-base);
    color: var(--text-1);
    background: var(--bg-1);
    resize: vertical;
    font-family: inherit;
    box-sizing: border-box;
}

.modal-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid rgba(17, 27, 33, 0.12);
    border-radius: 8px;
    font-size: var(--fs-base);
    color: var(--text-1);
    background: var(--bg-1);
    box-sizing: border-box;
    font-family: inherit;
}

.modal.schedule-modal {
    width: min(430px, calc(100vw - 40px));
    max-width: none;
    max-height: calc(100dvh - 40px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal.schedule-modal.has-schedules {
    width: min(760px, calc(100vw - 40px));
}

.schedule-body {
    display: flex;
    gap: 20px;
    min-height: 0;
    overflow: hidden;
}

.schedule-form-col {
    flex: 0 0 320px;
    min-width: 0;
}

.schedule-list-col {
    flex: 1;
    min-width: 0;
    max-height: 292px;
    border-left: 1px solid rgba(17, 27, 33, 0.08);
    padding-left: 20px;
    display: none;
    overflow: hidden;
}

.schedule-list-col.has-items {
    display: flex;
    flex-direction: column;
}

.schedule-mode-tabs {
    display: flex;
    gap: 0;
    background: rgba(17, 27, 33, 0.04);
    border-radius: 8px;
    padding: 3px;
    margin-bottom: 12px;
}

.schedule-mode-tab {
    flex: 1;
    padding: 7px 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-2);
    font-size: var(--fs-sm);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.schedule-mode-tab.active {
    background: #fff;
    color: var(--text-1);
    box-shadow: 0 1px 3px rgba(17, 27, 33, 0.08);
    font-weight: 500;
}

.delay-input-group {
    display: flex;
    gap: 10px;
}

.delay-field {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
}

.delay-field input {
    flex: 1;
    min-width: 0;
}

.delay-label {
    font-size: var(--fs-sm);
    color: var(--text-3);
    white-space: nowrap;
}

.schedule-list-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 0 6px;
    font-size: var(--fs-sm);
    color: var(--text-3);
    font-weight: 500;
    flex-shrink: 0;
}

.schedule-list-count {
    font-weight: 400;
}

.schedule-list {
    flex: 1;
    overflow-y: auto;
}

.schedule-list-em {
    color: var(--text-3);
    font-size: var(--fs-sm);
    padding: 6px 0;
}

.schedule-item {
    display: flex;
    align-items: flex-start;
    padding: 7px 0;
}

.schedule-item + .schedule-item {
    border-top: 1px solid rgba(17, 27, 33, 0.06);
}

.schedule-item-meta {
    flex: 1;
    min-width: 0;
    line-height: 1.45;
}

.schedule-item-text {
    font-size: var(--fs-sm);
    color: var(--text-1);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.schedule-item-time {
    font-size: var(--fs-xs);
    color: var(--text-3);
}

.schedule-item-del {
    flex-shrink: 0;
    margin-left: 8px;
    padding: 0 4px;
    border: none;
    background: transparent;
    color: var(--text-3);
    cursor: pointer;
    font-size: var(--fs-lg);
    line-height: 1.4;
    transition: color 0.15s ease;
}

.schedule-item-del:hover {
    color: var(--danger);
}

.scroll-bottom-btn {
    position: absolute;
    left: 50%;
    bottom: 96px;
    z-index: 5;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(17, 27, 33, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.96);
    color: var(--text-1);
    box-shadow: 0 6px 18px rgba(17, 27, 33, 0.14);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: translate(-50%, 8px) scale(0.96);
    transition: opacity 0.16s ease, transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}

.scroll-bottom-btn.show {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, 0) scale(1);
}

.scroll-bottom-btn:hover {
    border-color: rgba(0, 128, 105, 0.22);
    box-shadow: 0 8px 22px rgba(17, 27, 33, 0.18);
}

.scroll-bottom-btn svg {
    width: 22px;
    height: 22px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.date-div {
    text-align: center;
    margin: 4px 0 12px;
}

.date-div span {
    padding: 3px 10px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.28);
    color: #fff;
    font-size: var(--fs-xs);
    font-family: var(--font-mono);
}

.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 9px;
}

.msg-row.mine {
    justify-content: flex-end;
}

.msg-col {
    max-width: min(calc(66% - 34px), 64ch);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.msg-row.mine .msg-col {
    align-items: flex-end;
}

.msg-name {
    padding: 0 4px;
    color: var(--text-3);
    font-size: var(--fs-xs);
    font-family: var(--font-mono);
}

.bubble {
    width: fit-content;
    max-width: 100%;
    padding: 10px 14px 8px;
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(17, 27, 33, 0.06);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    letter-spacing: 0;
    text-align: left;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.bubble.in {
    background: var(--bg-bubble-in);
    border-bottom-left-radius: 5px;
}

.bubble.out {
    background: var(--teal-light);
    border-bottom-right-radius: 5px;
    color: #0a2e1a;
}

.bubble-body {
    display: block;
    max-width: var(--line-measure);
}

.bubble-reply-preview {
    display: flex;
    flex-direction: column;
    gap: 2px;
    width: 100%;
    margin-bottom: 8px;
    box-sizing: border-box;
    padding: 0 0 0 10px;
    border: 0;
    border-left: 3px solid rgba(0, 128, 105, 0.3);
    background: transparent;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.16s ease, background-color 0.16s ease;
}

.bubble-reply-preview:hover {
    border-left-color: rgba(0, 128, 105, 0.58);
    background: rgba(0, 128, 105, 0.06);
}

.bubble.out .bubble-reply-preview {
    padding: 7px 10px 7px 11px;
    border-left-width: 4px;
    border-left-color: #38b66f;
    border-radius: 7px;
    background: rgba(0, 128, 105, 0.07);
}

.bubble.out .bubble-reply-preview:hover {
    border-left-color: #24a55f;
    background: rgba(0, 128, 105, 0.1);
}

.bubble.out .bubble-reply-author {
    color: #168a5a;
}

.bubble.out .bubble-reply-text {
    color: #24343a;
}

.bubble-reply-author {
    font-size: var(--fs-xs);
    color: var(--teal-dark);
    font-weight: 700;
}

.bubble-reply-text {
    font-size: var(--fs-sm);
    color: var(--text-2);
}

.msg-actions {
    min-height: 26px;
    margin: 5px 0 1px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    flex-wrap: wrap;
    color: #68737a;
}

.msg-row.mine .msg-actions {
    justify-content: flex-end;
}

.msg-row.mine .msg-action-btn {
    color: #185b37;
}

.msg-row.is-selected .bubble {
    box-shadow: 0 0 0 2px rgba(0, 128, 105, 0.14), var(--shadow);
}

.msg-row.is-selectable {
    cursor: pointer;
}

.msg-row.is-selectable .msg-col,
.msg-row.is-selectable .avatar {
    cursor: pointer;
}

.msg-row.is-selectable .msg-action-btn,
.msg-row.is-selectable .bubble-reply-preview,
.msg-row.is-selectable a {
    cursor: pointer;
}

.msg-select-toggle {
    width: 22px;
    height: 22px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--teal-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    cursor: pointer;
}

.msg-select-toggle.active {
    border-color: var(--teal);
    background: #f0fffb;
}

.bubble-link {
    color: #0a5c8a;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
}

.bubble-foot {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 2px;
}

.bubble-edited {
    font-size: var(--fs-2xs);
    color: var(--text-3);
}

.bubble-time {
    font-size: var(--fs-2xs);
    color: rgba(17, 27, 33, 0.58);
}

.typing-row {
    display: none;
    align-items: flex-end;
    gap: 6px;
    width: min(100%, 1080px);
    margin: 0 auto;
}

.typing-row.show {
    display: flex;
}

.typing-bubble {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 11px 14px;
    border-radius: 10px;
    border-bottom-left-radius: 2px;
    background: var(--bg-bubble-in);
    box-shadow: var(--shadow);
}

.typing-bubble span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-3);
    animation: bounce 1.2s infinite;
}

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

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

@keyframes bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
    }

    30% {
        transform: translateY(-5px);
    }
}

.input-row {
    position: relative;
    z-index: 3;
    padding: 12px clamp(18px, 4vw, 48px) calc(14px + env(safe-area-inset-bottom));
    background-color: var(--bg-chat);
    background-image: var(--chat-pattern);
    background-size: var(--chat-pattern-size);
    background-attachment: fixed;
}

.composer-state-stack {
    display: none;
    flex-direction: column;
    gap: 8px;
    max-width: 760px;
    margin: 0 auto 8px;
}

.composer-state-stack.show {
    display: flex;
}

.composer-state-chip {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.96);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.composer-state-chip.is-warning {
    border-color: rgba(218, 155, 0, 0.26);
    background: #fff8e6;
}

.composer-state-chip.is-selection {
    border-color: rgba(0, 128, 105, 0.2);
    background: #f0fffb;
}

.composer-state-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.composer-state-label {
    font-size: var(--fs-xs);
    color: var(--text-2);
    font-weight: 700;
}

.composer-state-text {
    font-size: var(--fs-sm);
    color: var(--text-1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.composer-state-chip > button,
.composer-state-actions > button {
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #fff;
    color: var(--text-2);
    cursor: pointer;
}

.composer-state-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.chat-context-menu {
    position: fixed;
    z-index: 90;
    display: none;
    width: 136px;
    padding: 5px;
    border: 1px solid rgba(255, 255, 255, 0.48);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.68);
    box-shadow: 0 14px 30px rgba(17, 27, 33, 0.14);
    backdrop-filter: blur(18px) saturate(145%);
    -webkit-backdrop-filter: blur(18px) saturate(145%);
}

.chat-context-menu.show {
    display: block;
}

.chat-context-menu button {
    width: 100%;
    min-height: 32px;
    padding: 0 10px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-1);
    font-size: var(--fs-sm);
    text-align: left;
    cursor: pointer;
}

.chat-context-menu button:hover {
    background: var(--bg-hover);
}

.chat-context-menu button.is-danger {
    color: #b42318;
}

.input-inner {
    max-width: 760px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    border-radius: 26px;
}

.attach-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: #ffffff;
    color: var(--text-2);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.attach-btn:hover {
    color: var(--teal-dark);
    background: #f8fffd;
}

.composer-input-stack {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg-input {
    min-height: 44px;
    max-height: 144px;
    overflow-y: auto;
    padding: 10px 16px;
    border-radius: 24px;
    background: var(--bg-input);
    box-shadow: var(--shadow);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    letter-spacing: 0;
    word-break: break-word;
    white-space: pre-wrap;
    cursor: text;
    outline: none;
    transition: box-shadow 0.18s ease, background-color 0.18s ease;
}

.msg-input:focus {
    background: #ffffff;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1);
}

.msg-input.has-md-preview {
    border-radius: 18px 18px 10px 10px;
}

.msg-input:empty::before {
    content: attr(data-placeholder);
    color: var(--text-3);
}

.composer-md-preview {
    display: none;
    max-height: 220px;
    overflow-y: auto;
    padding: 10px 16px;
    border: 1px solid rgba(0, 128, 105, 0.16);
    border-radius: 10px 10px 18px 18px;
    background: rgba(255, 255, 255, 0.82);
    box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
    color: var(--text-1);
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    word-break: break-word;
}

.composer-md-preview.show {
    display: block;
}

.composer-md-preview .md-p:first-child,
.composer-md-preview .md-heading:first-child,
.composer-md-preview .md-list:first-child,
.composer-md-preview .md-blockquote:first-child,
.composer-md-preview .md-code-wrap:first-child {
    margin-top: 0;
}

.composer-md-preview .md-p:last-child,
.composer-md-preview .md-list:last-child,
.composer-md-preview .md-blockquote:last-child,
.composer-md-preview .md-code-wrap:last-child {
    margin-bottom: 0;
}

.browser-compat-banner {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 120;
    max-width: 760px;
    margin: 0 auto;
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
    font-size: var(--fs-sm);
    line-height: var(--lh-body);
}

.browser-compat-banner.is-warning {
    border: 1px solid rgba(0, 128, 105, 0.28);
    background: #f0fffb;
    color: var(--text-1);
}

.browser-compat-banner.is-error {
    border: 1px solid rgba(176, 54, 54, 0.24);
    background: #fff3f1;
    color: #7f1d1d;
}

.send-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: var(--teal);
    box-shadow: 0 2px 8px rgba(0, 168, 132, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.send-btn:hover {
    background: var(--teal-dark);
}

.send-btn.is-stop {
    background: #ffffff;
    box-shadow: var(--shadow);
}

.send-btn.is-stop:hover {
    background: var(--bg-hover);
}

.send-stop-icon {
    width: 13px;
    height: 13px;
    border-radius: 3px;
    background: var(--text-2);
}

.attachment-strip {
    max-width: 760px;
    margin: 8px auto 0;
    display: none;
}

.attachment-strip.show {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: min(100%, 420px);
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: var(--shadow);
}

.attachment-chip-preview,
.attachment-chip-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    flex: 0 0 auto;
}

.attachment-chip-preview {
    display: block;
    object-fit: cover;
    background: #dfe9ee;
}

.attachment-chip-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #dbe7ec, #edf4f7);
    color: #45606e;
    font-size: var(--fs-xs);
    font-weight: 700;
    letter-spacing: 0;
}

.attachment-chip-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1 1 auto;
    min-width: 0;
}

.attachment-chip-name {
    font-size: var(--fs-control);
    font-weight: 600;
    color: var(--text-1);
    max-width: min(60vw, 360px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-chip-meta {
    font-size: var(--fs-xs);
    color: var(--text-3);
    font-family: var(--font-mono);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-chip-remove {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: #eef3f6;
    color: var(--text-2);
    cursor: pointer;
}

.attachment-chip-remove:hover {
    background: #dbe5ea;
}

.bubble-file {
    display: block;
    margin-bottom: 8px;
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.55);
}

.bubble.out .bubble-file {
    background: rgba(255, 255, 255, 0.45);
}

.bubble-file-image {
    padding: 8px;
}

.bubble-file-link {
    display: block;
    width: 100%;
    padding: 0;
    border: none;
    background: transparent;
    color: inherit;
    text-decoration: none;
    text-align: left;
    cursor: pointer;
}

.bubble-image-link {
    overflow: hidden;
}

.bubble-image-preview {
    display: block;
    width: min(280px, 58vw);
    max-width: 100%;
    max-height: 280px;
    object-fit: cover;
    border-radius: 12px;
    background: rgba(214, 227, 236, 0.82);
    margin-bottom: 10px;
}

.bubble-file-image.image-only .bubble-image-preview {
    margin-bottom: 0;
}

.bubble-file-name {
    display: block;
    font-weight: 600;
    color: #0f5132;
}

.bubble.in .bubble-file-name {
    color: #12415c;
}

.bubble-file-meta {
    display: block;
    margin-top: 4px;
    font-size: var(--fs-xs);
    color: var(--text-2);
    font-family: var(--font-mono);
}

.bubble-caption {
    display: block;
    white-space: pre-wrap;
}

.drawer-backdrop {
    display: none;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(17, 27, 33, 0.38);
    backdrop-filter: blur(5px);
    z-index: 100;
}

.modal-overlay.show {
    display: flex;
}

.modal-overlay.show .modal {
    animation: modalEnter 0.18s ease-out;
}

.modal {
    width: 100%;
    max-width: 380px;
    padding: 28px 24px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 24px 60px rgba(17, 27, 33, 0.18);
}

.profile-modal {
    max-width: 360px;
}

.modal-title {
    font-size: var(--fs-xl);
    font-weight: 700;
    text-align: center;
}

.modal-sub {
    margin-top: 4px;
    margin-bottom: 18px;
    color: var(--text-3);
    font-size: var(--fs-sm);
    text-align: center;
}

.modal-field {
    margin-bottom: 14px;
}

.modal-field label {
    display: block;
    margin-bottom: 5px;
    color: var(--text-2);
    font-size: var(--fs-sm);
}

.modal-field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: var(--fs-body);
    outline: none;
}

.modal-field input:focus {
    border-color: var(--teal);
}

.modal-actions {
    margin-top: 18px;
    display: flex;
    gap: 10px;
}

.modal-submit,
.modal-cancel {
    padding: 10px 14px;
    border-radius: 8px;
    font-size: var(--fs-body);
    cursor: pointer;
}

.modal-submit {
    flex: 1;
    border: none;
    background: var(--teal);
    color: #fff;
}

.modal-submit:hover {
    background: var(--teal-dark);
}

.modal-cancel {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-2);
}

.modal-cancel:hover {
    background: var(--bg-hover);
}

.image-viewer-overlay {
    position: fixed;
    inset: 0;
    z-index: 130;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: rgba(10, 16, 20, 0.64);
    backdrop-filter: blur(18px) saturate(0.92);
}

.image-viewer-overlay.show {
    display: flex;
}

.image-viewer-panel {
    position: relative;
    width: 100%;
    height: 100%;
    min-height: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
}

.image-viewer-toolbar {
    position: absolute;
    top: calc(18px + env(safe-area-inset-top));
    left: 18px;
    right: 18px;
    z-index: 2;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: #f4f7f8;
    pointer-events: none;
}

.image-viewer-title {
    min-width: 0;
    max-width: min(52vw, 520px);
    padding: 10px 14px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(14, 22, 28, 0.52);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.14);
    backdrop-filter: blur(18px) saturate(1.1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: var(--fs-control);
    font-weight: 650;
    pointer-events: auto;
}

.image-viewer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    padding: 4px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    background: rgba(14, 22, 28, 0.52);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.14);
    backdrop-filter: blur(18px) saturate(1.1);
    pointer-events: auto;
}

.image-viewer-actions button,
.image-viewer-actions a {
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: #f4f7f8;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    line-height: 1;
    cursor: pointer;
}

.image-viewer-actions svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.image-viewer-actions button:hover,
.image-viewer-actions a:hover {
    background: rgba(255, 255, 255, 0.14);
}

.image-viewer-stage {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(82px + env(safe-area-inset-top)) 28px calc(28px + env(safe-area-inset-bottom));
    cursor: grab;
    touch-action: none;
    user-select: none;
}

.image-viewer-stage.is-dragging {
    cursor: grabbing;
}

.image-viewer-stage img {
    max-width: none;
    max-height: none;
    border-radius: 8px;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.36);
    transform-origin: center center;
    transition: transform 0.08s ease;
    user-select: none;
    pointer-events: none;
}

.image-viewer-stage.is-dragging img {
    transition: none;
    will-change: transform;
}

.hidden {
    display: none !important;
}

.btn-auth-secondary {
    border-color: rgba(17, 27, 33, 0.12);
    background: rgba(255, 255, 255, 0.9);
    color: var(--text-2);
}

.btn-auth-secondary:hover {
    background: #f5f7f8;
}

.ai-session-head-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    white-space: nowrap;
}

.ai-session-head-btn {
    width: auto;
    min-width: 44px;
    min-height: 26px;
    height: 26px;
    padding: 0 10px;
    border: 1px solid rgba(17, 27, 33, 0.08);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    color: var(--text-2);
    cursor: pointer;
    font-size: var(--fs-xs);
    font-weight: 700;
    backdrop-filter: blur(10px);
}

.ai-session-head-btn:hover {
    background: rgba(255, 255, 255, 0.96);
    color: var(--text-1);
}

.ai-session-head .ai-session-head-btn {
    width: auto;
    min-width: 44px;
    height: 26px;
    line-height: 1;
}

.ai-session-head-btn:disabled {
    cursor: default;
    opacity: 0.48;
}

.ai-session-head-btn-icon {
    width: 26px;
    min-width: 26px;
    height: 26px;
    padding: 0;
    line-height: 1;
}

.ai-session-head .ai-session-head-btn-icon {
    width: 26px;
    min-width: 26px;
}

.ai-session-item {
    border-radius: 12px;
}

.ai-session-item:hover {
    border-color: rgba(0, 128, 105, 0.12);
    background: rgba(0, 128, 105, 0.025);
    box-shadow: 0 1px 4px rgba(17, 27, 33, 0.045);
}

.ai-session-item.active {
    background: rgba(240, 255, 251, 0.94);
    box-shadow: inset 3px 0 0 var(--teal);
}

.ai-session-item.is-selected {
    border-color: rgba(0, 128, 105, 0.18);
    background: rgba(0, 128, 105, 0.08);
}

.ai-session-select {
    width: 24px;
    height: 24px;
    margin-left: 4px;
    border: 1px solid rgba(17, 27, 33, 0.12);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.86);
    color: var(--teal-dark);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: 0 0 auto;
}

.ai-session-select.active {
    border-color: rgba(0, 128, 105, 0.3);
    background: rgba(0, 128, 105, 0.14);
}

.msg-row {
    position: relative;
    padding: 2px 6px;
    margin: 0 -6px;
    border-radius: 18px;
    content-visibility: auto;
    contain-intrinsic-size: 86px;
    transition: background-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.msg-row.is-selected {
    background: linear-gradient(90deg, rgba(0, 128, 105, 0.08), rgba(0, 128, 105, 0.02));
}

.msg-row.is-selected .bubble {
    box-shadow: 0 0 0 2px rgba(0, 128, 105, 0.18), 0 10px 28px rgba(0, 128, 105, 0.12), var(--shadow);
}

.msg-row.is-context-open {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.42), rgba(0, 128, 105, 0.07));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.24);
}

.msg-row.is-context-open .bubble {
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.38), 0 16px 34px rgba(17, 27, 33, 0.12), var(--shadow);
}

.msg-row.is-jump-target {
    animation: chat-reply-jump 1.35s ease;
}

.msg-row.is-jump-target .bubble {
    box-shadow: 0 0 0 2px rgba(0, 128, 105, 0.2), 0 14px 30px rgba(0, 128, 105, 0.14), var(--shadow);
}

@keyframes chat-reply-jump {
    0% {
        background: rgba(0, 128, 105, 0);
    }
    18% {
        background: rgba(0, 128, 105, 0.12);
    }
    100% {
        background: rgba(0, 128, 105, 0);
    }
}

.msg-select-toggle.active {
    box-shadow: 0 6px 16px rgba(0, 128, 105, 0.18);
}

.chat-context-menu {
    width: 136px;
    padding: 6px;
    border: 1px solid rgba(255, 255, 255, 0.42);
    border-radius: 12px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.76), rgba(248, 251, 251, 0.58));
    box-shadow: 0 18px 34px rgba(17, 27, 33, 0.13), inset 0 1px 0 rgba(255, 255, 255, 0.62);
    backdrop-filter: blur(22px) saturate(155%);
    -webkit-backdrop-filter: blur(22px) saturate(155%);
}

.chat-context-menu button {
    min-height: 30px;
    padding: 0 10px;
    border-radius: 8px;
    font-size: var(--fs-sm);
    transition: background 0.14s ease, color 0.14s ease;
}

.chat-context-menu button:hover {
    background: rgba(0, 128, 105, 0.08);
    color: var(--teal-dark);
}

.attach-btn.hidden {
    display: none;
}

.dialog-overlay {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(17, 27, 33, 0.36);
    backdrop-filter: blur(5px);
}

.dialog-overlay.show {
    display: flex;
}

.dialog-overlay.show .dialog-card {
    animation: modalEnter 0.18s ease-out;
}

.dialog-card {
    width: min(420px, 100%);
    padding: 20px;
    border-radius: 14px;
    background: #ffffff;
    box-shadow: 0 24px 64px rgba(17, 27, 33, 0.2);
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 12px;
}

.dialog-icon {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: #fff4e5;
    color: #a15c00;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: var(--fs-title);
}

.dialog-icon.danger {
    background: #fff1f0;
    color: #b42318;
}

.dialog-content {
    min-width: 0;
}

.dialog-title {
    font-size: var(--fs-title);
    line-height: var(--lh-tight);
    font-weight: 700;
    color: var(--text-1);
}

.dialog-message {
    margin-top: 6px;
    font-size: var(--fs-body);
    line-height: var(--lh-body);
    color: var(--text-2);
    overflow-wrap: anywhere;
}

.dialog-actions {
    grid-column: 1 / -1;
    margin-top: 6px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.dialog-btn {
    min-height: 38px;
    padding: 0 15px;
    border-radius: 9px;
    font-size: var(--fs-control);
    cursor: pointer;
    transition: background-color 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.dialog-btn:active {
    transform: translateY(1px);
}

.dialog-cancel {
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text-2);
}

.dialog-cancel:hover {
    background: var(--bg-hover);
}

.dialog-confirm {
    border: 1px solid transparent;
    background: var(--teal);
    color: #ffffff;
}

.dialog-confirm:hover {
    background: var(--teal-dark);
}

.dialog-confirm.danger {
    background: #d92d20;
}

.dialog-confirm.danger:hover {
    background: #b42318;
}

@keyframes modalEnter {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }

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

@media (max-width: 768px) {
    .sidebar {
        width: 280px;
        min-width: 280px;
    }

    .chat-header-right {
        display: none;
    }

    .ai-settings-bar {
        align-items: center;
        padding: 10px 16px;
    }

    .ai-selector-group {
        flex: 1 1 100%;
        width: 100%;
    }

    .ai-model-switcher {
        max-width: none;
        width: 100%;
    }

    .ai-model-switcher-menu {
        width: 100%;
        max-width: none;
    }

    .composer-state-chip {
        align-items: flex-start;
        flex-direction: column;
    }

    .ai-config-panel {
        padding: 14px;
    }

    .ai-config-dialog {
        width: min(720px, 100%);
    }

    .ai-config-body {
        grid-template-columns: 1fr;
        overflow: auto;
    }

    .ai-provider-rail {
        min-height: 0;
        border-right: none;
        border-bottom: 1px solid var(--border);
        padding: 16px 18px;
    }

    .ai-provider-list {
        max-height: 170px;
    }

    .ai-config-head {
        min-height: 70px;
        padding: 16px 18px;
    }

    .ai-config-head::after {
        left: 18px;
        right: 18px;
    }

    .ai-provider-form {
        padding: 18px;
        overflow: visible;
    }

    .ai-form-grid {
        grid-template-columns: 1fr;
    }

    .msg-col {
        max-width: min(calc(78% - 34px), 60ch);
    }
}

@media (max-width: 540px) {
    .app {
        overflow: visible;
    }

    .drawer-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        opacity: 0;
        pointer-events: none;
        background: rgba(0, 0, 0, 0.4);
        transition: opacity 0.25s ease;
        z-index: 40;
    }

    .drawer-backdrop.show {
        opacity: 1;
        pointer-events: all;
    }

    body.sidebar-open .main {
        overscroll-behavior: contain;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 82vw;
        min-width: unset;
        max-width: 320px;
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.18);
        z-index: 50;
    }

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

    .hamburger {
        display: inline-flex;
    }

    .ai-selector-group {
        display: flex;
        width: 100%;
    }

    .ai-model-switcher-menu {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        z-index: 100;
        width: auto;
        max-width: none;
        max-height: min(74dvh, 620px);
        display: none;
        overflow: hidden;
        padding: 18px 14px calc(14px + env(safe-area-inset-bottom));
        border: 1px solid rgba(17, 27, 33, 0.1);
        border-width: 1px 0 0;
        border-radius: 22px 22px 0 0;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 -18px 44px rgba(17, 27, 33, 0.18);
        backdrop-filter: blur(18px) saturate(145%);
        -webkit-backdrop-filter: blur(18px) saturate(145%);
    }

    .ai-model-switcher-menu::before {
        content: "";
        display: block;
        width: 42px;
        height: 4px;
        margin: -4px auto 12px;
        border-radius: 999px;
        background: rgba(82, 99, 109, 0.28);
    }

    .ai-model-switcher.open .ai-model-switcher-menu {
        display: block;
    }

    .ai-model-switcher-options {
        max-height: calc(min(74dvh, 620px) - 114px - env(safe-area-inset-bottom));
        padding-right: 2px;
    }

    .ai-model-switcher-toolbar {
        align-items: stretch;
        gap: 8px;
    }

    .ai-model-switcher-search {
        height: 40px;
        border-radius: 12px;
    }

    .ai-switcher-action {
        min-height: 40px;
        border-radius: 12px;
    }

    .ai-model-switcher-provider {
        padding: 4px 2px 8px;
    }

    .ai-model-switcher-option {
        min-height: 42px;
        border-radius: 12px;
    }

    .ai-config-panel {
        align-items: flex-end;
        padding: 0;
    }

    .ai-config-dialog {
        width: 100%;
        height: auto;
        max-height: calc(96dvh - env(safe-area-inset-top));
        border-radius: 20px 20px 0 0;
    }

    .ai-config-head {
        min-height: 56px;
        padding: 12px 16px;
    }

    .ai-config-body {
        padding: 0;
        height: auto;
        max-height: calc(96dvh - 72px - env(safe-area-inset-top));
        overflow: auto;
    }

    .ai-provider-rail,
    .ai-provider-form {
        padding: 12px;
    }

    .ai-provider-rail {
        overflow: hidden;
    }

    .ai-provider-rail-head {
        margin-bottom: 8px;
    }

    .ai-provider-list {
        flex-direction: row;
        gap: 8px;
        max-height: none;
        padding-bottom: 2px;
        overflow-x: auto;
        overflow-y: hidden;
        scrollbar-gutter: stable;
    }

    .ai-provider-card {
        flex: 0 0 min(160px, 46vw);
        width: min(160px, 46vw);
        min-height: 38px;
    }

    .ai-provider-card .ai-provider-name {
        font-size: var(--fs-sm);
    }

    .ai-key-status-card {
        align-items: flex-start;
        flex-direction: column;
        padding: 10px;
    }

    .ai-key-status-actions,
    .ai-key-editor-foot {
        width: 100%;
        justify-content: space-between;
    }

    .ai-key-editor-grid {
        grid-template-columns: 1fr;
    }

    .ai-key-strategy-row {
        align-items: flex-start;
        flex-direction: column;
    }

    .ai-key-strategy-row select {
        width: 100%;
    }

    .ai-form-grid > label,
    .ai-form-grid > .ai-field,
    .ai-link-btn {
        font-size: var(--fs-control);
    }

    .ai-form-grid input,
    .ai-form-grid select,
    .ai-form-grid textarea {
        min-height: 38px;
        padding: 0 10px;
        font-size: var(--fs-control);
    }

    .ai-model-manager {
        padding: 8px;
    }

    .ai-enabled-model-list {
        max-height: 160px;
    }

    .ai-model-catalog-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .ai-model-catalog-actions {
        width: 100%;
    }

    .ai-model-catalog-actions .ai-link-btn {
        flex: 1 1 0;
        justify-content: center;
    }

    .ai-model-catalog-list {
        max-height: 220px;
    }

    #ai-model-tag-input {
        height: 34px;
        min-height: 34px;
        font-size: var(--fs-control);
    }

    .ai-config-actions {
        flex-wrap: wrap;
    }

    .ai-config-action-spacer {
        display: none;
    }

    .ai-config-actions .ai-save-btn,
    .ai-config-actions .ai-clear-btn {
        min-height: 42px;
        flex: 1 1 130px;
    }

    .ai-config-actions .ai-danger-btn {
        min-height: 42px;
        flex: 1 1 100%;
    }

    .ai-btn-text {
        display: none;
    }

    .main {
        position: fixed;
        left: 0;
        right: 0;
        top: 0;
        height: 100dvh;
        display: flex;
        flex-direction: column;
    }

    .chat-header {
        min-height: 56px;
        gap: 10px;
        padding: 8px 12px;
    }

    .chat-header .av-bot {
        width: 42px;
        height: 42px;
    }

    .chat-header-name {
        font-size: var(--fs-title);
        line-height: 1.2;
    }

    .chat-header-status {
        margin-top: 0;
        font-size: var(--fs-xs);
        line-height: 1.25;
    }

    .header-new-ai-btn {
        width: 42px;
        min-width: 42px;
        min-height: 42px;
        padding: 0;
        justify-content: center;
        border-radius: 50%;
        box-shadow: var(--shadow);
    }

    .header-new-ai-btn span:first-child {
        font-size: var(--fs-lg);
        line-height: 1;
    }

    .header-new-ai-btn span:last-child {
        display: none;
    }

    .ai-settings-bar {
        z-index: 80;
        padding: 6px 12px 8px;
        box-shadow: 0 1px 0 rgba(17, 27, 33, 0.06);
    }

    .ai-model-switcher-button {
        min-height: 44px;
        padding: 6px 10px;
        border-color: rgba(17, 27, 33, 0.1);
        border-radius: 14px;
        box-shadow: 0 8px 22px rgba(17, 27, 33, 0.08);
    }

    .ai-model-switcher-copy {
        display: grid;
        gap: 1px;
    }

    .ai-model-switcher-main {
        font-size: var(--fs-control);
        line-height: 1.18;
    }

    .ai-model-switcher-sub {
        font-size: var(--fs-2xs);
        line-height: 1.15;
    }

    .ai-model-switcher-sub::before {
        content: none;
    }

    .msgs {
        padding: 14px 12px 12px;
    }

    .input-row {
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
        box-shadow: 0 -1px 0 rgba(17, 27, 33, 0.04);
    }

    .input-inner {
        gap: 8px;
    }

    .plus-btn,
    .send-btn {
        width: 44px;
        height: 44px;
    }

    .msg-input {
        min-height: 44px;
        max-height: 116px;
        padding: 10px 14px;
    }

    .msg-col {
        max-width: min(calc(88% - 34px), 58ch);
    }

    .composer-state-actions {
        width: 100%;
    }

    .composer-state-actions > button {
        flex: 1 1 0;
    }

    .notif-bar {
        bottom: calc(76px + env(safe-area-inset-bottom));
        max-width: calc(100% - 24px);
    }

    .modal,
    .dialog-card {
        border-radius: 16px;
    }

    .modal-overlay {
        align-items: flex-end;
        padding: 10px;
    }

    .modal.schedule-modal,
    .modal.schedule-modal.has-schedules {
        width: 100%;
        max-height: calc(100dvh - 20px);
        padding: 24px;
        border-radius: 18px;
    }

    .schedule-body {
        flex-direction: column;
        gap: 14px;
        overflow: auto;
    }

    .schedule-form-col {
        flex: 0 0 auto;
        width: 100%;
    }

    .schedule-list-col {
        width: 100%;
        max-height: 180px;
        border-left: none;
        border-top: 1px solid rgba(17, 27, 33, 0.08);
        padding-left: 0;
        padding-top: 12px;
    }

    .plus-menu {
        bottom: 50px;
        min-width: 148px;
        border-radius: 12px;
        box-shadow: 0 12px 34px rgba(17, 27, 33, 0.18);
    }

    .dialog-card {
        padding: 18px;
    }

    .dialog-actions {
        justify-content: stretch;
    }

    .dialog-btn {
        flex: 1;
    }
}
