/* model.do — main.css v4 */
@import url('https://fonts.googleapis.com/css2?family=Geist+Mono:wght@300;400;500;600&family=Sora:wght@300;400;500;600&display=swap');

/* ══ TOKENS ══════════════════════════════════════ */
:root {
  --bg:         #0d0d0f;
  --bg2:        #111113;
  --surface:    #18181b;
  --surface2:   #1f1f23;
  --surface3:   #27272c;
  --border:     #2a2a30;
  --border2:    #333339;
  --ink:        #ececec;
  --ink2:       #a1a1aa;
  --ink3:       #52525b;
  --accent:     #7c6df0;
  --accent2:    #9d8ff5;
  --accent-bg:  rgba(124,109,240,0.1);
  --accent-glow:rgba(124,109,240,0.15);
  --green:      #34d399;
  --green-bg:   rgba(52,211,153,0.1);
  --red:        #f87171;
  --red-bg:     rgba(248,113,113,0.1);
  --amber:      #fbbf24;
  --amber-bg:   rgba(251,191,36,0.1);
  --blue:       #60a5fa;
  --blue-bg:    rgba(96,165,250,0.1);
  --sidebar-w:  264px;
  --font:       'Sora', sans-serif;
  --mono:       'Geist Mono', monospace;
  --r:          10px;
  --r-lg:       14px;
  --r-xl:       18px;
  --shadow:     0 2px 8px rgba(0,0,0,0.4);
  --shadow-lg:  0 12px 40px rgba(0,0,0,0.5);
  --tr:         0.15s ease;
}
[data-theme="light"] {
  --bg:         #f4f4f6;
  --bg2:        #ffffff;
  --surface:    #ffffff;
  --surface2:   #f4f4f6;
  --surface3:   #e8e8ec;
  --border:     #e2e2e8;
  --border2:    #d0d0d8;
  --ink:        #111113;
  --ink2:       #52525b;
  --ink3:       #a1a1aa;
  --accent:     #6050e0;
  --accent2:    #7c6df0;
  --accent-glow:rgba(96,80,224,0.1);
  --accent-bg:  rgba(96,80,224,0.07);
  --green:      #059669;
  --green-bg:   rgba(5,150,105,0.08);
  --red:        #dc2626;
  --red-bg:     rgba(220,38,38,0.08);
  --shadow:     0 2px 8px rgba(0,0,0,0.08);
  --shadow-lg:  0 12px 40px rgba(0,0,0,0.12);
}

/* ══ RESET ═══════════════════════════════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  /* Safe area for iPhone notch/home indicator */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
body { font-family: var(--font); background: var(--bg); color: var(--ink); display: flex; -webkit-font-smoothing: antialiased; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ══ SIDEBAR ═════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w); background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; height: 100vh; height: 100dvh;
  overflow-y: auto; overflow-x: hidden;
  transition: transform var(--tr); z-index: 50;
}
.sidebar-logo { padding: 16px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo-icon { width: 30px; height: 30px; border-radius: 7px; overflow: hidden; flex-shrink: 0; }
.logo-icon img { width: 100%; height: 100%; object-fit: cover; }
.logo-text { font-family: var(--mono); font-size: 15px; font-weight: 500; color: var(--ink); }
.logo-text span { color: var(--ink3); }

.sidebar-label { font-family: var(--mono); font-size: 9px; text-transform: uppercase; letter-spacing: .14em; color: var(--ink3); padding: 14px 16px 6px; flex-shrink: 0; }

.expert-nav { display: flex; flex-direction: column; gap: 1px; padding: 0 8px; flex-shrink: 0; }
.expert-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--r); cursor: pointer; font-size: 13px; font-weight: 400; color: var(--ink2); border: 1px solid transparent; user-select: none; transition: all var(--tr); }
.expert-item:hover { background: var(--surface2); color: var(--ink); }
.expert-item.active { background: var(--accent-bg); color: var(--ink); border-color: rgba(124,109,240,.2); }
.expert-icon { font-size: 15px; flex-shrink: 0; line-height: 1; }
.expert-name { flex: 1; font-weight: 500; }
.expert-tag { font-family: var(--mono); font-size: 9px; color: var(--ink3); background: var(--surface3); padding: 1px 6px; border-radius: 4px; opacity: 0; transition: opacity var(--tr); }
.expert-item.active .expert-tag { opacity: 1; color: var(--accent); background: var(--accent-bg); }

