/* Van Ark chat area restyle (v1). Loaded on / only, after app.v12.css and hub.v1.css.
   Scoped to the chat area: #modelView, #chatView, #conversationDrawer and the chat dialogs.
   Login, MFA, "no access" and the boot screen are not targeted by any selector here. */

#modelView,
#chatView,
#conversationDrawer,
dialog.modal {
  --cx-panel: rgba(255, 255, 255, 0.045);
  --cx-panel-strong: rgba(255, 255, 255, 0.08);
  --cx-line: rgba(255, 255, 255, 0.10);
  --cx-line-strong: rgba(255, 255, 255, 0.16);
  --cx-glass: rgba(17, 19, 17, 0.72);
  --cx-glass-strong: rgba(17, 19, 17, 0.94);
  --cx-accent: #76d3a3;
  --cx-accent-strong: #9be5bc;
  --cx-accent-2: #b4a6ff;
  --cx-warn: #f4d27a;
  --cx-danger: #ff8a80;
  --cx-ease: cubic-bezier(.2, .8, .2, 1);
}

/* ---------- shared backdrop (same glow as menu + voice) ---------- */
#modelView.screen--models,
#chatView.chat-screen {
  background:
    radial-gradient(95% 55% at -5% -12%, rgba(47, 143, 102, 0.20), transparent 62%),
    radial-gradient(90% 55% at 105% 112%, rgba(109, 91, 208, 0.18), transparent 62%),
    var(--bg, #080908);
}

/* ---------- model selection (Fable 5 / Grok 4.6) ---------- */
#modelView .model-picker__heading h1 { color: var(--text); letter-spacing: 0; }
#modelView .model-picker__heading p:last-child { max-width: 40ch; }
#modelView .model-grid { gap: 16px; }
#modelView .model-card {
  --card-accent: var(--cx-accent);
  --card-glow: rgba(47, 143, 102, 0.55);
  isolation: isolate;
  min-height: 176px;
  border: 1px solid var(--cx-line);
  border-radius: 28px;
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.015) 60%),
    var(--cx-glass);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 18px 40px -18px rgba(0, 0, 0, 0.8);
  padding: 24px 64px 24px 24px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 180ms var(--cx-ease), border-color 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}
#modelView .model-card[data-model="grok"] {
  --card-accent: var(--cx-accent-2);
  --card-glow: rgba(109, 91, 208, 0.6);
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.015) 60%),
    var(--cx-glass);
}
#modelView .model-card::before {
  position: absolute;
  z-index: -1;
  top: -45%;
  right: -18%;
  width: 70%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, var(--card-glow) 0%, transparent 68%);
  content: "";
  opacity: 0.55;
  pointer-events: none;
}
#modelView .model-card:hover {
  border-color: color-mix(in srgb, var(--card-accent) 45%, transparent);
  background:
    linear-gradient(155deg, rgba(255, 255, 255, 0.09), rgba(255, 255, 255, 0.02) 60%),
    var(--cx-glass);
  transform: translateY(-2px);
}
#modelView .model-card:active:not(:disabled) { transform: scale(0.985); }
#modelView .model-card:focus-visible { outline: 2px solid var(--card-accent); outline-offset: 3px; }
#modelView .model-card:disabled { opacity: 0.58; }
#modelView .model-card strong { color: var(--text); }
#modelView .model-card > span { color: var(--text-soft); }
#modelView .model-card i {
  right: 22px;
  bottom: 24px;
  width: 40px;
  height: 40px;
  border: 1px solid color-mix(in srgb, var(--card-accent) 40%, transparent);
  border-radius: 50%;
  background: color-mix(in srgb, var(--card-accent) 14%, transparent);
  transform: none;
}
#modelView .model-card i::after {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 9px;
  height: 9px;
  border-top: 2px solid var(--card-accent);
  border-right: 2px solid var(--card-accent);
  content: "";
  transform: translate(-65%, -50%) rotate(45deg);
}
#modelView .recent-conversations {
  border: 1px solid var(--cx-line);
  border-radius: 24px;
  background: var(--cx-panel);
  padding: 16px 10px 10px;
}
#modelView .recent-conversations h2 { margin-left: 8px; letter-spacing: 0.08em; }
#modelView .recent-conversation { min-height: 48px; border-radius: 14px; }
#modelView .recent-conversation:hover { background: var(--cx-panel-strong); }
#modelView .recent-conversation small {
  border: 1px solid var(--cx-line);
  border-radius: 999px;
  padding: 3px 8px;
}
#modelView .model-picker__footer { border-top-color: var(--cx-line); }
#modelView .model-picker__footer .text-button {
  min-height: 44px;
  border-radius: 999px;
  padding: 8px 14px;
}
#modelView .model-picker__footer .text-button:hover { background: var(--cx-panel); }

