:root {
  --bg: #07090e;
  --bg-2: #0d121f;
  --card: rgba(18, 25, 41, 0.8);
  --input: #111827;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.18);
  --focus: #0ea5e9;

  --cyan: #06b6d4;
  --emerald: #10b981;
  --rose: #f43f5e;
  --amber: #f59e0b;
  --brand: #e3262e;

  --text: #f8fafc;
  --text-2: #94a3b8;
  --muted: #64748b;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;

  --font: 'Be Vietnam Pro', system-ui, -apple-system, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(circle at 12% 8%, rgba(6, 182, 212, 0.07), transparent 40%),
    radial-gradient(circle at 88% 18%, rgba(139, 92, 246, 0.07), transparent 40%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

button, input, select, textarea { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 0.85em; color: #7dd3fc; }
[hidden] { display: none !important; }

.muted { color: var(--muted); font-size: 0.8rem; }
.hint { color: var(--text-2); font-size: 0.78rem; }
.center { text-align: center; }
.empty { color: var(--muted); font-size: 0.85rem; padding: 24px; text-align: center; grid-column: 1 / -1; }

.file-warning {
  background: var(--amber);
  color: #111;
  padding: 10px 20px;
  text-align: center;
  font-size: 0.9rem;
}
.file-warning code { color: #111; font-weight: 700; }

/* ---------------------------------------------------------------- header */

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 12px 24px;
  background: rgba(7, 9, 14, 0.88);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
}
.brand h1 { font-size: 1.05rem; font-weight: 800; }
.brand p { font-size: 0.75rem; color: var(--text-2); }

.tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.tab {
  background: none;
  border: 0;
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}
.tab:hover { color: var(--text); background: rgba(255, 255, 255, 0.04); }
.tab.active { background: #1e293b; color: var(--text); box-shadow: inset 0 -2px 0 var(--cyan); }

.header-actions { display: flex; align-items: center; gap: 10px; }
.status-pill {
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 3px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.status-pill.ok { color: var(--emerald); border-color: rgba(16, 185, 129, 0.35); }
.status-pill.warn { color: var(--amber); border-color: rgba(245, 158, 11, 0.4); }

/* ---------------------------------------------------------------- buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }

.btn-primary { background: linear-gradient(135deg, #0284c7, #0ea5e9); color: #fff; }
.btn-success { background: linear-gradient(135deg, #059669, #10b981); color: #fff; }
.btn-secondary { background: #1e293b; color: #e2e8f0; border-color: var(--line-strong); }
.btn-secondary:hover:not(:disabled) { background: #334155; }
.btn-outline { background: transparent; color: var(--text-2); border-color: var(--line-strong); }
.btn-outline:hover:not(:disabled) { color: var(--text); background: rgba(255, 255, 255, 0.05); }
.btn-danger { color: #fb7185; border-color: rgba(244, 63, 94, 0.35); }
.btn-danger:hover:not(:disabled) { background: rgba(244, 63, 94, 0.15); color: #fff; }

.icon-btn {
  background: none; border: 0; cursor: pointer;
  color: var(--muted); font-size: 1.1rem; padding: 4px 8px; border-radius: 6px;
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, 0.08); }

.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-col { display: flex; flex-direction: column; gap: 8px; }

/* ---------------------------------------------------------------- layout & panels */

.main { max-width: 1560px; margin: 20px auto; padding: 0 24px 40px; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 18px;
}
.panel-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-2);
  margin-bottom: 12px;
}
.panel-title:not(:first-child) { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.section-title { font-size: 0.9rem; margin: 20px 0 10px; color: var(--text-2); }

/* ---------------------------------------------------------------- forms */

.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 0.75rem; font-weight: 600; color: var(--text-2); }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

input:not([type='checkbox']):not([type='range']):not([type='color']),
select,
textarea {
  width: 100%;
  background: var(--input);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 8px 10px;
  font-size: 0.85rem;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }
input[type='checkbox'] { accent-color: var(--cyan); width: 15px; height: 15px; cursor: pointer; }
input[type='range'] { accent-color: var(--brand); width: 100%; }
input[type='color'] { width: 36px; height: 30px; border: 1px solid var(--line-strong); border-radius: 6px; background: none; cursor: pointer; padding: 2px; }

.inline { display: flex; gap: 6px; align-items: center; }
.checks { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 14px; font-size: 0.8rem; color: var(--text-2); }
.checks label { display: flex; align-items: center; gap: 8px; cursor: pointer; }

/* ---------------------------------------------------------------- tab 1: làm đẹp */

.toolbar-grid {
  display: grid;
  grid-template-columns: 1.1fr 1.3fr 0.9fr;
  gap: 16px;
  margin-bottom: 20px;
}

.dropzone {
  border: 2px dashed var(--line-strong);
  border-radius: var(--r-md);
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  text-align: center;
  font-size: 0.85rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--cyan); background: rgba(6, 182, 212, 0.06); }
.dropzone-icon { font-size: 1.6rem; color: var(--muted); }

.actions-panel { display: flex; flex-direction: column; gap: 10px; }
.actions-panel .panel-title { margin-bottom: 0; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
}

.photo-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  overflow: hidden;
  transition: border-color 0.2s;
}
.photo-card.is-selected { border-color: rgba(6, 182, 212, 0.5); }
.photo-card.status-working { border-color: var(--cyan); box-shadow: 0 0 22px rgba(6, 182, 212, 0.2); }
.photo-card.status-error { border-color: rgba(244, 63, 94, 0.5); }

.photo-thumb { position: relative; aspect-ratio: 1; background: #fff; }
.photo-thumb img { width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; display: block; }
.photo-pick {
  position: absolute; top: 8px; left: 8px;
  background: rgba(15, 23, 42, 0.8);
  border-radius: 6px; padding: 5px; display: flex;
}
.photo-flag {
  position: absolute; top: 8px; right: 8px;
  background: rgba(16, 185, 129, 0.92); color: #fff;
  font-size: 0.68rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
}
.photo-busy {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: rgba(9, 13, 22, 0.78);
  color: var(--cyan); font-size: 0.8rem; font-weight: 600;
}
.photo-error {
  position: absolute; left: 8px; right: 8px; bottom: 8px;
  background: rgba(244, 63, 94, 0.94); color: #fff;
  font-size: 0.7rem; padding: 6px 8px; border-radius: 6px;
  max-height: 60%; overflow: auto;
}

.photo-meta { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.photo-name { font-weight: 600; padding: 4px 8px !important; }
.photo-actions { display: grid; grid-template-columns: 1fr auto auto; gap: 6px; }

.chip-row { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  background: #1e293b; border: 1px solid var(--line); color: var(--text-2);
  font-size: 0.7rem; font-weight: 700;
  padding: 1px 8px; border-radius: 999px; cursor: pointer;
}
.chip.active { background: var(--cyan); color: #00131a; border-color: var(--cyan); }

.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(6, 182, 212, 0.2);
  border-top-color: var(--cyan);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- tab 2 & 3: studio */

.studio { display: grid; grid-template-columns: 380px 1fr; gap: 20px; align-items: start; }
.studio-controls { position: sticky; top: 84px; max-height: calc(100vh - 100px); overflow-y: auto; }

.canvas-frame {
  background:
    repeating-conic-gradient(#1a2233 0% 25%, #141b29 0% 50%) 50% / 24px 24px;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex;
  justify-content: center;
}
.canvas-frame canvas {
  max-width: 100%;
  max-height: 72vh;
  height: auto;
  width: auto;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.55);
  border-radius: 4px;
  background: #fff;
}

.combo-items { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; margin-bottom: 14px; }
.combo-row {
  display: grid;
  grid-template-columns: auto 40px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 0.8rem;
}
.combo-row.is-on { border-color: rgba(6, 182, 212, 0.5); background: rgba(6, 182, 212, 0.06); }
.combo-row img { width: 40px; height: 40px; object-fit: contain; background: #fff; border-radius: 4px; }
.combo-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-row-name em { color: var(--amber); font-style: normal; font-size: 0.7rem; }
.combo-qty { display: flex; align-items: center; gap: 2px; color: var(--text-2); }
.combo-qty input { width: 56px !important; padding: 4px 6px !important; text-align: center; }
.combo-row { grid-template-columns: auto 40px 1fr auto auto; }
.combo-remove { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.combo-remove:hover { color: #fb7185; background: rgba(244, 63, 94, 0.15); }
.combo-list-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 12px 0 8px; }
.combo-list-bar .muted { font-size: 0.75rem; }
#tab-combo.dragover .studio-controls { outline: 2px dashed var(--cyan); outline-offset: -6px; }
#comboDrop { min-height: 0; padding: 12px; margin-bottom: 10px; cursor: default; }
#comboDrop p { margin-bottom: 8px; }
#comboFolders { margin: 0 0 6px; }
.fp-job { margin-bottom: 12px; }
.fp-head { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 0.82rem; }
.fp-head b { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fp-grid { display: grid; grid-template-columns: repeat(auto-fill, 52px); gap: 5px; max-height: 190px; overflow-y: auto; }
.fp-cell { position: relative; width: 52px; height: 52px; border-radius: 6px; overflow: hidden; cursor: pointer; background: #1e293b; border: 2px solid transparent; }
.fp-cell:hover { border-color: var(--cyan); }
.fp-cell.is-in { border-color: var(--emerald); }
.fp-cell img { width: 100%; height: 100%; object-fit: cover; display: block; }
.fp-badge { position: absolute; right: 2px; bottom: 2px; background: var(--emerald); color: #00130b; font-size: 0.65rem; font-weight: 800; padding: 0 4px; border-radius: 4px; }

.ai-box { margin-top: 16px; padding: 10px 12px; border: 1px dashed var(--line-strong); border-radius: var(--r-sm); font-size: 0.8rem; }
.ai-box summary { cursor: pointer; color: var(--text-2); }
.ai-box[open] summary { margin-bottom: 10px; }
.ai-box textarea { margin-bottom: 8px; }
.ai-box .muted { margin-bottom: 8px; }
.batch-list { margin: 0 0 10px; }
.batch-list .combo-row { grid-template-columns: auto 40px 1fr; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.gallery-item { background: var(--card); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.gallery-item img { width: 100%; aspect-ratio: 1; object-fit: contain; background: #fff; cursor: zoom-in; display: block; }
.gallery-item figcaption { display: flex; align-items: center; gap: 6px; padding: 6px 8px; font-size: 0.72rem; }
.gallery-item figcaption span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

.brand-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-bottom: 12px; }
.logo-preview {
  height: 64px;
  background: #fff;
  border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: center;
  padding: 6px; text-align: center;
}
.logo-preview img { max-height: 100%; max-width: 100%; }
.logo-preview .muted { color: #6b7280; font-size: 0.72rem; }

.swatch-row { display: flex; align-items: center; gap: 10px; }
.swatches { display: flex; gap: 6px; }
.swatch {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--c); border: 2px solid transparent; cursor: pointer;
  box-shadow: 0 0 0 1px var(--line-strong);
}
.swatch.active { border-color: #fff; }

/* ---------------------------------------------------------------- tab 3: ý tưởng & ảnh AI */

.dropzone-sm { min-height: 90px; margin-bottom: 10px; }
.ref-list { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.ref-list:empty { display: none; }
.ref-thumb { position: relative; aspect-ratio: 1; background: #fff; border-radius: 6px; overflow: hidden; }
.ref-thumb img { width: 100%; height: 100%; object-fit: contain; }
.ref-thumb button {
  position: absolute; top: 3px; right: 3px;
  width: 20px; height: 20px; border-radius: 50%; border: 0;
  background: rgba(0, 0, 0, 0.65); color: #fff; font-size: 0.65rem; cursor: pointer;
}
.ref-thumb button:hover { background: var(--rose); }
.link-btn { width: 100%; margin: -4px 0 14px; }

.idea-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; margin-bottom: 14px;
  position: sticky; top: 76px; z-index: 5;
}
.idea-list { display: flex; flex-direction: column; gap: 12px; }

.idea-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.idea-card.is-selected { border-color: rgba(6, 182, 212, 0.45); }
.idea-card.status-working { border-color: var(--cyan); box-shadow: 0 0 18px rgba(6, 182, 212, 0.18); }
.idea-card.status-error { border-color: rgba(244, 63, 94, 0.5); }

.idea-head { display: flex; align-items: center; gap: 8px; }
.idea-title { flex: 1; font-weight: 700; padding: 4px 8px !important; }
.idea-style {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px;
  color: #c4b5fd; background: rgba(139, 92, 246, 0.15); border: 1px solid rgba(139, 92, 246, 0.3);
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.idea-prompt { font-family: var(--mono); font-size: 0.78rem !important; line-height: 1.45; }
.idea-status { color: #fb7185; font-size: 0.78rem; word-break: break-word; }

.idea-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.idea-results:empty { display: none; }
.idea-result { background: #fff; border-radius: var(--r-sm); overflow: hidden; border: 1px solid var(--line); }
.idea-result img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; cursor: zoom-in; }
.idea-result figcaption { display: flex; gap: 4px; padding: 5px; background: var(--bg-2); }
.idea-result figcaption .btn-success { flex: 1; }

/* ---------------------------------------------------------------- hàng loạt theo thư mục */

.status-pill.queue { color: var(--cyan); border-color: rgba(6, 182, 212, 0.4); }

.job-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.job-card.is-selected { border-color: rgba(6, 182, 212, 0.35); }
.job-card.status-running { border-color: var(--cyan); box-shadow: 0 0 18px rgba(6, 182, 212, 0.18); }
.job-card.status-done { border-color: rgba(16, 185, 129, 0.5); }
.job-card.status-error { border-color: rgba(244, 63, 94, 0.5); }

.job-head { display: flex; align-items: center; gap: 8px; }
.job-name { flex: 1; font-weight: 700; padding: 4px 8px !important; }
.job-count { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }
.job-badge { font-size: 0.72rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; background: #1e293b; color: var(--text-2); }
.job-badge:empty { display: none; }
.badge-running { background: rgba(6, 182, 212, 0.15); color: var(--cyan); }
.badge-done { background: rgba(16, 185, 129, 0.15); color: var(--emerald); }
.badge-error { background: rgba(244, 63, 94, 0.15); color: #fb7185; }

.job-progress { height: 3px; border-radius: 2px; background: transparent; overflow: hidden; }
.job-card.status-running .job-progress { background: #1e293b; }
.job-progress span { display: block; height: 100%; width: 35%; background: var(--cyan); border-radius: 2px; animation: progress-slide 1.1s ease-in-out infinite; }
.job-card:not(.status-running) .job-progress span { display: none; }
@keyframes progress-slide { from { margin-left: -35%; } to { margin-left: 100%; } }

.job-body { display: flex; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.job-results { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.job-results:empty { display: none; }

.job-tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.job-hint { font-size: 0.75rem; color: var(--text-2); margin-left: 4px; }
.job-hint.is-warn { color: var(--amber); }

/* lưới tất cả ảnh trong thư mục: bấm để tích / bỏ tích */
.job-picks {
  display: grid; grid-template-columns: repeat(auto-fill, 76px); gap: 6px;
  max-height: 252px; overflow-y: auto; padding: 2px;
}
.pick {
  position: relative; width: 76px; height: 76px; border-radius: 8px; overflow: hidden; cursor: pointer;
  background: #1e293b; border: 2px solid transparent; user-select: none;
}
.pick img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0.38; filter: grayscale(0.6); transition: opacity 0.15s, filter 0.15s; }
.pick:not(:has(img[src])) img { visibility: hidden; }
.pick.is-picked { border-color: var(--cyan); }
.pick.is-picked img { opacity: 1; filter: none; }
.pick-box {
  position: absolute; top: 4px; left: 4px; width: 20px; height: 20px; border-radius: 6px;
  display: grid; place-items: center; font-size: 0.75rem; font-weight: 800;
  background: rgba(15, 23, 42, 0.8); border: 1.5px solid rgba(255, 255, 255, 0.5); color: transparent;
}
.pick.is-picked .pick-box { background: var(--cyan); border-color: var(--cyan); color: #00131a; }
.pick-zoom {
  position: absolute; right: 3px; bottom: 3px; width: 22px; height: 22px; border-radius: 6px; border: 0;
  background: rgba(15, 23, 42, 0.8); color: #fff; font-size: 0.8rem; cursor: zoom-in; opacity: 0;
}
.pick:hover .pick-zoom { opacity: 1; }
.job-card.picking-locked .pick { cursor: not-allowed; }
.job-card.picking-locked .job-tools .btn { opacity: 0.5; pointer-events: none; }
.job-results { margin-left: auto; }
.job-results img { height: 88px; width: auto; border-radius: 6px; border: 1px solid var(--line-strong); background: #fff; cursor: zoom-in; }
.job-msg { font-size: 0.75rem; color: var(--text-2); word-break: break-word; }
.job-msg.is-error { color: #fb7185; }

/* ---------------------------------------------------------------- kho ảnh & đăng nhập */

.gallery-group { margin-bottom: 26px; }
.gallery-group header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.gallery-group h3 { font-size: 0.95rem; }
.gallery-group h3 .muted { margin-left: 8px; font-weight: 400; }
.gallery-item figcaption small { color: var(--muted); }
.gallery-item figcaption a { text-decoration: none; }

.login-page { display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(360px, 100%);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  padding: 32px 28px;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.6);
}
.login-card h1 { font-size: 1.25rem; }
.login-card input { margin-top: 6px; }
.login-card .btn { width: 100%; margin-top: 4px; }
.login-error { color: #fb7185; font-size: 0.85rem; text-align: center; }

/* ---------------------------------------------------------------- chat */

.chat-layout { display: grid; grid-template-columns: 250px 1fr; gap: 16px; height: calc(100vh - 150px); min-height: 520px; }
.chat-side { display: flex; flex-direction: column; gap: 12px; overflow: hidden; }
.chat-chats { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
.chat-item { display: flex; align-items: center; gap: 4px; padding: 7px 8px; border-radius: var(--r-sm); cursor: pointer; font-size: 0.83rem; border: 1px solid transparent; }
.chat-item:hover { background: rgba(255, 255, 255, 0.05); }
.chat-item.active { background: rgba(6, 182, 212, 0.12); border-color: rgba(6, 182, 212, 0.35); }
.chat-item-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .icon-btn { visibility: hidden; font-size: 0.8rem; padding: 2px 6px; }
.chat-item:hover .icon-btn, .chat-item.active .icon-btn { visibility: visible; }

.chat-main { display: flex; flex-direction: column; padding: 0; overflow: hidden; position: relative; }
#tab-chat.dragover .chat-main { outline: 2px dashed var(--cyan); outline-offset: -6px; }
.chat-messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.msg { display: flex; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: min(760px, 88%); padding: 10px 14px; border-radius: 14px; font-size: 0.9rem; line-height: 1.55; word-break: break-word; }
.msg.user .bubble { background: #0e4f6e; border-bottom-right-radius: 4px; }
.msg.bot .bubble { background: #1b2436; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.bubble code { font-family: var(--mono); font-size: 0.82em; background: rgba(0, 0, 0, 0.35); padding: 1px 5px; border-radius: 4px; }
.bubble pre { background: #0a0f1a; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin: 8px 0; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; }
.chat-thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.chat-thumbs img { height: 90px; width: auto; border-radius: 8px; background: #fff; }
.chat-error { color: #fb7185; margin-top: 4px; }
.msg-actions { display: flex; gap: 6px; margin-top: 6px; }
.msg-actions:empty { display: none; }
.spinner.small { width: 16px; height: 16px; border-width: 2px; display: inline-block; vertical-align: -3px; }

.chat-results { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; margin: 6px 0; }
.chat-result { background: #fff; border-radius: 10px; overflow: hidden; }
.chat-result img { width: 100%; display: block; cursor: zoom-in; }
.chat-result figcaption { display: flex; gap: 4px; padding: 5px; background: var(--bg-2); }
.chat-result figcaption .btn-success { flex: 1; }

.chat-empty { margin: auto; max-width: 640px; text-align: center; display: flex; flex-direction: column; gap: 10px; }
.chat-empty h3 { font-size: 1.1rem; }
.suggest { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }
.chip-suggest {
  background: #1b2436; color: var(--text-2); border: 1px solid var(--line-strong);
  border-radius: 999px; padding: 6px 12px; font-size: 0.8rem; cursor: pointer; text-align: left;
}
.chip-suggest:hover { color: var(--text); border-color: var(--cyan); }

.chat-composer { border-top: 1px solid var(--line); padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 8px; background: rgba(11, 16, 28, 0.6); }
.chat-composer .ref-list { grid-template-columns: repeat(auto-fill, 56px); margin: 0; }
.chat-composer textarea { resize: none; max-height: 180px; line-height: 1.5; }
.composer-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.composer-bar .btn-success { margin-left: auto; }
.composer-opts { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 0.78rem; color: var(--text-2); }
.composer-opts select { width: auto; padding: 5px 8px; font-size: 0.78rem; }
.composer-opts label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.mode-toggle { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 2px; }
.mode-toggle button { background: none; border: 0; padding: 5px 10px; border-radius: 6px; font-size: 0.8rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.mode-toggle button.active { background: #1e293b; color: var(--text); box-shadow: inset 0 -2px 0 var(--cyan); }

@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-side { max-height: 200px; }
  .chat-main { height: 70vh; }
}

/* ---------------------------------------------------------------- thẻ chọn chế độ & bố cục gọn */

.field-grid-3 { grid-template-columns: 1.1fr 1.4fr 1fr; gap: 8px; }
.mode-cards { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.mode-card {
  display: grid; grid-template-columns: auto auto 1fr; align-items: center; gap: 9px;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--r-sm); cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.mode-card:hover { border-color: var(--line-strong); background: rgba(255, 255, 255, 0.03); }
.mode-card:has(input:checked) { border-color: var(--cyan); background: rgba(6, 182, 212, 0.09); }
.mode-card input { accent-color: var(--cyan); width: 15px; height: 15px; }
.mode-icon { font-size: 1.2rem; line-height: 1; }
.mode-body b { display: block; font-size: 0.84rem; }
.mode-body small { display: block; color: var(--text-2); font-size: 0.72rem; line-height: 1.35; margin-top: 1px; }
#folderCutoutOptions input[type='range'] { margin-top: 2px; }
.cutout-preview { display: flex; flex-direction: column; align-items: center; gap: 4px; margin-bottom: 12px; }
.cutout-preview canvas {
  max-width: 100%; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: repeating-conic-gradient(#273247 0% 25%, #1b2436 0% 50%) 50% / 16px 16px; /* ca-rô = phần trong suốt */
}
.hint.is-warn { color: var(--amber); }
.cutout-preview .muted { font-size: 0.7rem; text-align: center; word-break: break-all; }
#folderDrop { min-height: 0; padding: 12px; margin-bottom: 4px; }
#folderDrop p { margin: 0; }
#ideaInfo { font-size: 0.85rem; line-height: 1.55; min-height: 190px; }
.studio-controls .field { margin-bottom: 10px; }
.studio-controls .panel-title:not(:first-child) { margin-top: 16px; padding-top: 14px; }

.build { color: var(--muted); font-family: var(--mono); font-size: 0.68rem; }

/* ---------------------------------------------------------------- dialogs */

.dialog {
  margin: auto;
  width: min(620px, calc(100vw - 32px));
  max-height: 90vh;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.7);
}
.dialog::backdrop { background: rgba(3, 5, 10, 0.78); backdrop-filter: blur(6px); }
.dialog-wide { width: min(1000px, calc(100vw - 32px)); }
.dialog-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; border-bottom: 1px solid var(--line);
}
.dialog-header h2 { font-size: 1rem; }
.dialog-body { padding: 18px 20px 20px; }

.test-result { margin-top: 14px; font-size: 0.82rem; display: flex; flex-direction: column; gap: 8px; }
.test-result .ok { color: var(--emerald); }
.test-result .err { color: #fb7185; word-break: break-word; }
.test-result img { max-width: 220px; border-radius: var(--r-sm); background: #fff; }

.lightbox-body { background: #fff; display: flex; justify-content: center; }
.lightbox-body img { max-width: 100%; max-height: 78vh; object-fit: contain; }

/* ---------------------------------------------------------------- toasts */

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast {
  display: flex; gap: 10px; align-items: flex-start;
  background: #1e293b; border-left: 4px solid #3b82f6;
  padding: 10px 16px; border-radius: var(--r-sm);
  font-size: 0.84rem; box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  animation: slide-in 0.25s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast-success { border-left-color: var(--emerald); }
.toast-error { border-left-color: var(--rose); }
.toast.leaving { opacity: 0; transform: translateY(8px); }
@keyframes slide-in { from { opacity: 0; transform: translateX(40px); } }

/* ---------------------------------------------------------------- responsive */

@media (max-width: 1200px) {
  .toolbar-grid { grid-template-columns: 1fr 1fr; }
  .actions-panel { grid-column: 1 / -1; }
}
@media (max-width: 900px) {
  .studio, .toolbar-grid { grid-template-columns: 1fr; }
  .studio-controls { position: static; max-height: none; }
  .tabs { order: 3; width: 100%; overflow-x: auto; }
  .main { padding: 0 16px 32px; }
  .app-header { padding: 10px 16px; }
}
