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

:root {
    --ios-bg: #F2F2F7;
    --ios-white: #FFFFFF;
    --ios-blue: #007AFF;
    --ios-green: #34C759;
    --ios-red: #FF3B30;
    --ios-orange: #FF9500;
    --ios-gray2: #AEAEB2;
    --ios-gray4: #D1D1D6;
    --ios-gray5: #E5E5EA;
    --ios-gray6: #F2F2F7;
    --ios-separator: #C6C6C8;
    --ios-text: #000000;
    --ios-text-secondary: #3C3C43;
    --ios-text-tertiary: #8E8E93;
    --ios-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
    --ios-shadow-lg: 0 10px 40px rgba(0,0,0,0.1);
    --ios-radius: 16px;
    --ios-radius-sm: 10px;
    --ios-radius-xs: 8px;
    --ios-transition: 0.25s cubic-bezier(0.25, 0.1, 0.25, 1);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
    background: var(--ios-bg);
    color: var(--ios-text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==================== Navbar ==================== */
.navbar {
    background: rgba(255,255,255,0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid rgba(0,0,0,0.08);
    position: sticky;
    top: 0;
    z-index: 100;
    height: 48px;
}

.nav-container {
    max-width: 100%;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 48px;
    padding: 0 16px;
}

.nav-brand {
    font-size: 17px;
    font-weight: 600;
    color: var(--ios-text);
    text-decoration: none;
    letter-spacing: -0.02em;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 8px;
}

.nav-links a {
    color: var(--ios-blue);
    text-decoration: none;
    font-size: 15px;
    padding: 6px 12px;
    border-radius: 8px;
    transition: all var(--ios-transition);
    font-weight: 500;
}

.nav-links a:hover {
    background: rgba(0,122,255,0.08);
}

.nav-user {
    color: var(--ios-text-secondary);
    font-size: 15px;
    font-weight: 500;
    padding: 0 8px;
}

/* Main container */
.main-container {
    max-width: 100%;
    min-height: calc(100vh - 48px);
}

/* Flash messages */
.flash-messages {
    max-width: 600px;
    margin: 12px auto;
    padding: 0 16px;
}

.flash-message {
    padding: 12px 16px;
    border-radius: var(--ios-radius-sm);
    margin-bottom: 8px;
    font-size: 14px;
    animation: iosSlideDown 0.35s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

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

.flash-success { background: #DCFCE7; color: #166534; border: 0.5px solid #BBF7D0; }
.flash-danger { background: #FEE2E2; color: #991B1B; border: 0.5px solid #FECACA; }
.flash-info { background: #DBEAFE; color: #1E40AF; border: 0.5px solid #BFDBFE; }
.flash-warning { background: #FEF3C7; color: #92400E; border: 0.5px solid #FDE68A; }

/* ==================== Auth ==================== */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 48px);
    padding: 20px;
}

.auth-card {
    background: var(--ios-white);
    border-radius: var(--ios-radius);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--ios-shadow-lg);
}

.auth-card h2 {
    text-align: center;
    margin-bottom: 28px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--ios-text-tertiary);
}

.auth-link a { color: var(--ios-blue); text-decoration: none; font-weight: 500; }

/* ==================== Forms ==================== */
.form-group { margin-bottom: 18px; }

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--ios-text-secondary);
}

.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="tel"],
.form-group input[type="number"],
.form-group textarea,
.form-select {
    width: 100%;
    padding: 12px 14px;
    border: 0.5px solid var(--ios-separator);
    border-radius: var(--ios-radius-sm);
    font-size: 15px;
    background: var(--ios-bg);
    color: var(--ios-text);
    transition: all var(--ios-transition);
    font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--ios-blue);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.15);
    background: var(--ios-white);
}

.form-group textarea { resize: vertical; min-height: 80px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.form-row-sms { display: flex; gap: 12px; align-items: flex-end; }

/* ==================== Buttons (existing layout compat) ==================== */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--ios-radius-xs);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--ios-transition);
    text-decoration: none;
    font-family: inherit;
}

.btn-primary { background: var(--ios-blue); color: white; }
.btn-primary:hover { background: #0066D6; }
.btn-secondary { background: var(--ios-gray5); color: var(--ios-text); }
.btn-secondary:hover { background: var(--ios-gray4); }
.btn-danger { background: var(--ios-red); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-warning { background: var(--ios-orange); color: white; }
.btn-warning:hover { background: #E07E00; }
.btn-info { background: var(--ios-blue); color: white; }
.btn-info:hover { background: #0066D6; }
.btn-success { background: var(--ios-green); color: white; }
.btn-success:hover { background: #2EA043; }
.btn-sm { padding: 6px 14px; font-size: 13px; border-radius: 6px; }
.btn-block { display: block; width: 100%; }
.btn-lg { padding: 14px 28px; font-size: 17px; border-radius: 12px; }

/* ==================== iOS Chat Layout ==================== */
.chat-container {
    display: flex;
    height: calc(100vh - 48px);
}

/* Sidebar */
.chat-sidebar {
    width: 260px;
    background: rgba(255,255,255,0.8);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-right: 0.5px solid rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 16px 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--ios-text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.sidebar-section {
    padding: 8px 12px;
}

.ios-select {
    width: 100%;
    padding: 10px 12px;
    border: 0.5px solid var(--ios-separator);
    border-radius: var(--ios-radius-sm);
    font-size: 14px;
    background: var(--ios-white);
    color: var(--ios-text);
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
    cursor: pointer;
    transition: all var(--ios-transition);
}

.ios-select:focus {
    outline: none;
    border-color: var(--ios-blue);
    box-shadow: 0 0 0 3px rgba(0,122,255,0.12);
}

.board-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: calc(100vh - 300px);
    overflow-y: auto;
}

.ios-board-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-radius: var(--ios-radius-sm);
    cursor: pointer;
    transition: all var(--ios-transition);
    background: transparent;
}

.ios-board-card:hover {
    background: rgba(0,122,255,0.06);
}

.ios-board-card.selected {
    background: rgba(0,122,255,0.1);
}

.ios-board-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: var(--ios-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.ios-board-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--ios-text);
}

.ios-board-desc {
    font-size: 12px;
    color: var(--ios-text-tertiary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-footer {
    margin-top: auto;
    padding: 12px;
    border-top: 0.5px solid rgba(0,0,0,0.06);
}

.ios-btn-ghost {
    background: transparent;
    color: var(--ios-red);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--ios-radius-xs);
    transition: all var(--ios-transition);
    font-family: inherit;
}

.ios-btn-ghost:hover {
    background: rgba(255,59,48,0.08);
}

/* Chat main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--ios-white);
    position: relative;
}

.chat-navbar {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 0.5px solid rgba(0,0,0,0.06);
    background: rgba(255,255,255,0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    z-index: 10;
    gap: 12px;
}

.chat-nav-left {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.chat-nav-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--ios-text);
    letter-spacing: -0.02em;
}

.chat-nav-subtitle {
    font-size: 12px;
    color: var(--ios-blue);
    font-weight: 500;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: var(--ios-white);
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.15);
    border-radius: 4px;
}

.chat-welcome {
    text-align: center;
    padding: 80px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    border-radius: 22px;
    background: linear-gradient(135deg, rgba(0,122,255,0.1), rgba(52,199,89,0.1));
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.chat-welcome h3 {
    font-size: 20px;
    font-weight: 600;
    color: var(--ios-text);
    margin-bottom: 6px;
}

.chat-welcome p {
    font-size: 14px;
    color: var(--ios-text-tertiary);
    line-height: 1.5;
    max-width: 320px;
}

.demo-prompts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 24px;
    max-width: 400px;
}

.demo-prompt {
    display: inline-block;
    padding: 8px 16px;
    font-size: 13px;
    color: var(--ios-blue);
    background: rgba(0,122,255,0.08);
    border: 1px solid rgba(0,122,255,0.2);
    border-radius: 20px;
    cursor: pointer;
    user-select: none;
    transition: all var(--ios-transition);
    white-space: nowrap;
}

.demo-prompt:hover {
    background: rgba(0,122,255,0.15);
    border-color: var(--ios-blue);
}

.demo-prompt:active {
    background: var(--ios-blue);
    color: #fff;
}

/* Message bubbles */
.chat-message {
    display: flex;
    gap: 10px;
    animation: iosMessageIn 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    max-width: 100%;
    min-width: 0;
}

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

.chat-message.user {
    flex-direction: row-reverse;
    padding-left: 60px;
}

.chat-message.assistant {
    padding-right: 60px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-message.user .message-avatar {
    background: linear-gradient(135deg, #007AFF, #5856D6);
    color: white;
}

.chat-message.assistant .message-avatar {
    background: linear-gradient(135deg, #34C759, #30B0C7);
    color: white;
}

.message-content {
    max-width: 100%;
    min-width: 0;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: normal;
    position: relative;
}

.message-content > *,
.ws-msg-content > * {
    max-width: 100%;
    min-width: 0;
}

.chat-message.user .message-content {
    background: var(--ios-blue);
    color: white;
    border-bottom-right-radius: 6px;
}

.chat-message.user.message-editing .message-content {
    outline: 2px solid rgba(10, 132, 255, 0.45);
    outline-offset: 2px;
}

.chat-message.user .message-content .md-p { color: white; }

.chat-message.assistant .message-content {
    background: var(--ios-gray5);
    color: var(--ios-text);
    border-bottom-left-radius: 6px;
}

.chat-message.assistant .message-content a {
    color: var(--ios-blue);
}

/* Thinking indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 0;
    color: var(--ios-text-tertiary);
    font-size: 13px;
    font-style: italic;
}

.thinking-dots {
    display: flex;
    gap: 3px;
}

.thinking-dots span {
    display: inline-block;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--ios-gray2);
    animation: iosTyping 1.4s infinite ease-in-out;
}

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

@keyframes iosTyping {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Thinking real-time output */
.thinking-real-time {
    background: #f8f9fa;
    border-left: 3px solid var(--ios-blue);
    border-radius: 4px;
    padding: 8px 12px;
    margin-bottom: 8px;
    max-height: 300px;
    overflow-y: auto;
}

.thinking-real-time .thinking-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--ios-blue);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.thinking-real-time .thinking-text {
    font-size: 12px;
    color: #555;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 240px;
    overflow-y: auto;
}

/* Streaming cursor */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 16px;
    background: var(--ios-blue);
    vertical-align: text-bottom;
    margin-left: 1px;
    animation: iosCursorBlink 0.8s infinite;
}

@keyframes iosCursorBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.assistant .streaming-cursor { background: var(--ios-blue); }

/* Streaming state — keep code blocks fully visible, no scroll freeze */
.message-content.streaming .code-pre {
    overflow: visible !important;
    max-height: none !important;
}

.message-content.streaming .code-block {
    opacity: 0.88;
    transition: opacity 0.3s;
}

/* Streaming status bar */
.streaming-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
    margin-bottom: 8px;
    font-size: 12px;
    color: var(--ios-text-tertiary);
    font-weight: 500;
    border-bottom: 1px solid rgba(0,0,0,0.04);
}

.streaming-status-bar {
    flex: 1;
    height: 2px;
    background: var(--ios-gray5);
    border-radius: 1px;
    overflow: hidden;
}

.streaming-status-bar::after {
    content: '';
    display: block;
    width: 30%;
    height: 100%;
    background: var(--ios-blue);
    border-radius: 1px;
    animation: iosStatusSlide 1.2s ease-in-out infinite;
}

@keyframes iosStatusSlide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* Markdown content */
.md-p {
    margin: 0 0 6px 0;
    line-height: 1.55;
}

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

.md-h2 { font-size: 18px; font-weight: 700; margin: 14px 0 6px 0; letter-spacing: -0.02em; }
.md-h3 { font-size: 16px; font-weight: 600; margin: 12px 0 4px 0; letter-spacing: -0.01em; }
.md-h4 { font-size: 14px; font-weight: 600; margin: 10px 0 3px 0; }

.md-ul, .md-ol { margin: 4px 0 10px 0; padding-left: 20px; }
.md-li, .md-li-ol { margin: 2px 0; line-height: 1.5; }

/* Long Markdown tables remain readable inside the chat bubble on small screens. */
.ai-chat-main .chat-message.assistant .md-p {
    margin-bottom: 10px;
    line-height: 1.72;
    white-space: pre-line;
}

.ai-chat-main .chat-message.assistant .md-table-wrap {
    width: 100%;
    max-width: 100%;
    margin: 16px 0;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e5e5ea;
    border-radius: 12px;
    background: #fff;
}

.ai-chat-main .chat-message.assistant .md-table {
    width: 100%;
    min-width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    color: #1d1d1f;
}

/* Short data tables keep centered values while all tables share fixed column tracks. */
.ai-chat-main .chat-message.assistant .md-table.md-table-compact {
    table-layout: fixed;
}

.ai-chat-main .chat-message.assistant .md-table-cell {
    min-width: 0;
    padding: 13px 16px;
    vertical-align: middle;
    text-align: left;
    white-space: normal;
    overflow-wrap: break-word;
    word-break: normal;
    border-bottom: 1px solid #e5e5ea;
    font-size: 13px;
    line-height: 1.6;
}

.ai-chat-main .chat-message.assistant .md-table th {
    background: #f5f5f7;
    color: #6e6e73;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.ai-chat-main .chat-message.assistant .md-table th:not(:last-child),
.ai-chat-main .chat-message.assistant .md-table td:not(:last-child) {
    border-right: 1px solid #e5e5ea;
}

.ai-chat-main .chat-message.assistant .md-table.md-table-compact .md-table-cell {
    text-align: center;
    vertical-align: middle;
}

.ai-chat-main .chat-message.assistant .md-table.md-table-compact td {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

/* Standard power overview: fixed tracks prevent voltage, current and heat data from drifting. */
.ai-chat-main .chat-message.assistant .md-table.md-table-power-overview {
    table-layout: fixed;
}

.ai-chat-main .chat-message.assistant .md-table-power-overview th:nth-child(1),
.ai-chat-main .chat-message.assistant .md-table-power-overview td:nth-child(1) {
    width: 29%;
}

.ai-chat-main .chat-message.assistant .md-table-power-overview th:nth-child(2),
.ai-chat-main .chat-message.assistant .md-table-power-overview td:nth-child(2) {
    width: 23%;
}

.ai-chat-main .chat-message.assistant .md-table-power-overview th:nth-child(3),
.ai-chat-main .chat-message.assistant .md-table-power-overview td:nth-child(3) {
    width: 48%;
}

.ai-chat-main .chat-message.assistant .md-table-power-overview .md-table-cell {
    padding: 14px 16px;
}

.ai-chat-main .chat-message.assistant .md-table-power-overview th {
    background: #eef5fc;
    color: #334155;
    font-size: 13px;
    font-weight: 700;
}

.ai-chat-main .chat-message.assistant .md-table-power-overview td {
    background: #fff;
}

.ai-chat-main .chat-message.assistant .md-table-power-overview td:nth-child(1),
.ai-chat-main .chat-message.assistant .md-table-power-overview td:nth-child(2),
.ai-chat-main .chat-message.assistant .md-table-power-overview .md-table-status-cell {
    text-align: center;
    white-space: nowrap;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.ai-chat-main .chat-message.assistant .md-table-status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 28px;
    padding: 4px 10px;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    line-height: 18px;
    white-space: nowrap;
}

.ai-chat-main .chat-message.assistant .md-table-status-low {
    border-color: #abefc6;
    background: #ecfdf3;
    color: #027a48;
}

.ai-chat-main .chat-message.assistant .md-table-status-warm {
    border-color: #fedf89;
    background: #fffaeb;
    color: #b54708;
}

.ai-chat-main .chat-message.assistant .md-table-status-hot {
    border-color: #fecdca;
    background: #fff1eb;
    color: #c4320a;
}

.ai-chat-main .chat-message.assistant .md-table-status-critical {
    border-color: #fecdca;
    background: #fef3f2;
    color: #b42318;
}

.ai-chat-main .chat-message.assistant .md-table tbody tr:last-child td {
    border-bottom: none;
}

.md-table-cell-center { text-align: center !important; }
.md-table-cell-right { text-align: right !important; }

@media (max-width: 720px) {
    .ai-chat-main .chat-message.assistant .md-table-wrap {
        margin: 14px 0 16px;
        width: 100%;
        max-width: 100%;
        overflow-x: auto;
        overflow-y: hidden;
        border-color: #e5e5ea;
    }

    .ai-chat-main .chat-message.assistant .md-table {
        min-width: 460px;
    }

    .ai-chat-main .chat-message.assistant .md-table.md-table-power-overview {
        min-width: 520px;
    }

    .ai-chat-main .chat-message.assistant .md-table-cell {
        padding: 12px 14px;
        font-size: 12px;
    }

    .ai-chat-main .chat-message.assistant .md-table-power-overview .md-table-cell {
        padding: 12px 14px;
    }
}

/* Full Markdown output used by normal AI conversations. */
.ai-chat-main .chat-message.assistant .message-content > :first-child {
    margin-top: 0;
}

.ai-chat-main .chat-message.assistant .message-content > :last-child {
    margin-bottom: 0;
}

.ai-chat-main .chat-message.assistant .message-content > h1,
.ai-chat-main .chat-message.assistant .message-content > h2,
.ai-chat-main .chat-message.assistant .message-content > h3,
.ai-chat-main .chat-message.assistant .message-content > h4,
.ai-chat-main .chat-message.assistant .message-content > h5,
.ai-chat-main .chat-message.assistant .message-content > h6 {
    color: #182230;
    font-weight: 700;
    letter-spacing: 0;
    line-height: 1.38;
}

.ai-chat-main .chat-message.assistant .message-content > h1 { font-size: 22px; margin: 22px 0 10px; }
.ai-chat-main .chat-message.assistant .message-content > h2 { font-size: 19px; margin: 20px 0 9px; }
.ai-chat-main .chat-message.assistant .message-content > h3 { font-size: 17px; margin: 18px 0 8px; }
.ai-chat-main .chat-message.assistant .message-content > h4,
.ai-chat-main .chat-message.assistant .message-content > h5,
.ai-chat-main .chat-message.assistant .message-content > h6 { font-size: 15px; margin: 15px 0 7px; }

.ai-chat-main .chat-message.assistant .message-content > p,
.ai-chat-main .chat-message.assistant .message-content li > p {
    margin: 0 0 11px;
    line-height: 1.72;
}

.ai-chat-main .chat-message.assistant .message-content > ul,
.ai-chat-main .chat-message.assistant .message-content > ol,
.ai-chat-main .chat-message.assistant .message-content li > ul,
.ai-chat-main .chat-message.assistant .message-content li > ol {
    margin: 8px 0 13px;
    padding-left: 1.4em;
}

.ai-chat-main .chat-message.assistant .message-content li {
    margin: 5px 0;
    line-height: 1.68;
}

.ai-chat-main .chat-message.assistant .message-content blockquote.md-blockquote {
    margin: 14px 0;
    padding: 8px 13px;
    border-left: 3px solid #0a84ff;
    border-radius: 0 8px 8px 0;
    background: #f1f7ff;
    color: #43536a;
}

.ai-chat-main .chat-message.assistant .message-content blockquote.md-blockquote > :last-child {
    margin-bottom: 0;
}

.ai-chat-main .chat-message.assistant .message-content hr {
    height: 1px;
    margin: 18px 0;
    border: 0;
    background: rgba(60, 60, 67, 0.16);
}

.ai-chat-main .chat-message.assistant .message-content p code,
.ai-chat-main .chat-message.assistant .message-content li code,
.ai-chat-main .chat-message.assistant .message-content td code,
.ai-chat-main .chat-message.assistant .message-content th code,
.ai-chat-main .chat-message.assistant .message-content blockquote code {
    padding: 1px 5px;
    border-radius: 4px;
    background: #edf1f6;
    color: #c0392b;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", "JetBrains Mono", Menlo, monospace;
    font-size: 0.9em;
}

.ai-chat-main .chat-message.assistant .message-content input[type="checkbox"] {
    width: 14px;
    height: 14px;
    margin: 0 7px 0 0;
    vertical-align: -2px;
    accent-color: var(--ios-blue);
}

.ai-chat-main .chat-message.assistant .math-block {
    display: block;
    width: fit-content;
    max-width: 100%;
    margin: 13px auto;
    padding: 9px 14px;
    overflow-x: auto;
    color: #172033;
    font-family: "Times New Roman", "Noto Serif CJK SC", serif;
    font-size: 1.08em;
    line-height: 1.7;
    text-align: center;
    white-space: nowrap;
    border-top: 1px solid rgba(60, 60, 67, 0.14);
    border-bottom: 1px solid rgba(60, 60, 67, 0.14);
}

.ai-chat-main .chat-message.assistant .math-expression,
.ai-chat-main .chat-message.assistant .math-inline {
    display: inline-block;
    font-family: "Times New Roman", "Noto Serif CJK SC", serif;
    letter-spacing: 0;
}

.ai-chat-main .chat-message.assistant .math-inline {
    margin: 0 0.14em;
    white-space: nowrap;
}

.ai-chat-main .chat-message.assistant .math-expression sup,
.ai-chat-main .chat-message.assistant .math-expression sub,
.ai-chat-main .chat-message.assistant .math-inline sup,
.ai-chat-main .chat-message.assistant .math-inline sub {
    margin-left: 0.04em;
    font-size: 0.72em;
    line-height: 0;
}

.ai-chat-main .chat-message.assistant .math-frac {
    display: inline-flex;
    flex-direction: column;
    min-width: 1.35em;
    margin: 0 0.12em;
    vertical-align: middle;
    line-height: 1.05;
    text-align: center;
}

.ai-chat-main .chat-message.assistant .math-frac-num {
    padding: 0 0.18em 0.1em;
    border-bottom: 1px solid currentColor;
}

.ai-chat-main .chat-message.assistant .math-frac-den {
    padding: 0.1em 0.18em 0;
}

.ai-chat-main .chat-message.assistant .math-text {
    margin: 0 0.03em;
    font-family: "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 0.9em;
}

.ai-chat-main .chat-message.assistant .message-content img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 12px 0;
    border: 1px solid rgba(60, 60, 67, 0.12);
    border-radius: 8px;
}

.ai-chat-main .chat-message.user .message-content > p,
.ai-chat-main .chat-message.user .message-content li > p {
    margin: 0 0 8px;
    line-height: 1.65;
}

.ai-chat-main .chat-message.user .message-content > ul,
.ai-chat-main .chat-message.user .message-content > ol,
.ai-chat-main .chat-message.user .message-content li > ul,
.ai-chat-main .chat-message.user .message-content li > ol {
    margin: 6px 0 10px;
    padding-left: 1.3em;
}

.ai-chat-main .chat-message.user .message-content strong,
.ai-chat-main .chat-message.user .message-content em,
.ai-chat-main .chat-message.user .message-content a {
    color: inherit;
}

.ai-chat-main .chat-message.user .message-content a {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.inline-code {
    background: rgba(0,0,0,0.06);
    color: var(--ios-red);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
    font-family: "SF Mono", "Fira Code", "Cascadia Code", "JetBrains Mono", Menlo, monospace;
}

.user .inline-code {
    background: rgba(255,255,255,0.2);
    color: rgba(255,255,255,0.9);
}

/* ==================== iOS Code Block ==================== */
.code-block {
    margin: 10px 0;
    border-radius: var(--ios-radius-sm);
    overflow: hidden;
    background: #1C1C1E;
    border: 0.5px solid rgba(255,255,255,0.08);
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px 8px 14px;
    background: #2C2C2E;
    border-bottom: 0.5px solid rgba(255,255,255,0.06);
}

.code-header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.code-lang {
    font-size: 11px;
    color: #8E8E93;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-family: "SF Mono", Menlo, monospace;
}

.code-header-actions {
    display: flex;
    gap: 4px;
}

.code-action-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 5px 10px;
    border: none;
    border-radius: 6px;
    background: rgba(255,255,255,0.06);
    color: #AEAEB2;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.code-action-btn:hover {
    background: rgba(255,255,255,0.12);
    color: white;
}

.code-action-btn.copied {
    background: rgba(52,199,89,0.2);
    color: var(--ios-green);
}

.code-pre {
    margin: 0;
    padding: 14px 16px;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.6;
    max-height: 420px;
    overflow-y: auto;
}

.code-pre::-webkit-scrollbar {
    height: 3px;
    width: 3px;
}

.code-pre::-webkit-scrollbar-track { background: transparent; }
.code-pre::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }

.code-pre code {
    font-family: "SF Mono", "Fira Code", "Cascadia Code", "JetBrains Mono", Menlo, monospace;
    color: #E5E5EA;
    white-space: pre;
    tab-size: 4;
    font-size: 13px;
}

/* Input area */
.chat-input-area {
    padding: 10px 16px 14px;
    background: var(--ios-white);
    border-top: 0.5px solid rgba(0,0,0,0.06);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ios-gray5);
    border-radius: 22px;
    padding: 4px 6px 4px 14px;
    transition: all var(--ios-transition);
    border: 1.5px solid transparent;
}

.chat-input-wrapper.input-expanded {
    align-items: flex-end;
    border-radius: 16px;
}

.chat-input-wrapper:focus-within {
    border-color: var(--ios-blue);
    background: var(--ios-white);
    box-shadow: 0 0 0 1px rgba(0,122,255,0.15);
}

.chat-input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    padding: 8px 0;
    font-family: inherit;
    color: var(--ios-text);
    max-height: 120px;
    overflow-y: auto;
}

.chat-input-wrapper.input-expanded textarea {
    min-height: 180px;
    max-height: 42vh;
}

.chat-expand-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--ios-gray);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: all var(--ios-transition);
}