/* ---------- top bar ---------- */
#chatView .top-bar {
  border-bottom: 1px solid var(--cx-line);
  background: linear-gradient(180deg, rgba(8, 9, 8, 0.92), rgba(8, 9, 8, 0.70));
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
}
#chatView .menu-icon {
  border: 1px solid var(--cx-line);
  background: var(--cx-panel);
  color: var(--text);
  transition: background 160ms ease, border-color 160ms ease, transform 160ms var(--cx-ease);
}
#chatView .menu-icon:hover { border-color: var(--cx-line-strong); background: var(--cx-panel-strong); }
#chatView .menu-icon:active { transform: scale(0.94); }
#chatView .menu-icon span,
#chatView .menu-icon span::before,
#chatView .menu-icon span::after { width: 17px; height: 2px; border-radius: 2px; }
#chatView .conversation-title-button {
  width: auto;
  min-width: 44px;
  max-width: 100%;
  flex: 0 1 auto;
  border-radius: 999px;
  padding: 0 14px;
}
#chatView .conversation-title-button:hover,
#chatView .conversation-title-button[aria-expanded="true"] { background: var(--cx-panel-strong); }
#chatView .conversation-title-button[aria-expanded="true"] { box-shadow: 0 0 0 1px var(--cx-line) inset; }
#chatView .model-badge {
  border-color: color-mix(in srgb, var(--cx-accent) 38%, transparent);
  background: color-mix(in srgb, var(--cx-accent) 14%, transparent);
  padding: 4px 8px;
  color: var(--cx-accent-strong);
  font-size: 10px;
}
#chatView .model-badge[data-model="grok"] {
  border-color: color-mix(in srgb, var(--cx-accent-2) 40%, transparent);
  background: color-mix(in srgb, var(--cx-accent-2) 15%, transparent);
  color: #d6ceff;
}
#chatView .notice-indicator,
#chatView .scroll-to-latest {
  border: 1px solid color-mix(in srgb, var(--cx-accent) 35%, transparent);
  background: rgba(17, 19, 17, 0.86);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  color: var(--cx-accent-strong);
}
#chatView .notice-indicator:hover,
#chatView .scroll-to-latest:hover {
  border-color: var(--cx-accent);
  background: color-mix(in srgb, var(--cx-accent) 18%, rgba(17, 19, 17, 0.9));
}
#chatView .scroll-to-latest { box-shadow: 0 10px 26px -8px rgba(0, 0, 0, 0.7); }
#chatView .connection-strip {
  border-bottom: 1px solid color-mix(in srgb, var(--cx-warn) 30%, transparent);
  background: color-mix(in srgb, var(--cx-warn) 14%, #080908);
  color: #fbe7b4;
}

/* ---------- settings popover ---------- */
#chatView .title-settings {
  border: 1px solid var(--cx-line-strong);
  border-radius: 22px;
  background: var(--cx-glass-strong);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  backdrop-filter: blur(22px) saturate(140%);
  padding: 14px;
  box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.85);
}
#chatView .title-settings__title { letter-spacing: 0.02em; }
#chatView .chat-settings .compact-select,
#chatView .chat-settings .thinking-toggle,
#chatView .chat-settings .settings-nav-button,
#chatView .chat-settings .settings-field select,
#chatView .chat-settings .settings-field input,
#chatView .chat-settings .settings-text-button,
#chatView .chat-settings .settings-help-button,
#chatView .chat-settings .domain-editor,
#chatView .chat-settings .domain-list__item,
#chatView .chat-settings .domain-editor__add input,
#chatView .chat-settings .domain-editor__add button,
#chatView .chat-settings .structured-schema textarea {
  border-color: var(--cx-line);
  border-radius: 14px;
}
#chatView .chat-settings .compact-select,
#chatView .chat-settings .thinking-toggle,
#chatView .chat-settings .settings-nav-button { background: var(--cx-panel); }
#chatView .chat-settings .settings-back-button { border-radius: 50%; }
#chatView .chat-settings .thinking-toggle__track { border-radius: 999px; }
#chatView .chat-settings .thinking-toggle input:checked + .thinking-toggle__track {
  border-color: var(--cx-accent);
  background: color-mix(in srgb, var(--cx-accent) 38%, #0d0f0d);
}