.sidebar-models { padding: 0 8px; display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.model-field { display: flex; flex-direction: column; gap: 4px; }
.model-slot-label { display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 9px; color: var(--ink3); text-transform: uppercase; letter-spacing: .1em; padding: 0 2px; }
.slot-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.slot-dot.a { background: var(--accent); }
.slot-dot.b { background: var(--green); }
.model-select { width: 100%; padding: 8px 26px 8px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); font-family: var(--mono); font-size: 11px; color: var(--ink2); outline: none; appearance: none; cursor: pointer; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2352525b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 8px center; transition: border-color var(--tr); }
.model-select:focus { border-color: var(--accent); color: var(--ink); }
.model-select option { background: var(--surface2); }

.sidebar-footer { margin-top: auto; padding: 10px 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }

.theme-toggle-wrap { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); }
.theme-toggle-label { display: flex; align-items: center; gap: 7px; }
.theme-icon { font-size: 13px; }
.toggle-switch { position: relative; width: 36px; height: 20px; cursor: pointer; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track { position: absolute; inset: 0; background: var(--surface3); border: 1px solid var(--border2); border-radius: 20px; transition: all .25s; }
.toggle-switch input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; background: #fff; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: transform .25s cubic-bezier(.4,0,.2,1); pointer-events: none; }
.toggle-switch input:checked ~ .toggle-thumb { transform: translateX(16px); }

.bmc-btn { display: flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 12px; background: rgba(255,221,0,.08); border: 1px solid rgba(255,221,0,.2); border-radius: var(--r); text-decoration: none; font-family: var(--mono); font-size: 11px; color: #FFDD00; font-weight: 500; transition: all var(--tr); }
.bmc-btn:hover { background: rgba(255,221,0,.14); border-color: rgba(255,221,0,.4); transform: translateY(-1px); }
.bmc-icon { font-size: 14px; }

.privacy-badge { display: flex; align-items: center; gap: 7px; padding: 8px 10px; background: var(--surface2); border: 1px solid var(--border); border-radius: var(--r); font-family: var(--mono); font-size: 10px; color: var(--ink3); }
.privacy-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); box-shadow: 0 0 6px var(--green); flex-shrink: 0; animation: glow 2.5s ease infinite; }
@keyframes glow { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ══ MAIN ════════════════════════════════════════ */
.main { flex: 1; display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; min-width: 0; }

/* Topbar */
.topbar { height: 52px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 20px; flex-shrink: 0; background: var(--bg); gap: 10px; }
.topbar-left { display: flex; align-items: center; gap: 8px; overflow: hidden; flex: 1; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.menu-btn { display: none; align-items: center; justify-content: center; width: 32px; height: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; cursor: pointer; color: var(--ink2); font-size: 14px; flex-shrink: 0; transition: all var(--tr); }
.menu-btn:hover { background: var(--surface2); }
.topbar-expert { display: flex; align-items: center; gap: 6px; padding: 5px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; font-size: 12px; font-weight: 500; color: var(--ink2); white-space: nowrap; flex-shrink: 0; }
.topbar-vs { font-family: var(--mono); font-size: 10px; color: var(--ink3); flex-shrink: 0; }
.topbar-models { display: flex; align-items: center; gap: 5px; overflow: hidden; }
.topbar-model-single { display: flex; align-items: center; }
.model-tag { display: flex; align-items: center; gap: 5px; padding: 4px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: 7px; font-family: var(--mono); font-size: 10px; color: var(--ink2); white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; }
.model-tag-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.model-tag.a .model-tag-dot { background: var(--accent); }
.model-tag.b .model-tag-dot { background: var(--green); }
.topbar-link { font-family: var(--mono); font-size: 10px; color: var(--ink3); text-decoration: none; letter-spacing: .06em; }
.topbar-link:hover { color: var(--ink2); }

/* Mode switcher */
.mode-switcher { display: flex; align-items: center; background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; padding: 3px; gap: 2px; }
.mode-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 12px; border-radius: 16px; border: none; background: transparent; color: var(--ink3); font-family: var(--font); font-size: 12px; font-weight: 500; cursor: pointer; transition: all .18s ease; white-space: nowrap; }
.mode-btn:hover { color: var(--ink2); }
.mode-btn.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.2); border: 1px solid var(--border); }