.chat-expand-btn:hover {
    background: rgba(0,0,0,0.06);
    color: var(--ios-blue);
}

.chat-expand-btn .icon-collapse,
.chat-input-wrapper.input-expanded .chat-expand-btn .icon-expand {
    display: none;
}

.chat-input-wrapper.input-expanded .chat-expand-btn .icon-collapse {
    display: block;
}

.chat-input-wrapper textarea::placeholder {
    color: var(--ios-gray2);
}

.chat-input-wrapper textarea:focus {
    outline: none;
}

.ios-send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--ios-blue);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--ios-transition);
    flex-shrink: 0;
    padding: 0;
}

.ios-send-btn:hover {
    background: #0066D6;
    transform: scale(1.05);
}

.ios-send-btn:active {
    transform: scale(0.95);
}

.ios-stop-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: var(--ios-red);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--ios-transition);
    flex-shrink: 0;
}

.ios-stop-btn:hover {
    background: #DC2626;
    transform: scale(1.05);
}

.ios-stop-btn:active {
    transform: scale(0.95);
}

/* Error text */
.error-text {
    color: var(--ios-red);
    font-size: 14px;
}

/* ==================== Admin Layout (preserved) ==================== */
.admin-container {
    display: flex;
    min-height: calc(100vh - 48px);
}

.admin-sidebar {
    width: 220px;
    background: var(--ios-white);
    border-right: 0.5px solid rgba(0,0,0,0.08);
    padding: 20px 16px;
    flex-shrink: 0;
}

.admin-sidebar h3 {
    font-size: 13px;
    color: var(--ios-text-tertiary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.admin-menu {
    list-style: none;
}

.admin-menu li { margin-bottom: 2px; }

.admin-menu a {
    display: block;
    padding: 10px 12px;
    color: var(--ios-text-secondary);
    text-decoration: none;
    border-radius: var(--ios-radius-xs);
    font-size: 15px;
    transition: all var(--ios-transition);
}

.admin-menu a:hover { background: var(--ios-gray6); }
.admin-menu a.active {
    background: rgba(0,122,255,0.08);
    color: var(--ios-blue);
    font-weight: 600;
}

.admin-content {
    flex: 1;
    padding: 24px 30px;
    overflow-y: auto;
    background: var(--ios-bg);
}

.admin-content h2 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 20px;
    letter-spacing: -0.02em;
}

.admin-content h3 {
    font-size: 17px;
    font-weight: 600;
    color: var(--ios-text-secondary);
    margin-bottom: 12px;
}

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
}

.stat-card {
    background: var(--ios-white);
    padding: 24px;
    border-radius: var(--ios-radius);
    box-shadow: var(--ios-shadow);
}

.stat-card h3 {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 4px;
    color: var(--ios-blue);
    letter-spacing: -0.02em;
}

.stat-card:nth-child(2) h3 { color: var(--ios-green); }
.stat-card:nth-child(3) h3 { color: var(--ios-orange); }
.stat-card:nth-child(4) h3 { color: #5856D6; }

.stat-card p {
    font-size: 14px;
    color: var(--ios-text-tertiary);
}

/* Table */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--ios-white);
    border-radius: var(--ios-radius);
    overflow: hidden;
    box-shadow: var(--ios-shadow);
}

.table th {
    background: var(--ios-gray6);
    padding: 12px 14px;
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: var(--ios-text-tertiary);
    border-bottom: 0.5px solid var(--ios-separator);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.table td {
    padding: 12px 14px;
    font-size: 14px;
    border-bottom: 0.5px solid var(--ios-gray5);
    color: var(--ios-text);
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--ios-gray6); }

.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Badges */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-success { background: #DCFCE7; color: #166534; }
.badge-danger { background: #FEE2E2; color: #991B1B; }
.badge-info { background: #DBEAFE; color: #1E40AF; }
.badge-warning { background: #FEF3C7; color: #92400E; }
.badge-secondary { background: var(--ios-gray5); color: #555; }

/* Card */
.card {
    background: var(--ios-white);
    border-radius: var(--ios-radius);
    padding: 24px;
    box-shadow: var(--ios-shadow);
}

/* Modal */
.modal {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    animation: iosFadeIn 0.2s ease;
}

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

.modal-content {
    background: var(--ios-white);
    border-radius: var(--ios-radius);
    padding: 24px;
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--ios-shadow-lg);
    animation: iosScaleIn 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

@keyframes iosScaleIn {
    from { transform: scale(0.95); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.modal-close {
    float: right;
    font-size: 24px;
    cursor: pointer;
    color: var(--ios-gray2);
    transition: color 0.2s;
}

.modal-close:hover { color: var(--ios-text); }

#modal-body {
    background: var(--ios-gray6);
    border-radius: var(--ios-radius-xs);
    padding: 16px;
    margin-top: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 13px;
    line-height: 1.5;
    max-height: 50vh;
    overflow-y: auto;
}

/* ==================== Utilities ==================== */
.text-center { text-align: center; }
.text-muted { color: var(--ios-text-tertiary); }

/* Rule presets */
.rule-presets {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 8px;
}

/* Model config specific */
#temperature_range {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--ios-gray4);
    outline: none;
}

#temperature_range::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--ios-white);
    border: 2px solid var(--ios-blue);
    cursor: pointer;
    box-shadow: var(--ios-shadow);
}

input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: var(--ios-blue);
    margin-right: 8px;
    vertical-align: middle;
}

input[type="number"].form-select {
    width: auto;
    text-align: center;
}

/* ==================== iOS Context Menu ==================== */
.ios-context-menu {
    position: fixed;
    z-index: 9999;
    min-width: 160px;
    padding: 6px 0;
    background: rgba(255,255,255,0.92);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-radius: 13px;
    box-shadow: 0 8px 40px rgba(0,0,0,0.18), 0 0 0 0.5px rgba(0,0,0,0.08);
    opacity: 0;
    transform: scale(0.92);
    transform-origin: top left;
    transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    pointer-events: none;
    user-select: none;
}

.ios-context-menu.visible {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
}

.ios-context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    font-size: 15px;
    color: var(--ios-text);
    cursor: pointer;
    transition: background 0.12s ease;
    white-space: nowrap;
}

.ios-context-menu-item:hover {
    background: rgba(0,0,0,0.04);
}

.ios-context-menu-item:active {
    background: rgba(0,0,0,0.08);
}

.ios-context-menu-item.destructive {
    color: var(--ios-red);
}

.ios-context-menu-divider {
    height: 0.5px;
    background: var(--ios-separator);
    margin: 4px 12px;
}

.ios-context-menu-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--ios-blue);
}

.ios-context-menu-item.destructive .ios-context-menu-icon {
    color: var(--ios-red);
}

