:root {
  color-scheme: dark;
  --bg: oklch(0.16 0.012 240);
  --panel: oklch(0.19 0.014 240);
  --panel-soft: oklch(0.22 0.012 240);
  --ink: oklch(0.96 0.005 240);
  --muted: oklch(0.66 0.02 240);
  --muted-dim: oklch(0.50 0.02 240);
  --line: oklch(0.28 0.012 240 / 60%);
  --accent: oklch(0.82 0.14 195);
  --accent-strong: oklch(0.72 0.16 260);
  --accent-glow: oklch(0.82 0.14 195 / 0.15);
  --danger: oklch(0.62 0.21 25);
  --warning: oklch(0.75 0.16 75);
  --gradient-brand: linear-gradient(135deg, oklch(0.82 0.14 195), oklch(0.72 0.16 260));
  --shadow: 0 16px 40px rgba(0, 0, 0, 0.40);
  --shadow-glow: 0 4px 24px oklch(0.82 0.14 195 / 0.15);
  --glass: oklch(0.19 0.014 240 / 0.6);
  --glass-strong: oklch(0.19 0.014 240 / 0.85);
  --sidebar-width: 288px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
}

/* Background texture matching landing */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(ellipse at 20% 50%, oklch(0.22 0.04 260 / 0.4), transparent 60%),
    radial-gradient(ellipse at 80% 20%, oklch(0.20 0.05 195 / 0.3), transparent 50%),
    var(--bg);
}

body::after {
  content: '';
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image: radial-gradient(oklch(0.96 0.005 240 / 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
}

h1,
h2,
h3,
h4 {
  font-family: "Space Grotesk", "Inter", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 20;
  transform: translateX(-50%);
  max-width: min(92vw, 520px);
  padding: 11px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass-strong);
  backdrop-filter: blur(20px);
  box-shadow: var(--shadow);
  color: var(--ink);
}

/* ===== Auth Shell ===== */
.auth-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.auth-panel {
  width: min(440px, 100%);
  padding: 36px 32px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--glass);
  backdrop-filter: blur(24px);
  box-shadow: var(--shadow), var(--shadow-glow);
}

.brand-row,
.mini-brand,
.usage-row,
.chat-header,
.admin-header,
.check-row {
  display: flex;
  align-items: center;
}

.brand-row {
  gap: 14px;
  margin-bottom: 28px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: oklch(0.15 0.02 240);
  font-family: "Space Grotesk", sans-serif;
  font-weight: 800;
  font-size: 1.1rem;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

h2 {
  font-size: 22px;
}

p,
small {
  color: var(--muted);
}

.auth-form,
.settings-grid {
  display: grid;
  gap: 16px;
}

.inline-code-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: oklch(0.19 0.014 240 / 0.8);
  color: var(--ink);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), 0 0 20px oklch(0.82 0.14 195 / 0.08);
}

/* ===== Buttons ===== */
.primary-btn,
.ghost-btn,
.side-action,
.send-btn,
.text-btn,
.icon-btn,
.tab-btn,
.mini-btn {
  border: 1px solid transparent;
  border-radius: 12px;
  min-height: 40px;
  font-weight: 500;
  transition: all 0.25s;
}

.primary-btn,
.send-btn {
  background: var(--gradient-brand);
  color: oklch(0.15 0.02 240);
  border: none;
  padding: 10px 18px;
  font-weight: 600;
}

.primary-btn:hover,
.send-btn:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 20px oklch(0.82 0.14 195 / 0.3);
}

.ghost-btn,
.side-action,
.tab-btn,
.mini-btn {
  background: oklch(0.19 0.014 240 / 0.6);
  border-color: var(--line);
  color: var(--ink);
  padding: 9px 14px;
  backdrop-filter: blur(8px);
}

.ghost-btn:hover,
.side-action:hover,
.tab-btn:hover,
.mini-btn:hover {
  background: var(--panel-soft);
  border-color: var(--muted-dim);
}

.text-btn {
  background: transparent;
  color: var(--muted);
  padding: 0 4px;
}

.text-btn:hover {
  color: var(--ink);
}

