:root {
  --font: system-ui, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --ease: cubic-bezier(0.25, 0.8, 0.3, 1);
}

html[data-theme="dark"] {
  --bg: #0a0c10;
  --bg-grad: radial-gradient(1200px 800px at 70% -10%, rgba(91, 141, 239, 0.08), transparent 60%), var(--bg);
  --surface: #11141a;
  --surface-2: #171b23;
  --surface-3: #1e2330;
  --border: #232836;
  --text: #e8eaf0;
  --muted: #8b93a5;
  --accent: #5b8def;
  --accent-soft: rgba(91, 141, 239, 0.14);
  --danger: #e5484d;
  --ok: #2fbf71;
  --warn: #f5a623;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --scrim: rgba(0, 0, 0, 0.55);
}

html[data-theme="light"] {
  --bg: #f6f7f9;
  --bg-grad: radial-gradient(1200px 800px at 70% -10%, rgba(91, 141, 239, 0.07), transparent 60%), var(--bg);
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --surface-3: #e8ebf0;
  --border: #e3e6ec;
  --text: #171a21;
  --muted: #5f6877;
  --accent: #3f6fe0;
  --accent-soft: rgba(63, 111, 224, 0.1);
  --danger: #d93439;
  --ok: #1d9e57;
  --warn: #c07f12;
  --shadow: 0 12px 40px rgba(20, 30, 50, 0.12);
  --scrim: rgba(15, 20, 30, 0.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg-grad);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  transition: background 0.25s var(--ease), color 0.25s var(--ease);
}

.hidden { display: none !important; }
button { font-family: inherit; }

/* ---------- splash ---------- */
.splash {
  position: fixed; inset: 0; z-index: 200;
  background: #0a0c10;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s var(--ease), visibility 0.5s;
}
.splash.gone { opacity: 0; visibility: hidden; }
.splash-video {
  width: 220px; height: 220px; object-fit: cover;
  border-radius: 24px; opacity: 0.95;
}
@media (max-width: 768px) {
  .splash-video {
    width: 100%; height: 100%;
    border-radius: 0; opacity: 1;
    object-fit: cover; object-position: center;
  }
}
.splash-mark {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  opacity: 0;
  animation: splashFallback 1.6s ease infinite;
}
.splash-mark img { width: 96px; height: 96px; }
@keyframes splashFallback {
  0%, 100% { opacity: 0; transform: scale(0.9); }
  50% { opacity: 0.85; transform: scale(1); }
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 10px;
  height: 56px; padding: 0 14px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 16.5px; letter-spacing: 0.02em; }
.brand img { width: 21px; height: 21px; }

.switch {
  display: flex; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px; gap: 2px; margin: 0 auto;
}
.switch button {
  border: none; background: transparent; color: var(--muted);
  padding: 7px 18px; border-radius: 999px; font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.18s var(--ease);
  min-height: 36px;
}
.switch button.active { background: var(--accent); color: #fff; box-shadow: 0 2px 10px var(--accent-soft); }

.iconbtn {
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); width: 40px; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; transition: all 0.15s var(--ease);
}
.iconbtn:active { transform: scale(0.94); }
.iconbtn svg { width: 19px; height: 19px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- layout ---------- */
.shell { display: flex; flex-direction: column; height: calc(100vh - 56px); height: calc(100dvh - 56px); min-height: 0; }
.main { flex: 1; min-height: 0; width: 100%; max-width: 880px; margin: 0 auto; padding: 16px 14px calc(90px + env(safe-area-inset-bottom)); }
.main.drive { max-width: 1080px; }
/* chat view: the composer lives in-flow at the bottom — no page scroll beyond it */
.main.chat-view { display: flex; flex-direction: column; overflow: hidden; padding-bottom: 0; }
.main.chat-view .chat { height: auto; flex: 1; min-height: 0; }
.main.chat-view .thread { flex: 1; min-height: 0; overflow-y: auto; }
.main.chat-view .composer-bar { flex: none; position: relative; }

/* ---------- side drawer ---------- */
.drawer-bg {
  position: fixed; inset: 0; z-index: 60; background: var(--scrim);
  opacity: 0; visibility: hidden; transition: opacity 0.22s var(--ease), visibility 0.22s;
}
.drawer-bg.open { opacity: 1; visibility: visible; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 61;
  width: min(320px, 86vw); background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-102%); transition: transform 0.26s var(--ease);
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); box-shadow: var(--shadow); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 15px; margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 10px; }

