/* ==========================================================================
   Ow — design system v2
   Warm "paper & charcoal" neutrals, one teal accent, serif display type.
   Day / night via  html[data-theme="light|dark"]  (set by theme-init.js).
   ========================================================================== */

/* ---- Tokens ------------------------------------------------------------- */
:root {
    color-scheme: light;
    --bg: #f5f2ec;
    --panel: #eeeae1;
    --card: #fffdf9;
    --sunken: #e8e3d8;
    --line: #dfd9cb;
    --line-soft: rgba(60, 45, 20, .08);
    --ink: #1d1b17;
    --ink-2: #57534a;
    --ink-3: #756f63;
    --accent: #0b7a6c;
    --accent-hover: #096357;
    --accent-ink: #ffffff;
    --accent-soft: #d8ece6;
    --accent-text: #0a6a5d;
    --user-bg: #e7e1d3;
    --code-bg: #ece7dc;
    --code-ink: #2b2a25;
    --danger: #b3261e;
    --danger-soft: rgba(179, 38, 30, .1);
    --ok: #1a7f4b;
    --shadow-sm: 0 1px 2px rgba(60, 45, 20, .07);
    --shadow-md: 0 10px 34px rgba(60, 45, 20, .12);
    --shadow-composer: 0 2px 4px rgba(60, 45, 20, .05), 0 14px 40px rgba(60, 45, 20, .1);

    --font-ui: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
    --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --ease: cubic-bezier(.22, .8, .3, 1);

    /* Bootstrap bridge so stock components follow our theme */
    --bs-body-bg: var(--bg);
    --bs-body-color: var(--ink);
    --bs-emphasis-color: var(--ink);
    --bs-secondary-color: var(--ink-2);
    --bs-tertiary-bg: var(--sunken);
    --bs-secondary-bg: var(--panel);
    --bs-border-color: var(--line);
    --bs-link-color: var(--accent-text);
    --bs-link-hover-color: var(--accent-hover);
    --bs-primary: var(--accent);
    --bs-primary-rgb: 11, 122, 108;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #11130f;
    --panel: #0d0f0c;
    --card: #191c17;
    --sunken: #0a0b09;
    --line: #2a2e26;
    --line-soft: rgba(255, 255, 255, .06);
    --ink: #ece9e0;
    --ink-2: #aaa698;
    --ink-3: #8a877b;
    --accent: #4fd1b8;
    --accent-hover: #7ae0cc;
    --accent-ink: #052a23;
    --accent-soft: rgba(79, 209, 184, .14);
    --accent-text: #7fe3cf;
    --user-bg: #232720;
    --code-bg: #0b0c0a;
    --code-ink: #d9d6cb;
    --danger: #ff8f80;
    --danger-soft: rgba(255, 143, 128, .12);
    --ok: #6ee7a8;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-md: 0 12px 40px rgba(0, 0, 0, .5);
    --shadow-composer: 0 2px 4px rgba(0, 0, 0, .3), 0 16px 44px rgba(0, 0, 0, .4);
    --bs-primary-rgb: 79, 209, 184;
}

/* ---- Base --------------------------------------------------------------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; margin: 0; }
body {
    overflow: hidden;
    overscroll-behavior: none;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    transition: background-color .25s ease, color .25s ease;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { color: var(--accent-hover); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
::selection { color: var(--accent-ink); background: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon { flex: 0 0 auto; display: block; }
.only-mobile { display: none !important; }
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Theme-aware icon swap */
.theme-icon { display: none; }
:root[data-theme="light"] .theme-moon, :root[data-theme="dark"] .theme-sun { display: inline-grid; place-items: center; }
:root:not([data-theme]) .theme-moon { display: inline-grid; place-items: center; }