.secondary-auth {
  margin-top: 20px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.divider::before,
.divider::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

/* ===== App Shell ===== */
.app-shell {
  min-height: 100%;
  display: grid;
  grid-template-columns: var(--sidebar-width) 6px minmax(0, 1fr);
}

/* ===== Sidebar ===== */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  border-right: 1px solid var(--line);
  background: oklch(0.14 0.014 240 / 0.9);
  backdrop-filter: blur(16px);
}

.sidebar-resize {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 100vh;
  cursor: col-resize;
  background: transparent;
}

.sidebar-resize:hover,
.resizing-sidebar .sidebar-resize {
  background: oklch(0.82 0.14 195 / 0.18);
}

.sidebar-top {
  display: grid;
  gap: 16px;
  padding: 20px;
}

.sidebar-actions {
  display: grid;
  gap: 10px;
}

.mini-brand {
  gap: 10px;
}

.mini-brand .brand-mark {
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
}

.mini-brand strong {
  font-family: "Space Grotesk", sans-serif;
  background: var(--gradient-brand);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.side-action {
  width: 100%;
}

.side-action.muted {
  background: oklch(0.22 0.012 240 / 0.5);
}

.conversation-list {
  display: grid;
  align-content: start;
  gap: 6px;
  overflow: auto;
  padding: 0 10px 12px;
}

/* Custom scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: oklch(0.28 0.012 240 / 0.5);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: oklch(0.40 0.02 240 / 0.6);
}

.conversation-folder {
  display: grid;
  gap: 4px;
}

.folder-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px 4px;
  font-size: 12px;
  font-weight: 700;
  text-align: left;
}

.folder-items {
  display: grid;
  gap: 6px;
}

.conversation-item {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  padding: 10px 12px;
  color: var(--ink);
  text-align: left;
  transition: background 0.2s, border-color 0.2s;
}

.conversation-item.active,
.conversation-item:hover {
  border-color: var(--line);
  background: var(--glass);
  backdrop-filter: blur(8px);
}

.conversation-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin-chat {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted-dim);
}

.pin-chat.active,
.pin-chat:hover {
  background: oklch(0.75 0.16 75 / 0.2);
  color: var(--warning);
}

.delete-chat {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}

.delete-chat:hover {
  background: oklch(0.62 0.21 25 / 0.15);
  color: var(--danger);
}

.usage-panel {
  display: grid;
  gap: 10px;
  padding: 16px;
  border-top: 1px solid var(--line);
}

.usage-row {
  justify-content: space-between;
  gap: 10px;
}

.usage-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: oklch(0.22 0.012 240);
}

.usage-bar span {
  display: block;
  height: 100%;
  width: 0%;
  background: var(--gradient-brand);
  border-radius: inherit;
}

/* ===== Chat Shell ===== */
.chat-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-header,
.admin-header {
  min-height: 72px;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  background: oklch(0.16 0.012 240 / 0.8);
  backdrop-filter: blur(20px);
}

.icon-btn {
  display: none;
  width: 40px;
  height: 40px;
  background: var(--glass);
  border-color: var(--line);
  backdrop-filter: blur(8px);
}

/* ===== Messages ===== */
.message-list {
  display: grid;
  align-content: start;
  gap: 20px;
  overflow: auto;
  padding: 28px max(24px, calc((100vw - 1040px) / 2));
}

.empty-state {
  align-self: center;
  justify-self: center;
  width: min(720px, 100%);
  display: grid;
  gap: 16px;
  text-align: center;
  padding: 28px;
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.prompt-chip {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  padding: 14px;
  text-align: left;
  color: var(--ink);
  transition: transform 0.2s, box-shadow 0.2s;
}

.prompt-chip:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.message {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  width: min(860px, 100%);
}

.message.user {
  justify-self: end;
  grid-template-columns: minmax(0, 1fr) 38px;
}

.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel-soft);
  color: var(--ink);
  font-weight: 700;
}

.message.user .avatar {
  grid-column: 2;
  background: var(--gradient-brand);
  color: oklch(0.15 0.02 240);
}

