:root {
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f4f0ea;
  --border: #e6dfd5;
  --text: #1f1b16;
  --muted: #74695d;
  --accent: #a96d26;
  --accent-hover: #8f5b1d;
  --accent-ink: #ffffff;
  --accent-soft: #f7ecdc;
  --danger: #c0392b;
  --danger-soft: #fbe9e7;
  --ok: #2e7d4f;
  --ok-soft: #e5f4ea;
  --info: #2f6db3;
  --info-soft: #e6f0fb;
  --warn: #a8670c;
  --warn-soft: #fdf1dc;
  --shadow: 0 1px 2px rgba(31, 27, 22, 0.06), 0 4px 16px rgba(31, 27, 22, 0.06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1c1916;
    --surface-2: #26221e;
    --border: #36302a;
    --text: #f2ede6;
    --muted: #a99e91;
    --accent: #d69a4f;
    --accent-hover: #e3ab62;
    --accent-ink: #1b140b;
    --accent-soft: #3a2c1a;
    --danger: #ef6f61;
    --danger-soft: #3b1f1c;
    --ok: #5cc48a;
    --ok-soft: #1b3326;
    --info: #74a8e8;
    --info-soft: #1c2a3b;
    --warn: #e2a64b;
    --warn-soft: #3a2c15;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 700; }
h2 { font-size: 16px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }
img { display: block; max-width: 100%; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 20px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; }
.brand-dot { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; color: var(--accent-ink); font-size: 14px; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; white-space: nowrap; }
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.userbox { display: flex; align-items: center; gap: 10px; white-space: nowrap; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--surface-2); display: grid; place-items: center; font-weight: 600; color: var(--muted); }
main { max-width: 1440px; margin: 0 auto; padding: 24px; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 7px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.block { width: 100%; }
.btn .spin { width: 14px; height: 14px; }
label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
label.field > .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input[type='text'], input[type='email'], input[type='password'], input[type='number'], input[type='search'], input[type='url'], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { resize: vertical; min-height: 70px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type='checkbox'] { width: 16px; height: 16px; accent-color: var(--accent); }
.counter { font-size: 11px; color: var(--muted); font-weight: 400; }
.counter.bad { color: var(--danger); }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel + .panel { margin-top: 16px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.error-box { background: var(--danger-soft); color: var(--danger); padding: 10px 14px; border-radius: 9px; }
.info-box { background: var(--info-soft); color: var(--info); padding: 10px 14px; border-radius: 9px; font-size: 13px; }
.warn-box { background: var(--warn-soft); color: var(--warn); padding: 10px 14px; border-radius: 9px; font-size: 13px; }
.ok-box { background: var(--ok-soft); color: var(--ok); padding: 10px 14px; border-radius: 9px; font-size: 13px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.gray { background: var(--surface-2); color: var(--muted); }
.badge.blue { background: var(--info-soft); color: var(--info); }
.badge.amber { background: var(--warn-soft); color: var(--warn); }
.badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.red { background: var(--danger-soft); color: var(--danger); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 9px 14px; font: inherit; font-weight: 500; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- card grid ---------- */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.idea-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; color: inherit; box-shadow: var(--shadow); display: flex; flex-direction: column; transition: transform 0.12s; }
.idea-card:hover { transform: translateY(-2px); text-decoration: none; }
.idea-card .thumb { aspect-ratio: 1; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); font-size: 34px; position: relative; }
.idea-card .thumb img { width: 100%; height: 100%; object-fit: cover; }
.idea-card .thumb .badge { position: absolute; top: 10px; left: 10px; }
.idea-card .thumb .pending { position: absolute; bottom: 10px; right: 10px; background: rgba(0, 0, 0, 0.6); color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.idea-card .body { padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.idea-card .title { font-weight: 600; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty { text-align: center; padding: 60px 20px; color: var(--muted); }

/* ---------- card detail ---------- */
.detail-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.name-input { font-size: 20px !important; font-weight: 700; border-color: transparent !important; padding: 4px 8px !important; margin-left: -8px; background: transparent !important; }
.name-input:hover { border-color: var(--border) !important; }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; transition: 0.15s; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.shot-list { display: flex; flex-direction: column; gap: 6px; }
.shot { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; }
.shot.on { border-color: var(--accent); background: var(--accent-soft); }
.shot .row { flex-wrap: nowrap; }
.shot select { width: 64px; padding: 4px 6px; }
.shot textarea { margin-top: 8px; font-size: 12px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.tile { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--surface); display: flex; flex-direction: column; }
.tile.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.tile .img { aspect-ratio: 1; background: var(--surface-2); position: relative; cursor: zoom-in; display: grid; place-items: center; }
.tile .img img { width: 100%; height: 100%; object-fit: cover; }
.tile .img .badge { position: absolute; top: 6px; left: 6px; }
.tile .img .order { position: absolute; top: 6px; right: 6px; background: var(--accent); color: var(--accent-ink); border-radius: 999px; min-width: 22px; height: 22px; display: grid; place-items: center; font-size: 11px; font-weight: 700; }
.tile .bar { display: flex; align-items: center; gap: 2px; padding: 4px 6px; border-top: 1px solid var(--border); }
.tile .bar label { display: flex; align-items: center; gap: 5px; font-size: 12px; flex: 1; cursor: pointer; }
.tile .bar .btn { height: 24px; padding: 0 6px; font-size: 12px; }
.tile .fail { padding: 10px; font-size: 11px; color: var(--danger); text-align: center; }
.spin { width: 26px; height: 26px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 3px 4px 3px 11px; font-size: 12px; font-weight: 500; }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; font-size: 14px; line-height: 1; padding: 0 5px; }
.chip.locked { background: var(--surface-2); color: var(--muted); padding-right: 11px; }
.chip .col { font-size: 11px; opacity: 0.85; }
.chip .col.add { cursor: pointer; text-decoration: underline; }
.preview-html { border: 1px solid var(--border); border-radius: 9px; padding: 4px 14px; background: var(--surface-2); max-height: 380px; overflow: auto; }
.checklist { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 4px; font-size: 13px; }
.checklist li.ok::before { content: '✓ '; color: var(--ok); font-weight: 700; }
.checklist li.no::before { content: '○ '; color: var(--muted); }
.linkrow { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--surface-2); border-radius: 9px; font-size: 13px; }
.linkrow a { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
td .thumb-sm { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--surface-2); }

.split { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(320px, 1fr); gap: 20px; align-items: start; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.tpl-card { display: grid; grid-template-columns: 110px 1fr; gap: 16px; }
.tpl-card img { width: 110px; height: 110px; object-fit: cover; border-radius: 10px; background: var(--surface-2); }
.checkgrid { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.checkgrid label { display: flex; align-items: center; gap: 6px; font-size: 13px; }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand { justify-content: center; margin-bottom: 18px; font-size: 18px; }

/* ---------- overlays ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 12, 8, 0.55); z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--surface); border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100vh - 40px); overflow: auto; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
.modal.wide { max-width: 860px; }
.modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.lightbox img { max-height: calc(100vh - 220px); margin: 0 auto; border-radius: 8px; }
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); max-width: 380px; font-size: 13px; animation: pop 0.18s ease-out; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
pre.brief { white-space: pre-wrap; background: var(--surface-2); padding: 14px; border-radius: 9px; font-size: 12px; max-height: 50vh; overflow: auto; }

@media (max-width: 1000px) {
  .detail-grid, .split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; gap: 10px; flex-wrap: wrap; }
  .nav { order: 3; flex-basis: 100%; }
  main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .card-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .tpl-card { grid-template-columns: 1fr; }
  .userbox .who { display: none; }
}
