:root {
  color-scheme: light;
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  --surface-3: #e5e5ea;
  --line: rgba(0,0,0,.10);
  --line-strong: rgba(0,0,0,.18);
  --text: #1d1d1f;
  --text-2: #3a3a3c;
  --muted: #6e6e73;
  --subtle: #aeaeb2;
  --brand: #0a84ff;
  --brand-dark: #0071e3;
  --danger: #ff3b30;
  --ok: #34c759;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 16px rgba(0,0,0,.10), 0 1px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 20px 60px rgba(0,0,0,.16), 0 4px 16px rgba(0,0,0,.08);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Inter, ui-sans-serif, system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --topbar-h: 52px;
  --sidebar-w: 280px;
  --composer-min-h: 72px;
  --drawer-w: 360px;
  --sidebar-speed: .3s;
  --drawer-speed: .28s;
  --spring: cubic-bezier(.34,1.56,.64,1);
  --ease-out: cubic-bezier(.16,1,.3,1);
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button, input, textarea, select { font: inherit; }
button { border: 0; cursor: pointer; }

/* ── App Shell ── */
.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: rgba(255,255,255,.72);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--line);
  z-index: 30;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  background: transparent;
  overflow: hidden;
  flex: 0 0 auto;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand h1 { margin: 0; font-size: 16px; line-height: 1.1; font-weight: 700; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-toggle {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  display: grid; place-items: center;
  transition: background .12s;
}
.sidebar-toggle:hover { background: var(--surface-2); }

.top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  position: relative;
}

.overflow-btn {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  display: grid; place-items: center;
  font-size: 18px; font-weight: 700;
  transition: background .12s;
}
.overflow-btn:hover { background: var(--surface-2); }

.overflow-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 6px;
  min-width: 200px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--line);
  padding: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(-4px) scale(.97);
  transition: opacity .15s, transform .15s var(--ease-out);
  z-index: 40;
}
.overflow-menu.open {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}

.overflow-menu .menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  text-align: left;
  transition: background .1s;
}
.overflow-menu .menu-item:hover { background: var(--surface-2); }
.overflow-menu .menu-item.danger { color: var(--danger); }
.overflow-menu .menu-divider { height: 1px; background: var(--line); margin: 4px 0; }

.session-name-display {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: background .12s;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-name-display:hover { background: var(--surface-2); }

/* ── App Body ── */
.app-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow: hidden;
  transition: width var(--sidebar-speed) var(--ease-out);
}
.sidebar.sidebar-collapsed { width: 0; }
.sidebar.sidebar-collapsed .sidebar-inner { opacity: 0; pointer-events: none; }

.sidebar-inner {
  width: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: opacity .15s;
}

.sidebar-section {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar-section-title {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  cursor: default;
  list-style: none;
}
details.sidebar-section > summary.sidebar-section-title {
  cursor: pointer;
  user-select: none;
}
details.sidebar-section > summary.sidebar-section-title::before {
  content: "▸ ";
}
details.sidebar-section[open] > summary.sidebar-section-title::before {
  content: "▾ ";
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.sidebar-head h2 {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.session-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

/* ── Session List ── */
.session-list { display: grid; gap: 4px; }

.session-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px;
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
}
.session-row:hover { background: var(--surface-2); }
.session-row.active { background: rgba(10,132,255,.08); }

.session-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--text);
  padding: 0;
  display: grid;
  gap: 2px;
  cursor: pointer;
  text-align: left;
}

.session-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity .12s;
}
.session-row:hover .session-actions { opacity: 1; }

.session-actions .btn { width: 28px; height: 28px; padding: 0; border-radius: var(--radius-sm); }