/* ══ CONSOLE ═════════════════════════════════════ */
.console { flex: 1; overflow-y: auto; padding: 28px 24px; display: flex; flex-direction: column; gap: 20px; scroll-behavior: smooth; }

/* Welcome */
.welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 28px; padding: 40px 20px; animation: fadein .5s ease both; }
.welcome.hidden { display: none; }
@keyframes fadein { from{opacity:0;transform:translateY(14px)} to{opacity:1;transform:translateY(0)} }
.welcome-glyph { width: 58px; height: 58px; background: var(--accent-bg); border: 1px solid rgba(124,109,240,.25); border-radius: 16px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.welcome-glyph img { width: 44px; height: 44px; object-fit: contain; }
.welcome h1 { font-size: clamp(22px,4vw,30px); font-weight: 500; line-height: 1.2; }
.welcome h1 em { font-style: italic; color: var(--accent2); }
.welcome p { font-size: 14px; color: var(--ink3); line-height: 1.65; max-width: 380px; }
.examples-grid { display: grid; grid-template-columns: repeat(3,1fr); gap: 8px; max-width: 660px; width: 100%; }
.example-card { padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); cursor: pointer; text-align: left; font-size: 12px; color: var(--ink2); line-height: 1.45; transition: all var(--tr); }
.example-card:hover { border-color: var(--accent); background: var(--surface2); color: var(--ink); transform: translateY(-1px); box-shadow: var(--shadow); }
.example-label { font-family: var(--mono); font-size: 9px; color: var(--ink3); text-transform: uppercase; letter-spacing: .1em; margin-bottom: 6px; display: block; }

/* Query bubble */
.query-block { display: flex; justify-content: flex-end; animation: fadein .25s ease both; }
.query-bubble { max-width: 68%; background: var(--accent-bg); border: 1px solid rgba(124,109,240,.2); border-radius: 12px 12px 2px 12px; padding: 12px 16px; font-size: 14px; line-height: 1.6; color: var(--ink); word-break: break-word; }

/* Response block */
.response-block { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; animation: fadein .35s ease both; }
.response-block.mode-single { grid-template-columns: 1fr; max-width: 780px; margin: 0 auto; width: 100%; }
.mode-single .rc-body { padding: 20px 24px; }
.mode-single .rc-content { font-size: 14.5px; line-height: 1.85; }

/* Response card */
.response-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; display: flex; flex-direction: column; transition: border-color .2s ease, box-shadow .2s ease; }
.response-card.thinking { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent-glow); }
.response-card.model-b.thinking { border-color: var(--green); box-shadow: 0 0 0 1px rgba(52,211,153,.1); }
.rc-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface2); flex-shrink: 0; }
.rc-model-info { display: flex; align-items: center; gap: 7px; overflow: hidden; }
.rc-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.model-a .rc-dot { background: var(--accent); }
.model-b .rc-dot { background: var(--green); }
.rc-name { font-family: var(--mono); font-size: 10px; color: var(--ink2); text-transform: uppercase; letter-spacing: .08em; }
.rc-sub { font-size: 10px; color: var(--ink3); }
.rc-faster { display: none; font-family: var(--mono); font-size: 9px; padding: 2px 7px; border-radius: 20px; background: var(--green-bg); color: var(--green); text-transform: uppercase; white-space: nowrap; }
.rc-faster.show { display: inline-block; }
.rc-meta { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.rc-timing { font-family: var(--mono); font-size: 10px; color: var(--ink3); }

/* Status pill */
.status-pill { display: flex; align-items: center; gap: 4px; font-family: var(--mono); font-size: 9px; padding: 2px 8px; border-radius: 20px; white-space: nowrap; transition: all .2s ease; }
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status-loading { background: var(--blue-bg); color: var(--blue); }
.status-loading .status-dot { animation: pulse 1s ease infinite; }
.status-ready   { background: var(--green-bg); color: var(--green); }
.status-busy    { background: var(--amber-bg); color: var(--amber); }
.status-error   { background: var(--red-bg); color: var(--red); }
@keyframes pulse { 0%,100%{opacity:1;transform:scale(1)} 50%{opacity:.2;transform:scale(.6)} }

.rc-body { padding: 16px; flex: 1; }
.rc-content { font-size: 13.5px; line-height: 1.8; color: var(--ink2); word-break: break-word; }
.rc-content p          { margin-bottom: .75em; }
.rc-content p:last-child { margin-bottom: 0; }
.rc-content strong     { color: var(--ink); font-weight: 600; }
.rc-content em         { color: var(--accent2); }
.rc-content h1,.rc-content h2,.rc-content h3 { color: var(--ink); font-weight: 600; margin: 1em 0 .4em; }
.rc-content h1 { font-size: 15px; } .rc-content h2 { font-size: 13px; } .rc-content h3 { font-size: 12px; color: var(--accent2); }
.rc-content ul,.rc-content ol { padding-left: 16px; margin-bottom: .75em; }
.rc-content li { margin-bottom: 3px; }
.rc-content code { font-family: var(--mono); font-size: 11px; background: var(--surface3); border: 1px solid var(--border2); padding: 1px 5px; border-radius: 4px; color: var(--accent2); }
.rc-content pre { background: var(--surface3); border: 1px solid var(--border); border-radius: var(--r); padding: 12px; overflow-x: auto; margin: 8px 0; }
.rc-content pre code { background: none; border: none; padding: 0; color: var(--ink2); }
.rc-content blockquote { border-left: 2px solid var(--accent); padding-left: 12px; color: var(--ink3); font-style: italic; margin: 8px 0; }
.rc-footer { display: none; align-items: center; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--border); flex-shrink: 0; }
.rc-footer.show { display: flex; }
.action-btn { display: inline-flex; align-items: center; gap: 5px; padding: 5px 10px; background: transparent; border: 1px solid var(--border2); border-radius: 6px; font-family: var(--mono); font-size: 10px; color: var(--ink3); cursor: pointer; transition: all var(--tr); text-transform: uppercase; letter-spacing: .06em; }
.action-btn:hover { color: var(--ink); background: var(--surface2); }