/* ---- Shell: icon rail + content ---------------------------------------- */
.page { display: flex; width: 100%; height: 100dvh; overflow: hidden; }
.rail { z-index: 4; display: flex; flex: 0 0 80px; flex-direction: column; align-items: center; width: 80px; height: 100%; padding: 18px 0 16px; gap: 6px; background: var(--panel); border-right: 1px solid var(--line); }
.rail-logo { display: grid; width: 46px; height: 46px; margin-bottom: 18px; place-items: center; border-radius: 15px; color: var(--accent-ink); background: var(--accent); box-shadow: var(--shadow-sm); transition: transform .2s var(--ease); }
.rail-logo:hover { color: var(--accent-ink); transform: rotate(-6deg) scale(1.04); }
.rail-nav { display: flex; flex-direction: column; gap: 6px; }
.rail-link { display: flex; flex-direction: column; align-items: center; gap: 4px; width: 62px; padding: 10px 0 8px; border-radius: 15px; color: var(--ink-3); font-size: 10.5px; font-weight: 600; letter-spacing: .01em; transition: background .15s ease, color .15s ease; }
.rail-link:hover { color: var(--ink); background: var(--line-soft); }
.rail-link.active { color: var(--accent-text); background: var(--accent-soft); }
.rail-foot { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: auto; }
.rail-local { display: grid; width: 32px; height: 32px; place-items: center; color: var(--ink-3); }
.rail-btn { display: grid; width: 44px; height: 44px; place-items: center; border: 1px solid var(--line); border-radius: 14px; color: var(--ink-2); background: var(--card); box-shadow: var(--shadow-sm); transition: transform .15s ease, color .15s ease; }
.rail-btn:hover { color: var(--accent-text); transform: translateY(-1px); }
.app-main { display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
.tabbar { display: none; }

/* ---- Shared controls ---------------------------------------------------- */
.icon-btn { display: inline-grid; flex: 0 0 auto; width: 40px; height: 40px; place-items: center; padding: 0; border: 0; border-radius: 12px; color: var(--ink-2); background: transparent; transition: background .15s ease, color .15s ease; }
.icon-btn:hover { color: var(--ink); background: var(--line-soft); }
.icon-btn:active { background: var(--line); }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 9px; }
.icon-btn.on { color: var(--accent-text); }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.menu-btn, .mobile-theme, .drawer-close { display: none; }
.fab { display: inline-grid; flex: 0 0 auto; width: 38px; height: 38px; place-items: center; border: 0; border-radius: 12px; color: var(--accent-ink); background: var(--accent); box-shadow: var(--shadow-sm); transition: transform .15s ease, background .15s ease; }
.fab:hover { background: var(--accent-hover); }
.fab:active { transform: scale(.94); }
.btn-primary-pill, .btn-quiet { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 20px; border: 1px solid transparent; border-radius: 999px; font-size: 14px; font-weight: 600; transition: transform .15s ease, background .15s ease; }
.btn-primary-pill { color: var(--accent-ink); background: var(--accent); box-shadow: var(--shadow-sm); }
.btn-primary-pill:hover { background: var(--accent-hover); }
.btn-primary-pill:active { transform: scale(.97); }
.btn-quiet { color: var(--ink); border-color: var(--line); background: var(--card); }