.session-title { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-sub { color: var(--subtle); font-size: 11px; display: flex; gap: 6px; flex-wrap: wrap; }
.session-running { color: var(--brand); font-weight: 700; }

/* ── Chat Main ── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  min-width: 0;
}

.chat-main.drag { background: rgba(10,132,255,.04); }

/* ── Chat Tabs ── */
.chat-tabs {
  display: flex;
  gap: 0;
  padding: 0 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.chat-tabs button {
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
  cursor: pointer;
}
.chat-tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }
.chat-tabs button:hover:not(.active) { color: var(--text-2); }

/* ── Chat Scroll ── */
.chat-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  min-width: 0;
}

.gallery-view {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* ── Messages ── */
.message {
  flex: 0 0 auto;
  border-radius: var(--radius-lg);
  overflow: hidden;
  animation: msgIn .24s var(--ease-out) both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 8px 14px;
  font-size: 12px;
  color: var(--muted);
}

.message.user-msg {
  align-self: flex-end;
  max-width: 75%;
  background: var(--brand);
  color: #fff;
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.message.user-msg .message-head { color: rgba(255,255,255,.7); }
.message.user-msg .text-output { color: #fff; }

.message.assistant-msg {
  align-self: flex-start;
  max-width: 90%;
  background: var(--surface);
  border-radius: var(--radius-sm) var(--radius-lg) var(--radius-lg) var(--radius-lg);
  box-shadow: var(--shadow);
}
.message.assistant-msg .message-head { border-bottom: 1px solid var(--line); background: var(--surface-2); }

.message-body { padding: 14px; display: grid; gap: 12px; min-width: 0; overflow: hidden; }
.text-output { white-space: pre-wrap; word-break: break-all; overflow-wrap: break-word; font-size: 14px; line-height: 1.6; min-width: 0; }

.message-attachments {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 8px;
  min-width: 0;
}
.message-attachment {
  position: relative;
  width: 82px;
  height: 82px;
  flex: 0 0 82px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.55);
  background: rgba(255,255,255,.16);
  box-shadow: 0 1px 4px rgba(0,0,0,.16);
}
.message-attachment-btn {
  appearance: none;
  padding: 0;
  cursor: zoom-in;
}
.message-attachment-btn:hover {
  border-color: rgba(255,255,255,.9);
}
.message-attachment-btn:focus-visible {
  outline: 2px solid rgba(255,255,255,.9);
  outline-offset: 2px;
}
.message-attachment img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.message-actions {
  display: flex;
  align-items: center;
  gap: 3px;
  width: max-content;
  padding: 3px;
  margin: 0 10px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,.90);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
}
.message.user-msg .message-actions {
  margin-left: auto;
  background: rgba(255,255,255,.20);
  border-color: rgba(255,255,255,.24);
  box-shadow: none;
}
.message-action-btn {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--muted);
  transition: background .12s, color .12s, transform .12s;
}
.message-action-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: translateY(-1px);
}
.message.user-msg .message-action-btn { color: rgba(255,255,255,.78); }
.message.user-msg .message-action-btn:hover {
  background: rgba(255,255,255,.18);
  color: #fff;
}
.message-action-btn svg {
  width: 15px;
  height: 15px;
}

.empty {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--subtle);
  text-align: center;
  padding: 40px;
  font-size: 15px;
}