/* ==================== iOS Toggle Switch ==================== */
.ios-toggle {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

.ios-toggle input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.ios-toggle-track {
    position: relative;
    display: inline-block;
    width: 50px;
    height: 30px;
    background: var(--ios-gray4);
    border-radius: 15px;
    transition: background 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.ios-toggle input:checked + .ios-toggle-track {
    background: var(--ios-green);
}

.ios-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 26px;
    height: 26px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2), 0 0 0 0.5px rgba(0,0,0,0.04);
    transition: transform 0.25s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

.ios-toggle input:checked + .ios-toggle-track .ios-toggle-thumb {
    transform: translateX(20px);
}

.ios-toggle input:focus-visible + .ios-toggle-track {
    box-shadow: 0 0 0 3px rgba(52,199,89,0.3);
}

/* User message hover hint */
.chat-message.user .message-content {
    cursor: context-menu;
}

/* ==================== Profile Page ==================== */
.profile-container {
    max-width: 640px;
    margin: 40px auto;
    padding: 0 16px;
}

.profile-card {
    background: var(--ios-white);
    border-radius: var(--ios-radius);
    box-shadow: var(--ios-shadow);
    overflow: hidden;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 24px 20px;
    border-bottom: 0.5px solid var(--ios-separator);
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0,122,255,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.profile-info {
    flex: 1;
}

.profile-info h2 {
    font-size: 18px;
    font-weight: 600;
}

.profile-info p {
    font-size: 13px;
    color: var(--ios-text-tertiary);
    margin-top: 2px;
}

.membership-badge {
    padding: 5px 12px;
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    flex-shrink: 0;
}

.membership-free { background: #f0f0f0; color: #666; }
.membership-monthly { background: rgba(0,122,255,0.1); color: var(--ios-blue); }
.membership-yearly { background: rgba(52,199,89,0.1); color: var(--ios-green); }
.membership-lifetime { background: linear-gradient(135deg, rgba(255,149,0,0.1), rgba(255,59,48,0.1)); color: var(--ios-orange); }

.profile-expiry {
    padding: 10px 20px;
    font-size: 13px;
    color: var(--ios-text-secondary);
    background: rgba(0,122,255,0.04);
    border-bottom: 0.5px solid var(--ios-separator);
}

.quota-section {
    padding: 20px;
}

.quota-section h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 14px;
    color: var(--ios-text-secondary);
}

.quota-card {
    background: var(--ios-gray6);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 10px;
}

.quota-card.unlimited {
    background: rgba(52,199,89,0.06);
    display: flex;
    align-items: center;
    gap: 12px;
}

.quota-card.total {
    background: rgba(0,122,255,0.04);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.quota-icon {
    flex-shrink: 0;
}

.quota-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ios-text-secondary);
    margin-bottom: 6px;
}

.quota-info {
    width: 100%;
}

.quota-bar {
    height: 6px;
    background: rgba(0,0,0,0.08);
    border-radius: 3px;
    margin: 8px 0;
    overflow: hidden;
}

.quota-bar-fill {
    height: 100%;
    background: var(--ios-blue);
    border-radius: 3px;
    transition: width 0.3s ease;
    min-width: 2px;
}

.quota-detail {
    font-size: 12px;
    color: var(--ios-text-tertiary);
}

.quota-value {
    font-size: 14px;
    color: var(--ios-green);
    font-weight: 500;
}

.quota-value-lg {
    font-size: 16px;
    font-weight: 600;
    color: var(--ios-blue);
}

/* ==================== Purchase Plans ==================== */
.plans-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 12px;
}

.plan-card {
    background: var(--ios-white);
    border: 1px solid var(--ios-gray5);
    border-radius: 14px;
    padding: 20px;
    text-align: center;
    transition: all var(--ios-transition);
}

.plan-card:hover {
    border-color: var(--ios-blue);
    box-shadow: 0 4px 12px rgba(0,122,255,0.1);
}

.plan-header {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 8px;
}

.plan-name {
    font-size: 16px;
    font-weight: 600;
}

.plan-badge {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(52,199,89,0.1);
    color: var(--ios-green);
}

.plan-badge.token {
    background: rgba(0,122,255,0.1);
    color: var(--ios-blue);
}

.plan-price {
    font-size: 28px;
    font-weight: 700;
    color: var(--ios-orange);
    margin: 8px 0;
}

.plan-desc {
    font-size: 12px;
    color: var(--ios-text-tertiary);
    margin-bottom: 14px;
}

.buy-btn {
    width: 100%;
}

.pay-modal-content {
    max-width: 720px;
    width: min(720px, 94vw);
    text-align: center;
}

#pay-frame {
    min-height: 520px;
}

@media (max-width: 640px) {
    .pay-modal-content {
        width: 96vw;
        max-height: 92vh;
        padding: 16px;
    }

    #pay-frame {
        height: 560px;
        min-height: 560px;
    }
}

/* ==================== Workspace ==================== */
.workspace-panel {
    width: 240px;
    min-width: 200px;
    background: var(--ios-white);
    border-right: 0.5px solid var(--ios-separator);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.workspace-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    border-bottom: 0.5px solid var(--ios-gray5);
}

.workspace-actions { display: flex; gap: 4px; }

.ws-btn {
    padding: 3px 8px;
    font-size: 11px;
    border: 1px solid var(--ios-gray4);
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    color: var(--ios-blue);
}

.ws-btn:hover { background: var(--ios-gray6); }
.ws-btn-close { color: var(--ios-red); font-size: 14px; padding: 0 6px; }

.file-tree { flex: 1; overflow-y: auto; padding: 8px 0; }

.tree-ul { list-style: none; padding: 0; margin: 0; }

.tree-li {
    padding: 5px 12px 5px 16px;
    cursor: pointer;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
}

.tree-li:hover { background: rgba(0,122,255,0.06); }

.tree-icon { font-size: 14px; margin-right: 4px; }
.tree-count { font-size: 11px; color: var(--ios-text-tertiary); }
.tree-size { font-size: 11px; color: var(--ios-text-tertiary); float: right; }
.tree-empty { padding: 20px; text-align: center; color: var(--ios-text-tertiary); font-size: 13px; }

/* Code Editor Modal */
.code-modal-content { max-width: 900px; max-height: 85vh; display: flex; flex-direction: column; }

.modal-header {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 0.5px solid var(--ios-separator);
    font-weight: 600;
    font-size: 15px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 16px;
    border-top: 0.5px solid var(--ios-separator);
}

.code-editor {
    flex: 1;
    min-height: 400px;
    padding: 12px 16px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    border: none;
    outline: none;
    resize: none;
    background: #1e1e1e;
    color: #d4d4d4;
    tab-size: 4;
}

.chat-nav-right { display: flex; align-items: center; gap: 8px; margin-left: auto; }

/* File icons */
.file-icon { font-size: 13px; }

/* ==================== Workspace (iOS Style) ==================== */
.ws {
    display: flex;
    height: calc(100vh - 48px);
    overflow: hidden;
    background: var(--ios-bg);
}

/* Sidebar — two columns */
.ws-sidebar {
    width: 480px;
    min-width: 360px;
    background: var(--ios-white);
    border-right: 0.5px solid var(--ios-separator);
    display: flex;
    overflow: hidden;
    transition: width var(--ios-transition), min-width var(--ios-transition);
}
.ws-sidebar-collapsed { width: 0; min-width: 0; border: none; }

.ws-sidebar-left {
    width: 200px;
    min-width: 160px;
    display: flex;
    flex-direction: column;
    border-right: 0.5px solid var(--ios-gray5);
    overflow: hidden;
}
.ws-sidebar-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ws-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-bottom: 0.5px solid var(--ios-gray5);
    flex-shrink: 0;
}
.ws-sidebar-title { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--ios-text); }

/* Project list (left column) */
.ws-project-list { overflow-y: auto; flex: 1; }
.ws-project {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 0.5px solid var(--ios-gray6);
}
.ws-project:hover { background: var(--ios-gray6); }
.ws-project-active { background: rgba(0,122,255,0.06); }
.ws-project-active .ws-project-name { color: var(--ios-blue); }
.ws-project-icon { flex-shrink: 0; display: flex; }
.ws-project-body { flex: 1; min-width: 0; }
.ws-project-name { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ws-project-meta { font-size: 10px; color: var(--ios-text-tertiary); margin-top: 1px; }
.ws-project-del {
    flex-shrink: 0;
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    display: flex;
}
.ws-project:hover .ws-project-del { opacity: 1; }

/* Tree container (right column) */
.ws-tree-container { flex: 1; overflow-y: auto; padding: 2px 0; }
.ws-tree-loading { padding: 12px 16px; text-align: center; color: var(--ios-text-tertiary); font-size: 12px; }

/* Breadcrumb */
.ws-breadcrumb {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    padding: 4px 10px;
    font-size: 11px;
    color: var(--ios-text-tertiary);
    border-bottom: 0.5px solid var(--ios-gray5);
    gap: 2px;
    flex-shrink: 0;
}
.ws-bc-root { cursor: pointer; padding: 2px 4px; border-radius: 3px; font-size: 13px; }
.ws-bc-root:hover { background: var(--ios-gray6); }
.ws-bc-item { cursor: pointer; padding: 1px 4px; border-radius: 3px; }
.ws-bc-item:hover { background: var(--ios-gray6); color: var(--ios-blue); }
.ws-bc-last { cursor: default; color: var(--ios-text); font-weight: 500; }
.ws-bc-last:hover { background: transparent; color: var(--ios-text); }
.ws-bc-sep { color: var(--ios-gray4); margin: 0 2px; }

/* File tree (right column) */
.ws-file-tree { padding: 0; }
.ws-tree-node { }
.ws-tree-item {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 6px 3px 4px;
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    border-radius: 3px;
    margin: 0 4px;
    transition: background 0.1s;
}
.ws-tree-item:hover { background: rgba(0,122,255,0.08); }
.ws-tree-item .ws-tree-label { overflow: hidden; text-overflow: ellipsis; flex: 1; margin-left: 2px; }
.ws-tree-item .ws-tree-del {
    display: none; flex-shrink: 0;
    background: none; border: none; cursor: pointer;
    font-size: 11px; padding: 0 2px; line-height: 1;
    opacity: 0.4; transition: opacity 0.15s;
}
.ws-tree-item:hover .ws-tree-del { display: inline-block; }
.ws-tree-item .ws-tree-del:hover { opacity: 1; }
.ws-tree-arrow { font-size: 8px; color: #9ca3af; flex-shrink: 0; width: 14px; text-align: center; transition: transform 0.15s; }
.ws-tree-icon { flex-shrink: 0; font-size: 14px; }
.ws-tree-children { }
.ws-tree-children .ws-tree-item { padding-left: 8px; }
.ws-tree-empty { padding: 16px; text-align: center; color: var(--ios-text-tertiary); font-size: 12px; }

/* Top bar */
.ws-topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: rgba(255,255,255,0.72);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid rgba(0,0,0,0.08);
    min-height: 44px;
}
.ws-topbar-title { font-size: 15px; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-topbar-actions { display: flex; align-items: center; gap: 6px; }

.ws-icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    color: var(--ios-blue);
    transition: background 0.15s;
}
.ws-icon-btn:hover { background: rgba(0,122,255,0.1); }

.ws-ios-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ios-blue);
    background: var(--ios-white);
    border: 0.5px solid var(--ios-gray4);
    border-radius: var(--ios-radius-xs);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.ws-ios-btn:hover { background: var(--ios-gray6); }
.ws-ios-btn-primary { background: var(--ios-blue); color: white; border-color: var(--ios-blue); }
.ws-ios-btn-primary:hover { opacity: 0.85; }
.ws-ios-btn:disabled { cursor: wait; opacity: 0.58; }

@media (max-width: 760px) {
    .ws-topbar {
        gap: 6px;
        padding: 7px 8px;
    }

    .ws-topbar-title {
        min-width: 92px;
        font-size: 14px;
    }

    .ws-topbar-actions {
        min-width: 0;
        max-width: calc(100vw - 138px);
        overflow-x: auto;
        scrollbar-width: none;
    }

    .ws-topbar-actions::-webkit-scrollbar {
        display: none;
    }

    .ws-topbar-actions .ws-ios-btn {
        flex: 0 0 auto;
        padding-right: 9px;
        padding-left: 9px;
    }
}

.ws-ios-select {
    appearance: none;
    -webkit-appearance: none;
    padding: 5px 22px 5px 10px;
    font-size: 12px;
    font-weight: 500;
    color: var(--ios-blue);
    background: var(--ios-white);
    border: 0.5px solid var(--ios-gray4);
    border-radius: var(--ios-radius-xs);
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23007AFF' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

/* Main chat area */
.ws-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.ws-chat {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    background: var(--ios-bg);
}

.ws-welcome {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--ios-text-tertiary);
    gap: 8px;
}
.ws-welcome h3 { font-size: 18px; font-weight: 600; color: var(--ios-text); margin: 0; }
.ws-welcome p { font-size: 14px; max-width: 300px; line-height: 1.5; }

/* Input bar */
.ws-inputbar {
    padding: 10px 16px 14px;
    background: var(--ios-white);
    border-top: 0.5px solid var(--ios-separator);
}
.ws-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ios-gray6);
    border-radius: 22px;
    padding: 6px 6px 6px 16px;
    border: 0.5px solid var(--ios-gray5);
    transition: border-color 0.2s;
}

.ws-input-wrap.input-expanded {
    border-radius: 16px;
}

.ws-input-wrap:focus-within { border-color: var(--ios-blue); }
.ws-input-wrap textarea {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    height: 33px;
    min-height: 33px;
    max-height: 100px;
    padding: 6px 0;
    line-height: 1.4;
    overflow-y: auto;
}

.ws-input-wrap.input-expanded textarea {
    min-height: 180px;
    max-height: 42vh;
}

.ws-expand-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--ios-text-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    transition: all 0.15s;
}

.ws-expand-btn:hover {
    background: rgba(0,0,0,0.06);
    color: var(--ios-blue);
}

.ws-expand-btn .icon-collapse,
.ws-input-wrap.input-expanded .ws-expand-btn .icon-expand {
    display: none;
}

.ws-input-wrap.input-expanded .ws-expand-btn .icon-collapse {
    display: block;
}

.ws-send-btn, .ws-stop-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s;
}
.ws-send-btn { background: var(--ios-blue); color: white; }
.ws-send-btn:hover { opacity: 0.85; }
.ws-stop-btn { background: var(--ios-red); color: white; font-size: 14px; }

.ws-oplog, .ws-result {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(0, 122, 255, 0.08);
    color: var(--ios-text);
    font-size: 13px;
    line-height: 1.5;
}

.ws-oplog strong, .ws-result strong {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
}

.ws-oplog ul {
    margin: 0;
    padding-left: 18px;
}

.ws-oplog li {
    margin: 2px 0;
}

/* Messages */
.ws-msg { display: flex; gap: 10px; margin-bottom: 16px; max-width: 85%; }
.ws-msg { min-width: 0; }
.ws-msg-user { flex-direction: row-reverse; margin-left: auto; }
.ws-msg-assistant { margin-right: auto; }
.ws-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
}
.ws-msg-user .ws-avatar { background: var(--ios-blue); color: white; }
.ws-msg-assistant .ws-avatar { background: var(--ios-green); color: white; }