/* ---- Chat page ---------------------------------------------------------- */
.chat-page { position: relative; display: flex; width: 100%; height: 100%; min-height: 0; background: var(--bg); }
.chat-sidebar { z-index: 1; display: flex; flex: 0 0 300px; flex-direction: column; width: 300px; min-width: 0; border-right: 1px solid var(--line); background: var(--bg); }
.side-top { display: flex; align-items: center; gap: 8px; padding: 22px 18px 10px 22px; }
.side-title { flex: 1; margin: 0; font-size: 26px; }
.side-persona { padding: 6px 18px 14px; }
.side-label { display: block; margin-bottom: 6px; color: var(--ink-3); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.conv-list { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 14px; border-top: 1px solid var(--line-soft); }
.conv-item { position: relative; display: flex; align-items: center; margin: 2px 0; border-radius: 14px; transition: background .15s ease; }
.conv-item:hover { background: var(--line-soft); }
.conv-item.active { background: var(--card); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }
.conv-link { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; padding: 10px 6px 10px 14px; color: var(--ink-2); }
.conv-link:hover, .conv-item.active .conv-link { color: var(--ink); }
.conv-title { overflow: hidden; font-size: 14px; font-weight: 550; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { display: flex; align-items: center; gap: 5px; color: var(--ink-3); font-size: 11.5px; }
.conv-meta .icon { color: var(--accent-text); }
.conv-actions { display: flex; flex: 0 0 auto; padding-right: 4px; opacity: 0; transition: opacity .15s ease; }
.conv-item:hover .conv-actions, .conv-item:focus-within .conv-actions { opacity: 1; }
.conv-empty { padding: 36px 16px; color: var(--ink-3); font-size: 13px; line-height: 1.7; text-align: center; }
.chat-main { position: relative; display: flex; flex: 1; flex-direction: column; min-width: 0; min-height: 0; }
.drawer-scrim { display: none; }

.chat-view { display: flex; flex-direction: column; width: 100%; height: 100%; min-width: 0; min-height: 0; }
.chat-header { display: flex; flex: 0 0 auto; align-items: center; gap: 10px; min-height: 76px; padding: 14px clamp(18px, 4vw, 48px); }
.chat-title { flex: 1; min-width: 0; }
.chat-header h1 { overflow: hidden; margin: 0; font-size: 22px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { display: flex; align-items: center; gap: 6px; min-width: 0; margin-top: 3px; color: var(--ink-3); font-size: 12.5px; }
.chat-sub .icon { color: var(--accent-text); }
.chat-sub i { font-style: normal; opacity: .6; }
.chat-model { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; width: 100%; padding: 8px clamp(16px, 4vw, 48px) 24px; scroll-behavior: smooth; }
.thread { max-width: 760px; margin: 0 auto; }

.chat-welcome { position: relative; display: flex; flex: 1; align-items: center; justify-content: center; padding: 24px; }
.welcome-bar { position: absolute; top: 12px; right: 16px; left: 16px; display: flex; justify-content: space-between; }
.welcome-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 26px; }

/* Messages: assistant text sits on the page; user text in a soft bubble. */
.msg { display: flex; margin: 0 0 28px; animation: rise .3s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.msg-user { justify-content: flex-end; }
.msg-body { min-width: 0; max-width: 100%; }
.msg-user .msg-body { max-width: min(82%, 600px); padding: 11px 18px; border-radius: 22px 22px 6px 22px; background: var(--user-bg); }
.msg-text { color: var(--ink); font-size: 16px; line-height: 1.72; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg-text.markdown-content { white-space: normal; }
.msg-actions { display: flex; gap: 2px; margin: 6px 0 0 -8px; opacity: 0; transition: opacity .15s ease; }
.msg:hover .msg-actions, .msg-actions:focus-within { opacity: 1; }
.msg-action { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 10px; border: 0; border-radius: 9px; color: var(--ink-3); background: transparent; font-size: 12px; font-weight: 550; }
.msg-action:hover { color: var(--ink); background: var(--line-soft); }
.typing { display: inline-flex; gap: 5px; padding: 12px 2px; }
.typing i { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: bounce 1.1s infinite ease-in-out; }
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { opacity: .3; transform: scale(.75); } 40% { opacity: 1; transform: scale(1); } }
.gen-skeleton { position: relative; display: grid; width: min(440px, 100%); aspect-ratio: 1; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 20px; color: var(--ink-2); background: var(--card); font-size: 13px; }
.gen-skeleton::before { content: ""; position: absolute; inset: 0; background: linear-gradient(110deg, transparent 30%, var(--accent-soft) 50%, transparent 70%); background-size: 220% 100%; animation: shimmer 1.6s infinite linear; }
.gen-skeleton span { position: relative; }
@keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }

.markdown-content > :first-child { margin-top: 0; }
.markdown-content > :last-child { margin-bottom: 0; }
.markdown-content p { margin: 0 0 .9em; }
.markdown-content h1, .markdown-content h2, .markdown-content h3, .markdown-content h4 { margin: 1.3em 0 .5em; line-height: 1.3; }
.markdown-content h1 { font-size: 1.5em; }
.markdown-content h2 { font-size: 1.3em; }
.markdown-content h3 { font-size: 1.12em; }
.markdown-content ul, .markdown-content ol { margin: .4em 0 .9em; padding-left: 1.5em; }
.markdown-content li { margin: .3em 0; padding-left: .1em; }
.markdown-content li::marker { color: var(--ink-3); }
.markdown-content blockquote { margin: .9em 0; padding: .2em 0 .2em 1em; border-left: 3px solid var(--accent); color: var(--ink-2); }
.markdown-content :not(pre) > code { padding: .14em .4em; border-radius: 6px; color: var(--ink); background: var(--code-bg); font-family: var(--font-mono); font-size: .86em; overflow-wrap: anywhere; }
.markdown-content pre { overflow: auto; margin: 1em 0; padding: 15px 17px; border: 1px solid var(--line); border-radius: 14px; color: var(--code-ink); background: var(--code-bg); font-family: var(--font-mono); font-size: 13px; line-height: 1.6; -webkit-overflow-scrolling: touch; }
.markdown-content pre code { color: inherit; white-space: pre; }
.markdown-content table { display: block; overflow-x: auto; width: max-content; max-width: 100%; margin: .9em 0; border-collapse: collapse; font-size: .92em; }
.markdown-content th, .markdown-content td { padding: 8px 12px; border: 1px solid var(--line); text-align: left; }
.markdown-content th { background: var(--sunken); font-weight: 600; }
.markdown-content hr { margin: 1.2em 0; border-color: var(--line); opacity: 1; }
.markdown-content a { color: var(--accent-text); text-decoration: underline; text-decoration-color: var(--accent-soft); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.markdown-content a:hover { text-decoration-color: currentColor; }
.markdown-content img { max-width: 100%; border-radius: 12px; }
.msg-image-link { display: block; overflow: hidden; max-width: min(600px, 100%); border: 1px solid var(--line); border-radius: 20px; background: var(--sunken); box-shadow: var(--shadow-sm); }
.msg-image { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto; object-fit: contain; }
.image-download { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; margin-top: 6px; color: var(--ink-3); font-size: 12.5px; font-weight: 550; }
.image-download:hover { color: var(--accent-text); }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; max-width: 640px; margin: 7vh auto 0; text-align: center; }
.empty-mark { display: grid; width: 72px; height: 72px; margin-bottom: 22px; place-items: center; border-radius: 24px; color: var(--accent-text); background: var(--accent-soft); }
.empty-state h2 { margin: 0 0 10px; font-size: clamp(28px, 5vw, 38px); line-height: 1.15; }
.empty-state p { max-width: 420px; margin: 0; color: var(--ink-2); font-size: 15.5px; line-height: 1.65; }
.chips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; width: 100%; margin-top: 30px; }
.chip { min-height: 74px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 18px; color: var(--ink); background: var(--card); box-shadow: var(--shadow-sm); font-size: 13.5px; line-height: 1.4; text-align: left; transition: border-color .15s ease, transform .15s ease, box-shadow .15s ease; }
.chip:hover { border-color: var(--accent); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.chip:active { transform: scale(.98); }

/* Composer */
.chat-input-wrap { flex: 0 0 auto; padding: 4px clamp(14px, 4vw, 48px) 14px; }
.composer-col { max-width: 760px; margin: 0 auto; }
.composer { padding: 12px 14px 10px 18px; border: 1px solid var(--line); border-radius: 26px; background: var(--card); box-shadow: var(--shadow-composer); transition: border-color .16s ease, box-shadow .16s ease; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea.form-control { display: block; width: 100%; min-height: 28px; max-height: 200px; padding: 4px 0; resize: none; overflow-y: auto; border: 0; border-radius: 0; color: var(--ink); background: transparent; box-shadow: none; font-size: 16px; line-height: 1.55; }
.composer textarea.form-control:focus { color: var(--ink); background: transparent; box-shadow: none; }
.composer textarea::placeholder { color: var(--ink-3); opacity: 1; }
.composer-bar { display: flex; align-items: center; gap: 10px; padding-top: 8px; }
.mode-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--sunken); }
.mode-option { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 13px; border: 0; border-radius: 999px; color: var(--ink-2); background: transparent; font-size: 13px; font-weight: 600; transition: background .15s ease, color .15s ease; }
.mode-option.selected { color: var(--ink); background: var(--card); box-shadow: var(--shadow-sm); }
.mode-option.selected .icon { color: var(--accent-text); }
.composer-hint { flex: 1; color: var(--ink-3); font-size: 12px; text-align: right; }
.send-button { display: grid; flex: 0 0 42px; width: 42px; height: 42px; place-items: center; border: 0; border-radius: 50%; color: var(--accent-ink); background: var(--accent); transition: transform .15s ease, background .15s ease; }
.send-button:hover:not(:disabled) { background: var(--accent-hover); transform: translateY(-1px); }
.send-button:active:not(:disabled) { transform: scale(.93); }
.send-button:disabled { color: var(--ink-3); background: var(--sunken); cursor: default; }
.send-spinner { width: 17px; height: 17px; border: 2px solid color-mix(in srgb, var(--accent-ink) 25%, transparent); border-top-color: var(--accent-ink); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.composer-note { padding-top: 8px; color: var(--ink-3); font-size: 11.5px; text-align: center; }
.chat-error { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin: 0 0 10px; padding: 10px 8px 10px 16px; border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent); border-radius: 16px; color: var(--danger); background: var(--danger-soft); font-size: 13.5px; line-height: 1.5; }
.chat-error span { padding-top: 3px; overflow-wrap: anywhere; }

/* ---- Settings ----------------------------------------------------------- */
.settings-scroll { flex: 1; min-height: 0; overflow-y: auto; }
.settings-page { max-width: 1180px; margin: 0 auto; padding: 36px clamp(18px, 4vw, 48px) 64px; }
.settings-page > h1 { margin: 0 0 22px; font-size: 34px; }
.appearance { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 28px; padding: 16px 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--card); box-shadow: var(--shadow-sm); }
.appearance-text { display: flex; flex-direction: column; gap: 2px; }
.appearance-text strong { font-size: 15px; }
.appearance-text span { color: var(--ink-3); font-size: 13px; }
.seg { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--sunken); }
.seg button { display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 14px; border: 0; border-radius: 999px; color: var(--ink-2); background: transparent; font-size: 13px; font-weight: 600; transition: background .15s ease, color .15s ease; }
.seg button:hover { color: var(--ink); }
:root[data-mode="system"] .seg [data-theme-set="system"],
:root[data-mode="light"] .seg [data-theme-set="light"],
:root[data-mode="dark"] .seg [data-theme-set="dark"] { color: var(--ink); background: var(--card); box-shadow: var(--shadow-sm); }
:root[data-mode="system"] .seg [data-theme-set="system"] .icon,
:root[data-mode="light"] .seg [data-theme-set="light"] .icon,
:root[data-mode="dark"] .seg [data-theme-set="dark"] .icon { color: var(--accent-text); }