.message-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
  font-size: 13px;
}
.assistant-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--subtle);
}
.spinner {
  width: 16px; height: 16px;
  border: 2.5px solid var(--surface-3);
  border-top-color: var(--brand);
  border-radius: 999px;
  animation: spin .75s linear infinite;
  flex: 0 0 auto;
}
.message-status.done .spinner { display: none; }
.elapsed { color: var(--subtle); font-variant-numeric: tabular-nums; font-size: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Composer Bar ── */
.composer-bar {
  flex: 0 0 auto;
  padding: 12px 20px 16px;
  background: var(--bg);
}

.composer-bar-inner {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.composer-attachments {
  display: flex;
  gap: 8px;
  padding: 10px 12px 0;
  overflow-x: auto;
  flex-wrap: nowrap;
}

.attachment-import {
  display: grid;
  gap: 6px;
  padding: 8px 12px 0;
}
.attachment-import-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}
.attachment-import-head span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-import-track {
  height: 4px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.attachment-import-track div {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--brand);
  transition: width .12s linear;
}

.attachment {
  position: relative;
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface-2);
}
.attachment img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}
.attachment > button {
  position: absolute; top: 3px; right: 3px;
  width: 22px; height: 22px;
  border-radius: 999px;
  background: rgba(0,0,0,.6);
  color: #fff;
  display: grid; place-items: center;
  cursor: pointer;
  font-size: 10px;
}
.attachment-tools {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  display: flex;
  gap: 2px;
  padding: 3px;
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(8px);
  opacity: 0;
  transition: opacity .12s;
}
.attachment:hover .attachment-tools { opacity: 1; }
.attachment-tools button {
  flex: 1;
  height: 22px;
  border-radius: 4px;
  border: none;
  background: rgba(0,0,0,.06);
  color: var(--muted);
  display: grid; place-items: center;
  cursor: pointer;
  font-size: 10px;
}
.attachment-label {
  display: none;
}
.mask-badge {
  position: absolute; left: 4px; top: 4px;
  padding: 0 5px;
  border-radius: 4px;
  background: rgba(10,132,255,.85);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  line-height: 18px;
}

.composer-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
}

.composer-input-row #prompt {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  max-height: 160px;
  overflow-y: auto;
  padding: 4px 0;
  min-height: 24px;
  color: var(--text);
}
.composer-input-row #prompt::placeholder { color: var(--subtle); }

.composer-icon-btn {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  display: grid; place-items: center;
  flex: 0 0 auto;
  transition: background .12s, color .12s;
}
.composer-icon-btn:hover { background: var(--surface-2); color: var(--text); }

#sendBtn {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-pill);
  background: var(--brand);
  color: #fff;
  display: grid; place-items: center;
  flex: 0 0 auto;
  border: none;
  transition: background .15s, transform .12s var(--spring);
}
#sendBtn:hover { background: var(--brand-dark); }
#sendBtn:active { transform: scale(.92); }
#sendBtn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

#abortBtn {
  width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  display: grid; place-items: center;
  flex: 0 0 auto;
  border: none;
  transition: opacity .15s;
}
#abortBtn:disabled { opacity: 0; pointer-events: none; width: 0; overflow: hidden; }

.system-prompt-details {
  padding: 0 12px 8px;
}
.system-prompt-details summary {
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 0;
  list-style: none;
}
.system-prompt-details summary::-webkit-details-marker { display: none; }
.system-prompt-details input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 13px;
  background: var(--surface-2);
  color: var(--text);
  outline: none;
  margin-top: 4px;
}
.system-prompt-details input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(10,132,255,.12);
}

/* ── Dropzone (hidden, functional) ── */
.dropzone { display: none; }
.dropzone-compact { display: none; }

/* ── Parameters Drawer ── */
.params-drawer {
  position: fixed;
  top: var(--topbar-h);
  right: 0;
  bottom: 0;
  width: var(--drawer-w);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--drawer-speed) var(--ease-out);
  z-index: 25;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.params-drawer.open { transform: translateX(0); }

.params-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.2);
  backdrop-filter: blur(2px);
  z-index: 24;
  opacity: 0; pointer-events: none;
  transition: opacity var(--drawer-speed) ease;
}
.params-overlay.visible { opacity: 1; pointer-events: auto; }

.params-drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.params-drawer-head h2 { margin: 0; font-size: 16px; font-weight: 700; }

.params-drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}

.params-section {
  padding: 16px;
  border-bottom: 1px solid var(--line);
}
.params-section h3 {
  margin: 0 0 12px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
}

.params-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.params-grid .field-full { grid-column: 1 / -1; }