.ws-msg-content {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
    overflow-wrap: break-word;
    overflow: visible;
    min-width: 0;
    max-width: 100%;
    white-space: normal;
}
.ws-msg-content img { max-width: 100%; height: auto; border-radius: 8px; }
.ws-msg-content table { max-width: 100%; overflow-x: auto; display: block; }
.ws-msg-user .ws-msg-content {
    background: var(--ios-blue);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-message.user .message-content,
.ws-msg-user .ws-msg-content {
    cursor: context-menu;
}

.md-p,
.md-li,
.md-li-ol,
.ws-msg-content p,
.ws-msg-content li,
.ws-msg-content div:not(.ws-code):not(.ws-code-header):not(.ws-thinking):not(.ws-thinking-dot):not(.ws-compile-progress-wrap):not(.ws-compile-log) {
    overflow-wrap: anywhere;
    word-break: break-word;
}

.md-ul,
.md-ol,
.ws-msg-content ul,
.ws-msg-content ol {
    max-width: 100%;
    padding-left: 20px;
}
.ws-msg-assistant .ws-msg-content {
    background: var(--ios-white);
    color: var(--ios-text);
    border-bottom-left-radius: 4px;
    box-shadow: var(--ios-shadow);
}
.ws-msg-assistant .ws-msg-content,
.ws-msg-assistant .ws-msg-content * {
    color: var(--ios-text);
}
.ws-msg-assistant .ws-msg-content h2,
.ws-msg-assistant .ws-msg-content h3,
.ws-msg-assistant .ws-msg-content h4 {
    color: var(--ios-text);
    font-weight: 700;
    line-height: 1.35;
    margin: 12px 0 6px;
}
.ws-msg-assistant .ws-msg-content h2 { font-size: 18px; }
.ws-msg-assistant .ws-msg-content h3 { font-size: 16px; }
.ws-msg-assistant .ws-msg-content h4 { font-size: 15px; }
.ws-msg-assistant .ws-msg-content ul,
.ws-msg-assistant .ws-msg-content ol {
    margin: 6px 0 10px;
    padding-left: 22px;
}
.ws-msg-assistant .ws-msg-content li {
    margin: 4px 0;
    line-height: 1.65;
}
.ws-msg-assistant .ws-msg-content strong {
    color: var(--ios-text);
    font-weight: 700;
}
.ws-msg-assistant .ws-msg-content .ws-error,
.ws-msg-assistant .ws-msg-content .ws-clog-err,
.ws-msg-assistant .ws-msg-content .ws-chg-del {
    color: var(--ios-red);
}
.ws-msg-assistant .ws-msg-content .ws-clog-ok,
.ws-msg-assistant .ws-msg-content .ws-chg-add {
    color: var(--ios-green);
}
.ws-msg-assistant .ws-msg-content .ws-clog-warn,
.ws-msg-assistant .ws-msg-content .ws-chg-mod {
    color: var(--ios-orange);
}
.ws-msg-assistant .ws-msg-content .ws-code-header,
.ws-msg-assistant .ws-msg-content .ws-code-header span,
.ws-msg-assistant .ws-msg-content .ws-code-copy-btn {
    color: var(--ios-text-secondary);
}
.ws-msg-assistant .ws-msg-content .ws-code,
.ws-msg-assistant .ws-msg-content .ws-code *,
.ws-msg-assistant .ws-msg-content .ws-code-copy-btn {
    color: inherit;
}
.ws-msg-assistant .ws-msg-content .ws-code pre code {
    color: #f2f2f7;
}

/* Thinking indicator */
.ws-thinking { display: flex; gap: 4px; padding: 4px 0; }
.ws-thinking-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ios-gray4);
    animation: wsBounce 1.2s infinite;
}
.ws-thinking-dot:nth-child(2) { animation-delay: 0.2s; }
.ws-thinking-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes wsBounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }
.ws-thinking-text {
    color: var(--ios-gray4);
    font-size: 12px;
    font-style: italic;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

/* Changes indicator */
.ws-changes {
    margin-top: 10px;
    padding: 10px 14px;
    background: rgba(0,122,255,0.05);
    border-radius: 10px;
    font-size: 12px;
    color: var(--ios-text);
}
.ws-changes strong { display: block; margin-bottom: 4px; font-size: 13px; }
.ws-changes ul { margin: 4px 0 0 14px; padding: 0; }
.ws-changes li { margin: 2px 0; font-family: 'SF Mono', monospace; font-size: 12px; }
.ws-chg-add { color: var(--ios-green); }
.ws-chg-mod { color: var(--ios-orange); }
.ws-chg-del { color: var(--ios-red); }

.ws-error { color: var(--ios-red); font-size: 13px; }

.ws-stream-output:empty,
.ws-stream-status:empty {
    display: none;
}
.ws-stream-status {
    margin-top: 8px;
}

.ws-teaching-ppt-request {
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.ws-teaching-ppt-request strong {
    color: inherit;
}

.ws-teaching-ppt-progress {
    display: flex;
    align-items: center;
    gap: 9px;
    min-height: 28px;
    color: var(--ios-text-secondary);
    font-size: 13px;
}

.ws-teaching-ppt-progress .ws-thinking {
    flex: 0 0 auto;
    padding: 0;
}

.ws-msg-assistant .ws-msg-content .ws-teaching-ppt-progress,
.ws-msg-assistant .ws-msg-content .ws-teaching-ppt-progress span {
    color: var(--ios-text-secondary);
}

.ws-ppt-result-card {
    width: min(520px, 100%);
    margin: 0;
    overflow: hidden;
    border: 1px solid rgba(10, 132, 255, 0.22);
    border-radius: 10px;
    background: #f7fbff;
}

.ws-ppt-result-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px;
    border-bottom: 1px solid rgba(10, 132, 255, 0.14);
}

.ws-ppt-result-icon {
    display: inline-flex;
    width: 38px;
    height: 38px;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border-radius: 9px;
    color: #ffffff;
    background: #ff6b35;
}

.ws-msg-assistant .ws-msg-content .ws-ppt-result-icon,
.ws-msg-assistant .ws-msg-content .ws-ppt-result-icon * {
    color: #ffffff;
}

.ws-ppt-result-copy {
    display: flex;
    min-width: 0;
    flex: 1;
    flex-direction: column;
    gap: 2px;
}

.ws-msg-assistant .ws-msg-content .ws-ppt-result-copy strong {
    color: #1d1d1f;
    font-size: 14px;
}

.ws-msg-assistant .ws-msg-content .ws-ppt-result-copy span {
    color: #6e6e73;
    font-size: 12px;
    line-height: 1.4;
}

.ws-ppt-result-state {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    align-self: flex-start;
    color: #1b7f3b;
    font-size: 11px;
    white-space: nowrap;
}

.ws-ppt-result-state i {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #34c759;
}

.ws-msg-assistant .ws-msg-content .ws-ppt-result-state {
    color: #1b7f3b;
}

.ws-ppt-result-meta {
    display: flex;
    gap: 7px;
    padding: 10px 14px 0;
}

.ws-ppt-result-meta span {
    padding: 3px 7px;
    border-radius: 5px;
    color: #386a8d;
    background: #e6f3ff;
    font-size: 11px;
    font-weight: 600;
}

.ws-msg-assistant .ws-msg-content .ws-ppt-result-meta span {
    color: #386a8d;
}

.ws-ppt-result-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 12px 14px 14px;
}

.ws-ppt-result-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 32px;
    padding: 6px 10px;
    border: 1px solid #0a84ff;
    border-radius: 6px;
    color: #ffffff;
    background: #0a84ff;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
}

.ws-ppt-result-action:hover {
    color: #ffffff;
    background: #0072dc;
}

.ws-ppt-result-edit {
    border-color: #b9c7d3;
    color: #265d80;
    background: #ffffff;
}

.ws-ppt-result-edit:hover {
    color: #17435f;
    background: #edf7ff;
}

.ws-msg-assistant .ws-msg-content .ws-ppt-result-action,
.ws-msg-assistant .ws-msg-content .ws-ppt-result-action * {
    color: #ffffff;
}

.ws-msg-assistant .ws-msg-content .ws-ppt-result-edit,
.ws-msg-assistant .ws-msg-content .ws-ppt-result-edit * {
    color: #265d80;
}

@media (max-width: 560px) {
    .ws-ppt-result-head {
        align-items: flex-start;
    }

    .ws-ppt-result-state {
        display: none;
    }
}

.ws-write-file-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    max-width: 100%;
    margin: 10px 0 6px;
    padding: 6px 10px;
    border: 0.5px solid rgba(0,122,255,0.22);
    border-radius: 8px;
    background: rgba(0,122,255,0.08);
    color: var(--ios-text);
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
}
.ws-write-file-label span {
    flex-shrink: 0;
    color: var(--ios-blue);
    font-size: 12px;
    font-weight: 700;
}
.ws-write-file-label strong {
    min-width: 0;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 12px;
    color: var(--ios-text);
    word-break: break-all;
}

/* Code blocks in chat - iOS style */
.ws-code {
    margin: 8px 0;
    border-radius: 10px;
    overflow: hidden;
    border: 0.5px solid var(--ios-gray5);
    max-width: 100%;
    min-width: 0;
}
.ws-code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--ios-text-tertiary);
    background: var(--ios-gray6);
    text-transform: uppercase;
}
.ws-code-copy-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: none;
    border-radius: 6px;
    padding: 4px 8px;
    background: rgba(0,0,0,0.06);
    color: var(--ios-text-secondary);
    font-size: 11px;
    cursor: pointer;
}
.ws-code-copy-btn:hover { background: rgba(0,0,0,0.1); color: var(--ios-text); }
.ws-code-copy-btn.copied,
.ws-ios-btn.copied {
    background: rgba(52,199,89,0.16);
    color: var(--ios-green);
    border-color: rgba(52,199,89,0.28);
}
.ws-code pre {
    margin: 0;
    padding: 12px;
    background: #1e1e1e;
    overflow-x: auto;
    overflow-y: auto;
    font-size: 12px;
    line-height: 1.5;
    max-width: 100%;
    white-space: pre;
    word-wrap: normal;
    overflow-wrap: normal;
}
.ws-code pre code {
    color: #d4d4d4;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    white-space: pre;
}
.ws-inline-code {
    display: inline;
    background: rgba(0,122,255,0.08);
    border: 0.5px solid rgba(0,122,255,0.18);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    color: #0A3D91;
    word-break: break-all;
}
.ws-msg-user .ws-inline-code {
    background: rgba(255,255,255,0.18);
    border-color: rgba(255,255,255,0.3);
    color: #fff;
}

/* Editor panel */
.ws-editor {
    width: 50%;
    min-width: 350px;
    background: #1e1e1e;
    border-left: 0.5px solid #333;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ws-editor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: #252526;
    border-bottom: 0.5px solid #333;
}
.ws-editor-fileinfo { display: flex; align-items: center; gap: 8px; }
#ws-editor-name { font-size: 13px; font-weight: 600; color: #ccc; }
.ws-editor-path { font-size: 11px; color: #888; }
.ws-editor-input {
    flex: 1;
    min-height: 0;
    padding: 12px 16px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    border: none;
    outline: none;
    resize: none;
    background: #1e1e1e;
    color: #d4d4d4;
    tab-size: 4;
}
.ws-editor-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: #252526;
    border-top: 0.5px solid #333;
}
.ws-editor-hint { margin-left: auto; font-size: 11px; color: #666; }
.ws-editor-hint.is-warning { color: #ff9f0a; }
.ws-editor-reload-btn { color: #0a84ff; }

/* Progress bar */
.ws-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: rgba(0,122,255,0.08);
    border-radius: 10px;
    margin-bottom: 8px;
}
.ws-progress-bar {
    flex: 1;
    height: 4px;
    background: var(--ios-gray5);
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}
.ws-progress-fill {
    height: 100%;
    width: 30%;
    background: linear-gradient(90deg, var(--ios-blue), #5AC8FA);
    border-radius: 2px;
    animation: wsProgress 1.8s ease-in-out infinite;
}
@keyframes wsProgress {
    0% { width: 10%; margin-left: 0; }
    50% { width: 50%; margin-left: 25%; }
    100% { width: 10%; margin-left: 90%; }
}
.ws-progress-text {
    font-size: 12px;
    color: var(--ios-blue);
    white-space: nowrap;
    font-weight: 500;
    flex-shrink: 0;
}

/* Streaming status (deprecated) */
.streaming-status { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ios-text-tertiary); }
.streaming-status-bar {
    width: 60px;
    height: 4px;
    border-radius: 2px;
    background: var(--ios-gray5);
    overflow: hidden;
    position: relative;
}
.streaming-status-bar::after {
    content: '';
    position: absolute;
    left: -100%;
    width: 100%;
    height: 100%;
    background: var(--ios-blue);
    border-radius: 2px;
    animation: streamBar 1.5s infinite;
}
@keyframes streamBar { 0% { left: -100%; } 100% { left: 200%; } }

/* Project switch at bottom */
.ws-project-switch {
    padding: 8px 14px;
    border-top: 0.5px solid var(--ios-gray5);
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}
.ws-project-tag {
    padding: 3px 10px;
    font-size: 11px;
    border-radius: 12px;
    background: var(--ios-gray6);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 120px;
}
.ws-project-tag:hover { background: var(--ios-gray5); }
.ws-project-tag-active { background: var(--ios-blue); color: white; }

/* Compile output dialog */
.ws-compile-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ws-compile-dialog {
    background: var(--ios-bg);
    border-radius: 14px;
    width: min(800px, 90vw);
    max-height: min(600px, 80vh);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}
.ws-compile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 0.5px solid var(--ios-gray5);
    font-weight: 600;
    font-size: 15px;
}
.ws-compile-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    min-height: 200px;
    max-height: 400px;
}
.ws-compile-output {
    font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--ios-gray);
}
.ws-compile-output .ws-compile-err {
    color: var(--ios-red);
}
.ws-compile-output .ws-compile-ok {
    color: var(--ios-green);
}
.ws-compile-output .ws-compile-info {
    color: var(--ios-blue);
}
.ws-compile-output .ws-compile-warn {
    color: #FF9500;
}
.ws-compile-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 18px;
    border-top: 0.5px solid var(--ios-gray5);
    gap: 8px;
}
.ws-compile-status {
    font-size: 13px;
    color: var(--ios-gray);
}
.ws-compile-status .ws-compile-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 6px;
    vertical-align: middle;
}
.ws-compile-dot-ok { background: var(--ios-green); }
.ws-compile-dot-err { background: var(--ios-red); }
.ws-compile-dot-busy { background: #FF9500; animation: ws-pulse 1s infinite; }
@keyframes ws-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ====== Compile Progress Bar (in chat bubble) ====== */
.ws-compile-progress-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 8px 10px;
    background: rgba(0,122,255,0.06);
    border-radius: 10px;
}
.ws-compile-progress-bar {
    flex: 1;
    height: 6px;
    background: var(--ios-gray4);
    border-radius: 3px;
    overflow: hidden;
}
.ws-compile-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--ios-blue), #5AC8FA);
    border-radius: 3px;
    transition: width 0.3s ease;
}
.ws-compile-progress-pct {
    font-size: 11px;
    font-weight: 600;
    color: var(--ios-blue);
    min-width: 32px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* ====== Compile Log (in chat bubble) ====== */
.ws-compile-log {
    font-family: "SF Mono", "Menlo", "Consolas", monospace;
    font-size: 12px;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
    background: rgba(0,0,0,0.03);
    border-radius: 8px;
    padding: 8px 10px;
}
.ws-clog-line {
    white-space: pre-wrap;
    word-break: break-all;
}
.ws-clog-info { color: var(--ios-text-secondary); }
.ws-clog-err { color: var(--ios-red); }
.ws-clog-warn { color: var(--ios-orange); }
.ws-clog-ok { color: var(--ios-green); }
.ws-clog-line::before {
    content: '';
    display: inline-block;
    width: 6px;
    margin-right: 4px;
}
.ws-compile-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}
.ws-compile-actions .ws-ios-btn {
    font-size: 12px;
}

.ws-modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ws-modal-dialog {
    background: var(--ios-bg);
    border-radius: 14px;
    width: min(420px, 90vw);
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}
.ws-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 0.5px solid var(--ios-gray5);
    font-weight: 600;
    font-size: 15px;
}
.ws-modal-body {
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ws-modal-body .form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.ws-modal-body label {
    font-size: 13px;
    font-weight: 500;
    color: var(--ios-text-secondary);
}
.ws-modal-input, .ws-modal-select {
    padding: 10px 12px;
    border: 1px solid var(--ios-gray4);
    border-radius: 10px;
    font-size: 15px;
    background: var(--ios-white);
    outline: none;
    transition: border-color 0.2s;
}
.ws-modal-input:focus, .ws-modal-select:focus {
    border-color: var(--ios-blue);
}
.ws-modal-hint {
    font-size: 12px;
    color: var(--ios-text-tertiary);
    margin: 2px 0 0 0;
}
.ws-modal-footer {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 18px;
    border-top: 0.5px solid var(--ios-gray5);
}

/* ==================== Announcements ==================== */
.announcements-page {
    max-width: 860px;
    margin: 0 auto;
    padding: 28px 20px 48px;
}
.announcements-header {
    margin-bottom: 18px;
}
.announcements-header h2 {
    font-size: 24px;
    font-weight: 700;
}
.announcements-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.announcement-card {
    background: var(--ios-white);
    border: 0.5px solid var(--ios-gray5);
    border-radius: var(--ios-radius-sm);
    padding: 18px;
    box-shadow: var(--ios-shadow);
}
.announcement-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}
.announcement-card h3 {
    font-size: 18px;
    line-height: 1.4;
}
.announcement-badge {
    flex-shrink: 0;
    color: #92400E;
    background: #FEF3C7;
    border: 0.5px solid #FDE68A;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 600;
}
.announcement-date,
.announcement-dialog-date {
    color: var(--ios-text-tertiary);
    font-size: 12px;
    margin-top: 6px;
}
.announcement-content,
.announcement-dialog-content {
    color: var(--ios-text-secondary);
    font-size: 14px;
    line-height: 1.7;
    margin-top: 12px;
    white-space: pre-wrap;
}
.empty-state {
    background: var(--ios-white);
    color: var(--ios-text-tertiary);
    border-radius: var(--ios-radius-sm);
    padding: 24px;
    text-align: center;
}
.announcement-modal {
    position: fixed;
    inset: 0;
    z-index: 1200;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(0,0,0,0.42);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}