.menu-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: none; color: var(--text);
  padding: 12px; border-radius: var(--radius-sm); font-size: 14.5px;
  cursor: pointer; text-align: left; transition: background 0.15s;
  min-height: 44px;
}
.menu-btn:hover { background: var(--surface-2); }
.menu-btn svg { width: 18px; height: 18px; stroke: var(--muted); flex: none; }
.menu-btn.danger { color: var(--danger); }
.menu-sep { height: 1px; background: var(--border); margin: 8px 4px; }
.menu-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); padding: 10px 12px 6px; }

/* ---------- chat ---------- */
.chat { display: flex; flex-direction: column; height: calc(100vh - 56px - 60px); height: calc(100dvh - 56px - 60px); }
.thread { flex: 1; overflow-y: auto; padding: 18px 4px 10px; }
.welcome { text-align: center; margin-top: 12vh; color: var(--muted); }
.welcome .logo { width: 56px; height: 56px; margin: 0 auto 12px; animation: float 3.2s ease-in-out infinite; }
.welcome .logo img { width: 100%; height: 100%; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-7px); } }
.welcome h1 { font-size: 21px; color: var(--text); margin: 0 0 6px; }
.welcome p { font-size: 14px; margin: 0; }

.msg { display: flex; gap: 10px; margin-bottom: 16px; animation: msgIn 0.22s var(--ease); }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg .bubble { max-width: 84%; padding: 11px 14px; border-radius: 16px; font-size: 14.5px; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }
.msg.user { flex-direction: row-reverse; }
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.msg.assistant .bubble p { margin: 0 0 8px; }
.msg.assistant .bubble p:last-child { margin-bottom: 0; }
.msg.assistant .bubble code { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: 2px 5px; border-radius: 5px; }
.msg.assistant .bubble pre { background: var(--surface-2); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.msg.assistant .bubble ul { margin: 6px 0; padding-left: 20px; }
.msg.assistant .bubble table { border-collapse: collapse; margin: 8px 0; }
.msg.assistant .bubble td, .msg.assistant .bubble th { border: 1px solid var(--border); padding: 6px 9px; font-size: 13.5px; }

.toolchip {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  padding: 7px 11px; border-radius: 999px; margin-bottom: 12px;
  animation: msgIn 0.2s var(--ease);
}
.toolchip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.composer-bar { position: sticky; bottom: 0; padding: 10px 0 calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 35%); }
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow);
  transition: border-color 0.2s;
}
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; border: none; background: none; resize: none; color: var(--text);
  font-family: inherit; font-size: 15px; line-height: 1.5;
  max-height: 150px; padding: 6px 0; outline: none;
}
.composer .send {
  border: none; background: var(--accent); color: #fff;
  width: 40px; height: 40px; border-radius: 12px; flex: none;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: transform 0.15s var(--ease), opacity 0.15s;
}
.composer .send:disabled { opacity: 0.4; cursor: not-allowed; }
.composer .send:active { transform: scale(0.92); }
.composer .send svg { width: 18px; height: 18px; }
.quotanote { text-align: center; font-size: 11.5px; color: var(--muted); padding: 6px 0 2px; }

/* ---------- drive ---------- */
.drivebar { display: flex; gap: 8px; margin-bottom: 14px; align-items: center; }
.drivebar .search { flex: 1; }
.input {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; outline: none; transition: border-color 0.15s;
  font-family: inherit;
}
.input:focus { border-color: var(--accent); }