/* ══ INPUT BAR ═══════════════════════════════════ */
.input-area { padding: 14px 20px 18px; border-top: 1px solid var(--border); background: var(--bg); flex-shrink: 0; }
.input-box { background: var(--surface); border: 1px solid var(--border2); border-radius: var(--r-xl); padding: 14px 16px 12px; display: flex; flex-direction: column; gap: 10px; transition: border-color .2s ease, box-shadow .2s ease; }
.input-box:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }
.prompt-input { width: 100%; background: transparent; border: none; outline: none; resize: none; font-family: var(--mono); font-size: 14px; color: var(--ink); line-height: 1.6; caret-color: var(--accent); min-height: 24px; max-height: 180px; overflow-y: auto; }
.prompt-input::placeholder { color: var(--ink3); }
.input-footer { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.input-meta { display: flex; align-items: center; gap: 12px; overflow: hidden; }
.engine-tag { display: flex; align-items: center; gap: 5px; font-family: var(--mono); font-size: 10px; color: var(--ink3); white-space: nowrap; }
.engine-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: glow 2.5s ease infinite; flex-shrink: 0; }
.char-count { font-family: var(--mono); font-size: 10px; color: var(--ink3); white-space: nowrap; }
.send-btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 20px; background: var(--accent); color: #fff; border: none; border-radius: 20px; font-family: var(--font); font-size: 13px; font-weight: 600; cursor: pointer; transition: all .18s ease; white-space: nowrap; flex-shrink: 0; }
.send-btn:hover:not(:disabled) { background: var(--accent2); transform: translateY(-1px); box-shadow: 0 4px 16px -4px rgba(124,109,240,.5); }
.send-btn:disabled { opacity: .4; cursor: not-allowed; }
.spinner { width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .65s linear infinite; flex-shrink: 0; }
@keyframes spin { to{transform:rotate(360deg)} }

/* ══ COOKIE BANNER ═══════════════════════════════ */
.ck-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.5); backdrop-filter: blur(4px);
  z-index: 1100;
}
.ck-overlay.show { display: block; }

/* Floating banner — bottom right */
.ck-banner {
  position: fixed; bottom: 20px; right: 20px;
  width: 320px; background: var(--bg2);
  border: 1px solid var(--border2); border-radius: 16px;
  padding: 18px; z-index: 1050;
  box-shadow: 0 16px 48px rgba(0,0,0,.5);
  animation: ck-in .35s cubic-bezier(.34,1.4,.64,1) both;
}
@keyframes ck-in { from{opacity:0;transform:translateY(20px) scale(.96)} to{opacity:1;transform:translateY(0) scale(1)} }
.ck-banner-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 14px; font-weight: 600; color: var(--ink); }
.ck-banner-desc { font-size: 12px; color: var(--ink3); line-height: 1.55; margin-bottom: 14px; }
.ck-banner-btns { display: flex; flex-direction: column; gap: 6px; }