.announcement-dialog {
    width: min(620px, 100%);
    max-height: min(720px, 86vh);
    background: var(--ios-white);
    border-radius: 14px;
    box-shadow: 0 24px 70px rgba(0,0,0,0.28);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.announcement-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 0.5px solid var(--ios-gray5);
}
.announcement-dialog-header h3 {
    font-size: 18px;
}
.announcement-close {
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: 50%;
    background: var(--ios-gray6);
    color: var(--ios-text-secondary);
    cursor: pointer;
    font-size: 22px;
    line-height: 32px;
}
.announcement-dialog-body {
    overflow: auto;
    padding: 4px 20px;
}
.announcement-dialog-item {
    padding: 16px 0;
    border-bottom: 0.5px solid var(--ios-gray5);
}
.announcement-dialog-item:last-child {
    border-bottom: 0;
}
.announcement-dialog-item h4 {
    font-size: 16px;
}
.announcement-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 14px 20px;
    border-top: 0.5px solid var(--ios-gray5);
}

/* ====== Admin Improvements ====== */
.admin-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}
.admin-page-head h2 {
    margin-bottom: 4px;
}
.admin-form-card,
.admin-table-card {
    padding: 20px;
    margin-bottom: 18px;
}
.admin-form-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 14px;
}
.admin-switch-row,
.admin-form-actions,
.admin-row-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.admin-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    border: 0.5px solid var(--ios-gray5);
    border-radius: 8px;
    background: var(--ios-gray6);
    font-size: 13px;
}
.admin-card-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.admin-announcement-card {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
    background: var(--ios-white);
    border: 0.5px solid var(--ios-gray5);
    border-radius: 10px;
    box-shadow: var(--ios-shadow);
}
.admin-announcement-main {
    min-width: 0;
    flex: 1;
}
.admin-announcement-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 8px;
}
.admin-announcement-content {
    color: var(--ios-text-secondary);
    font-size: 13px;
    line-height: 1.6;
    white-space: pre-wrap;
    max-height: 92px;
    overflow: auto;
}
.admin-announcement-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
    color: var(--ios-text-tertiary);
    font-size: 12px;
}
.admin-empty {
    padding: 22px;
    color: var(--ios-text-tertiary);
    text-align: center;
}
.admin-search-form {
    display: flex;
    align-items: center;
    gap: 8px;
}
.admin-search-form input {
    width: min(320px, 38vw);
    padding: 8px 10px;
    border: 0.5px solid var(--ios-gray4);
    border-radius: 8px;
    background: var(--ios-white);
}
.admin-user-table td {
    vertical-align: middle;
}
.admin-detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.admin-detail-card {
    padding: 18px;
}
.admin-detail-card h3 {
    font-size: 16px;
    margin-bottom: 12px;
}
.admin-detail-list {
    display: grid;
    grid-template-columns: 92px minmax(0, 1fr);
    gap: 8px 12px;
    font-size: 13px;
}
.admin-detail-list dt {
    color: var(--ios-text-tertiary);
}
.admin-detail-list dd {
    min-width: 0;
    word-break: break-word;
}
.admin-label {
    display: block;
    margin: 12px 0 6px;
    color: var(--ios-text-tertiary);
    font-size: 12px;
}
.admin-hash-box {
    padding: 10px;
    border-radius: 8px;
    background: #1e1e1e;
    color: #d4d4d4;
    font: 12px/1.5 "SF Mono", "Menlo", "Consolas", monospace;
    word-break: break-all;
}
.admin-reset-form {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}
.admin-reset-form input {
    min-width: 0;
    flex: 1;
    padding: 8px 10px;
    border: 0.5px solid var(--ios-gray4);
    border-radius: 8px;
}
.admin-chat-preview {
    max-width: 680px;
    max-height: 84px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--ios-text-secondary);
    font-size: 12px;
}
.admin-quota-card {
    margin-bottom: 20px;
    padding: 18px 20px;
}
.admin-quota-form {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}
.admin-quota-copy {
    min-width: 0;
}
.admin-quota-copy h3 {
    margin-bottom: 4px;
}
.admin-quota-copy p {
    font-size: 13px;
}
.admin-quota-controls {
    display: grid;
    grid-template-columns: auto 132px auto;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.admin-quota-controls label {
    color: var(--ios-text-secondary);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
}
.admin-quota-controls input {
    height: 36px;
    padding: 0 10px;
    border: 0.5px solid var(--ios-gray4);
    border-radius: 8px;
    background: var(--ios-white);
}
.admin-quota-controls .btn {
    height: 36px;
    padding-top: 0;
    padding-bottom: 0;
}
.admin-quota-hint {
    margin-top: 10px;
    color: var(--ios-text-tertiary);
    font-size: 12px;
}

@media (max-width: 900px) {
    .admin-page-head,
    .admin-announcement-card {
        flex-direction: column;
    }
    .admin-search-form {
        width: 100%;
        flex-wrap: wrap;
    }
    .admin-search-form input {
        width: 100%;
    }
    .admin-detail-grid {
        grid-template-columns: 1fr;
    }
    .admin-quota-form {
        align-items: stretch;
        flex-direction: column;
    }
    .admin-quota-controls {
        grid-template-columns: 1fr;
    }
    .admin-quota-controls label {
        white-space: normal;
    }
}

/* ==================== General AI Chat ==================== */
.ai-chat-shell {
    min-height: calc(100vh - 48px);
    height: calc(100vh - 48px);
    background:
        radial-gradient(circle at 12% 10%, rgba(0, 122, 255, 0.10), transparent 28%),
        radial-gradient(circle at 86% 8%, rgba(52, 199, 89, 0.10), transparent 26%),
        linear-gradient(180deg, #f8fafc 0%, #eef2f7 100%);
}

.ai-session-sidebar {
    width: 280px;
    padding: 16px 12px;
    border-right: 1px solid rgba(148, 163, 184, 0.20);
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: blur(22px);
    backdrop-filter: blur(22px);
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
}

.ai-session-sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 4px 0;
}

.ai-session-kicker {
    color: #94a3b8;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.ai-session-sidebar h2 {
    margin: 2px 0 0;
    color: #0f172a;
    font-size: 22px;
    letter-spacing: -0.04em;
}

.ai-new-chat-btn {
    width: 34px;
    height: 34px;
    border: none;
    border-radius: 12px;
    background: #111827;
    color: #fff;
    font-size: 24px;
    line-height: 30px;
    cursor: pointer;
    box-shadow: 0 14px 30px rgba(15, 23, 42, 0.18);
}

.ai-new-chat-wide-btn {
    height: 42px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 14px;
    background: #111827;
    color: #fff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 12px 34px rgba(15, 23, 42, 0.15);
}

.ai-new-chat-btn:hover,
.ai-new-chat-wide-btn:hover {
    transform: translateY(-1px);
}

.ai-session-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    overflow-y: auto;
    min-height: 0;
    padding-right: 2px;
}

.ai-session-item {
    width: 100%;
    min-height: 58px;
    border: 1px solid transparent;
    border-radius: 16px;
    padding: 10px 12px;
    background: transparent;
    color: #334155;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-session-item:hover {
    background: rgba(255, 255, 255, 0.70);
    border-color: rgba(148, 163, 184, 0.16);
}

.ai-session-item.active {
    background: #fff;
    border-color: rgba(14, 165, 233, 0.22);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

.ai-session-title {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 700;
}

.ai-session-time {
    display: block;
    margin-top: 4px;
    color: #94a3b8;
    font-size: 12px;
}

.ai-session-empty {
    padding: 14px 10px;
    color: #94a3b8;
    font-size: 13px;
    text-align: center;
}

.ai-chat-main {
    width: min(100%, 1120px);
    margin: 0 auto;
    background: transparent;
}

.ai-chat-navbar {
    margin: 18px 18px 0;
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.72);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.08);
    justify-content: space-between;
}

.ai-chat-navbar .chat-nav-title {
    font-size: 18px;
    font-weight: 750;
    color: #111827;
}

.ai-chat-navbar .chat-nav-subtitle {
    color: #64748b;
}

.ai-chat-clear-btn {
    border: 1px solid rgba(15, 23, 42, 0.08);
    background: rgba(255, 255, 255, 0.8);
    color: #475569;
    border-radius: 999px;
    padding: 8px 13px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ai-chat-clear-btn:hover {
    background: #fff;
    color: #ef4444;
    border-color: rgba(239, 68, 68, 0.22);
}

.ai-chat-messages {
    padding: 26px 18px 20px;
    background: transparent;
    gap: 18px;
}

.history-page-loading {
    align-self: center;
    padding: 7px 12px;
    border-radius: 999px;
    font-size: 12px;
    color: #64748b;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(148, 163, 184, 0.18);
}

.guest-chat-notice {
    margin: 14px auto 0;
    max-width: 860px;
    padding: 10px 14px;
    border: 1px solid rgba(0, 122, 255, 0.18);
    border-radius: 14px;
    background: rgba(0, 122, 255, 0.08);
    color: var(--ios-text-primary);
    font-size: 13px;
    line-height: 1.6;
}

.guest-chat-notice a {
    color: var(--ios-blue);
    font-weight: 700;
    margin-left: 8px;
    text-decoration: none;
}

.ai-chat-welcome {
    padding: 64px 20px 38px;
}

.ai-welcome-icon {
    background: linear-gradient(135deg, #ffffff, #e0f2fe);
    border: 1px solid rgba(14, 165, 233, 0.16);
    box-shadow: 0 24px 70px rgba(14, 165, 233, 0.16);
}

.ai-chat-welcome h3 {
    font-size: clamp(28px, 4vw, 46px);
    letter-spacing: -0.05em;
    color: #0f172a;
    margin-bottom: 12px;
}

.ai-chat-welcome p {
    max-width: 560px;
    font-size: 16px;
    color: #64748b;
}

.ai-demo-prompts,
.ai-chat-welcome .demo-prompts {
    max-width: 720px;
    gap: 10px;
}

.ai-chat-welcome .demo-prompt {
    color: #0f172a;
    background: rgba(255, 255, 255, 0.76);
    border-color: rgba(148, 163, 184, 0.24);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

.ai-chat-welcome .demo-prompt:hover {
    color: #0369a1;
    border-color: rgba(14, 165, 233, 0.32);
    transform: translateY(-1px);
}

.ai-chat-shell.dragging-images::after {
    content: '松开鼠标上传图片';
    position: fixed;
    inset: 62px 18px 18px;
    border: 2px dashed rgba(0, 122, 255, 0.45);
    border-radius: 28px;
    background: rgba(239, 246, 255, 0.74);
    color: #0369a1;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 700;
    z-index: 90;
    pointer-events: none;
}

.ai-chat-main .chat-message {
    width: min(100%, 880px);
    margin: 0 auto;
}

.ai-chat-main .chat-message.user,
.ai-chat-main .chat-message.assistant {
    padding-left: 0;
    padding-right: 0;
}

.ai-chat-main .message-avatar {
    width: 34px;
    height: 34px;
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.ai-chat-main .chat-message.user .message-avatar {
    background: #111827;
}

.ai-chat-main .chat-message.assistant .message-avatar {
    background: linear-gradient(135deg, #0ea5e9, #22c55e);
}

.ai-chat-main .message-content {
    max-width: min(760px, calc(100vw - 92px));
    padding: 14px 16px;
    border-radius: 20px;
    box-shadow: 0 12px 36px rgba(15, 23, 42, 0.07);
}

.ai-chat-main .chat-message.user .message-content {
    background: #111827;
    border-bottom-right-radius: 8px;
}

.ai-chat-main .chat-message.assistant .message-content {
    background: rgba(255, 255, 255, 0.88);
    border: 1px solid rgba(148, 163, 184, 0.18);
    border-bottom-left-radius: 8px;
}

.message-image-gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.message-image-gallery > img {
    width: 148px;
    max-width: 100%;
    height: 112px;
    object-fit: cover;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.26);
    background: rgba(255, 255, 255, 0.1);
    cursor: zoom-in;
}

.message-image-gallery.image-attachment-gallery {
    width: 100%;
    align-items: flex-start;
}

.message-image-gallery .uploaded-image-card {
    width: min(100%, 320px);
    margin: 0;
}

.ai-chat-input-area {
    width: min(100%, 920px);
    margin: 0 auto;
    padding: 10px 18px 18px;
    background: transparent;
    border-top: none;
}

.ai-chat-input-wrapper {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 26px;
    padding: 8px 9px 8px 10px;
    box-shadow: 0 18px 60px rgba(15, 23, 42, 0.12);
}

.ai-chat-input-wrapper:focus-within {
    background: #fff;
    border-color: rgba(0, 122, 255, 0.34);
    box-shadow: 0 20px 70px rgba(2, 132, 199, 0.17);
}

.chat-tool-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    color: #64748b;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.chat-tool-btn:hover {
    color: #0ea5e9;
    background: rgba(14, 165, 233, 0.10);
}

.chat-tool-btn.disabled,
.chat-tool-btn:disabled {
    color: #cbd5e1;
    cursor: not-allowed;
    opacity: 0.55;
}

.chat-tool-btn.disabled:hover,
.chat-tool-btn:disabled:hover {
    color: #cbd5e1;
    background: transparent;
}

.ai-chat-input-wrapper textarea {
    font-size: 16px;
    padding: 9px 0;
}

.ai-image-preview-list {
    flex-wrap: wrap;
    gap: 10px;
    padding: 0 4px 10px;
}

.ai-image-preview-item {
    position: relative;
    width: 86px;
    height: 86px;
    border-radius: 18px;
    overflow: hidden;
    background: #fff;
    border: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.10);
}

.ai-image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.ai-image-preview-item.loading img,
.ai-image-preview-item.error img {
    filter: grayscale(0.2);
    opacity: 0.58;
}

.ai-image-preview-state {
    position: absolute;
    left: 50%;
    bottom: 7px;
    transform: translateX(-50%);
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 11px;
    color: #fff;
    background: rgba(15, 23, 42, 0.72);
    white-space: nowrap;
}

.ai-image-preview-item button {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 50%;
    background: rgba(15, 23, 42, 0.75);
    color: #fff;
    cursor: pointer;
    line-height: 20px;
    font-size: 16px;
}

.ai-chat-input-hint {
    margin-top: 8px;
    color: #94a3b8;
    font-size: 12px;
    text-align: center;
}

@media (max-width: 720px) {
    .ai-chat-shell {
        flex-direction: column;
    }
    .ai-session-sidebar {
        width: 100%;
        max-height: 132px;
        padding: 10px;
        border-right: none;
        border-bottom: 1px solid rgba(148, 163, 184, 0.20);
    }
    .ai-session-sidebar-head {
        display: none;
    }
    .ai-new-chat-wide-btn {
        height: 36px;
        flex-shrink: 0;
    }
    .ai-session-list {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
    }
    .ai-session-item {
        min-width: 164px;
        min-height: 48px;
    }
    .ai-chat-navbar {
        margin: 10px 10px 0;
        border-radius: 18px;
        padding: 10px 12px;
    }
    .ai-chat-clear-btn {
        padding: 7px 10px;
        font-size: 12px;
    }
    .ai-chat-messages {
        padding: 18px 10px 14px;
    }
    .ai-chat-main .message-avatar {
        display: none;
    }
    .ai-chat-main .message-content {
        max-width: calc(100vw - 28px);
    }
    .ai-chat-input-area {
        padding: 8px 10px 12px;
    }
    .ai-chat-input-hint {
        display: none;
    }
}

/* ==================== iOS AI Chat Controls ==================== */
.ai-chat-shell {
    background:
        radial-gradient(circle at 8% 0%, rgba(0, 122, 255, 0.12), transparent 24%),
        radial-gradient(circle at 92% 8%, rgba(52, 199, 89, 0.12), transparent 24%),
        linear-gradient(180deg, #F9F9FB 0%, var(--ios-gray6) 100%);
}

.ai-mode-rail {
    width: 76px;
    padding: 14px 8px;
    border-right: 0.5px solid rgba(60, 60, 67, 0.12);
    background: rgba(247, 247, 250, 0.86);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
    backdrop-filter: saturate(180%) blur(22px);
    display: flex;
    flex-direction: column;
    align-items: center;
    flex-shrink: 0;
}

.ai-session-sidebar {
    width: 268px;
    background: rgba(242, 242, 247, 0.78);
    border-right-color: rgba(60, 60, 67, 0.12);
}

.ai-session-sidebar h2,
.ai-chat-navbar .chat-nav-title,
.ai-chat-welcome h3 {
    color: var(--ios-text);
}

.ai-mode-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 0;
}

.ai-mode-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 66px;
    width: 58px;
    padding: 8px 4px;
    border: 0.5px solid rgba(60, 60, 67, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.62);
    color: var(--ios-text-secondary);
    font-size: 12px;
    font-weight: 700;
    line-height: 1.15;
    text-decoration: none;
    cursor: pointer;
    transition: all var(--ios-transition);
}

.ai-mode-item:hover {
    background: rgba(255, 255, 255, 0.86);
}

.ai-mode-item.active {
    background: var(--ios-blue);
    color: #fff;
    border-color: rgba(0, 122, 255, 0.32);
    box-shadow: 0 12px 24px rgba(0, 122, 255, 0.20);
}

.ai-mode-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 11px;
    background: rgba(0, 122, 255, 0.10);
    font-size: 0;
}

