@font-face {
  font-family: "Be Vietnam Pro";
  src: url("/fonts/BeVietnamPro-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Be Vietnam Pro";
  src: url("/fonts/BeVietnamPro-SemiBold.ttf") format("truetype");
  font-weight: 600;
  font-display: swap;
}

:root {
  --bg: #f3f4f6;
  --surface: #fff;
  --subtle: #f9fafb;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --accent-soft-strong: #dbeafe;
  --success: #16a34a;
  --success-soft: #f0fdf4;
  --warn: #b45309;
  --warn-soft: #fff7e6;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --radius: 6px;
  --shadow-lg: 0 10px 32px rgba(0, 0, 0, .14);
  --font: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 400 13.5px/1.45 var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-weight: 600; margin: 0; }
b, strong { font-weight: 600; }
img { display: block; }
.muted { color: var(--muted); }
.caption { color: var(--muted); font-size: 12px; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* ---------------------------------------------------------------- controls */

.btn {
  font: 600 13.5px/1 var(--font);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  height: 32px;
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--subtle); border-color: #9ca3af; }
.btn:active:not(:disabled) { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.primary:disabled { background: #93b1f3; border-color: #93b1f3; opacity: 1; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #b91c1c; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--bg); border-color: transparent; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn.block { width: 100%; height: 36px; }
.link {
  font: inherit; background: none; border: 0; padding: 2px 4px; color: var(--accent); cursor: pointer; border-radius: 4px;
}
.link:hover { background: var(--accent-soft); }
.link.danger { color: var(--danger); }
.link.danger:hover { background: var(--danger-soft); }
.icon-btn {
  width: 30px; height: 30px; border: 0; background: none; border-radius: 6px; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--muted);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }

input[type=text], input[type=url], input[type=password], input:not([type]), input[type=number], textarea, select {
  font: 400 13.5px/1.4 var(--font);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 10px;
  width: 100%;
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
input::placeholder, textarea::placeholder { color: #9ca3af; }
textarea { resize: vertical; min-height: 60px; }
select {
  appearance: none; padding-right: 28px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, #6b7280 50%), linear-gradient(135deg, #6b7280 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat;
}
input[type=color] {
  width: 36px; height: 32px; padding: 2px; border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); cursor: pointer;
}
input[type=range] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field > span, .field-label { font-weight: 600; font-size: 13px; }
.field-label { display: block; margin: 10px 0 6px; }
.row { display: flex; align-items: center; gap: 8px; }
.row > .grow { flex: 1; min-width: 0; }
.form-error { color: var(--danger); font-size: 12.5px; margin: 0 0 10px; }

.segmented {
  display: flex; gap: 2px; background: var(--bg); border-radius: 8px; padding: 3px;
}
.segmented button {
  flex: 1; height: 30px; border: 1px solid transparent; border-radius: 6px; background: transparent;
  font: 400 13.5px var(--font); color: var(--muted); cursor: pointer; white-space: nowrap; padding: 0 6px;
}
.segmented button:hover:not(.active) { background: rgba(0, 0, 0, .04); }
.segmented button.active { background: var(--surface); border-color: var(--border); color: var(--text); font-weight: 600; }

.section-title {
  font-weight: 600; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
}
.divider { height: 1px; background: var(--border); margin: 16px 0; }

.callout {
  border-radius: 8px; padding: 9px 12px; font-size: 12.5px; border: 1px solid;
}
.callout.warn { background: var(--warn-soft); color: var(--warn); border-color: rgba(180, 83, 9, .25); }
.callout.danger { background: var(--danger-soft); color: var(--danger); border-color: rgba(220, 38, 38, .25); }
.callout.success { background: var(--success-soft); color: var(--success); border-color: rgba(22, 163, 74, .25); }
.callout.info { background: var(--accent-soft); color: var(--accent); border-color: rgba(37, 99, 235, .2); }

.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; }
.dot.ok { background: var(--success); }
.dot.err { background: var(--danger); }

.spinner {
  width: 14px; height: 14px; border: 2px solid var(--accent-soft-strong); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; vertical-align: -2px; margin-right: 8px;
}
.spinner.big { width: 30px; height: 30px; border-width: 3px; margin: 0 auto 10px; display: block; }
@keyframes spin { to { transform: rotate(360deg); } }

table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); }
.table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table th, .table td.num { white-space: nowrap; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { border: 1px solid var(--border); border-radius: 8px; overflow: auto; }
.badge {
  display: inline-block; font-size: 11.5px; font-weight: 600; border-radius: 10px; padding: 2px 8px;
  background: var(--bg); color: var(--muted);
}
.badge.admin { background: var(--accent-soft-strong); color: var(--accent); }
.badge.off { background: var(--danger-soft); color: var(--danger); }

/* ---------------------------------------------------------------- login */

.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card {
  width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 32px 28px 24px; box-shadow: var(--shadow-lg);
}
.login-logo { width: 52px; height: 52px; margin: 0 auto 10px; }
.login-card h1 { text-align: center; font-size: 20px; }
.login-card > p.muted { text-align: center; margin: 4px 0 22px; }
.login-card .caption { margin: 14px 0 0; }

/* ---------------------------------------------------------------- layout */

.app {
  height: 100%;
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr) 384px;
  grid-template-rows: 56px minmax(0, 1fr) 30px;
  grid-template-areas: "top top top" "side stage panel" "status status status";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15.5px; margin-right: 14px; white-space: nowrap; }
.brand img { width: 30px; height: 30px; }
.url-form { flex: 1; display: flex; gap: 8px; min-width: 0; }
.url-form input { height: 34px; }
.url-form .btn { height: 34px; min-width: 96px; }
#export-open { height: 34px; }
.menu-wrap { position: relative; }
.user-btn { height: 34px; padding: 0 8px; font-weight: 400; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft-strong); color: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; text-transform: uppercase;
}
.menu {
  position: absolute; right: 0; top: 40px; z-index: 30; min-width: 210px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px;
}
.menu button {
  display: block; width: 100%; text-align: left; font: 400 13.5px var(--font); color: var(--text);
  background: none; border: 0; border-radius: 6px; padding: 8px 10px; cursor: pointer;
}
.menu button:hover { background: var(--bg); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

.sidebar {
  grid-area: side; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 12px 10px; }
.sidebar-head h2 { font-size: 15px; }
.sidebar-head .count { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 4px; }
.project-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.project {
  position: relative; padding: 8px 34px 8px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
.project:hover { background: var(--bg); }
.project.active { background: var(--accent-soft); }
.project.active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--accent);
}
.project-title { font-weight: 600; font-size: 13px; line-height: 1.3; word-break: break-word; }
.project.active .project-title { color: var(--accent); }
.project-meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.project-del {
  position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; border: 0; border-radius: 6px;
  background: none; cursor: pointer; color: var(--muted); display: none; align-items: center; justify-content: center;
}
.project:hover .project-del, .project.active .project-del { display: flex; }
.project-del:hover { background: var(--danger-soft); color: var(--danger); }
.project-del svg { width: 15px; height: 15px; }
.confirm-box { margin: 4px 0 8px; }
.confirm-box .row { margin-top: 8px; }
.empty-list { color: var(--muted); padding: 8px 4px; }