/* ── Form Elements ── */
.field { display: grid; gap: 5px; min-width: 0; }
.field label, .mini-label {
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.field input, .field textarea, .field select, .input {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  min-height: 36px;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { min-height: 120px; resize: vertical; }
.field input:focus, .field textarea:focus, .field select:focus, .input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(10,132,255,.12);
}
.field input::placeholder, .field textarea::placeholder { color: var(--subtle); }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.inline-range { display: grid; grid-template-columns: 1fr 36px; gap: 8px; align-items: center; }
.inline-range input[type="range"] { width: 100%; accent-color: var(--brand); }
.inline-range output { color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; font-size: 12px; }

/* ── Segmented Control ── */
.segmented {
  position: relative;
  display: inline-flex;
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  padding: 3px;
  gap: 0;
}
.segmented button {
  position: relative;
  z-index: 1;
  height: 28px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: color .15s;
  white-space: nowrap;
}
.segmented button.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

/* ── Checkboxes ── */
.check { display: flex; align-items: center; gap: 8px; min-height: 32px; color: var(--text-2); font-size: 13px; }
.check input { width: 17px; height: 17px; accent-color: var(--brand); }
.check input:disabled { opacity: .45; cursor: not-allowed; }
.check input:disabled + span { color: var(--subtle); }

.toggle-row { display: grid; gap: 6px; }
.compact-toggles { display: grid; gap: 6px; }
.transparent-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ── Buttons ── */
.btn {
  height: 34px;
  border-radius: var(--radius-sm);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  font-size: 13px;
  font-weight: 500;
  transition: background .12s, border-color .12s, transform .1s var(--spring);
}
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.97); }
.btn:disabled { cursor: not-allowed; opacity: .5; transform: none; }
.btn.primary { color: #fff; background: var(--brand); border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.icon { width: 34px; padding: 0; flex: 0 0 auto; }
.btn.sm { height: 28px; padding: 0 8px; font-size: 12px; }

.button-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

/* ── Gallery & Image Cards ── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }

.image-card {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .15s, transform .15s var(--spring);
  animation: msgIn .24s var(--ease-out) both;
}
.image-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

.image-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
  display: block;
  object-fit: cover;
  cursor: zoom-in;
}

.favorite-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  display: grid;
  place-items: center;
  color: #fff;
  background: rgba(29,29,31,.58);
  box-shadow: 0 2px 8px rgba(0,0,0,.20);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  transition: color .16s, background .16s, transform .16s var(--spring);
  z-index: 2;
}
.favorite-btn:hover { transform: scale(1.06); background: rgba(29,29,31,.72); }
.favorite-btn.active {
  color: #ffcc00;
  background: rgba(29,29,31,.76);
}
.favorite-btn.active svg { fill: currentColor; }
.favorite-btn.favorite-pop { animation: favoritePop .42s var(--spring) both; }

.favorite-bubble {
  position: absolute;
  top: 8px;
  right: 46px;
  z-index: 3;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 10px;
  border-radius: var(--radius-pill);
  background: rgba(52,199,89,.96);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow);
  pointer-events: none;
  animation: favoriteBubble 1.1s var(--ease-out) both;
}

@keyframes favoritePop {
  0% { transform: scale(1); }
  45% { transform: scale(1.28) rotate(-9deg); }
  100% { transform: scale(1); }
}
@keyframes favoriteBubble {
  0% { opacity: 0; transform: translateY(6px) scale(.92); }
  18% { opacity: 1; transform: translateY(0) scale(1); }
  78% { opacity: 1; transform: translateY(0) scale(1); }
  100% { opacity: 0; transform: translateY(-8px) scale(.96); }
}

.image-info { padding: 10px; display: grid; gap: 6px; }

.image-title {
  margin: 0;
  font-size: 12px;
  color: var(--text-2);
  min-height: 28px;
  max-height: 42px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.meta { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; color: var(--subtle); font-size: 11px; }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  max-width: 100%;
}

.image-actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 4px; }
.image-actions .btn { height: 30px; padding: 0 6px; gap: 4px; font-size: 11px; }
.image-actions .btn svg { width: 13px; height: 13px; }
.image-actions .danger-text { color: var(--danger); }

/* ── Codebox ── */
.codebox {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #1c1c1e;
  color: #e5e5ea;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  overflow: auto;
  padding: 12px;
  max-height: 300px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Toast ── */
.toast { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 8px; z-index: 80; pointer-events: none; }
.toast-item {
  width: min(380px, calc(100vw - 36px));
  border-radius: var(--radius);
  background: rgba(30,30,30,.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: #fff;
  padding: 12px 16px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .22s var(--spring) both;
  pointer-events: auto;
}
.toast-item.error { background: rgba(255,59,48,.92); }
.toast-item.success { background: rgba(52,199,89,.94); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px) scale(.95); }
  to { opacity: 1; transform: none; }
}

/* ── Dialog / Modal ── */
dialog {
  border: 0;
  border-radius: var(--radius-lg);
  width: min(1080px, calc(100vw - 28px));
  max-height: calc(100vh - 28px);
  padding: 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0,0,0,.4); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }

.modal-head {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
}
.modal-title { margin: 0; font-size: 15px; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-body {
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 16px;
  align-items: start;
  max-height: calc(100vh - 80px);
  overflow: auto;
}
.modal-image { width: 100%; max-height: calc(100vh - 112px); object-fit: contain; background: var(--surface-2); border-radius: var(--radius); border: 1px solid var(--line); }
.modal-side { display: grid; gap: 10px; }

/* ── Mask Editor ── */
.mask-stage { position: relative; width: 100%; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface-2); display: grid; place-items: center; }
.mask-stage img, .mask-stage canvas { width: 100%; height: auto; display: block; grid-area: 1 / 1; }
.mask-stage canvas { touch-action: none; cursor: crosshair; }

/* ── Details panels (for debug) ── */
details.panel, .details-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
details.panel summary, .details-panel summary {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid transparent;
  background: var(--surface-2);
  cursor: pointer;
  list-style: none;
  color: var(--text-2);
  font-weight: 600;
  font-size: 13px;
}
details.panel summary::-webkit-details-marker, .details-panel summary::-webkit-details-marker { display: none; }
details.panel summary span, .details-panel summary span { display: inline-flex; align-items: center; gap: 8px; }
details.panel summary small, .details-panel summary small { color: var(--subtle); font-size: 11px; font-weight: 500; }
details.panel[open] summary, .details-panel[open] summary { border-bottom-color: var(--line); }

.debug-stack { display: grid; gap: 8px; }

/* ── Utility ── */
.hidden { display: none !important; }
svg { width: 17px; height: 17px; stroke-width: 2; flex: 0 0 auto; }
.stack { display: grid; gap: 12px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-2);
}
.panel-head h2 { margin: 0; font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.panel-body { padding: 14px; }

.status-strip, .meter { display: none; }

/* ── Input images section (in drawer) ── */
.input-images-section { display: grid; gap: 8px; }
.input-images-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* ── Attachments grid (in drawer context) ── */
.attachments-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

/* ── Responsive ── */
@media (max-width: 1024px) {
  .sidebar { position: fixed; top: var(--topbar-h); left: 0; bottom: 0; z-index: 22; box-shadow: var(--shadow-lg); }
  .sidebar.sidebar-collapsed { width: 0; box-shadow: none; }
}

@media (max-width: 768px) {
  :root { --drawer-w: 100vw; }
  .topbar { padding: 0 12px; }
  .chat-scroll { padding: 12px; }
  .composer-bar { padding: 8px 12px 12px; }
  .modal-body { grid-template-columns: 1fr; }
  .gallery { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .message.user-msg, .message.assistant-msg { max-width: 95%; }
  .params-drawer { top: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .session-name-display { max-width: 140px; }
}