/* ---------- transcript ---------- */
#chatView .transcript { scrollbar-color: rgba(255, 255, 255, 0.14) transparent; }
#chatView .empty-state { gap: 18px; }
#chatView #emptyState .brand-mark {
  width: 64px;
  height: 64px;
  border: 1px solid var(--cx-line);
  border-radius: 20px;
  background: var(--cx-panel);
  box-shadow: 0 0 0 8px rgba(118, 211, 163, 0.05), 0 18px 44px -12px rgba(47, 143, 102, 0.55);
  overflow: hidden;
}
#chatView .empty-state h2 {
  max-width: 15ch;
  color: var(--text);
  font-size: clamp(26px, 7vw, 34px);
  font-weight: 500;
  line-height: 1.12;
}

#chatView .message--user .message__body {
  border: 1px solid rgba(118, 211, 163, 0.22);
  border-radius: 20px 20px 6px 20px;
  background: rgba(118, 211, 163, 0.14);
  padding: 10px 15px;
}
#chatView .message--assistant {
  border: 1px solid rgba(180, 166, 255, 0.13);
  border-radius: 6px 20px 20px 20px;
  background: rgba(180, 166, 255, 0.07);
  padding: 12px 48px 10px 16px;
}
#chatView .message--assistant .message__body { color: #e9ece6; }
#chatView .message--assistant .message__timestamp { padding-right: 0; text-align: left; }
#chatView .message__timestamp { margin-top: 5px; color: #7d857f; font-size: 11px; }
#chatView .message--assistant:has(> .typing) {
  width: fit-content;
  min-width: 72px;
  margin-left: max(0px, calc((100% - var(--content-width)) / 2));
  padding: 8px 16px;
}
#chatView .message--pending .message__body { opacity: 0.74; }
#chatView .message--failed .message__body {
  border-color: color-mix(in srgb, var(--cx-danger) 55%, transparent);
  background: color-mix(in srgb, var(--cx-danger) 12%, transparent);
}
#chatView .message--unknown .message__body { border-color: color-mix(in srgb, var(--cx-warn) 55%, transparent); }
#chatView .message__status,
#chatView .message__status--assistant { color: var(--cx-warn); }
#chatView .reasoning-summary {
  border-left: 2px solid color-mix(in srgb, var(--cx-accent-2) 60%, transparent);
}
#chatView .reasoning-summary summary { color: #cfc6ff; }
#chatView .web-search-status { color: var(--cx-accent-strong); }
#chatView .message-sources { border-top-color: var(--cx-line); }
#chatView .message-sources a { color: var(--cx-accent-strong); text-decoration-color: rgba(118, 211, 163, 0.45); }
#chatView .message-copy { top: 2px; right: 2px; }
#chatView .message-copy:hover { background: var(--cx-panel-strong); }
#chatView .typing span { background: var(--cx-accent-2); }
#chatView .load-older-messages {
  border: 1px solid var(--cx-line);
  border-radius: 999px;
  background: var(--cx-panel);
  padding: 8px 18px;
}
#chatView .load-older-messages:hover { background: var(--cx-panel-strong); }

/* ---------- send error ---------- */
#chatView .send-error {
  border: 1px solid color-mix(in srgb, var(--cx-danger) 40%, transparent);
  border-left-width: 1px;
  border-radius: 18px;
  background: color-mix(in srgb, var(--cx-danger) 12%, #0d0f0d);
  padding: 10px 14px 4px;
}
#chatView .send-error .text-button { padding: 8px 4px; }

/* ---------- composer ---------- */
#chatView .composer { background: transparent; }
#chatView .composer__surface {
  min-height: 56px;
  align-items: flex-end;
  border: 1px solid var(--cx-line-strong);
  border-radius: 28px;
  background: var(--cx-glass-strong);
  -webkit-backdrop-filter: blur(18px) saturate(140%);
  backdrop-filter: blur(18px) saturate(140%);
  padding: 5px 5px 5px 16px;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.05) inset, 0 16px 36px -18px rgba(0, 0, 0, 0.9);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