.stage { grid-area: stage; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.canvas-area {
  flex: 1; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center;
  padding: 24px; background: var(--bg);
}
.empty-card, .busy-card {
  width: min(460px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; text-align: center;
}
.empty-card h3, .busy-card h3 { font-size: 18px; margin-bottom: 6px; }
.empty-card p { margin: 6px 0 0; }
.preview { margin: 0; display: flex; flex-direction: column; align-items: center; max-width: 100%; max-height: 100%; }
.preview-frame { position: relative; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); border-radius: 8px; line-height: 0; }
.preview-frame img { max-width: 100%; border-radius: 8px; user-select: none; }
.preview figcaption { margin-top: 12px; text-align: center; }
.woo-handle {
  position: absolute; border: 1.5px solid transparent; border-radius: 4px; cursor: grab; touch-action: none;
}
.preview-frame:hover .woo-handle, .woo-handle.dragging { border-color: var(--accent); background: rgba(37, 99, 235, .06); }
.woo-handle.dragging { cursor: grabbing; }

.history {
  height: 172px; flex: none; display: flex; gap: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: 14px 18px;
}
.history-side { width: 200px; flex: none; display: flex; flex-direction: column; gap: 10px; padding-right: 16px; border-right: 1px solid var(--border); }
.history-side .check { font-size: 12.5px; }
.history-strip { flex: 1; display: flex; gap: 16px; overflow-x: auto; padding: 4px 4px 4px 18px; }
.history-empty { color: var(--muted); align-self: center; margin: 0 auto; }
.thumb { width: 192px; flex: none; cursor: pointer; }
.thumb-img {
  width: 192px; height: 100px; border-radius: 6px; background: var(--bg); object-fit: cover;
  outline: 1px solid rgba(0, 0, 0, .08); outline-offset: -1px;
}
.thumb:hover .thumb-img { outline-color: var(--border-strong); }
.thumb.active .thumb-img { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--accent); }
.thumb-label {
  font-size: 12px; color: var(--muted); margin-top: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thumb.active .thumb-label { color: var(--text); }
.thumb-label b { margin-right: 6px; }

.panel {
  grid-area: panel; background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; padding: 14px 16px 16px;
}
#notices:not(:empty) { margin-top: 10px; }
#notices .callout p { margin: 0 0 4px; }
.panel-body { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-top: 12px; }
.panel-scroll { flex: 1; overflow-y: auto; padding-right: 6px; margin-right: -6px; }
.panel-footer { padding-top: 12px; border-top: 1px solid var(--border); margin-top: 8px; }
.panel-empty { color: var(--muted); text-align: center; padding: 24px 8px; }
.panel .section-title { margin: 4px 0 2px; }
.panel .field-label:first-of-type { margin-top: 6px; }
.panel textarea.title-input { font-size: 14.5px; min-height: 74px; }

/* Columns are set from JS (--cols) so the palette fills whole rows. */
.swatches { display: grid; grid-template-columns: repeat(var(--cols, 12), minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
.swatch {
  width: 100%; aspect-ratio: 1; max-width: 32px; border-radius: 6px; border: 0; cursor: pointer; padding: 0; transition: transform .1s;
}
.swatches + .row + .caption { margin-top: 6px; }
.swatch:hover { transform: scale(1.08); }
.swatch.active { box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.hex-input { width: 96px !important; }
.grid-2 { display: grid; grid-template-columns: 56px 1fr; gap: 8px 12px; align-items: center; }
.grid-2 > .muted { font-size: 13px; }

/* chat */
.chat-log {
  flex: 1; min-height: 120px; overflow-y: auto; background: var(--subtle); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.bubble { max-width: 86%; padding: 8px 12px; white-space: pre-wrap; word-break: break-word; }
.bubble.user { align-self: flex-end; background: var(--accent); color: #fff; border-radius: 12px 12px 4px 12px; }
.bubble.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-radius: 12px 12px 12px 4px; }
.chat-hint { color: var(--muted); margin: 6px 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 8px; }
.chip {
  font: 400 12px var(--font); height: 26px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 13px;
  background: var(--surface); cursor: pointer; color: var(--text);
}
.chip:hover:not(:disabled) { background: var(--subtle); }
.chip:disabled { opacity: .5; cursor: default; }
.composer-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.composer-foot .btn { min-width: 84px; }

.statusbar {
  grid-area: status; display: flex; align-items: center; gap: 12px; padding: 0 16px; font-size: 12.5px;
  background: var(--subtle); border-top: 1px solid var(--border); white-space: nowrap; overflow: hidden;
}
.status-error { color: var(--danger); overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------------- modal, toasts */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(17, 24, 39, .35); z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 24px;
}
.modal {
  background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: 480px; max-width: 100%;
  max-height: calc(100vh - 48px); display: flex; flex-direction: column;
}
.modal.wide { width: 860px; }
.modal.mid { width: 600px; }
.modal-head {
  display: flex; align-items: center; justify-content: center; position: relative; padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 16px; }
.modal-head .icon-btn { position: absolute; right: 12px; top: 10px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-body .segmented { margin-bottom: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.tabs { max-width: 520px; margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 136px 1fr; gap: 12px 16px; align-items: center; }
.form-grid > label { font-weight: 600; font-size: 13px; }

.toasts { position: fixed; right: 16px; bottom: 44px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg);
  max-width: 380px; font-size: 13px; animation: toast-in .18s ease-out;
}
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 1180px) {
  .app { grid-template-columns: 220px minmax(0, 1fr) 340px; }
  .brand span { display: none; }
}

/* ---------------------------------------------------------------- misc */
.spacer { height: 8px; }
.mt { margin-top: 10px; }
.grow { flex: 1; min-width: 0; }
.panel-body-inner { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.panel-body-inner > .caption:first-child { margin-bottom: 10px; }
.preview-frame img { max-height: calc(100vh - 56px - 30px - 172px - 48px - 40px); width: auto; }
.modal-actions .grow { align-self: center; }