.crumbs { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; flex-wrap: wrap; }
.crumbs button { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 4px 6px; border-radius: 6px; }
.crumbs button:hover { color: var(--accent); }
.crumbs .sep { opacity: 0.5; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.card-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; cursor: pointer;
  display: flex; flex-direction: column; gap: 8px; min-height: 96px;
  transition: border-color 0.15s, transform 0.15s var(--ease), background 0.15s;
  position: relative;
}
.card-item:hover { border-color: var(--accent); }
.card-item:active { transform: scale(0.98); }
.card-item.selected { border-color: var(--accent); background: var(--accent-soft); }
.card-item .icon { font-size: 26px; line-height: 1; }
.card-item .name { font-size: 13.5px; font-weight: 600; word-break: break-all; line-height: 1.3; }
.card-item .meta { font-size: 11.5px; color: var(--muted); }
.card-item .check {
  position: absolute; top: 10px; right: 10px; width: 20px; height: 20px;
  border-radius: 50%; border: 1.5px solid var(--border); background: var(--surface);
  display: none; align-items: center; justify-content: center; color: #fff; font-size: 12px;
}
.card-item.selected .check { display: flex; background: var(--accent); border-color: var(--accent); }
.selecting .card-item { cursor: pointer; }
.selecting .card-item:hover { background: var(--surface-2); }

.actionbar {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 55; display: flex; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  padding: 8px 10px; border-radius: 999px; box-shadow: var(--shadow);
  animation: barIn 0.2s var(--ease);
}
@keyframes barIn { from { opacity: 0; transform: translateX(-50%) translateY(12px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  padding: 11px 18px; font-size: 14px; font-weight: 600;
  background: var(--accent); color: #fff; min-height: 44px;
  transition: filter 0.15s, transform 0.15s var(--ease);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn.small { padding: 8px 14px; font-size: 13px; min-height: 38px; }
.btn.wide { width: 100%; }

.pill { display: inline-flex; gap: 6px; }
.pill .opt {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  padding: 9px 14px; font-size: 13px; cursor: pointer; min-height: 40px; font-weight: 600;
}
.pill .opt:first-child { border-radius: 10px 0 0 10px; }
.pill .opt:last-child { border-radius: 0 10px 10px 0; }
.pill .opt + .opt { border-left: none; }
.pill .opt.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

/* ---------- panels / settings ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; }
.panel h3 { margin: 0 0 12px; font-size: 14.5px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.row:last-child { border-bottom: none; }
.row .k { color: var(--muted); font-size: 13px; }
.rowlabel { font-size: 13px; color: var(--muted); margin: 12px 0 6px; }

/* ---------- modal ---------- */
.modal-bg {
  position: fixed; inset: 0; z-index: 70; background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.2s var(--ease);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-top-left-radius: 20px; border-top-right-radius: 20px;
  padding: 22px 18px calc(20px + env(safe-area-inset-bottom)); width: 100%; max-width: 560px;
  max-height: 86dvh; overflow-y: auto; animation: slideUp 0.26s var(--ease);
}
@keyframes slideUp { from { transform: translateY(40px); opacity: 0.5; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) {
  .modal-bg { align-items: center; }
  .modal { border-radius: 18px; }
}
.modal h2 { font-size: 16.5px; margin: 0 0 14px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(400px, 92vw); }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 10px; padding: 12px 16px; font-size: 14px; box-shadow: var(--shadow);
  animation: toastIn 0.22s var(--ease);
}
.toast.error { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--ok); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }

/* ---------- gate (setup/login) ---------- */
.gate { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.gate-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px 26px; width: 400px; max-width: 94vw; text-align: center; box-shadow: var(--shadow); }
.gate-card .logo { width: 48px; height: 48px; margin: 0 auto; display: block; }
.gate-card h1 { font-size: 20px; margin: 10px 0 6px; }
.gate-card .sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.field { text-align: left; margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.codes {
  background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px;
  padding: 14px; font-family: var(--mono); font-size: 14px; line-height: 2; margin: 14px 0;
}
.warnbox { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent); border-radius: 10px; padding: 12px; font-size: 13px; margin: 12px 0; text-align: left; }

/* ---------- media strip ---------- */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.media-item { border-radius: 10px; overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); aspect-ratio: 16/10; position: relative; cursor: pointer; }
.media-item img, .media-item video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item .status { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); background: var(--surface-2); }