#chatView .composer__surface:focus-within {
  border-color: color-mix(in srgb, var(--cx-accent) 70%, transparent);
  box-shadow: 0 0 0 3px rgba(118, 211, 163, 0.16), 0 16px 36px -18px rgba(0, 0, 0, 0.9);
}
#chatView .composer textarea { min-height: 44px; padding: 11px 0 10px; }
#chatView .send-button,
#chatView .cancel-stream-button { width: 44px; min-width: 44px; height: 44px; }
#chatView .send-button {
  background: linear-gradient(145deg, var(--cx-accent-strong), var(--cx-accent));
  box-shadow: 0 6px 18px -6px rgba(118, 211, 163, 0.6);
}
#chatView .send-button:hover:not(:disabled) { background: var(--cx-accent-strong); }
#chatView .send-button:disabled { opacity: 0.28; box-shadow: none; }
#chatView .cancel-stream-button {
  border: 1px solid var(--cx-line-strong);
  background: #eef2ee;
}
#chatView .attachment-button {
  width: 44px;
  height: 44px;
  margin-bottom: 0;
  border-color: var(--cx-line);
  background: var(--cx-panel);
}
#chatView .attachment-chip {
  min-width: 160px;
  height: 52px;
  grid-template-columns: 42px minmax(0, 1fr) 44px;
  border-color: var(--cx-line);
  border-radius: 16px;
  background: var(--cx-glass-strong);
}
#chatView .attachment-chip img { border-radius: 11px; }
#chatView .attachment-chip button { width: 44px; height: 44px; }

/* keyboard open on iPhone: the home-indicator inset is covered by the keyboard */
html[data-cx-keyboard] #chatView .composer { padding-bottom: 6px; }
html[data-cx-keyboard] #chatView .scroll-to-latest { bottom: calc(var(--composer-height) + 14px); }

/* ---------- conversations drawer ---------- */
#conversationDrawer .drawer__panel {
  border-right: 1px solid var(--cx-line);
  border-radius: 0 28px 28px 0;
  background:
    radial-gradient(120% 40% at 0% 0%, rgba(47, 143, 102, 0.16), transparent 60%),
    radial-gradient(120% 40% at 100% 100%, rgba(109, 91, 208, 0.14), transparent 60%),
    rgba(12, 14, 12, 0.96);
  -webkit-backdrop-filter: blur(22px) saturate(140%);
  backdrop-filter: blur(22px) saturate(140%);
  box-shadow: 24px 0 60px -20px rgba(0, 0, 0, 0.8);
}
#conversationDrawer .drawer__header h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 24px;
  font-weight: 500;
}
#conversationDrawer .close-icon {
  border: 1px solid var(--cx-line);
  background: var(--cx-panel);
  color: var(--text);
}
#conversationDrawer .close-icon:hover { background: var(--cx-panel-strong); }
#conversationDrawer .drawer-new-button {
  min-height: 48px;
  border: 1px solid var(--cx-line);
  border-radius: 999px;
  background: var(--cx-panel);
  color: var(--text);
  font-weight: 650;
}
#conversationDrawer .drawer-new-button:hover { border-color: var(--cx-line-strong); background: var(--cx-panel-strong); }
#conversationDrawer #drawerNewChatButton {
  border-color: transparent;
  background: linear-gradient(145deg, var(--cx-accent-strong), var(--cx-accent));
  box-shadow: 0 10px 24px -12px rgba(118, 211, 163, 0.7);
  color: #07150d;
}
#conversationDrawer #drawerNewChatButton:hover { background: var(--cx-accent-strong); }
#conversationDrawer #drawerNewChatButton > span[aria-hidden="true"] { color: #07150d; }
#conversationDrawer .conversation-list { gap: 4px; }
#conversationDrawer .conversation-item {
  border: 1px solid transparent;
  border-radius: 16px;
  transition: background 140ms ease, border-color 140ms ease;
}
#conversationDrawer .conversation-item:hover { background: var(--cx-panel); }
#conversationDrawer .conversation-item--active,
#conversationDrawer .conversation-item--active:hover {
  border-color: color-mix(in srgb, var(--cx-accent) 30%, transparent);
  background: color-mix(in srgb, var(--cx-accent) 11%, transparent);
}
#conversationDrawer .conversation-open { min-height: 52px; padding: 0 12px; font-weight: 600; }
#conversationDrawer .conversation-open small { margin-top: 3px; font-size: 11px; font-weight: 500; }
#conversationDrawer .conversation-action:hover { background: var(--cx-panel-strong); }
#conversationDrawer .conversation-empty {
  margin: 8px 2px;
  border: 1px dashed var(--cx-line);
  border-radius: 18px;
}
#conversationDrawer .load-more-button {
  border: 1px solid var(--cx-line);
  border-radius: 999px;
  background: var(--cx-panel);
}
#conversationDrawer .drawer__footer { border-top-color: var(--cx-line); padding-top: 12px; }
#conversationDrawer .account-dot { box-shadow: 0 0 0 4px rgba(118, 211, 163, 0.14); }
#conversationDrawer .language-selector {
  gap: 2px;
  border: 1px solid var(--cx-line);
  border-radius: 999px;
  background: var(--cx-panel);
  padding: 2px;
}
#conversationDrawer .language-button { border-radius: 999px; }
#conversationDrawer .language-button[aria-pressed="true"] {
  border-color: color-mix(in srgb, var(--cx-accent) 55%, transparent);
  background: color-mix(in srgb, var(--cx-accent) 18%, transparent);
}
#conversationDrawer .logout-button { border-radius: 999px; }
#conversationDrawer .logout-button:hover { background: var(--cx-panel-strong); }
#conversationDrawer::backdrop {
  background: rgba(0, 0, 0, 0.62);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