.settings-tabs { flex-wrap: nowrap; gap: 4px; margin-bottom: 22px; padding: 4px; overflow-x: auto; overflow-y: hidden; border: 0; border-radius: 999px; background: var(--sunken); white-space: nowrap; scrollbar-width: none; width: fit-content; max-width: 100%; }
.settings-tabs::-webkit-scrollbar { display: none; }
.nav-tabs .nav-link { min-height: 38px; padding: 0 18px; border: 0; border-radius: 999px; color: var(--ink-2); background: transparent; font-size: 13.5px; font-weight: 600; }
.nav-tabs .nav-link:hover { color: var(--ink); }
.nav-tabs .nav-link.active { color: var(--ink); background: var(--card); box-shadow: var(--shadow-sm); }

.card { overflow: hidden; border: 1px solid var(--line); border-radius: 22px; color: var(--ink); background: var(--card); box-shadow: var(--shadow-sm); }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--line-soft); color: var(--ink); background: transparent; font-family: var(--font-display); font-size: 17px; font-weight: 600; }
.card-body { padding: 18px 20px; }
.card-body > .border.rounded { border: 1px solid var(--line) !important; border-radius: 16px !important; background: var(--bg); padding: 14px 16px !important; }
.card-body .d-flex.justify-content-between { flex-wrap: wrap; gap: 8px 12px; }
.text-muted { color: var(--ink-3) !important; }
.text-success { color: var(--ok) !important; }
.text-danger { color: var(--danger) !important; }
.badge.text-bg-info { padding: 6px 11px; border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 999px; color: var(--accent-text) !important; background: var(--accent-soft) !important; font-size: 12px; font-weight: 600; }
.badge.text-bg-info a { cursor: pointer; color: inherit; }