textarea.input { resize: vertical; min-height: 90px; }

.spin {
  width: 15px; height: 15px; flex: none;
  border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: 8px; min-height: 60px; }
@keyframes sh { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}

/* ---------- agent status line + typing indicator ---------- */
.agent-status {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  font-size: 12.5px; color: var(--muted);
  padding: 2px 4px 10px;
  animation: msgIn 0.2s var(--ease);
}
.agent-status.error { color: var(--danger); }
.agent-status .spin {
  width: 12px; height: 12px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; background: transparent;
}
.agent-chips { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.agent-status .toolchip {
  margin-bottom: 0; padding: 3px 9px; font-size: 11.5px;
  background: var(--surface-2);
}
.agent-status .toolchip .dot { width: 6px; height: 6px; }

.typing { display: inline-flex; align-items: center; gap: 4px; padding: 10px 2px; }
.typing span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent); opacity: 0.35;
  animation: typingBlink 1.1s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.18s; }
.typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes typingBlink { 0%, 100% { opacity: 0.3; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }

@media (prefers-reduced-motion: reduce) {
  .agent-status .spin, .typing span { animation-duration: 2s; }
}

/* ---------- inline chat media + drive thumbnails ---------- */
.chat-media { max-width: 100%; border-radius: 14px; display: block; margin: 8px 0; border: 1px solid var(--border); }
.chat-media img, a .chat-media { cursor: zoom-in; }
video.chat-media { max-height: 62dvh; background: #000; width: 100%; object-fit: contain; }

.card-item .thumb-holder { height: 72px; overflow: hidden; border-radius: 8px; background: var(--surface-2); }
.card-item .thumb-holder img { width: 100%; height: 100%; object-fit: cover; display: block; }

.media-item .cap {
  position: absolute; left: 0; right: 0; bottom: 0;
  font-size: 10.5px; color: #fff; padding: 14px 6px 5px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.72));
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.msg.assistant .bubble table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- mobile (≤480px) ---------- */
@media (max-width: 480px) {
  .brand-text { display: none; }
  .topbar { padding: 0 8px; gap: 6px; }
  .switch button { padding: 7px 12px; font-size: 13px; }
  .main { padding: 12px 8px calc(84px + env(safe-area-inset-bottom)); }
  .thread { padding: 12px 2px 8px; }
  .msg .bubble { max-width: 88%; padding: 10px 12px; font-size: 14px; }
  .composer textarea { font-size: 16px; } /* prevent iOS auto-zoom */
  .composer { border-radius: 16px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
  .card-item { padding: 11px; min-height: 84px; }
  .welcome { margin-top: 8vh; }
  .welcome h1 { font-size: 19px; }
  .agent-status { font-size: 12px; }
  video.chat-media { max-height: 50dvh; }
  .modal { padding: 18px 14px; }
  .toasts { width: 94vw; }
  .actionbar { max-width: 94vw; }
}

/* ---------- v3 polish: scrollbars, icons, media actions, preview, notice ---------- */
/* custom scrollbars matching the theme */
.thread, .drawer-body, .modal, body, #mMedia {
  scrollbar-width: thin;
  scrollbar-color: var(--surface-3) transparent;
}
.thread::-webkit-scrollbar, .drawer-body::-webkit-scrollbar, .modal::-webkit-scrollbar, body::-webkit-scrollbar {
  width: 8px; height: 8px;
}
.thread::-webkit-scrollbar-track, .drawer-body::-webkit-scrollbar-track, .modal::-webkit-scrollbar-track {
  background: transparent;
}
.thread::-webkit-scrollbar-thumb, .drawer-body::-webkit-scrollbar-thumb, .modal::-webkit-scrollbar-thumb, body::-webkit-scrollbar-thumb {
  background: var(--surface-3); border-radius: 8px;
}
.thread::-webkit-scrollbar-thumb:hover, .drawer-body::-webkit-scrollbar-thumb:hover, .modal::-webkit-scrollbar-thumb:hover {
  background: var(--accent);
}

/* icons inside buttons/rows: stroke-based, like the rest of the app */
.btn svg, .row svg, .menu-btn svg, .actions svg {
  width: 16px; height: 16px; stroke: currentColor; fill: none;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none;
}
.modal .menu-btn { border: 1px solid var(--border); border-radius: var(--radius-sm); margin-top: 6px; }
.modal .menu-btn:first-of-type { margin-top: 0; }

/* chat media wrapper + download button */
.media-wrap { position: relative; display: inline-block; max-width: 100%; margin: 8px 0; }
.media-wrap .media-dl {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  width: 34px; height: 34px; border-radius: 10px;
  background: rgba(10, 12, 16, 0.62); backdrop-filter: blur(6px);
  color: #fff; display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.18);
  opacity: 0; transition: opacity 0.15s;
}
.media-wrap:hover .media-dl, .media-wrap .media-dl:focus-visible { opacity: 1; }
.media-wrap .media-dl svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* drive preview lightbox */
.preview-box { border-radius: 12px; overflow: hidden; background: var(--surface-2); display: flex; align-items: center; justify-content: center; min-height: 180px; }
.preview-box img, .preview-box video { max-width: 100%; max-height: 56dvh; display: block; }

/* archive notice bubble */
.msg.notice .bubble {
  background: var(--surface-2); border: 1px dashed var(--border);
  color: var(--muted); font-size: 12.5px; text-align: center;
  border-radius: 12px; max-width: 92%; margin: 4px auto 16px;
}

/* ---------- attachments, top status, memory view ---------- */
.composer .attach {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  width: 38px; height: 38px; border-radius: 11px; flex: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.composer .attach svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.attach-preview { display: flex; flex-wrap: wrap; gap: 6px; padding-top: 8px; }
.atchip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 4px 10px 4px 6px; font-size: 12px; color: var(--text); max-width: 100%;
}
.atchip img { width: 22px; height: 22px; border-radius: 6px; object-fit: cover; }
.atchip-x { border: none; background: transparent; color: var(--muted); cursor: pointer; padding: 2px; display: flex; }
.atchip-x svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; }
.atchip.small { background: transparent; border-color: transparent; padding: 0; }
.msg.user .bubble .atchips { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.msg.user .bubble .atchip { background: rgba(255,255,255,0.14); border-color: transparent; color: #fff; }

.top-status {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  z-index: 65; background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); font-size: 12.5px; padding: 6px 14px; border-radius: 999px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px;
  max-width: 92vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.top-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease infinite; flex: none; }

.mem-view .mempre {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px; font-family: var(--mono); font-size: 12.5px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; max-height: 56dvh; overflow: auto;
}
select.input { appearance: auto; }

/* ---------- media ops (in-progress/failed), retry button ---------- */
.retrybtn {
  border: 1px solid var(--accent); color: var(--accent); background: transparent;
  border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer;
  flex: none; margin-left: 8px;
}
.retrybtn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }

.media-op {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: 10px; padding: 8px 10px; margin: 4px 0 8px; font-size: 12px;
}
.media-op-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.media-op-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-op-state { color: var(--muted); display: inline-flex; align-items: center; gap: 5px; flex: none; max-width: 60%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.media-op-state.bad { color: var(--danger); }
.opbar { height: 5px; background: var(--surface-3); border-radius: 99px; overflow: hidden; margin-top: 7px; }
.opbar-fill { height: 100%; background: var(--accent); border-radius: 99px; transition: width .6s ease; }
.opbar-fill.bad { background: var(--danger); }
.opbar-fill.indet { width: 38%; animation: indet 1.6s ease-in-out infinite; }
@keyframes indet { 0% { margin-left: -38%; } 100% { margin-left: 100%; } }
.keep-open {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid var(--accent); color: var(--text);
  border-radius: 8px; padding: 6px 10px; margin: 2px 0 8px; font-size: 12px;
}
.media-op-meta { color: var(--muted); margin-top: 4px; font-size: 11px; }
.media-op-actions { display: flex; gap: 6px; margin-top: 7px; }
.mini-btn {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 8px;
  padding: 4px 9px; font-size: 11.5px; cursor: pointer; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.mini-btn svg { width: 12px; height: 12px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mini-btn.ok { border-color: var(--accent); color: var(--accent); }
.mini-btn.danger { border-color: var(--danger); color: var(--danger); }

/* ---------- upload loading chips ---------- */
.atchip.pending { color: var(--muted); }
.atchip.pending .spin { width: 12px; height: 12px; border-width: 2px; }
.actionbar .spin { width: 12px; height: 12px; border-width: 2px; }

/* approval cards (drive critical ops) */
.approval-card {
  margin: 10px 16px 4px;
  padding: 12px 14px;
  border: 1px solid var(--border, #2c2f3a);
  border-left: 4px solid #f0a93b;
  border-radius: 10px;
  background: var(--surface, #171a23);
  max-width: 640px;
}
.approval-head { font-weight: 600; margin-bottom: 4px; }
.approval-summary { opacity: .9; font-size: 13px; margin-bottom: 8px; }
.approval-preview {
  max-height: 160px;
  overflow: auto;
  font-size: 11px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  background: rgba(0,0,0,.35);
  border-radius: 6px;
  padding: 8px;
  margin: 0 0 8px;
}
.approval-actions { display: flex; gap: 8px; }
.approval-actions .btn { padding: 7px 16px; border-radius: 8px; cursor: pointer; border: 0; font-size: 13px; font-weight: 600; }
.approve-btn { background: #2f9e63; color: #fff; }
.deny-btn { background: #b3403f; color: #fff; }
.approve-btn:hover { background: #38b573; }
.deny-btn:hover { background: #c94f4d; }

/* ---------------- settings tabs ---------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs .tab {
  border: 0; background: none; color: var(--muted); font-size: 13.5px; font-weight: 600;
  padding: 9px 14px 11px; cursor: pointer; border-bottom: 2px solid transparent;
  transition: color 0.15s var(--ease), border-color 0.15s var(--ease); white-space: nowrap;
}
.tabs .tab:hover { color: var(--text); }
.tabs .tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabpane { animation: paneIn 0.2s var(--ease); }
@keyframes paneIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------------- permissions ---------------- */
.perm-opts { display: flex; flex-direction: column; gap: 10px; }
.perm-opt {
  display: flex; flex-direction: column; gap: 3px; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; transition: border-color 0.15s var(--ease), background 0.15s var(--ease), transform 0.12s var(--ease);
}
.perm-opt:hover { border-color: var(--accent); transform: translateY(-1px); }
.perm-opt.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.perm-opt input { accent-color: var(--accent); }
.perm-opt b { font-size: 14px; }
.perm-opt span { font-size: 12.5px; color: var(--muted); line-height: 1.45; }

/* session token line under the chat */
.sessiontokens { text-align: center; font-size: 11.5px; padding: 2px 0 6px; }

/* ---------------- atmosphere / polish pass ---------------- */
/* view content entrance */
.main > * > .chat, .main .drive, #mainContent > * { animation: viewIn 0.25s var(--ease); }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* approval cards enter softly */
.approval-card { animation: msgIn 0.24s var(--ease); }

/* buttons: tactile press + consistent focus ring */
button, .btn, .menu-btn { -webkit-tap-highlight-color: transparent; }
button:active, .btn:active { transform: scale(0.97); }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px;
}

/* hover lift for drive cards + media */
.grid-card, .media-card { transition: transform 0.16s var(--ease), box-shadow 0.16s var(--ease), border-color 0.16s var(--ease); }
.grid-card:hover, .media-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }

/* inputs: soft focus glow */
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }

/* smooth theme shift for surfaces */
body, .sidebar, .thread, .main, .modal, .drawer, .actionbar, .grid-card, .media-card, .bubble { transition: background 0.25s var(--ease), border-color 0.25s var(--ease), color 0.25s var(--ease); }

/* respect reduced motion — drop all decorative motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* attachment cost warning */
.attach-warn { margin-top: 6px; font-size: 11.5px; color: var(--warn, #b7791f); line-height: 1.4; }