.ai-mode-label {
    display: block;
    white-space: nowrap;
}

.ai-mode-item.active .ai-mode-icon {
    background: rgba(255, 255, 255, 0.20);
}

.ai-new-chat-btn,
.ai-new-chat-wide-btn {
    background: var(--ios-blue);
    box-shadow: 0 12px 28px rgba(0, 122, 255, 0.22);
}

.ai-session-item {
    color: var(--ios-text-secondary);
}

.ai-session-item:hover {
    background: rgba(255, 255, 255, 0.72);
}

.ai-session-item.active {
    background: rgba(255, 255, 255, 0.92);
    border-color: rgba(0, 122, 255, 0.20);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.06);
}

.ai-chat-navbar {
    background: rgba(255, 255, 255, 0.78);
    border-color: rgba(60, 60, 67, 0.12);
    -webkit-backdrop-filter: saturate(180%) blur(22px);
    backdrop-filter: saturate(180%) blur(22px);
}

.ai-chat-nav-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.ai-chat-bottom-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin: 10px 0 0;
    padding: 9px 10px;
    border: 0.5px solid rgba(60, 60, 67, 0.12);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.72);
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    backdrop-filter: saturate(180%) blur(18px);
    box-shadow: 0 12px 34px rgba(15, 23, 42, 0.08);
}

.ai-model-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 10px;
    border: 0.5px solid rgba(60, 60, 67, 0.16);
    border-radius: 999px;
    background: rgba(242, 242, 247, 0.82);
    color: var(--ios-text-tertiary);
    font-size: 12px;
    font-weight: 600;
}

.ai-chat-model-select {
    min-width: 150px;
    max-width: 240px;
    height: 30px;
    border: none;
    outline: none;
    background: transparent;
    color: var(--ios-text);
    font-size: 13px;
    font-weight: 650;
    font-family: inherit;
}

.desktop-model-select-display {
    position: relative;
    display: inline-flex;
    min-width: 0;
    align-items: center;
}

.desktop-model-select-icon {
    display: block;
    width: 21px;
    height: 21px;
    flex: 0 0 21px;
    border-radius: 6px;
    object-fit: cover;
}

.desktop-model-native-select {
    position: absolute;
    width: 1px !important;
    min-width: 1px !important;
    height: 1px !important;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
    opacity: 0;
    pointer-events: none;
    white-space: nowrap;
}

.desktop-model-select-trigger {
    display: flex;
    width: min(242px, 34vw);
    min-width: 158px;
    height: 32px;
    align-items: center;
    justify-content: space-between;
    gap: 7px;
    padding: 0 4px 0 2px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--ios-text);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.desktop-model-select-trigger:hover:not(:disabled),
.desktop-model-select-trigger[aria-expanded="true"] {
    background: rgba(255, 255, 255, 0.72);
}

.desktop-model-select-trigger:focus-visible {
    outline: 2px solid rgba(0, 122, 255, 0.52);
    outline-offset: 2px;
}

.desktop-model-select-trigger:disabled {
    color: var(--ios-text-tertiary);
    cursor: not-allowed;
}

.desktop-model-select-name {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    font-size: 13px;
    font-weight: 650;
    line-height: 1.45;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.desktop-model-select-arrow {
    display: block;
    flex: 0 0 16px;
    color: var(--ios-text-tertiary);
    transition: transform 0.16s ease;
}

.desktop-model-select-trigger[aria-expanded="true"] .desktop-model-select-arrow {
    transform: rotate(180deg);
}

.desktop-model-select-popover {
    position: fixed;
    z-index: 1100;
    top: 0;
    left: 0;
    display: flex;
    width: min(340px, calc(100vw - 48px));
    max-height: 360px;
    flex-direction: column;
    padding: 6px;
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 18px 46px rgba(15, 23, 42, 0.18);
    isolation: isolate;
    -webkit-backdrop-filter: saturate(180%) blur(18px);
    backdrop-filter: saturate(180%) blur(18px);
}

.desktop-model-select-popover[hidden] {
    display: none;
}

.desktop-model-select-options {
    display: flex;
    min-height: 0;
    flex: 1 1 auto;
    flex-direction: column;
    gap: 3px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    scrollbar-gutter: stable;
    touch-action: pan-y;
}

.desktop-model-option {
    display: grid;
    width: 100%;
    min-height: 60px;
    grid-template-columns: 28px minmax(0, 1fr) 20px;
    align-items: center;
    gap: 9px;
    padding: 9px 10px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: transparent;
    color: #344054;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.desktop-model-option:hover,
.desktop-model-option:focus-visible {
    border-color: #cfe5ff;
    background: #f5f9ff;
    outline: none;
}

.desktop-model-option[aria-selected="true"] {
    border-color: #b8dcff;
    background: #eaf4ff;
    color: #0875dd;
}

.desktop-model-option-icon {
    display: block;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    object-fit: cover;
}

.desktop-model-option-copy {
    display: grid;
    min-width: 0;
    gap: 1px;
}

.desktop-model-option-name,
.desktop-model-option-detail {
    display: block;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.desktop-model-option-name {
    font-size: 13px;
    font-weight: 700;
    line-height: 1.45;
}

.desktop-model-option-detail {
    color: #7b8797;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.45;
}

.desktop-model-option-tags {
    display: flex;
    min-width: 0;
    gap: 4px;
    overflow: hidden;
    white-space: nowrap;
}

.desktop-model-option-tags span {
    display: inline-flex;
    min-height: 16px;
    align-items: center;
    padding: 0 5px;
    border-radius: 999px;
    background: #eef6ff;
    color: #0875dd;
    font-size: 10px;
    font-weight: 700;
}

.desktop-model-option-check {
    position: relative;
    display: block;
    width: 18px;
    height: 18px;
}

.desktop-model-option[aria-selected="true"] .desktop-model-option-check::after {
    position: absolute;
    top: 3px;
    left: 5px;
    width: 5px;
    height: 9px;
    border: solid currentColor;
    border-width: 0 2px 2px 0;
    content: "";
    transform: rotate(45deg);
}

.ai-chat-model-select:disabled {
    color: var(--ios-text-tertiary);
}

.ai-mode-settings {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.ai-image-count-select {
    min-width: 72px;
    max-width: 86px;
}

.ai-poster-style-select {
    min-width: 108px;
    max-width: 132px;
}

.ai-poster-size-select {
    min-width: 114px;
    max-width: 142px;
}

.ai-ppt-small-select {
    min-width: 78px;
    max-width: 92px;
}

.ai-ppt-template-select {
    min-width: 104px;
    max-width: 128px;
}

.ai-ppt-template-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 36px;
    padding: 0 12px;
    border: 0.5px solid rgba(0, 122, 255, 0.22);
    border-radius: 999px;
    background: rgba(0, 122, 255, 0.10);
    color: var(--ios-blue);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    transition: all var(--ios-transition);
}

.ai-ppt-template-action:hover {
    background: rgba(0, 122, 255, 0.16);
    border-color: rgba(0, 122, 255, 0.34);
}

.ai-ppt-template-action:disabled {
    cursor: not-allowed;
    opacity: 0.62;
}

.ai-ppt-toggle-picker {
    min-width: auto;
    gap: 6px;
}

.ai-ppt-toggle-picker input {
    width: 14px;
    height: 14px;
    accent-color: #007aff;
}

.ai-image-gen-switch {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 10px;
    border: 0.5px solid rgba(60, 60, 67, 0.16);
    border-radius: 999px;
    background: rgba(242, 242, 247, 0.82);
    cursor: pointer;
    user-select: none;
}

.ai-image-gen-switch input {
    display: none;
}

.ai-image-gen-switch em {
    color: var(--ios-text-secondary);
    font-size: 13px;
    font-style: normal;
    font-weight: 650;
}

.ai-image-gen-track {
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: var(--ios-gray4);
    transition: all var(--ios-transition);
}

.ai-image-gen-track span {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.22);
    transition: all var(--ios-transition);
}

.ai-image-gen-switch input:checked + .ai-image-gen-track {
    background: var(--ios-green);
}

.ai-image-gen-switch input:checked + .ai-image-gen-track span {
    transform: translateX(18px);
}

.ai-chat-clear-btn {
    background: rgba(242, 242, 247, 0.82);
    border-color: rgba(60, 60, 67, 0.16);
    color: var(--ios-red);
}

.ai-chat-main .chat-message.user .message-avatar {
    background: linear-gradient(135deg, var(--ios-blue), #5AC8FA);
}

.ai-chat-main .chat-message.assistant .message-avatar {
    background: linear-gradient(135deg, var(--ios-green), #30D158);
}

.ai-chat-main .chat-message.user .message-content {
    background: var(--ios-blue);
}

.ai-chat-main .chat-message.assistant .message-content {
    background: rgba(255, 255, 255, 0.94);
    border-color: rgba(60, 60, 67, 0.10);
}

.generated-image-card {
    box-sizing: border-box;
    width: min(100%, 800px);
    max-width: 100%;
    margin: 8px 0;
    padding: 8px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.05);
    color: #374151;
}

.uploaded-image-card {
    border-color: #cfe3f6;
    background: #f8fbff;
    box-shadow: 0 1px 5px rgba(15, 23, 42, 0.04);
}

.uploaded-image-card .generated-image-card__heading svg {
    color: #5687b6;
}

.uploaded-image-card[data-image-state="loaded"] .generated-image-status {
    color: #557d9f;
}

.generated-image-card *,
.generated-image-card *::before,
.generated-image-card *::after {
    box-sizing: border-box;
}

.generated-image-card__header {
    display: flex;
    min-height: 34px;
    align-items: center;
    padding: 0 4px 6px;
}

.generated-image-card__heading {
    display: inline-flex;
    min-width: 0;
    align-items: center;
    gap: 7px;
    color: #374151;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.4;
}

.generated-image-card__heading svg {
    flex: 0 0 auto;
    color: #4385c5;
}

.generated-image-preview {
    display: block;
    width: 100%;
    max-width: 100%;
    cursor: zoom-in;
}

.generated-image-media {
    position: relative;
    display: block;
    width: 100%;
    overflow: hidden;
    border-radius: 10px;
    background: #f7f8fb;
}

.generated-image {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    max-height: min(68vh, 640px);
    object-fit: contain;
    background: #f7f8fb;
}

.generated-image-skeleton {
    display: none;
}

.generated-image-card[data-image-state="loading"] .generated-image-media {
    min-height: clamp(180px, 34vw, 320px);
}

.generated-image-card[data-image-state="loading"] .generated-image {
    visibility: hidden;
}

.generated-image-card[data-image-state="loading"] .generated-image-skeleton {
    position: absolute;
    inset: 0;
    display: block;
    background: linear-gradient(90deg, #f2f4f7 0%, #e7edf5 48%, #f2f4f7 100%);
    background-size: 220% 100%;
    animation: generated-image-skeleton-pulse 1.25s ease-in-out infinite;
}

.generated-image-card[data-image-state="error"] .generated-image-media {
    display: grid;
    min-height: 180px;
    place-items: center;
    border: 1px dashed #d7dee8;
    background: #fafbfc;
}

.generated-image-card[data-image-state="error"] .generated-image {
    display: none;
}

.generated-image-card[data-image-state="error"] .generated-image-media::after {
    color: #8a94a3;
    content: "图片加载失败";
    font-size: 13px;
    line-height: 1.5;
}

.generated-image-card--placeholder[data-image-state="error"] .generated-image-media::after {
    content: attr(data-image-empty-message);
    max-width: 80%;
    text-align: center;
}

@keyframes generated-image-skeleton-pulse {
    from { background-position: 100% 0; }
    to { background-position: -120% 0; }
}

.generated-image-card__footer {
    display: flex;
    min-height: 44px;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 2px 0;
}

.generated-image-status {
    min-width: 0;
    overflow: hidden;
    color: #9ca3af;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.45;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.generated-image-card[data-image-state="loaded"] .generated-image-status {
    color: #499166;
}

.generated-image-card[data-image-state="loading"] .generated-image-status {
    color: #5d7fa6;
}

.generated-image-card[data-image-state="error"] .generated-image-status {
    color: #c75f5f;
}

.generated-image-actions {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 8px;
}

.generated-image-download,
.generated-image-reload {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 0 11px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.generated-image-download {
    border-color: #bfdbfe;
    background: #eff6ff;
    color: #1976d2;
}

.generated-image-reload {
    border-color: #f3c8c8;
    background: #fff7f7;
    color: #bd4f4f;
}

.generated-image-download:hover {
    border-color: #93c5fd;
    background: #e4f1ff;
}

.generated-image-reload:hover {
    border-color: #e9a8a8;
    background: #fff0f0;
}

.generated-image-download:focus-visible,
.generated-image-reload:focus-visible,
.generated-image-preview:focus-visible {
    outline: 2px solid rgba(10, 132, 255, 0.58);
    outline-offset: 2px;
}

.ppt-download-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 36px;
    margin: 2px 0;
    padding: 0 15px;
    border-radius: 999px;
    background: var(--ios-blue);
    color: #fff !important;
    font-size: 13px;
    font-weight: 760;
    line-height: 1;
    text-decoration: none !important;
    box-shadow: 0 10px 24px rgba(0, 122, 255, 0.22);
}

.ppt-download-button:hover {
    background: #0067d8;
}

.ppt-edit-button {
    background: linear-gradient(135deg, #111827, #334155);
    box-shadow: 0 8px 18px rgba(17, 24, 39, 0.18);
}

.ppt-edit-button:hover {
    background: linear-gradient(135deg, #020617, #1e293b);
    box-shadow: 0 10px 22px rgba(17, 24, 39, 0.24);
}

.ppt-download-button svg {
    flex: 0 0 auto;
}

.ppt-result-card {
    width: min(100%, 520px);
    padding: 14px;
    border: 1px solid rgba(10, 132, 255, 0.18);
    border-radius: 14px;
    background: #F8FBFF;
    color: var(--ios-text);
}

.ppt-result-head {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.ppt-result-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    color: #0A84FF;
    background: rgba(10, 132, 255, 0.12);
}

.ppt-result-copy {
    min-width: 0;
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
}

.ppt-result-copy strong {
    color: #111827;
    font-size: 15px;
    font-weight: 760;
    line-height: 1.25;
}

.ppt-result-copy span {
    color: #6B7280;
    font-size: 12px;
    line-height: 1.4;
}

.ppt-result-state {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    flex: 0 0 auto;
    color: #16803D;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.ppt-result-state i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #30D158;
}

.ppt-result-meta {
    display: flex;
    align-items: center;
    gap: 7px;
    margin: 12px 0;
    color: #6B7280;
    font-size: 12px;
}

.ppt-result-meta span:first-child {
    padding: 2px 7px;
    border-radius: 5px;
    color: #2563EB;
    font-size: 11px;
    font-weight: 800;
    background: rgba(37, 99, 235, 0.10);
}

.ppt-result-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.ppt-result-actions:has(.ppt-result-action:only-child) {
    grid-template-columns: minmax(0, 1fr);
}

.ppt-result-action {
    min-width: 0;
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0 10px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-size: 13px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none !important;
    white-space: nowrap;
}

.ppt-result-action svg {
    flex: 0 0 auto;
}

.ppt-result-download {
    color: #fff !important;
    background: #0A84FF;
    box-shadow: 0 7px 16px rgba(10, 132, 255, 0.20);
}

.ppt-result-download:hover {
    background: #0074E8;
}

.ppt-result-edit {
    border-color: rgba(60, 60, 67, 0.16);
    color: #1D1D1F !important;
    background: #fff;
}

.ppt-result-edit:hover {
    background: #F2F2F7;
}

@media (max-width: 460px) {
    .ppt-result-card {
        padding: 12px;
    }

    .ppt-result-copy span {
        display: none;
    }

    .ppt-result-actions {
        grid-template-columns: 1fr;
    }
}

.ppt-editor-page {
    min-height: 100vh;
    margin: 0;
    background:
        radial-gradient(circle at 12% 8%, rgba(0, 122, 255, 0.12), transparent 28%),
        radial-gradient(circle at 80% 12%, rgba(52, 199, 89, 0.10), transparent 26%),
        linear-gradient(180deg, #f5f7fb 0%, #eef2f7 100%);
    color: #111827;
    overflow: hidden;
}

.ppt-editor-topbar {
    height: 72px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(255, 255, 255, 0.86);
    backdrop-filter: blur(22px);
    box-shadow: 0 10px 32px rgba(15, 23, 42, 0.08);
    position: relative;
    z-index: 3;
}

.ppt-editor-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.ppt-editor-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 104px;
    height: 38px;
    padding: 0 14px;
    border-radius: 999px;
    background: #111827;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    box-shadow: 0 10px 24px rgba(17, 24, 39, 0.20);
}

.ppt-editor-brand h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 850;
    letter-spacing: -0.03em;
}

.ppt-editor-brand p {
    margin: 4px 0 0;
    color: #64748b;
    font-size: 13px;
}

.ppt-editor-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    flex-shrink: 0;
}

.ppt-editor-model-field {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 220px;
    padding: 6px 6px 6px 12px;
    border-radius: 999px;
    background: rgba(241, 245, 249, 0.95);
    color: #475569;
    font-size: 12px;
    font-weight: 750;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.28);
}

.ppt-editor-model-field select {
    min-width: 130px;
    max-width: 220px;
    height: 30px;
    border: 0;
    border-radius: 999px;
    padding: 0 28px 0 12px;
    background: #fff;
    color: #111827;
    font-size: 12px;
    font-weight: 750;
    outline: none;
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
}

.ppt-editor-id {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #64748b;
    font-size: 12px;
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(241, 245, 249, 0.9);
}

.ppt-editor-action {
    border: 0;
    border-radius: 999px;
    padding: 10px 14px;
    background: #fff;
    color: #111827;
    font-size: 13px;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
    box-shadow: inset 0 0 0 1px rgba(148, 163, 184, 0.30);
}

.ppt-editor-action.primary {
    background: #007aff;
    color: #fff;
    box-shadow: 0 10px 24px rgba(0, 122, 255, 0.25);
}

.ppt-editor-main {
    height: calc(100vh - 72px);
    padding: 14px;
}

.ppt-editor-frame {
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 22px;
    background: #fff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.16);
}

.ppt-editor-error {
    max-width: 520px;
    margin: 12vh auto 0;
    padding: 34px;
    border-radius: 28px;
    background: #fff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.12);
    text-align: center;
}

.ppt-editor-error h2 {
    margin: 0 0 12px;
    font-size: 24px;
}

.ppt-editor-error p {
    color: #64748b;
}

.ppt-editor-error a {
    display: inline-flex;
    margin-top: 12px;
    padding: 10px 16px;
    border-radius: 999px;
    background: #007aff;
    color: #fff;
    text-decoration: none;
    font-weight: 800;
}

@media (max-width: 980px) {
    .ppt-editor-topbar {
        height: auto;
        min-height: 72px;
        align-items: flex-start;
        flex-direction: column;
        padding: 12px;
    }

    .ppt-editor-actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .ppt-editor-model-field {
        min-width: min(100%, 280px);
    }

    .ppt-editor-main {
        height: calc(100vh - 138px);
        padding: 10px;
    }
}

.image-preview-open {
    overflow: hidden;
}

.image-download-open {
    overflow: hidden;
}

.image-download-modal {
    position: fixed;
    inset: 0;
    z-index: 10020;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.image-download-modal.visible {
    display: flex;
}

.image-download-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.54);
    -webkit-backdrop-filter: blur(18px);
    backdrop-filter: blur(18px);
}

.image-download-dialog {
    position: relative;
    z-index: 1;
    width: min(92vw, 420px);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.96);
    border: 0.5px solid rgba(60, 60, 67, 0.16);
    box-shadow: 0 28px 90px rgba(15, 23, 42, 0.28);
    padding: 22px;
}

.image-download-dialog h3 {
    margin: 0 0 16px;
    font-size: 20px;
    font-weight: 800;
    color: var(--ios-text);
}

.image-download-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    background: rgba(120, 120, 128, 0.14);
    color: var(--ios-text-secondary);
    font-size: 24px;
    line-height: 28px;
    cursor: pointer;
}