.bubble {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  padding: 28px 16px 14px;
  line-height: 1.65;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.message.user .bubble {
  grid-row: 1;
  background: oklch(0.82 0.14 195 / 0.12);
  border-color: oklch(0.82 0.14 195 / 0.2);
  padding: 14px 16px 36px;
}

.message-meta {
  position: absolute;
  top: 6px;
  left: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.2;
}

.bubble-tool {
  position: absolute;
  top: 5px;
  right: 8px;
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  color: var(--muted);
  text-decoration: none;
  line-height: 1;
  transition: all 0.2s;
}

.message.user .message-actions {
  position: absolute;
  right: 8px;
  bottom: 6px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.message-actions .bubble-tool {
  position: static;
}

.more-tools {
  position: relative;
}

.more-tools summary {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  color: var(--muted);
  list-style: none;
}

.more-tools summary::-webkit-details-marker {
  display: none;
}

.more-tools[open] summary {
  color: var(--accent);
  border-color: var(--accent);
}

.more-tools button {
  display: none;
  width: 86px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 7px 9px;
  text-align: left;
  font-size: 13px;
}

.more-tools[open] button {
  position: absolute;
  right: 0;
  bottom: 28px;
  display: block;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  z-index: 4;
}

.more-tools[open] button + button {
  bottom: 60px;
}

.more-tools button:last-child {
  border-bottom: 0;
  color: var(--danger);
}

.bubble-tool:hover {
  color: var(--accent);
  border-color: var(--accent);
}

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

.image-bubble p {
  padding: 0 4px 2px;
  font-size: 13px;
}

.generated-image {
  display: block;
  width: min(100%, 640px);
  max-height: 720px;
  border-radius: 12px;
  object-fit: contain;
  background: var(--panel-soft);
  cursor: zoom-in;
}

.image-pending {
  color: var(--muted);
}

.progress-block {
  display: grid;
  gap: 8px;
  min-width: min(360px, 70vw);
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.progress-track,
.inline-progress div {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--panel-soft);
}

.progress-track i,
.inline-progress i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: var(--gradient-brand);
  transition: width 0.35s ease;
}

.progress-block.failed .progress-track i,
.inline-progress.failed i {
  background: var(--danger);
}

/* ===== Composer ===== */
.composer {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 18px max(24px, calc((100vw - 1040px) / 2));
  border-top: 1px solid var(--line);
  background: oklch(0.16 0.012 240 / 0.8);
  backdrop-filter: blur(20px);
}

.composer-field {
  min-width: 0;
}

.mode-switch {
  display: inline-flex;
  gap: 2px;
  margin: 0 0 10px 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.mode-btn {
  min-width: 54px;
  min-height: 30px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  transition: all 0.2s;
}

.mode-btn.active {
  background: var(--gradient-brand);
  color: oklch(0.15 0.02 240);
}

.reference-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.reference-count {
  color: var(--muted);
  font-size: 13px;
}

.selected-references,
.message-references {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.reference-chip {
  position: relative;
  width: 52px;
  height: 52px;
  overflow: hidden;
  border: 2px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
  padding: 0;
}

.reference-chip img,
.message-references img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.reference-chip span {
  position: absolute;
  top: 2px;
  right: 4px;
  color: white;
  font-size: 12px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
}

.message-references img {
  width: 56px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.composer textarea {
  max-height: 180px;
  min-height: 48px;
}

.send-btn {
  align-self: end;
  min-width: 88px;
  height: 48px;
}

.composer-actions {
  align-self: end;
  display: flex;
  gap: 8px;
  align-items: end;
}

.text-model-select,
.image-model-select,
.folder-select {
  width: 160px;
  height: 48px;
  padding: 0 12px;
  font-size: 13px;
}

.folder-select {
  width: 140px;
}

/* ===== Admin ===== */
.admin-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.admin-toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.admin-toolbar select {
  width: 160px;
}

.admin-shell {
  min-height: 100vh;
  background: var(--bg);
}

.admin-tabs {
  display: flex;
  gap: 8px;
  padding: 18px 24px 0;
}

.tab-btn.active {
  background: var(--gradient-brand);
  border-color: transparent;
  color: oklch(0.15 0.02 240);
}

.admin-section {
  padding: 20px 24px 28px;
}

/* ===== Modal ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: oklch(0.10 0.012 240 / 0.6);
  backdrop-filter: blur(8px);
}

.modal-panel {
  width: min(860px, 100%);
  max-height: min(760px, 92vh);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass-strong);
  backdrop-filter: blur(24px);
  box-shadow: var(--shadow), var(--shadow-glow);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  display: grid;
}

.image-library-grid,
.admin-images-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  overflow: auto;
  padding: 16px;
}

.library-image,
.admin-image-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(8px);
  padding: 8px;
  text-align: left;
}

.library-image.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.library-image img,
.admin-image-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 10px;
  background: var(--panel-soft);
  cursor: zoom-in;
}

.editor-backdrop {
  padding: 12px;
}

.image-editor-panel {
  width: min(1180px, 100%);
  height: min(860px, 96vh);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass-strong);
  backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.editor-toolbar .mini-btn.active {
  border-color: var(--accent);
  color: var(--accent);
}

.editor-toolbar input[type="color"] {
  width: 42px;
  height: 34px;
  padding: 2px;
}

.image-editor-stage {
  overflow: auto;
  display: grid;
  place-items: center;
  background:
    linear-gradient(45deg, oklch(0.22 0.012 240) 25%, transparent 25%),
    linear-gradient(-45deg, oklch(0.22 0.012 240) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, oklch(0.22 0.012 240) 75%),
    linear-gradient(-45deg, transparent 75%, oklch(0.22 0.012 240) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.image-editor-canvas-wrap {
  position: relative;
  transform-origin: 0 0;
}

.image-editor-canvas-wrap.panning,
.image-editor-canvas-wrap.panning canvas {
  cursor: grab;
}

.image-editor-canvas-wrap img {
  display: block;
  max-width: none;
  user-select: none;
  pointer-events: none;
}

.image-editor-canvas-wrap canvas {
  position: absolute;
  inset: 0;
  opacity: 0.42;
  cursor: crosshair;
}

.image-editor-canvas-wrap canvas.paint-mode {
  cursor: cell;
}

.image-edit-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
}

.photoshop-panel {
  width: min(1280px, 100%);
  height: min(900px, 96vh);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass-strong);
  backdrop-filter: blur(24px);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.photoshop-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.photoshop-toolbar select {
  width: 220px;
}

.photoshop-toolbar input[type="number"] {
  width: 90px;
}

.photoshop-toolbar input[type="color"] {
  width: 42px;
  height: 34px;
  padding: 2px;
}

.photoshop-stage {
  overflow: auto;
  display: grid;
  place-items: center;
  background: oklch(0.18 0.012 240);
}

.photoshop-canvas-wrap {
  position: relative;
  transform-origin: 0 0;
  cursor: grab;
}

.photoshop-canvas-wrap img {
  display: block;
  max-width: none;
  user-select: none;
  pointer-events: none;
}

#photoshopTextLayer {
  position: absolute;
  inset: 0;
}

.ps-text-item {
  position: absolute;
  min-width: 40px;
  padding: 2px 6px;
  border: 1px dashed transparent;
  cursor: move;
  white-space: pre;
  outline: none;
}

.ps-text-item.selected,
.ps-text-item:focus {
  border-color: var(--accent);
  background: oklch(0.19 0.014 240 / 0.8);
}

.photoshop-note {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.detected-object-list {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.detected-object-list[hidden] {
  display: none;
}

.object-chip.active {
  border-color: var(--accent);
  color: var(--accent);
  background: oklch(0.82 0.14 195 / 0.1);
}

.object-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.object-detect-progress {
  grid-column: 1 / -1;
  color: var(--ink);
}

.object-detect-progress .progress-block {
  min-width: 100%;
}

.region-prompt-list {
  max-height: 148px;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.region-prompt-row {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.region-prompt-row span {
  min-height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.region-prompt-row input {
  width: 100%;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.inline-progress {
  display: grid;
  gap: 6px;
  align-content: center;
  color: var(--muted);
  font-size: 12px;
}

.library-image span,
.admin-image-card small,
.admin-image-card p {
  font-size: 12px;
  color: var(--muted);
}

.admin-image-card strong,
.admin-image-card small,
.admin-image-card p {
  display: block;
  overflow-wrap: anywhere;
}

/* ===== Settings ===== */
.settings-grid {
  width: min(920px, 100%);
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass);
  backdrop-filter: blur(12px);
}

.profile-grid {
  align-items: start;
}

.profile-avatar-box {
  grid-row: span 2;
  display: grid;
  gap: 10px;
  justify-items: start;
}

.profile-avatar-preview,
.user-cell > img,
.user-cell > span {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--gradient-brand);
  color: oklch(0.15 0.02 240);
  font-weight: 800;
  overflow: hidden;
}

.profile-avatar-preview {
  width: 88px;
  height: 88px;
  font-size: 30px;
}

.profile-avatar-preview img,
.user-cell img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.user-cell {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}

.user-cell strong,
.user-cell small {
  display: block;
  overflow-wrap: anywhere;
}

.wide {
  grid-column: 1 / -1;
}

.check-row {
  grid-template-columns: auto 1fr;
  align-self: center;
}

.check-row input {
  width: 18px;
  height: 18px;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  backdrop-filter: blur(8px);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 14px;
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.password-input {
  width: 120px;
  min-height: 34px;
  padding: 6px 9px;
  font-size: 13px;
}

.mini-btn {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 13px;
}

.danger {
  color: var(--danger);
}

.danger-btn {
  color: var(--danger);
}

.danger-btn:hover {
  border-color: var(--danger);
}

.warn {
  color: var(--warning);
}

/* ===== Responsive ===== */
@media (max-width: 820px) {
  html,
  body {
    overflow-x: hidden;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 10;
    width: min(86vw, 310px);
    transform: translateX(-102%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-resize {
    display: none;
  }

  .icon-btn {
    display: grid;
    place-items: center;
  }

  .chat-header {
    justify-content: start;
    gap: 8px;
    padding: 10px 12px;
  }

  .chat-heading {
    min-width: 0;
  }

  .chat-heading h2,
  .chat-heading p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .chat-header .ghost-btn {
    min-height: 34px;
    padding: 6px 8px;
    font-size: 12px;
  }

  .prompt-grid,
  .settings-grid,
  .inline-form {
    grid-template-columns: 1fr;
  }

  .composer {
    grid-template-columns: 1fr;
    gap: 8px;
    padding: 10px;
  }

  .composer-field,
  .composer-actions {
    min-width: 0;
  }

  .composer textarea {
    min-height: 42px;
    max-height: 132px;
  }

  .reference-tools,
  .selected-references,
  .composer-actions {
    overflow-x: auto;
  }

  .mode-switch {
    margin-left: 0;
  }

  .send-btn {
    width: 100%;
  }

  .composer-actions {
    width: 100%;
    display: flex;
    gap: 8px;
  }

  .image-edit-form {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    padding: 0;
  }

  .modal-panel,
  .image-editor-panel,
  .photoshop-panel {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
  }

  .modal-header {
    padding: 10px 12px;
  }

  .modal-header h2 {
    font-size: 16px;
  }

  .modal-actions,
  .editor-toolbar,
  .photoshop-toolbar {
    overflow-x: auto;
    flex-wrap: nowrap;
  }

  .editor-toolbar,
  .photoshop-toolbar {
    padding: 8px 10px;
  }

  .detected-object-list {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .object-chip-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .object-chip {
    flex: 0 0 auto;
  }

  .image-editor-stage,
  .photoshop-stage {
    place-items: start;
  }

  .region-prompt-row {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .region-prompt-row .danger-btn {
    grid-column: 2;
    justify-self: start;
  }

  .admin-shell,
  .chat-shell {
    min-width: 0;
  }

  .admin-tabs {
    overflow-x: auto;
  }

  .table-wrap {
    max-width: 100vw;
  }

  .text-model-select,
  .image-model-select,
  .folder-select {
    flex: 1;
    min-width: 0;
  }
}