@media (max-width: 599px) {
  #conversationDrawer::backdrop { background: rgba(0, 0, 0, 0.7); -webkit-backdrop-filter: none; backdrop-filter: none; }
}

/* ---------- chat dialogs (rename, delete, notice, help) ---------- */
dialog.modal {
  border: 1px solid var(--cx-line-strong);
  border-radius: 24px;
  background: var(--cx-glass-strong);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.9);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.66); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
dialog.modal h2 { font-family: Georgia, "Times New Roman", serif; font-size: 22px; font-weight: 500; }
dialog.modal .field input { border-radius: 14px; }
dialog.modal .primary-button,
dialog.modal .secondary-button,
dialog.modal .danger-button { border-radius: 999px; }
dialog.modal .help-dialog__header { border-bottom-color: var(--cx-line); }
dialog.modal .help-dialog__content details { border-top-color: var(--cx-line); }

/* toasts only while the chat area is visible */
body:has(#chatView:not([hidden])) .toast,
body:has(#modelView:not([hidden])) .toast {
  border-color: var(--cx-line-strong, rgba(255, 255, 255, 0.16));
  border-radius: 999px;
  background: rgba(17, 19, 17, 0.94);
  -webkit-backdrop-filter: blur(18px);
  backdrop-filter: blur(18px);
}

/* ---------- desktop ---------- */
@media (min-width: 800px) {
  #chatView .top-bar { padding-right: 24px; padding-left: 24px; }
  #chatView .message--assistant { padding-left: 20px; }
  #conversationDrawer .drawer__panel { border-radius: 0 28px 28px 0; }
}

/* ---------- gentle motion (off with prefers-reduced-motion) ---------- */
@media (prefers-reduced-motion: no-preference) {
  #chatView .title-settings:not([hidden]) { animation: cx-pop 180ms var(--cx-ease) both; }
  #modelView:not([hidden]) .model-card-wrap { animation: cx-rise 320ms var(--cx-ease) both; }
  #modelView:not([hidden]) .model-card-wrap:nth-child(2) { animation-delay: 60ms; }
  #chatView .send-error:not([hidden]) { animation: cx-rise 220ms var(--cx-ease) both; }
  #chatView .empty-state:not([hidden]) { animation: cx-fade 360ms ease both; }
}
@keyframes cx-pop {
  from { opacity: 0; transform: translateX(-50%) translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
@keyframes cx-rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes cx-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  #modelView .model-card:hover,
  #modelView .model-card:active:not(:disabled) { transform: none; }
}