.image-download-field {
    display: grid;
    gap: 7px;
    margin-bottom: 14px;
    color: var(--ios-text-secondary);
    font-size: 13px;
    font-weight: 700;
}

.image-download-field input,
.image-download-field select {
    width: 100%;
    min-height: 42px;
    border: 0.5px solid rgba(60, 60, 67, 0.18);
    border-radius: 14px;
    background: rgba(242, 242, 247, 0.82);
    color: var(--ios-text);
    font-size: 15px;
    padding: 0 12px;
    outline: none;
}

.image-download-field input:focus,
.image-download-field select:focus {
    border-color: rgba(0, 122, 255, 0.48);
    box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.10);
}

.image-download-note {
    margin: 2px 0 12px;
    color: var(--ios-text-tertiary);
    font-size: 12px;
    line-height: 1.5;
}

.image-download-error {
    min-height: 18px;
    margin-bottom: 10px;
    color: var(--ios-red);
    font-size: 12px;
    line-height: 1.45;
}

.image-download-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.image-download-actions button {
    min-height: 38px;
    border: none;
    border-radius: 999px;
    padding: 0 18px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

.image-download-cancel {
    background: rgba(120, 120, 128, 0.14);
    color: var(--ios-text-secondary);
}

.image-download-confirm {
    background: var(--ios-blue);
    color: #fff;
}

.image-download-confirm:disabled {
    opacity: 0.62;
    cursor: not-allowed;
}

.image-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.image-preview-modal.visible {
    display: flex;
}

.image-preview-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.72);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
}

.image-preview-dialog {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: min(96vw, 1120px);
    max-height: 92vh;
}

.image-preview-large {
    display: block;
    max-width: 100%;
    max-height: 92vh;
    border-radius: 18px;
    background: #fff;
    box-shadow: 0 28px 90px rgba(0, 0, 0, 0.34);
}

.image-preview-close {
    position: absolute;
    top: -14px;
    right: -14px;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.94);
    color: #111827;
    font-size: 26px;
    line-height: 34px;
    cursor: pointer;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

.image-preview-close:hover {
    background: #fff;
}