/* Preferences modal — centered */
.ck-modal {
  display: none; position: fixed; inset: 0; z-index: 1200;
  align-items: center; justify-content: center; padding: 16px;
}
.ck-modal[style*="flex"] { display: flex !important; }

.ck-panel {
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 18px; width: 100%; max-width: 460px;
  max-height: 90vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 64px rgba(0,0,0,.7);
  animation: ck-in .3s cubic-bezier(.34,1.2,.64,1) both;
}
.ck-panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ck-panel-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; color: var(--ink); }
.ck-close { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; background: var(--surface3); border: none; border-radius: 50%; color: var(--ink2); cursor: pointer; font-size: 13px; transition: all var(--tr); }
.ck-close:hover { background: var(--border2); color: var(--ink); }
.ck-panel-desc { padding: 12px 20px 4px; font-size: 12px; color: var(--ink3); line-height: 1.6; flex-shrink: 0; }

.ck-cats { padding: 8px 16px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.ck-cat { background: var(--surface2); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.ck-cat-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; cursor: default; gap: 12px; }
.ck-cat-row[onclick] { cursor: pointer; }
.ck-cat-row[onclick]:hover { background: var(--surface3); }
.ck-cat-info { flex: 1; display: flex; flex-direction: column; gap: 2px; }
.ck-cat-info strong { font-size: 13px; font-weight: 500; color: var(--ink); }
.ck-cat-info span { font-size: 11px; color: var(--ink3); }
.ck-cat-body { padding: 0 14px 12px; font-size: 11px; color: var(--ink3); line-height: 1.55; display: none; }
.ck-cat-body.open { display: block; }

/* Toggle */
.ck-toggle { position: relative; width: 40px; height: 22px; flex-shrink: 0; cursor: pointer; }
.ck-toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.ck-track { position: absolute; inset: 0; background: var(--surface3); border: 1px solid var(--border2); border-radius: 22px; transition: all .2s ease; }
.ck-toggle input:checked + .ck-track { background: var(--accent); border-color: var(--accent); }
.ck-toggle input:disabled + .ck-track { opacity: .5; cursor: not-allowed; }
.ck-thumb { position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; background: #fff; border-radius: 50%; box-shadow: 0 1px 4px rgba(0,0,0,.3); transition: transform .2s cubic-bezier(.4,0,.2,1); pointer-events: none; }
.ck-toggle input:checked ~ .ck-thumb { transform: translateX(18px); }

.ck-panel-foot { display: flex; gap: 8px; padding: 14px 16px 18px; border-top: 1px solid var(--border); flex-shrink: 0; flex-wrap: wrap; }

/* Cookie buttons */
.ck-b { flex: 1; min-width: 70px; padding: 9px 10px; border-radius: 10px; font-family: var(--font); font-size: 12px; font-weight: 600; cursor: pointer; border: none; transition: all .15s ease; text-align: center; white-space: nowrap; }
.ck-solid { background: var(--ink); color: var(--bg); }
.ck-solid:hover { background: var(--ink2); transform: translateY(-1px); }
.ck-ghost { background: var(--surface2); color: var(--ink2); border: 1px solid var(--border2) !important; }
.ck-ghost:hover { background: var(--surface3); color: var(--ink); }
.ck-link { background: transparent; color: var(--ink3); border: 1px solid var(--border) !important; font-size: 11px; }
.ck-link:hover { color: var(--accent2); border-color: var(--accent2) !important; }

/* ══ PWA PROMPT ══════════════════════════════════ */
.pwa-prompt { position: fixed; bottom: 20px; right: 20px; z-index: 999; width: 310px; background: var(--surface2); border: 1px solid var(--border2); border-radius: var(--r-xl); padding: 18px; box-shadow: var(--shadow-lg); animation: ck-in .35s cubic-bezier(.34,1.4,.64,1) both; }
.pwa-content { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.pwa-icon { width: 44px; height: 44px; border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.pwa-icon img { width: 100%; height: 100%; object-fit: cover; }
.pwa-title { font-size: 14px; font-weight: 600; color: var(--ink); margin-bottom: 3px; }
.pwa-sub { font-size: 11px; color: var(--ink3); line-height: 1.4; }
.pwa-actions { display: flex; gap: 8px; }
.pwa-btn { flex: 1; padding: 9px 12px; border-radius: 20px; font-family: var(--font); font-size: 12px; font-weight: 600; cursor: pointer; border: 1px solid var(--border2); text-align: center; transition: all var(--tr); background: transparent; }
.pwa-dismiss { color: var(--ink3); }
.pwa-dismiss:hover { color: var(--ink); }
.pwa-install { background: var(--accent); color: #fff; border-color: var(--accent); }
.pwa-install:hover { background: var(--accent2); }
.pwa-ios-hint { font-size: 11px; color: var(--ink3); text-align: center; margin-top: 8px; line-height: 1.4; }

/* Sidebar overlay (mobile) */
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; backdrop-filter: blur(2px); }

/* ══ RESPONSIVE ══════════════════════════════════ */
@media (max-width: 1024px) {
  :root { --sidebar-w: 240px; }
  .model-tag { max-width: 110px; }
}
@media (max-width: 767px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); box-shadow: var(--shadow-lg); transition: transform .25s ease; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .menu-btn { display: flex; }
  .topbar-models, .topbar-vs { display: none; }
  .console { padding: 16px 14px; }
  .response-block { grid-template-columns: 1fr; }
  .query-bubble { max-width: 88%; }
  .examples-grid { grid-template-columns: 1fr 1fr; }
  .welcome { gap: 20px; padding: 24px 16px; }
  .input-area { padding: 10px 14px 16px; }
  .engine-tag { display: none; }
  .ck-banner { left: 12px; right: 12px; bottom: 12px; width: auto; }
  .ck-modal { padding: 10px; }
  .ck-panel { max-height: 95vh; border-radius: 14px; }
  .ck-panel-foot { padding: 12px; }
  .pwa-prompt { left: 12px; right: 12px; width: auto; }
  .mode-btn span { display: none; }
  .mode-btn { padding: 6px 8px; }
}
@media (max-width: 380px) {
  .topbar { padding: 0 10px; }
  .topbar-expert { display: none; }
  .char-count { display: none; }
}
@media (min-width: 1400px) {
  :root { --sidebar-w: 280px; }
}

/* ══ MOBILE VIEWPORT FIXES ═══════════════════════ */
/* iOS Safari and modern Android handling */

/* When mobile keyboard opens, the viewport shrinks.
   The interactive-widget=resizes-content meta handles this automatically,
   but we add extra safety for the console scroll area. */

@media (max-width: 767px) {
  /* Ensure body uses full available height including safe areas */
  body {
    height: 100vh;
    height: 100dvh;
  }

  .main {
    height: 100vh;
    height: 100dvh;
    /* Account for iOS safe areas */
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* Console: extra bottom space so last message isn't hidden by input bar */
  .console {
    padding-bottom: 24px;
    /* Smooth momentum scrolling on iOS */
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }

  /* Input area: account for safe area on phones with home indicator */
  .input-area {
    padding-bottom: max(16px, calc(16px + env(safe-area-inset-bottom)));
  }

  /* Sidebar: full safe height */
  .sidebar {
    height: 100vh;
    height: 100dvh;
    padding-top: env(safe-area-inset-top);
  }

  /* Topbar: respect notch on iPhones */
  .topbar {
    padding-top: env(safe-area-inset-top);
    height: calc(52px + env(safe-area-inset-top));
  }

  /* Cookie banner: lift above home indicator */
  .ck-banner {
    bottom: max(12px, calc(12px + env(safe-area-inset-bottom)));
  }

  /* PWA prompt: same lift */
  .pwa-prompt {
    bottom: max(20px, calc(20px + env(safe-area-inset-bottom)));
  }

  /* Prevent iOS from auto-zooming on input focus (font-size must be ≥16px) */
  .prompt-input {
    font-size: 16px;
  }

  /* When keyboard opens, allow console to scroll while keeping input fixed */
  .console {
    /* Push content above input bar; the actual layout uses flex but this
       ensures last item is reachable when keyboard pushes the viewport up */
    scroll-padding-bottom: 80px;
  }
}

/* Very small / older Android browsers — fallback to old vh */
@supports not (height: 100dvh) {
  @media (max-width: 767px) {
    /* Use a JS-set CSS variable as ultimate fallback */
    body, .main, .sidebar {
      height: var(--vh, 100vh);
    }
  }
}

/* Landscape orientation on phones — reduce welcome padding to save space */
@media (max-width: 767px) and (orientation: landscape) {
  .welcome { gap: 12px; padding: 16px 12px; }
  .welcome h1 { font-size: 20px; }
  .welcome-glyph { width: 44px; height: 44px; }
  .welcome p { font-size: 12px; }
  .examples-grid { gap: 6px; }
  .example-card { padding: 10px; font-size: 11px; }
}

/* Foldable / very narrow screens */
@media (max-width: 320px) {
  .topbar { padding: 0 8px; gap: 6px; }
  .topbar-expert { padding: 4px 8px; font-size: 11px; }
  .console { padding: 12px 10px; }
  .input-area { padding: 8px 10px 12px; }
  .send-btn { padding: 8px 14px; font-size: 12px; }
}

/* ══ NEW CONVERSATION BUTTON ════════════════════ */
.new-conv-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px 5px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--ink2);
  font-family: var(--font);
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--tr);
  white-space: nowrap;
}
.new-conv-btn:hover {
  background: var(--accent-bg);
  border-color: var(--accent);
  color: var(--ink);
}
.new-conv-btn svg { flex-shrink: 0; }

.conv-badge {
  font-family: var(--mono);
  font-size: 9px;
  padding: 2px 6px;
  background: var(--accent-bg);
  color: var(--accent);
  border-radius: 10px;
  margin-left: 2px;
}
.conv-badge.warn {
  background: var(--amber-bg);
  color: var(--amber);
}

@media (max-width: 767px) {
  .new-conv-btn span:not(.conv-badge) { display: none; }
  .new-conv-btn { padding: 6px 8px; }
}

/* ══ SPLASH SCREEN ═══════════════════════════════ */
.splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Match safe areas on iOS */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  /* Smooth fadeout after load */
  transition: opacity 0.4s ease, visibility 0.4s ease;
}
.splash.hide {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.splash-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  animation: splash-pop 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

@keyframes splash-pop {
  0%   { opacity: 0; transform: translateY(12px) scale(0.92); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

.splash-logo {
  width: 92px;
  height: 92px;
  border-radius: 22px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow:
    0 0 0 1px var(--accent-glow),
    0 12px 40px rgba(124, 109, 240, 0.35),
    0 0 80px rgba(124, 109, 240, 0.15);
  animation: splash-glow 2.4s ease-in-out infinite;
}
.splash-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

@keyframes splash-glow {
  0%, 100% {
    box-shadow:
      0 0 0 1px var(--accent-glow),
      0 12px 40px rgba(124, 109, 240, 0.35),
      0 0 80px rgba(124, 109, 240, 0.15);
  }
  50% {
    box-shadow:
      0 0 0 2px rgba(124, 109, 240, 0.4),
      0 12px 48px rgba(124, 109, 240, 0.55),
      0 0 120px rgba(124, 109, 240, 0.3);
  }
}

.splash-text {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.splash-name {
  font-family: var(--mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.splash-dot {
  color: var(--accent);
}

.splash-tagline {
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--ink3);
}

/* Progress bar */
.splash-bar {
  width: 140px;
  height: 2px;
  background: var(--surface3);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 8px;
}
.splash-bar-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  background-size: 200% 100%;
  animation: splash-bar-slide 1.4s ease-in-out infinite;
}

@keyframes splash-bar-slide {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
  .splash-content { animation: none; }
  .splash-logo    { animation: none; }
  .splash-bar-fill { animation: none; opacity: 0.5; }
}

/* ══ FALLBACK BADGE ══════════════════════════════ */
/* Shown when primary AI provider failed and the fallback served the response */
.fallback-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 9px;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--amber-bg);
  color: var(--amber);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  cursor: help;
}

/* ══ RETRY WITH OTHER MODEL ═════════════════════ */
.retry-with-wrap {
  position: relative;
  display: inline-flex;
}
.retry-menu {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 6px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  min-width: 200px;
  max-height: 260px;
  overflow-y: auto;
  z-index: 80;
  padding: 4px;
}
.retry-menu-item {
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink2);
  cursor: pointer;
  border-radius: 6px;
  transition: all var(--tr);
  white-space: nowrap;
}
.retry-menu-item:hover {
  background: var(--accent-bg);
  color: var(--ink);
}

@media (max-width: 767px) {
  .retry-menu {
    position: fixed;
    bottom: auto;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 80px;
    min-width: auto;
    max-height: 50vh;
  }
}
