:root {
  color-scheme: light dark;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --panel-soft: #f0f3f7;
  --panel-strong: #e8ecf2;
  --text: #15171b;
  --muted: #68707d;
  --line: #dde2e8;
  --accent: #111827;
  --accent-text: #ffffff;
  --success: #18a558;
  --danger: #d43b3b;
  --focus: #2878ff;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --shadow: 0 14px 40px rgba(20, 28, 40, .08);
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); text-size-adjust: 100%; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
button, textarea, select, input { font: inherit; }
button, select, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
button, .attach, select { touch-action: manipulation; }
button:focus-visible, textarea:focus-visible, select:focus-visible, .attach:focus-visible {
  outline: 3px solid var(--focus);
  outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
  outline-offset: 2px;
}

.app-shell { display: grid; grid-template-columns: 280px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; height: 100dvh;
  display: flex; flex-direction: column; gap: 18px;
  padding: max(22px, env(safe-area-inset-top)) 16px max(18px, env(safe-area-inset-bottom));
  border-right: 1px solid var(--line); background: #f8fafc;
}
.brand { display: flex; gap: 11px; align-items: center; padding: 0 6px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; flex: 0 0 38px; display: grid; place-items: center; border-radius: 11px; background: var(--accent); color: white; font-weight: 800; letter-spacing: -.05em; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand span { margin-top: 2px; color: var(--muted); font-size: 12px; }
.new-chat { width: 100%; min-height: 44px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); text-align: left; cursor: pointer; }
.history { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 4px; scrollbar-width: thin; scrollbar-color: var(--panel-strong) transparent; }
.history-row { display: grid; grid-template-columns: minmax(0,1fr) 34px; gap: 3px; align-items: center; border-radius: 10px; }
.history button { border: 0; background: transparent; cursor: pointer; color: #4e5561; }
.history-open { min-width: 0; text-align: left; padding: 10px 11px; border-radius: 10px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.history-open.active { background: var(--panel-strong); color: var(--text); }
.history-delete { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 9px; color: var(--muted) !important; font-size: 18px; opacity: .55; }
.history-row:hover .history-delete, .history-delete:focus-visible { opacity: 1; }
.history-delete:hover { background: color-mix(in srgb, var(--danger) 10%, transparent) !important; color: var(--danger) !important; }
.delete-chat { width: 42px; height: 42px; border-radius: 11px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); }
.delete-chat:hover { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.sidebar-footer { display: flex; align-items: center; gap: 8px; padding: 7px; font-size: 12px; color: var(--muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; box-shadow: 0 0 0 3px color-mix(in srgb, #9ca3af 12%, transparent); }
.status-dot.online { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 13%, transparent); }
.status-dot.offline { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 13%, transparent); }

.main { min-width: 0; min-height: 100vh; min-height: 100dvh; display: grid; grid-template-rows: auto 1fr auto; }
.topbar {
  position: sticky; top: 0; z-index: 4; display: flex; align-items: center; gap: 16px; justify-content: space-between;
  padding: max(14px, env(safe-area-inset-top)) clamp(18px, 4vw, 54px) 14px;
  border-bottom: 1px solid color-mix(in srgb, var(--line) 82%, transparent);
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(18px) saturate(125%); -webkit-backdrop-filter: blur(18px) saturate(125%);
}
.topbar-title { min-width: 0; }
.topbar h1 { margin: 0; font-size: 16px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.topbar-actions { display: flex; align-items: center; gap: 9px; flex: 0 0 auto; }
.mode-select { min-height: 42px; border: 1px solid var(--line); border-radius: 11px; padding: 8px 34px 8px 11px; background: var(--panel); color: var(--text); }
.mode-select:disabled { opacity: .62; }
.tier-badge { min-height: 42px; display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); user-select: none; }
.tier-indicator { width: 8px; height: 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 12%, transparent); }
.tier-copy { display: grid; line-height: 1.05; }
.tier-copy small { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .06em; }
.tier-copy strong { margin-top: 3px; font-size: 12px; }
.tier-lock { color: var(--muted); font-size: 15px; transform: rotate(-25deg); }

.chat { width: min(920px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 calc(168px + env(safe-area-inset-bottom)); }
.welcome { min-height: 54vh; display: grid; align-content: center; justify-items: center; text-align: center; }
.welcome-icon { width: 56px; height: 56px; display: grid; place-items: center; border-radius: 18px; background: var(--accent); color: white; font-weight: 750; box-shadow: var(--shadow); }
.welcome h2 { margin: 18px 0 6px; font-size: clamp(25px, 4vw, 35px); letter-spacing: -.035em; line-height: 1.12; }
.welcome > p { margin: 0; color: var(--muted); max-width: 620px; }
.tier-note { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); background: color-mix(in srgb, var(--panel) 85%, transparent); font-size: 11px; color: var(--muted); }
.tier-note strong { color: var(--text); font-size: 11px; }
.suggestions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 22px; }
.suggestions button { min-height: 40px; padding: 9px 11px; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; cursor: pointer; }

.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; margin: 20px 0; }
.avatar { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 11px; font-weight: 750; background: var(--accent); color: white; }
.message.user .avatar { background: #dfe4eb; color: #222831; }
.bubble { min-width: 0; padding-top: 5px; line-height: 1.62; overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble .meta { margin-top: 8px; color: var(--muted); font-size: 11px; }

.activity-bubble { padding-top: 0; }
.activity-card { min-height: 62px; display: flex; align-items: center; gap: 12px; width: min(100%, 520px); padding: 11px 13px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); box-shadow: 0 8px 24px rgba(20, 28, 40, .045); overflow: hidden; position: relative; }
.activity-card::after { content: ""; position: absolute; inset: auto 0 0; height: 2px; background: linear-gradient(90deg, transparent, var(--focus), transparent); transform: translateX(-100%); animation: activity-scan 1.8s ease-in-out infinite; }
.activity-orb { position: relative; width: 34px; height: 34px; flex: 0 0 34px; display: grid; place-items: center; }
.activity-orb::before { content: ""; width: 18px; height: 18px; border-radius: 50%; background: var(--accent); animation: activity-pulse 1.45s ease-in-out infinite; }
.activity-orb span { position: absolute; width: 29px; height: 29px; border: 1px solid color-mix(in srgb, var(--focus) 45%, transparent); border-radius: 50%; opacity: 0; animation: activity-ring 1.8s ease-out infinite; }
.activity-orb span:nth-child(2) { animation-delay: .55s; }
.activity-orb span:nth-child(3) { animation-delay: 1.1s; }
.activity-text { min-width: 0; display: grid; gap: 2px; }
.activity-label { font-size: 13px; }
.activity-detail { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-dots { margin-left: auto; display: flex; gap: 4px; padding: 0 2px; }
.activity-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: activity-dot 1s ease-in-out infinite; }
.activity-dots i:nth-child(2) { animation-delay: .14s; }.activity-dots i:nth-child(3) { animation-delay: .28s; }
.activity-card.is-working .activity-orb::before { border-radius: 7px; animation-name: activity-work; }
.activity-card.is-creating .activity-orb::before { border-radius: 5px; animation-name: activity-create; }

.composer-wrap { position: fixed; z-index: 5; left: 280px; right: 0; bottom: 0; padding: 12px 24px max(18px, env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 74%, transparent); }
.composer, .file-list, .composer-note { width: min(920px, 100%); margin-left: auto; margin-right: auto; }
.composer { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: end; padding: 9px; border: 1px solid var(--line); border-radius: 18px; background: var(--panel); box-shadow: var(--shadow); }
.composer:focus-within { border-color: color-mix(in srgb, var(--focus) 46%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 9%, transparent), var(--shadow); }
.composer textarea { width: 100%; resize: none; max-height: 180px; border: 0; outline: 0; background: transparent; color: var(--text); padding: 9px 4px; line-height: 1.45; }
.composer textarea::placeholder { color: color-mix(in srgb, var(--muted) 82%, transparent); }
.attach, .send, .icon-button { border: 0; cursor: pointer; display: grid; place-items: center; }
.attach { width: 40px; height: 40px; border-radius: 11px; background: var(--panel-soft); font-size: 22px; cursor: pointer; }
.send { width: 40px; height: 40px; border-radius: 11px; background: var(--accent); color: var(--accent-text); font-size: 20px; font-weight: 700; }
.send:disabled { opacity: .42; cursor: default; }
.file-list { display: flex; gap: 7px; overflow-x: auto; padding: 0 3px 8px; scrollbar-width: thin; }
.file-chip { max-width: 240px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.composer-note { text-align: center; margin-top: 7px; margin-bottom: 0; font-size: 11px; color: #838b97; }
.mobile-only { display: none; }.icon-button { width: 40px; height: 40px; background: transparent; border-radius: 10px; font-size: 20px; }

@keyframes activity-scan { 0% { transform: translateX(-100%); } 55%,100% { transform: translateX(100%); } }
@keyframes activity-pulse { 0%,100% { transform: scale(.88); opacity: .72; } 50% { transform: scale(1); opacity: 1; } }
@keyframes activity-ring { 0% { transform: scale(.45); opacity: .5; } 85%,100% { transform: scale(1.25); opacity: 0; } }
@keyframes activity-dot { 0%,100% { transform: translateY(0); opacity: .35; } 50% { transform: translateY(-3px); opacity: 1; } }
@keyframes activity-work { 0%,100% { transform: rotate(0) scale(.88); } 50% { transform: rotate(90deg) scale(1); } }
@keyframes activity-create { 0%,100% { transform: rotate(-8deg) scale(.86); } 50% { transform: rotate(8deg) scale(1); } }

@media (hover: hover) {
  .new-chat:hover, .suggestions button:hover, .attach:hover { background: var(--panel-strong); }
  .history-open:hover { background: var(--panel-strong); color: var(--text); }
  .send:hover:not(:disabled) { filter: brightness(1.08); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101217; --panel: #171a20; --panel-soft: #1f232a; --panel-strong: #272c34;
    --text: #f3f5f7; --muted: #929aa6; --line: #2b3038; --accent: #f2f4f7; --accent-text: #101217;
    --focus: #68a0ff; --shadow: 0 14px 42px rgba(0,0,0,.24);
  }
  .sidebar { background: #13161b; }
  .history button { color: #abb1bb; }
  .message.user .avatar { background: #303640; color: #f4f6f8; }
  .composer-note { color: #7f8793; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; z-index: 10; width: min(86vw, 310px); transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow); }
  .sidebar.open { transform: translateX(0); }
  .composer-wrap { left: 0; padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .mobile-only { display: grid; }
  .topbar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .topbar p { display: none; }
  .chat { width: min(calc(100% - 26px), 920px); }
}

@media (max-width: 560px) {
  .topbar { gap: 8px; }
  .topbar-title { flex: 1; }
  .topbar-actions { gap: 6px; }
  .tier-badge { padding: 6px 8px; }
  .tier-copy small, .tier-lock { display: none; }
  .mode-select { width: 112px; padding-right: 28px; }
  .activity-detail { max-width: 215px; }
  .activity-dots { display: none; }
  .composer-wrap { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (pointer: coarse) {
  .new-chat, .history button, .suggestions button, .mode-select { min-height: 44px; }
  .attach, .send, .icon-button { width: 44px; height: 44px; }
}

@media (prefers-contrast: more) {
  :root { --line: #aeb5bf; }
  .composer, .tier-badge, .new-chat, .activity-card { border-width: 2px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

@media (forced-colors: active) {
  .brand-mark, .welcome-icon, .avatar, .send { forced-color-adjust: auto; border: 1px solid ButtonText; }
  .tier-indicator, .status-dot { border: 1px solid CanvasText; }
  .activity-card::after { display: none; }
}

/* Conversation/session identity */
.session-id {
  display: block;
  max-width: min(52vw, 560px);
  margin-top: 4px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 10px/1.25 ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 860px) {
  .session-id { max-width: 44vw; }
}

@media (max-width: 560px) {
  .session-id { max-width: 34vw; font-size: 9px; }
}

/* v0.5 official knowledge / research */
.knowledge-badge { display: inline-grid; grid-template-columns: auto auto; grid-template-rows: auto auto; column-gap: 7px; align-items: center; min-height: 42px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 13px; background: var(--panel); color: var(--text); white-space: nowrap; }
.knowledge-badge > span { grid-row: 1 / span 2; font-size: 19px; color: var(--focus); }
.knowledge-badge strong { font-size: 13px; line-height: 1; }
.knowledge-badge small { font-size: 9px; line-height: 1; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.activity-card.is-researching .activity-orb::before { border-radius: 50% 50% 42% 58%; animation: activity-research 1.5s ease-in-out infinite; }
.activity-card.is-researching::after { animation-duration: 1.2s; }
@keyframes activity-research { 0%,100% { transform: translateX(-3px) rotate(-15deg) scale(.82); } 50% { transform: translateX(3px) rotate(15deg) scale(1); } }
@media (max-width: 760px) { .knowledge-badge { min-height: 40px; padding: 6px 9px; } .knowledge-badge small { display: none; } .knowledge-badge > span { grid-row: auto; } }
.source-list { margin-top: 11px; padding-top: 10px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.source-list strong { width: 100%; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .055em; }
.source-list a { max-width: 100%; padding: 5px 8px; border: 1px solid var(--line); border-radius: 9px; color: var(--focus); background: color-mix(in srgb, var(--panel) 88%, var(--focus) 12%); text-decoration: none; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-list a:hover { text-decoration: underline; }

/* v0.6 local vision */
.activity-card.is-reading .activity-orb::before { border-radius: 7px; animation: activity-read 1.25s ease-in-out infinite; }
.activity-card.is-reading::after { animation-duration: 1s; }
@keyframes activity-read { 0%,100% { transform: scale(.82); box-shadow: 0 0 0 0 color-mix(in srgb, var(--focus) 24%, transparent); } 50% { transform: scale(1); box-shadow: 0 0 0 6px color-mix(in srgb, var(--focus) 0%, transparent); } }

/* v0.7 private conversations / ZIP */
.privacy-badge { min-height: 42px; display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); white-space: nowrap; }
.privacy-badge span { color: var(--success); font-size: 14px; }
.privacy-badge strong { font-size: 11px; }
.activity-card.is-archive .activity-orb::before { border-radius: 5px 10px 5px 10px; animation: activity-archive 1.1s ease-in-out infinite; }
.activity-card.is-archive::after { animation-duration: .9s; }
@keyframes activity-archive { 0%,100% { transform: scale(.84) rotate(-6deg); } 50% { transform: scale(1) rotate(6deg); } }
@media (max-width: 700px) { .privacy-badge strong { display: none; } .privacy-badge { padding: 7px 9px; } }

/* v0.8 adaptive learning feedback */
.learning-feedback {
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 9px;
}
.feedback-question { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.feedback-question > div { min-width: 0; display: grid; gap: 2px; }
.feedback-question strong { font-size: 12px; line-height: 1.35; }
.feedback-question span { color: var(--muted); font-size: 10px; line-height: 1.35; }
.feedback-actions { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; }
.feedback-button, .feedback-dismiss, .feedback-link {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.feedback-button { min-height: 34px; padding: 6px 10px; border-radius: 9px; font-size: 11px; }
.feedback-button.is-right { border-color: color-mix(in srgb, var(--success) 38%, var(--line)); }
.feedback-button.is-wrong { border-color: color-mix(in srgb, #d45959 34%, var(--line)); }
.feedback-button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.feedback-button:disabled, .feedback-dismiss:disabled { opacity: .45; cursor: default; }
.feedback-dismiss { flex: 0 0 auto; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 8px; font-size: 16px; color: var(--muted); }
.feedback-correction-label { color: var(--muted); font-size: 10px; }
.feedback-correction { width: 100%; min-height: 62px; resize: vertical; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-soft); color: var(--text); padding: 9px 10px; outline: 0; line-height: 1.4; }
.feedback-correction:focus { border-color: color-mix(in srgb, var(--focus) 55%, var(--line)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 9%, transparent); }
.feedback-settled { font-size: 10px; line-height: 1.4; color: var(--muted); }
.feedback-settled.is-right { color: color-mix(in srgb, var(--success) 72%, var(--text)); }
.feedback-settled.is-wrong { color: color-mix(in srgb, #d66a6a 72%, var(--text)); }
.feedback-link { width: fit-content; padding: 0; border: 0; background: transparent; color: var(--focus); font-size: 10px; text-decoration: underline; text-underline-offset: 2px; }
@media (hover: hover) {
  .feedback-button:hover:not(:disabled), .feedback-dismiss:hover:not(:disabled) { background: var(--panel-strong); }
  .feedback-button.primary:hover:not(:disabled) { filter: brightness(1.08); }
}
@media (pointer: coarse) {
  .feedback-button { min-height: 42px; }
  .feedback-dismiss { width: 40px; height: 40px; }
}

/* Document extraction/analysis activity */
.activity-card.is-document .activity-orb::before { border-radius: 4px; animation: activity-document 1.35s ease-in-out infinite; }
.activity-card.is-document::after { animation-duration: 1.05s; }
@keyframes activity-document {
  0%, 100% { transform: scale(.72) rotate(0deg); opacity: .55; }
  50% { transform: scale(1.02) rotate(90deg); opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
  .activity-card.is-document .activity-orb::before { animation: none; }
}


.diagnostic-actions { margin-top: 10px; padding-top: 9px; border-top: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 7px; }
.diagnostic-action { min-height: 34px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); color: inherit; cursor: pointer; font-size: 11px; }
.diagnostic-action:hover { background: var(--panel-strong); }
@media (pointer: coarse) { .diagnostic-action { min-height: 42px; } }

/* v0.20 private project workspace */
.workspace-summary {
  margin-top: 9px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: color-mix(in srgb, var(--panel) 92%, var(--focus) 8%);
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

/* v0.21 GDPR/TDDDG consent system */
.legal-links {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 14px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 10px;
}
.legal-links a,
.legal-link-button {
  appearance: none;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.legal-links a:hover,
.legal-link-button:hover { color: var(--text); }

.consent-banner {
  position: fixed;
  z-index: 9000;
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: 980px;
  margin: 0 auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  box-shadow: 0 24px 70px rgba(0, 0, 0, .22);
  backdrop-filter: blur(22px) saturate(1.15);
  -webkit-backdrop-filter: blur(22px) saturate(1.15);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 20px;
  align-items: center;
}
.consent-banner[hidden] { display: none !important; }
.consent-banner-copy { min-width: 0; }
.consent-banner-copy strong { display: block; margin-bottom: 5px; font-size: 14px; }
.consent-banner-copy p { margin: 0 0 7px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.consent-privacy-link,
.consent-dialog-links a { color: var(--focus); font-size: 10px; text-underline-offset: 2px; }
.consent-banner-actions,
.consent-dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: flex-end; }
.consent-button {
  appearance: none;
  min-height: 40px;
  padding: 8px 13px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
  font: 600 11px/1.2 inherit;
  cursor: pointer;
}
.consent-button:hover:not(:disabled) { background: var(--panel-strong); }
.consent-button.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.consent-button.primary:hover:not(:disabled) { filter: brightness(1.06); }
.consent-button.neutral { background: var(--panel); }
.consent-button:disabled { opacity: .5; cursor: default; }

.consent-overlay {
  position: fixed;
  z-index: 9100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
  background: rgba(10, 12, 17, .54);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.consent-overlay[hidden] { display: none !important; }
.consent-open { overflow: hidden; }
.consent-dialog {
  width: min(720px, 100%);
  max-height: min(86vh, 840px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 30px 100px rgba(0,0,0,.36);
  padding: 20px;
}
.consent-dialog-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.consent-dialog-head h2 { margin: 3px 0 0; font-size: clamp(18px, 4vw, 24px); letter-spacing: -.02em; }
.consent-kicker { color: var(--focus); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.consent-close {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
}
.consent-intro { margin: 12px 0 16px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.consent-categories { display: grid; gap: 9px; }
.consent-category {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel-soft);
}
.consent-category.is-unavailable { opacity: .62; }
.consent-category-copy { min-width: 0; display: grid; gap: 4px; color: var(--muted); font-size: 10px; line-height: 1.4; }
.consent-category-title { color: var(--text); font-size: 12px; font-weight: 700; }
.consent-category-title em { margin-left: 5px; color: var(--muted); font-size: 9px; font-style: normal; font-weight: 600; }
.consent-switch { position: relative; flex: 0 0 auto; width: 46px; height: 28px; }
.consent-switch input { position: absolute; opacity: 0; pointer-events: none; }
.consent-switch span { position: absolute; inset: 0; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-strong); transition: .18s ease; }
.consent-switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: var(--muted); transition: .18s ease; }
.consent-switch input:checked + span { background: color-mix(in srgb, var(--focus) 24%, var(--panel)); border-color: color-mix(in srgb, var(--focus) 60%, var(--line)); }
.consent-switch input:checked + span::after { transform: translateX(18px); background: var(--focus); }
.consent-switch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--focus) 28%, transparent); outline-offset: 2px; }
.consent-switch input:disabled + span { opacity: .7; }
.consent-cookie-details { margin-top: 12px; }
.consent-cookie-details details { border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); }
.consent-cookie-details summary { cursor: pointer; padding: 11px 13px; color: var(--text); font-size: 11px; font-weight: 650; }
.consent-cookie-table-wrap { overflow-x: auto; padding: 0 10px 10px; }
.consent-cookie-table { width: 100%; border-collapse: collapse; min-width: 570px; font-size: 9px; line-height: 1.4; }
.consent-cookie-table th, .consent-cookie-table td { padding: 8px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.consent-cookie-table th { color: var(--muted); font-weight: 700; }
.consent-cookie-table code { font-size: 9px; }
.consent-dialog-links { margin: 12px 0; }
.consent-dialog-actions { padding-top: 13px; border-top: 1px solid var(--line); }
.consent-footnote { margin: 10px 0 0; color: var(--muted); font-size: 9px; line-height: 1.4; }

@media (max-width: 760px) {
  .consent-banner { grid-template-columns: 1fr; gap: 12px; padding: 15px; }
  .consent-banner-actions { justify-content: stretch; }
  .consent-banner-actions .consent-button { flex: 1 1 140px; }
  .consent-dialog { padding: 16px; border-radius: 16px; }
  .consent-dialog-actions { justify-content: stretch; }
  .consent-dialog-actions .consent-button { flex: 1 1 150px; }
}
@media (prefers-reduced-motion: reduce) {
  .consent-switch span, .consent-switch span::after { transition: none; }
}

/* Public privacy/legal page */
.legal-page { min-height: 100vh; background: var(--bg); color: var(--text); }
.legal-document { width: min(900px, calc(100% - 28px)); margin: 0 auto; padding: max(26px, env(safe-area-inset-top)) 0 max(50px, env(safe-area-inset-bottom)); }
.legal-document-head { padding: 18px 0 22px; }
.legal-document-head h1 { margin: 8px 0; font-size: clamp(28px, 6vw, 46px); letter-spacing: -.035em; }
.legal-document-head p { max-width: 720px; margin: 0; color: var(--muted); line-height: 1.6; }
.legal-back { display: inline-block; margin-bottom: 20px; color: var(--muted); text-decoration: none; font-size: 11px; }
.legal-back:hover { color: var(--text); }
.legal-section, .legal-warning { margin: 12px 0; padding: 18px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); }
.legal-section h2 { margin: 0 0 9px; font-size: 16px; }
.legal-section p, .legal-section address { margin: 8px 0; color: var(--muted); font-size: 11px; line-height: 1.65; font-style: normal; }
.legal-section a { color: var(--focus); }
.legal-warning { border-color: color-mix(in srgb, #d78c35 55%, var(--line)); background: color-mix(in srgb, var(--panel) 90%, #d78c35 10%); }
.legal-warning strong { font-size: 12px; }
.legal-warning p { margin: 5px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.legal-small { font-size: 9px !important; }
.legal-cookie-table-wrap { overflow-x: auto; margin-top: 12px; }
.legal-cookie-table { width: 100%; min-width: 650px; border-collapse: collapse; font-size: 10px; }
.legal-cookie-table th, .legal-cookie-table td { padding: 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.legal-cookie-table th { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .04em; }
.legal-cookie-table code { font-size: 9px; }
.legal-document-footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 18px 2px; color: var(--muted); font-size: 9px; }
.legal-document-footer a { color: var(--focus); }

/* v0.25 adaptive clarity / cross-platform polish */
:root {
  --sidebar-width: 284px;
  --content-max: 980px;
  --surface-glass: color-mix(in srgb, var(--panel) 88%, transparent);
  --shadow-xs: 0 1px 2px rgba(20, 28, 40, .045);
  --shadow-sm: 0 8px 24px rgba(20, 28, 40, .07);
  --transition-fast: 140ms ease;
  --code-bg: #11151b;
  --code-text: #edf2f7;
}

::selection { background: color-mix(in srgb, var(--focus) 26%, transparent); color: var(--text); }
button, select, input, textarea, .attach, .history-open, .diagnostic-action, .feedback-button {
  transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), opacity var(--transition-fast), transform var(--transition-fast), box-shadow var(--transition-fast);
}
button:active:not(:disabled), .attach:active { transform: scale(.975); }

.app-shell { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
.sidebar {
  background: linear-gradient(180deg, color-mix(in srgb, var(--panel) 72%, var(--bg)), color-mix(in srgb, var(--bg) 92%, var(--panel)));
  padding-left: 17px;
  padding-right: 17px;
}
.brand-mark, .welcome-icon { box-shadow: var(--shadow-sm); }
.new-chat { box-shadow: var(--shadow-xs); font-weight: 620; }
.history-row { border: 1px solid transparent; }
.history-row:has(.history-open.active) { border-color: color-mix(in srgb, var(--line) 80%, transparent); background: color-mix(in srgb, var(--panel) 72%, transparent); }

.topbar {
  min-height: 72px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  box-shadow: 0 1px 0 color-mix(in srgb, var(--line) 55%, transparent);
}
.topbar-actions { min-width: 0; }
.mode-select, .tier-badge, .privacy-badge, .knowledge-badge, .delete-chat { box-shadow: var(--shadow-xs); }

.chat { width: min(var(--content-max), calc(100% - 38px)); padding-top: 38px; }
.welcome { min-height: 58vh; }
.welcome > p { line-height: 1.65; }
.suggestions button { box-shadow: var(--shadow-xs); }

.message { margin: 24px 0; align-items: start; }
.avatar { box-shadow: var(--shadow-xs); user-select: none; }
.bubble { line-height: 1.68; }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.message-text + .message-text { margin-top: 10px; }
.message.user .bubble {
  width: fit-content;
  max-width: min(760px, 100%);
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: color-mix(in srgb, var(--panel) 86%, var(--panel-soft));
  box-shadow: var(--shadow-xs);
  line-height: 1.55;
}
.message.assistant .bubble { max-width: 100%; }
.bubble .meta {
  padding-top: 7px;
  border-top: 1px solid color-mix(in srgb, var(--line) 72%, transparent);
  line-height: 1.45;
}

.code-block {
  margin: 12px 0;
  overflow: hidden;
  border: 1px solid color-mix(in srgb, var(--line) 74%, #000 26%);
  border-radius: 14px;
  background: var(--code-bg);
  color: var(--code-text);
  box-shadow: var(--shadow-sm);
}
.code-block-head {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 9px 7px 13px;
  border-bottom: 1px solid rgba(255,255,255,.09);
  background: rgba(255,255,255,.035);
  color: #aeb8c5;
  font: 600 10px/1.2 ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  letter-spacing: .02em;
}
.code-copy {
  min-height: 28px;
  padding: 5px 8px;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 8px;
  background: rgba(255,255,255,.06);
  color: #e8edf3;
  cursor: pointer;
  font: 600 10px/1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}
.code-copy:hover { background: rgba(255,255,255,.11); }
.code-block pre {
  margin: 0;
  padding: 14px 15px 16px;
  overflow: auto;
  overscroll-behavior-inline: contain;
  tab-size: 4;
  white-space: pre;
  scrollbar-width: thin;
  font: 12.5px/1.6 ui-monospace, "SFMono-Regular", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
.code-block code { color: inherit; font: inherit; }

.source-list a, .file-chip, .workspace-summary { box-shadow: var(--shadow-xs); }
.activity-card { box-shadow: var(--shadow-sm); }

.composer-wrap { left: var(--sidebar-width); padding-left: 26px; padding-right: 26px; }
.composer, .file-list, .composer-note { width: min(var(--content-max), 100%); }
.composer {
  border-radius: 20px;
  padding: 10px;
  background: var(--surface-glass);
  backdrop-filter: blur(22px) saturate(125%);
  -webkit-backdrop-filter: blur(22px) saturate(125%);
}
.composer textarea { min-height: 42px; max-height: min(34vh, 260px); font-size: 15px; }
.attach, .send { flex: 0 0 auto; }
.file-list { scroll-snap-type: x proximity; }
.file-chip { scroll-snap-align: start; }

@media (prefers-color-scheme: dark) {
  :root {
    --code-bg: #090c10;
    --code-text: #e8edf4;
    --shadow-xs: 0 1px 2px rgba(0,0,0,.18);
    --shadow-sm: 0 10px 30px rgba(0,0,0,.24);
  }
  .message.user .bubble { background: color-mix(in srgb, var(--panel) 72%, var(--panel-soft)); }
}

@media (max-width: 1000px) {
  :root { --sidebar-width: 264px; --content-max: 900px; }
  .topbar { padding-left: 24px; padding-right: 24px; }
}

@media (max-width: 860px) {
  :root { --content-max: 840px; }
  .sidebar { width: min(88vw, 320px); }
  .composer-wrap { left: 0; }
  .topbar { min-height: 64px; }
  .chat { width: min(var(--content-max), calc(100% - 28px)); padding-top: 26px; }
  .message { gap: 10px; }
}

@media (max-width: 680px) {
  .knowledge-badge { display: none; }
  .topbar-actions { gap: 5px; }
  .mode-select { max-width: 110px; }
  .composer-note { display: none; }
  .composer-wrap { padding-top: 9px; }
  .chat { padding-bottom: calc(118px + env(safe-area-inset-bottom)); }
  .message { grid-template-columns: 30px minmax(0,1fr); margin: 18px 0; }
  .avatar { width: 30px; height: 30px; border-radius: 9px; font-size: 10px; }
  .message.user .bubble { padding: 9px 11px; border-radius: 13px; }
  .code-block { margin-left: -1px; margin-right: -1px; border-radius: 12px; }
  .code-block pre { padding: 12px; font-size: 12px; }
}

@media (max-width: 470px) {
  .privacy-badge { display: none; }
  .topbar h1 { font-size: 14px; }
  .session-id { display: none; }
  .mode-select { width: 100px; min-height: 40px; }
  .tier-badge { min-height: 40px; }
  .delete-chat { width: 40px; height: 40px; }
  .chat { width: calc(100% - 22px); }
  .suggestions { display: grid; grid-template-columns: 1fr; width: min(100%, 360px); }
  .suggestions button { width: 100%; text-align: left; }
  .activity-card { width: 100%; }
  .activity-detail { max-width: 48vw; }
}

@media (pointer: coarse) {
  .code-copy { min-height: 36px; padding-inline: 10px; }
  .source-list a { min-height: 34px; display: inline-flex; align-items: center; }
}

@supports (-webkit-touch-callout: none) {
  .composer textarea { font-size: 16px; } /* prevents iOS focus zoom */
  .composer-wrap { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}