.form-control, .form-select { min-height: 44px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink); background-color: var(--bg); font-size: 14px; }
.form-control:focus, .form-select:focus { border-color: var(--accent); color: var(--ink); background-color: var(--bg); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-control::placeholder { color: var(--ink-3); opacity: 1; }
textarea.form-control { line-height: 1.55; }
.form-label { margin-bottom: 6px; color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.form-check-input:checked { border-color: var(--accent); background-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 18px; border-radius: 999px; font-size: 13.5px; font-weight: 600; }
.btn-sm { min-height: 36px; padding: 0 15px; font-size: 13px; }
.btn-primary { border-color: var(--accent); color: var(--accent-ink); background: var(--accent); }
.btn-primary:hover, .btn-primary:focus, .btn-primary:active { border-color: var(--accent-hover); color: var(--accent-ink); background: var(--accent-hover); }
.btn-primary:disabled { border-color: var(--sunken); color: var(--ink-3); background: var(--sunken); }
.btn-outline-secondary { border-color: var(--line); color: var(--ink); background: var(--card); }
.btn-outline-secondary:hover, .btn-outline-secondary:active { border-color: var(--ink-3); color: var(--ink); background: var(--line-soft); }
.btn-outline-danger { border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); background: transparent; }
.btn-outline-danger:hover, .btn-outline-danger:active { border-color: var(--danger); color: var(--bg); background: var(--danger); }

.eyebrow { color: var(--accent-text); font-size: 11.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; }
.comfy-settings { max-width: 1120px; margin: 0 auto; padding: 0; }
.settings-intro { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }
.settings-intro h2 { margin: 4px 0 4px; font-size: 28px; }
.settings-intro p { margin: 0; color: var(--ink-2); font-size: 14px; }
.engine-mark { display: grid; flex: 0 0 auto; width: 56px; height: 56px; place-items: center; border-radius: 18px; color: var(--accent-text); background: var(--accent-soft); font-size: 26px; }
.comfy-grid { display: grid; grid-template-columns: minmax(280px, .8fr) minmax(440px, 1.2fr); align-items: start; gap: 18px; }
.settings-card { padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: var(--card); box-shadow: var(--shadow-sm); }
.card-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.card-heading h3 { margin: 0 0 2px; font-size: 18px; }
.card-heading p { margin: 0; color: var(--ink-3); font-size: 12.5px; }
.step-mark { display: grid; flex: 0 0 auto; width: 36px; height: 36px; place-items: center; border-radius: 12px; color: var(--accent-text); background: var(--accent-soft); font-size: 12px; font-weight: 700; }
.field-hint { margin-top: 6px; color: var(--ink-3); font-size: 12px; line-height: 1.5; }
.settings-divider { height: 1px; margin: 22px 0; background: var(--line-soft); }
.settings-card-title { margin-bottom: 10px; color: var(--ink); font-size: 14px; font-weight: 650; }
.generation-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.generation-fields label { display: flex; flex-direction: column; gap: 6px; color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.generation-fields .form-control { min-height: 42px; padding: 7px 12px; font-weight: 400; }
.workflow-editor { min-height: 280px; resize: vertical; color: var(--code-ink); background: var(--code-bg) !important; font-family: var(--font-mono); font-size: 12px; tab-size: 2; }
.workflow-meta { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; color: var(--ink-3); font-size: 12px; }
.workflow-meta span:last-child { flex: 0 0 auto; }
.mapping-warning { color: var(--danger); }
.mapping-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.mapping-heading p { margin: 0; color: var(--ink-3); font-size: 12.5px; line-height: 1.5; }
.prompt-mode { flex: 0 0 170px; min-height: 40px; padding: 6px 28px 6px 12px; font-size: 13px; }
.prompt-mappings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.prompt-map { padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--bg); }
.map-label { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 13px; font-weight: 650; }
.map-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.negative-map .map-dot { background: var(--danger); }
.prompt-map .form-label { margin-bottom: 5px; font-size: 12px; }
.prompt-map .form-select { min-height: 40px; padding: 6px 28px 6px 10px; font-size: 13px; }
.save-row { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 20px; }
.save-status { margin-right: auto; font-size: 13px; }
.save-status.success { color: var(--ok); }
.save-status.error { color: var(--danger); }

.blazor-error-boundary { margin: 14px; padding: 14px 18px; border: 1px solid var(--danger); border-radius: 14px; color: var(--danger); background: var(--danger-soft); }
#blazor-error-ui { position: fixed; z-index: 100; right: 0; bottom: 0; left: 0; display: none; padding: 12px 16px calc(12px + var(--safe-bottom)); color: var(--bg); background: var(--danger); }
#blazor-error-ui a { color: inherit; text-decoration: underline; }
#blazor-error-ui .dismiss { position: absolute; top: 10px; right: 14px; cursor: pointer; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 1100px) {
    .chat-sidebar { flex-basis: 264px; width: 264px; }
    .comfy-grid { grid-template-columns: 1fr; }
    .chips { grid-template-columns: 1fr; }
    .chip { min-height: 54px; }
}