@media (max-width: 720px) {
    .ai-chat-shell {
        flex-direction: row;
        overflow: hidden;
    }
    .ai-mode-rail {
        width: 64px;
        padding: 10px 6px;
        border-right: 0.5px solid rgba(60, 60, 67, 0.12);
        border-bottom: none;
    }
    .ai-mode-item {
        width: 50px;
        min-height: 58px;
        gap: 5px;
        border-radius: 16px;
        font-size: 11px;
    }
    .ai-mode-icon {
        width: 24px;
        height: 24px;
        border-radius: 9px;
    }
    .ai-session-sidebar {
        width: 168px;
        max-height: none;
        padding: 10px 8px;
        border-right: 0.5px solid rgba(60, 60, 67, 0.12);
        border-bottom: none;
    }
    .ai-session-sidebar-head {
        display: flex;
        padding: 0 2px;
    }
    .ai-session-sidebar h2 {
        font-size: 18px;
    }
    .ai-session-kicker {
        font-size: 10px;
    }
    .ai-new-chat-btn {
        width: 30px;
        height: 30px;
        border-radius: 10px;
        font-size: 21px;
    }
    .ai-session-list {
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
    }
    .ai-session-item {
        width: 100%;
        min-width: 0;
        min-height: 50px;
        padding: 9px 10px;
    }
    .ai-chat-main {
        min-width: 0;
    }
    .ai-chat-navbar {
        align-items: flex-start;
        gap: 8px;
    }
    .ai-chat-nav-controls,
    .ai-chat-bottom-toolbar {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
    .ai-mode-settings {
        width: 100%;
    }
    .ai-model-picker {
        flex: 1 1 100%;
    }
    .ai-chat-model-select {
        flex: 1;
        max-width: none;
    }
    .ai-ppt-toggle-picker {
        flex: 0 1 auto;
    }
    .ai-image-gen-switch,
    .ai-chat-clear-btn {
        height: 34px;
    }
}

@media (max-width: 560px) {
    .ai-mode-rail {
        width: 58px;
        padding-left: 4px;
        padding-right: 4px;
    }
    .ai-mode-item {
        width: 48px;
    }
    .ai-session-sidebar {
        width: 150px;
    }
    .ai-session-sidebar-head {
        display: none;
    }
}

/* ==================== Admin Managed Models ==================== */
.managed-model-toolbar {
    display: flex;
    align-items: center;
    gap: 8px 10px;
    margin: 12px 0;
    padding: 10px 12px;
    border: 1px solid rgba(60, 60, 67, 0.10);
    border-radius: 10px;
    background: #f8fafc;
    flex-wrap: wrap;
}

.managed-model-toolbar > * {
    min-width: 0;
    max-width: 100%;
}

.managed-model-toolbar-actions {
    display: inline-flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
    flex: 0 1 auto;
    flex-wrap: wrap;
}

.managed-model-toolbar .btn {
    min-height: 36px;
    max-width: 100%;
    overflow-wrap: anywhere;
    text-align: center;
    white-space: nowrap;
}

.managed-model-toolbar-status {
    flex: 1 1 240px;
    min-width: 0;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.managed-model-source-field {
    display: inline-flex;
    min-width: 0;
    align-items: center;
    gap: 7px;
    color: var(--ios-text-secondary);
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

.managed-model-source-field .form-select {
    width: min(260px, 52vw);
    min-width: 0;
    max-width: 100%;
}

.managed-model-list {
    display: flex;
    container-name: managed-model-list;
    container-type: inline-size;
    flex-direction: column;
    gap: 10px;
}

.managed-model-empty {
    padding: 14px;
    border: 1px dashed var(--ios-gray4);
    border-radius: 10px;
    color: var(--ios-text-tertiary);
    font-size: 13px;
    background: #fafbfc;
}

.managed-model-row {
    position: relative;
    display: block;
    padding: 14px 16px;
    border: 1px solid rgba(60, 60, 67, 0.12);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.03);
    transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.managed-model-row:hover {
    border-color: #cbd5e1;
    box-shadow: 0 5px 16px rgba(15, 23, 42, 0.06);
}

.managed-model-row-main {
    display: grid;
    grid-template-columns: minmax(220px, 1.55fr) minmax(160px, 1fr) max-content max-content;
    grid-template-areas: "summary meta rate actions";
    gap: 10px 14px;
    align-items: center;
}

.managed-model-row-main > *,
.managed-model-profile-call-grid > *,
.managed-model-profile-grid > * {
    min-width: 0;
    max-width: 100%;
}

.managed-model-row.image-model-row .managed-model-row-main {
    grid-template-columns: minmax(220px, 1.55fr) minmax(180px, 1fr) max-content max-content;
}

.managed-model-summary {
    grid-area: summary;
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 10px;
}

.managed-model-summary > img {
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    border: 1px solid #dfe5ee;
    border-radius: 9px;
    background: #f8fafc;
    object-fit: cover;
}

.managed-model-summary-copy {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.managed-model-summary-copy strong,
.managed-model-summary-copy span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.managed-model-summary-copy strong {
    color: var(--ios-text);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.35;
}

.managed-model-summary-copy span {
    color: var(--ios-text-tertiary);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11px;
    line-height: 1.35;
}

.managed-model-summary-meta {
    grid-area: meta;
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 7px;
    flex-wrap: wrap;
}

.managed-model-default {
    position: relative;
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 0 9px;
    border: 1px solid #dbe3ed;
    border-radius: 999px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.managed-model-default input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.managed-model-default.is-active {
    border-color: #92c8ff;
    background: #eaf5ff;
    color: #0074d9;
}

.managed-model-default input:focus-visible + span {
    outline: 2px solid #0a84ff;
    outline-offset: 3px;
    border-radius: 4px;
}

.managed-model-api-chip {
    flex: 0 1 148px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    overflow: hidden;
    max-width: 148px;
    padding: 4px 8px;
    border: 1px solid #e2e8f0;
    border-radius: 999px;
    background: #f8fafc;
    color: #64748b;
    font-size: 11px;
    font-weight: 650;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.managed-model-api-chip.is-following {
    border-color: #b9dcff;
    background: #f1f8ff;
    color: #0a72ca;
}

.managed-model-api-chip.is-bound {
    border-color: #dbe3ed;
    background: #f8fafc;
    color: #475569;
}

.managed-model-fallback-chip {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 0 9px;
    border: 1px solid #c7e2ff;
    border-radius: 999px;
    background: #f1f8ff;
    color: #1672c4;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.managed-model-reference {
    position: relative;
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 0 9px;
    border: 1px solid #dbe3ed;
    border-radius: 999px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

.managed-model-reference input {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

.managed-model-reference.is-active {
    border-color: #9ed6c1;
    background: #effaf4;
    color: #218553;
}

.managed-model-reference input:focus-visible + span {
    outline: 2px solid #0a84ff;
    outline-offset: 3px;
    border-radius: 4px;
}

.managed-model-rate-field {
    grid-area: rate;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    color: var(--ios-text-secondary);
    font-size: 12px;
    font-weight: 650;
    white-space: nowrap;
}

.managed-model-rate-label {
    color: #64748b;
}

.managed-model-rate-control {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.managed-model-rate {
    width: 82px;
    min-width: 82px;
    min-height: 36px;
    padding-right: 23px;
    padding-left: 9px;
    border-color: #dbe3ed;
    background: #fbfdff;
    text-align: center;
}

.managed-model-rate-control em {
    position: absolute;
    right: 9px;
    color: #94a3b8;
    font-size: 12px;
    font-style: normal;
    pointer-events: none;
}

.managed-model-row-actions {
    grid-area: actions;
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    min-height: 36px;
    gap: 7px;
    white-space: normal;
}

.managed-model-action-menu {
    position: relative;
}

.managed-model-action-trigger {
    display: inline-grid;
    width: 36px;
    height: 36px;
    padding: 0;
    place-items: center;
    border: 1px solid #dbe3ed;
    border-radius: 8px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
}

.managed-model-action-trigger:hover,
.managed-model-action-menu.is-open .managed-model-action-trigger {
    border-color: #9dceff;
    background: #eff8ff;
    color: #0074d9;
}

.managed-model-action-trigger:focus-visible {
    outline: 2px solid #0a84ff;
    outline-offset: 2px;
}

.managed-model-action-menu-panel {
    position: absolute;
    z-index: 40;
    top: calc(100% + 7px);
    right: 0;
    display: none;
    width: 148px;
    padding: 5px;
    border: 1px solid #dfe5ee;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.15);
}

.managed-model-action-menu.is-open .managed-model-action-menu-panel {
    display: grid;
    gap: 2px;
}

.managed-model-action-menu-panel button {
    min-height: 34px;
    padding: 0 9px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #334155;
    cursor: pointer;
    font: inherit;
    font-size: 12px;
    font-weight: 650;
    text-align: left;
}

.managed-model-action-menu-panel button:hover {
    background: #f1f5f9;
}

.managed-model-action-menu-panel button.is-danger {
    color: #d92d20;
}

.managed-model-action-menu-panel button.is-danger:hover {
    background: #fff1f0;
}

.managed-model-profile {
    margin-top: 10px;
    border-top: 1px solid rgba(60, 60, 67, 0.10);
}

.managed-model-profile > summary {
    display: flex;
    min-height: 36px;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 0 0;
    color: var(--ios-text-secondary);
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
    list-style: none;
}

.managed-model-profile > summary::-webkit-details-marker {
    display: none;
}

.managed-model-profile > summary::before {
    width: 6px;
    height: 6px;
    margin-right: 2px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    content: "";
    transform: rotate(-45deg);
    transition: transform 0.16s ease;
}

.managed-model-profile[open] > summary::before {
    transform: rotate(45deg);
}

.managed-model-profile > summary > span {
    margin-right: auto;
}

.managed-model-profile > summary > img {
    width: 22px;
    height: 22px;
    border: 1px solid var(--ios-gray4);
    border-radius: 6px;
    object-fit: cover;
}

.managed-model-profile-body {
    display: grid;
    gap: 12px;
    padding: 14px 0 3px;
}

.managed-model-profile-call {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid #e7ebf0;
    border-radius: 10px;
    background: #fafbfc;
}

.managed-model-profile-call > div:first-child {
    display: grid;
    gap: 3px;
}

.managed-model-profile-call > div:first-child strong {
    color: var(--ios-text);
    font-size: 13px;
}

.managed-model-profile-call > div:first-child .text-muted {
    color: var(--ios-text-tertiary);
    font-size: 12px;
    line-height: 1.45;
}

.managed-model-profile-call-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(210px, 1fr) auto;
    gap: 10px;
    align-items: end;
}

.managed-model-profile-call-grid label {
    display: grid;
    min-width: 0;
    gap: 5px;
    color: var(--ios-text-secondary);
    font-size: 12px;
    font-weight: 650;
}

.managed-model-profile-call-grid .form-control,
.managed-model-profile-call-grid .form-select,
.managed-model-profile-grid .form-control,
.managed-model-icon-url .form-control {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.managed-model-fetch-button {
    min-height: 36px;
    white-space: nowrap;
}

.managed-model-fallback-settings {
    display: grid;
    gap: 9px;
    padding: 11px 12px 12px;
    border: 1px solid #e7ebf0;
    border-radius: 10px;
    background: #fbfcfe;
}

.managed-model-fallback-heading {
    display: grid;
    gap: 3px;
}

.managed-model-fallback-heading strong {
    color: var(--ios-text);
    font-size: 13px;
}

.managed-model-fallback-heading span {
    color: var(--ios-text-tertiary);
    font-size: 11px;
    line-height: 1.45;
}

.managed-model-fallback-api-list {
    display: grid;
    gap: 6px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.managed-model-fallback-api-item {
    display: grid;
    grid-template-columns: 25px minmax(150px, .85fr) minmax(220px, 1.25fr) auto;
    grid-template-areas: "order copy target actions";
    min-width: 0;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 5px 6px;
    border: 1px solid #e3eaf2;
    border-radius: 8px;
    background: #fff;
}

.managed-model-fallback-api-item.is-unavailable {
    border-color: #f3c7c3;
    background: #fffafa;
}

.managed-model-fallback-api-order {
    grid-area: order;
    display: inline-grid;
    width: 24px;
    height: 24px;
    place-items: center;
    border-radius: 7px;
    background: #eef6ff;
    color: #1672c4;
    font-size: 11px;
    font-weight: 750;
}

.managed-model-fallback-api-copy {
    grid-area: copy;
    display: grid;
    min-width: 0;
    gap: 1px;
}

.managed-model-fallback-api-copy strong,
.managed-model-fallback-api-copy small {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.managed-model-fallback-api-copy strong {
    color: var(--ios-text);
    font-size: 12px;
    font-weight: 700;
}

.managed-model-fallback-api-copy small {
    color: var(--ios-text-tertiary);
    font-size: 10px;
    line-height: 1.35;
}

.managed-model-fallback-target {
    grid-area: target;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    min-width: 0;
    align-items: end;
    gap: 7px;
}

.managed-model-fallback-target label {
    display: grid;
    min-width: 0;
    gap: 3px;
    color: var(--ios-text-tertiary);
    font-size: 10px;
    font-weight: 650;
}

.managed-model-fallback-target .form-select {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 34px;
    padding-top: 5px;
    padding-bottom: 5px;
    color: var(--ios-text);
    font-size: 12px;
}

.managed-model-fallback-fetch {
    min-height: 34px;
    padding-right: 9px;
    padding-left: 9px;
    white-space: nowrap;
}

.managed-model-fallback-api-actions {
    grid-area: actions;
    display: inline-flex;
    min-width: max-content;
    align-items: center;
    gap: 3px;
}

.managed-model-fallback-api-button {
    display: inline-grid;
    width: 28px;
    height: 28px;
    padding: 0;
    place-items: center;
    border: 1px solid #dbe3ed;
    border-radius: 6px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    font: inherit;
    font-size: 14px;
    line-height: 1;
}

.managed-model-fallback-api-button:hover:not(:disabled) {
    border-color: #9dceff;
    background: #eff8ff;
    color: #0074d9;
}

.managed-model-fallback-api-button.is-danger {
    color: #c2410c;
}

.managed-model-fallback-api-button.is-danger:hover:not(:disabled) {
    border-color: #f3b4ae;
    background: #fff1f0;
    color: #b42318;
}

.managed-model-fallback-api-button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.managed-model-fallback-api-empty {
    padding: 8px 2px;
    color: var(--ios-text-tertiary);
    font-size: 11px;
    line-height: 1.45;
}

.managed-model-fallback-add {
    display: grid;
    gap: 5px;
    color: var(--ios-text-secondary);
    font-size: 11px;
    font-weight: 650;
}

.managed-model-fallback-add .form-select {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
}

.managed-model-profile-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.managed-model-profile-grid label,
.managed-model-icon-url {
    display: grid;
    min-width: 0;
    gap: 5px;
    color: var(--ios-text-secondary);
    font-size: 12px;
    font-weight: 650;
}

.managed-model-profile-grid input,
.managed-model-icon-url input {
    min-width: 0;
}

.managed-model-profile-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.managed-model-profile-toggles label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--ios-text-secondary);
    font-size: 12px;
    font-weight: 600;
}

.managed-model-icon-settings {
    display: grid;
    gap: 10px;
    padding-top: 2px;
}

.managed-model-icon-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.managed-model-icon-heading > div {
    display: grid;
    gap: 3px;
}

.managed-model-icon-heading strong {
    color: var(--ios-text);
    font-size: 13px;
}

.managed-model-icon-heading span {
    color: var(--ios-text-tertiary);
    font-size: 11px;
    line-height: 1.45;
}

.managed-model-icon-heading > img {
    width: 42px;
    height: 42px;
    border: 1px solid var(--ios-gray4);
    border-radius: 10px;
    background: var(--ios-gray6);
    object-fit: cover;
}

.managed-model-icon-library {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
    gap: 7px;
}

.managed-model-icon-choice {
    display: grid;
    min-height: 70px;
    place-items: center;
    gap: 4px;
    padding: 7px 4px;
    border: 1px solid var(--ios-gray4);
    border-radius: 9px;
    background: #fff;
    color: var(--ios-text-secondary);
    font: inherit;
    cursor: pointer;
}

.managed-model-icon-choice:hover,
.managed-model-icon-choice.is-selected {
    border-color: #91c9ff;
    background: #eff8ff;
    color: #0875dd;
}

.managed-model-icon-choice img {
    width: 27px;
    height: 27px;
    border-radius: 7px;
    object-fit: cover;
}

.managed-model-icon-choice span {
    overflow: hidden;
    max-width: 100%;
    font-size: 10px;
    font-weight: 650;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.managed-model-icon-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.managed-model-icon-upload {
    cursor: pointer;
}

.managed-model-icon-file {
    overflow: hidden;
    max-width: min(260px, 100%);
    color: var(--ios-text-tertiary);
    font-size: 11px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.managed-model-picker-modal {
    position: fixed;
    z-index: 12000;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 24px;
    background: rgba(15, 23, 42, 0.38);
}

.managed-model-picker-modal.is-open {
    display: flex;
}

body.managed-model-picker-open {
    overflow: hidden;
}

.managed-model-picker-dialog {
    display: grid;
    grid-template-rows: auto auto auto auto minmax(152px, 1fr) auto;
    width: min(680px, 100%);
    max-height: min(720px, calc(100vh - 48px));
    overflow: hidden;
    border: 1px solid rgba(148, 163, 184, 0.28);
    border-radius: 16px;
    background: #fff;
    box-shadow: 0 24px 64px rgba(15, 23, 42, 0.22);
    outline: none;
}

.managed-model-picker-dialog > * {
    min-width: 0;
}

.managed-model-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #edf0f3;
}

.managed-model-picker-kicker {
    margin: 0 0 3px;
    color: #64748b;
    font-size: 12px;
    font-weight: 650;
}

.managed-model-picker-header h3 {
    margin: 0;
    color: var(--ios-text);
    font-size: 18px;
    line-height: 1.35;
}

.managed-model-picker-header > div {
    min-width: 0;
}

.managed-model-picker-close {
    display: inline-grid;
    width: 32px;
    height: 32px;
    padding: 0;
    place-items: center;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
}

.managed-model-picker-close:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.managed-model-picker-source,
.managed-model-picker-search {
    display: grid;
    gap: 6px;
    padding-right: 20px;
    padding-left: 20px;
}

.managed-model-picker-source {
    padding-top: 14px;
}

.managed-model-picker-source label {
    color: var(--ios-text-secondary);
    font-size: 12px;
    font-weight: 650;
}

.managed-model-picker-source .form-select,
.managed-model-picker-search .form-control {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    max-width: 100%;
}

.managed-model-picker-search {
    position: relative;
    padding-top: 12px;
    padding-bottom: 10px;
}

.managed-model-picker-search .form-control {
    min-height: 38px;
    padding-right: 100px;
}

.managed-model-picker-search .text-muted {
    position: absolute;
    right: 31px;
    bottom: 21px;
    color: #94a3b8;
    font-size: 11px;
    pointer-events: none;
}

.managed-model-picker-status {
    display: none;
    margin: 0 20px 10px;
    color: #64748b;
    font-size: 12px;
    line-height: 1.45;
}

.managed-model-picker-status.is-visible {
    display: block;
}

.managed-model-picker-status.is-error {
    color: #c2410c;
}

.managed-model-picker-list {
    display: grid;
    min-height: 152px;
    max-height: 360px;
    margin: 0 20px;
    overflow-y: auto;
    border-top: 1px solid #edf0f3;
    border-bottom: 1px solid #edf0f3;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}

.managed-model-picker-option {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr) auto;
    width: 100%;
    min-height: 64px;
    align-items: center;
    gap: 11px;
    padding: 10px 4px;
    border: 0;
    border-bottom: 1px solid #f0f2f5;
    background: #fff;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.managed-model-picker-option:last-child {
    border-bottom: 0;
}

.managed-model-picker-option:hover,
.managed-model-picker-option.is-selected {
    background: #f0f7ff;
}

.managed-model-picker-option:focus-visible {
    position: relative;
    z-index: 1;
    outline: 2px solid #0a84ff;
    outline-offset: -2px;
}

.managed-model-picker-option.is-selected {
    box-shadow: inset 3px 0 0 #0a84ff;
}

.managed-model-picker-option.is-used {
    color: #94a3b8;
    background: #fafafa;
    cursor: not-allowed;
}

.managed-model-picker-option > img {
    width: 30px;
    height: 30px;
    justify-self: center;
    border: 1px solid #dfe5ee;
    border-radius: 8px;
    background: #f8fafc;
    object-fit: cover;
}

.managed-model-picker-option-copy {
    display: grid;
    min-width: 0;
    gap: 2px;
}

.managed-model-picker-option-copy strong,
.managed-model-picker-option-copy small,
.managed-model-picker-option-copy em {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.managed-model-picker-option-copy strong {
    color: var(--ios-text);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.35;
}

.managed-model-picker-option.is-used .managed-model-picker-option-copy strong {
    color: #64748b;
}

.managed-model-picker-option-copy small {
    color: #64748b;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 11px;
    line-height: 1.35;
}

.managed-model-picker-option-copy em {
    color: #94a3b8;
    font-size: 11px;
    font-style: normal;
    line-height: 1.35;
}

.managed-model-picker-option-mark {
    min-width: 40px;
    padding-right: 12px;
    color: #0a84ff;
    font-size: 14px;
    font-weight: 800;
    text-align: right;
}

.managed-model-picker-option.is-used .managed-model-picker-option-mark {
    color: #94a3b8;
    font-size: 11px;
    font-weight: 650;
}

.managed-model-picker-empty {
    display: flex;
    min-height: 152px;
    align-items: center;
    justify-content: center;
    gap: 9px;
    padding: 22px;
    color: #64748b;
    font-size: 13px;
    line-height: 1.5;
    text-align: center;
}

.managed-model-picker-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #bfdbfe;
    border-top-color: #0a84ff;
    border-radius: 50%;
    animation: managed-model-picker-spin 0.75s linear infinite;
}

@keyframes managed-model-picker-spin {
    to { transform: rotate(360deg); }
}

.managed-model-picker-footer {
    display: flex;
    min-height: 66px;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 13px 20px;
    flex-wrap: wrap;
}

.managed-model-picker-footer > .text-muted {
    flex: 1 1 140px;
    min-width: 0;
    color: #64748b;
    font-size: 12px;
    line-height: 1.45;
    overflow-wrap: anywhere;
}

.managed-model-picker-actions {
    display: inline-flex;
    flex: 0 1 auto;
    min-width: 0;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* The admin sidebar can reduce content width before the viewport reaches a media breakpoint. */
@container managed-model-list (max-width: 760px) {
    .managed-model-row-main,
    .managed-model-row.image-model-row .managed-model-row-main {
        grid-template-columns: minmax(0, 1fr) max-content;
        grid-template-areas:
            "summary summary"
            "meta rate"
            "actions actions";
    }
    .managed-model-profile-grid,
    .managed-model-profile-call-grid {
        grid-template-columns: 1fr;
    }
    .managed-model-fallback-api-item {
        grid-template-columns: 25px minmax(0, 1fr) auto;
        grid-template-areas:
            "order copy actions"
            "order target target";
        align-items: start;
    }
    .managed-model-fallback-target {
        margin-top: 2px;
    }
}

@media (max-width: 1180px) {
    .managed-model-row-main,
    .managed-model-row.image-model-row .managed-model-row-main {
        grid-template-columns: minmax(0, 1fr) max-content;
        grid-template-areas:
            "summary summary"
            "meta rate"
            "actions actions";
    }
    .managed-model-summary {
        grid-column: auto;
    }
    .managed-model-profile-grid,
    .managed-model-profile-call-grid {
        grid-template-columns: 1fr;
    }
    .managed-model-rate {
        width: 82px;
        max-width: none;
    }
    .managed-model-fetch-button {
        justify-self: start;
    }
}

@media (max-width: 620px) {
    .managed-model-toolbar {
        align-items: stretch;
    }
    .managed-model-source-field {
        width: 100%;
    }
    .managed-model-source-field .form-select {
        width: auto;
        min-width: 0;
        flex: 1;
    }
    .managed-model-toolbar-actions {
        width: 100%;
    }
    .managed-model-toolbar-status {
        flex-basis: 100%;
    }
    .managed-model-row-main,
    .managed-model-row.image-model-row .managed-model-row-main {
        grid-template-columns: 1fr;
        grid-template-areas:
            "summary"
            "meta"
            "rate"
            "actions";
    }
    .managed-model-summary,
    .managed-model-summary-meta,
    .managed-model-rate-field,
    .managed-model-row-actions {
        grid-column: auto;
        justify-content: flex-start;
    }
    .managed-model-row-actions {
        justify-content: flex-end;
    }
    .managed-model-fallback-target {
        grid-template-columns: minmax(0, 1fr) auto;
    }
    .managed-model-fallback-fetch {
        min-width: 74px;
    }
    .managed-model-picker-modal {
        align-items: end;
        padding: 12px;
    }
    .managed-model-picker-dialog {
        max-height: calc(100vh - 24px);
        border-radius: 16px;
    }
    .managed-model-picker-list {
        max-height: min(360px, 47vh);
    }
    .managed-model-picker-header,
    .managed-model-picker-source,
    .managed-model-picker-search,
    .managed-model-picker-footer {
        padding-right: 16px;
        padding-left: 16px;
    }
    .managed-model-picker-status,
    .managed-model-picker-list {
        margin-right: 16px;
        margin-left: 16px;
    }
    .managed-model-picker-search .text-muted {
        right: 27px;
    }
}

@media (max-width: 420px) {
    .managed-model-toolbar-actions .btn {
        flex: 1 1 132px;
    }
    .managed-model-summary-meta {
        align-items: flex-start;
    }
    .managed-model-api-chip {
        max-width: 100%;
    }
    .managed-model-fallback-api-item {
        gap: 7px;
    }
    .managed-model-fallback-target {
        grid-template-columns: minmax(0, 1fr);
    }
    .managed-model-fallback-fetch {
        width: 100%;
    }
    .managed-model-picker-footer {
        align-items: stretch;
        flex-direction: column;
    }
    .managed-model-picker-actions {
        width: 100%;
    }
    .managed-model-picker-actions .btn {
        flex: 1 1 0;
        min-width: 0;
        padding-right: 12px;
        padding-left: 12px;
    }
    .managed-model-picker-option {
        grid-template-columns: 30px minmax(0, 1fr) auto;
        gap: 8px;
        padding-right: 2px;
        padding-left: 2px;
    }
    .managed-model-picker-option-mark {
        min-width: 34px;
        padding-right: 7px;
    }
}

/* Keep the conversation hierarchy simple: user bubbles, assistant article flow. */
.ai-chat-main .ai-chat-messages {
    gap: 14px;
}

.ai-chat-main .chat-message.assistant {
    align-items: flex-start;
}

.ai-chat-main .chat-message.assistant .message-avatar {
    width: 30px;
    height: 30px;
    margin-top: 4px;
    box-shadow: none;
}

.ai-chat-main .chat-message.assistant .message-content {
    max-width: min(760px, calc(100vw - 92px));
    padding: 4px 4px 8px;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
}

@media (max-width: 720px) {
    .ai-chat-main .chat-message.assistant .message-content {
        max-width: calc(100vw - 28px);
        padding: 2px 0 8px;
    }
}