/* Phones & small tablets: bottom tab bar + slide-in conversation drawer. */
@media (max-width: 768px) {
    .only-mobile { display: inline-flex !important; }
    .page { flex-direction: column; }
    .rail { display: none; }

    .tabbar { z-index: 20; display: flex; flex: 0 0 auto; gap: 6px; padding: 6px 12px calc(6px + var(--safe-bottom)); border-top: 1px solid var(--line); background: color-mix(in srgb, var(--panel) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); }
    .tab { display: flex; flex: 1; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 52px; border-radius: 16px; color: var(--ink-3); font-size: 11px; font-weight: 600; transition: color .15s ease, background .15s ease; }
    .tab.active { color: var(--accent-text); background: var(--accent-soft); }

    .menu-btn { display: inline-grid; margin-left: -8px; }
    .mobile-theme { display: inline-grid; margin-right: -6px; }
    .drawer-close { display: inline-grid; }

    .drawer-scrim { position: fixed; z-index: 40; inset: 0; display: block; background: rgba(8, 8, 6, .5); opacity: 0; pointer-events: none; transition: opacity .25s ease; }
    .drawer-scrim.show { opacity: 1; pointer-events: auto; }
    .chat-sidebar { position: fixed; z-index: 41; top: 0; bottom: 0; left: 0; flex: none; width: min(88vw, 360px); padding-top: var(--safe-top); box-shadow: var(--shadow-md); transform: translateX(-104%); visibility: hidden; transition: transform .3s var(--ease), visibility 0s .3s; }
    .chat-sidebar.open { transform: translateX(0); visibility: visible; transition: transform .3s var(--ease), visibility 0s; }
    .conv-link { padding-top: 12px; padding-bottom: 12px; }
    .conv-actions { opacity: 1; }
    .icon-btn.sm { width: 40px; height: 40px; }
    .side-persona .form-select { font-size: 16px; }

    .chat-header { min-height: 60px; gap: 6px; padding: calc(8px + var(--safe-top)) 14px 8px; }
    .chat-header h1 { font-size: 18px; }
    .chat-messages { padding: 6px 16px 16px; }
    .msg { margin-bottom: 24px; }
    .msg-user .msg-body { max-width: 88%; }
    .msg-text { font-size: 16px; }
    .msg-actions { opacity: 1; }
    .empty-state { margin-top: 3vh; }
    .welcome-bar { top: calc(8px + var(--safe-top)); }

    .chat-input-wrap { padding: 4px 10px 8px; }
    .composer { padding: 10px 10px 8px 16px; border-radius: 24px; }
    .composer-hint { display: none; }
    .composer-bar { justify-content: space-between; }
    .mode-option { min-height: 36px; }
    .send-button { flex-basis: 44px; width: 44px; height: 44px; }
    .composer-note { padding-top: 6px; font-size: 11px; }

    .settings-page { padding: 20px 16px 28px; }
    .settings-page > h1 { margin-bottom: 16px; font-size: 30px; }
    .appearance { flex-direction: column; align-items: stretch; }
    .seg { display: flex; }
    .seg button { flex: 1; justify-content: center; min-height: 40px; }
    .settings-tabs { width: 100%; }
    .form-control, .form-select { min-height: 46px; font-size: 16px; }
    .generation-fields .form-control, .prompt-map .form-select, .prompt-mode { font-size: 16px; }
    .btn, .btn-sm { min-height: 42px; }
    .card-body, .settings-card { padding: 16px; }
    .settings-intro h2 { font-size: 24px; }
    .engine-mark { width: 46px; height: 46px; }
    .save-row { position: sticky; bottom: -1px; margin: 18px -16px -16px; padding: 12px 16px; border-top: 1px solid var(--line); background: color-mix(in srgb, var(--card) 94%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
}

@media (max-width: 470px) {
    .prompt-mappings { grid-template-columns: 1fr; }
    .mapping-heading { flex-direction: column; }
    .prompt-mode { flex-basis: auto; width: 100%; }
    .workflow-meta { flex-direction: column; }
    .generation-fields { gap: 10px; }
    .card-body .btn-sm { flex: 1 1 auto; }
}

/* Short landscape phones: reclaim vertical space. */
@media (max-height: 480px) and (max-width: 900px) {
    .tabbar { padding-top: 2px; padding-bottom: calc(2px + var(--safe-bottom)); }
    .tab { flex-direction: row; min-height: 38px; gap: 8px; }
    .chat-header { min-height: 46px; }
    .composer-note { display: none; }
}
