:root {
  --bg: #f3f6fb;
  --card: #ffffff;
  --ink: #152138;
  --muted: #77839a;
  --line: #e3e9f2;
  --navy: #153b72;
  --accent: #2474ff;
  --accent-soft: #eaf2ff;
  --green: #149578;
  --shadow: 0 14px 36px rgba(28, 42, 70, .08);
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh;
  background: radial-gradient(circle at 8% 0%, #eaf2ff 0, transparent 34%), var(--bg);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", "Noto Sans Thai", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.app-shell { max-width: 1780px; margin: 0 auto; padding: 18px; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 8px 4px 18px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; background: linear-gradient(135deg, #113965, #2474ff); color: white; font-weight: 900; font-size: 21px; box-shadow: 0 9px 24px rgba(36,116,255,.26); }
.brand-name { font-size: 18px; font-weight: 850; letter-spacing: .2px; }
.brand-sub { color: var(--muted); font-size: 11px; margin-top: 3px; letter-spacing: .2px; }
.pill { padding: 8px 12px; background: var(--accent-soft); color: #2f5ca9; border-radius: 999px; font-size: 12px; font-weight: 750; }
.workspace { display: grid; grid-template-columns: 310px minmax(0, 1fr) 380px; gap: 14px; align-items: stretch; min-height: calc(100vh - 94px); }
.card { background: rgba(255,255,255,.96); border: 1px solid rgba(225,232,242,.95); border-radius: 18px; box-shadow: var(--shadow); }
.sidebar, .editor { padding: 18px; overflow: auto; max-height: calc(100vh - 112px); }
.section-title { font-size: 13px; font-weight: 850; color: #35415b; }
.section-title.spaced { margin-top: 20px; }
.dropzone { margin-top: 12px; padding: 20px 14px; min-height: 145px; border: 1.5px dashed #b9c6db; border-radius: 15px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: #fbfcff; transition: .2s ease; }
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); background: #f5f8ff; transform: translateY(-1px); }
.drop-icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: 26px; font-weight: 300; }
.drop-title { margin-top: 10px; font-weight: 750; font-size: 14px; }
.drop-desc { margin-top: 5px; font-size: 11px; color: var(--muted); }
.form-grid { display: grid; grid-template-columns: 1fr 22px 1fr; gap: 7px; align-items: end; margin-top: 10px; }
.form-grid label > span, .form-stack label > span, .style-grid label > span { display: block; color: var(--muted); font-size: 10.5px; margin-bottom: 5px; }
.form-stack { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
select, .style-grid input[type=number] { width: 100%; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 9px; outline: none; color: var(--ink); }
select:focus, textarea:focus, input:focus { border-color: #92aaff; box-shadow: 0 0 0 3px rgba(47,107,255,.07); }
.swap { text-align: center; padding-bottom: 11px; color: #9aa5ba; }
.range-wrap { display: block; margin-top: 16px; }
.range-head { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.range-head b { color: #40506c; }
input[type=range] { width: 100%; margin-top: 8px; accent-color: var(--accent); }
.primary, .secondary, .ghost { border: 0; border-radius: 11px; font-weight: 800; }
.primary { width: 100%; margin-top: 12px; padding: 12px 14px; background: var(--accent); color: #fff; box-shadow: 0 9px 20px rgba(47,107,255,.2); }
.secondary { width: 100%; margin-top: 8px; padding: 10px 12px; background: var(--accent-soft); color: #3158c7; }
.primary:disabled, .secondary:disabled { opacity: .52; box-shadow: none; cursor: not-allowed; }
.ghost { padding: 9px 12px; color: #47546c; background: #f3f6fa; }
.ghost.strong { background: #183f76; color: #fff; }
.ghost.compact { padding: 7px 9px; font-size: 11px; }
.ghost.active-mode { color: white; background: var(--green); }
.ghost:disabled { opacity: .45; cursor: not-allowed; }
.mini-note { color: var(--muted); font-size: 10.5px; line-height: 1.55; margin-top: 8px; }
.protect-panel { border: 1px solid #dfe9e6; background: #f7fbfa; border-radius: 12px; padding: 10px; margin-top: 13px; }
.protect-head b { display: block; font-size: 11px; color: #326458; }
.protect-head span { display: block; font-size: 9.5px; line-height: 1.5; color: #77958d; margin-top: 3px; }
.protect-actions { display: flex; gap: 6px; margin-top: 8px; }
.queue-head { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.text-btn { border:0; background:transparent; color:#8995aa; font-size:10px; padding:3px; }
.text-btn:hover { color:#d14a5f; }
.stage { min-width: 0; overflow: hidden; display: flex; flex-direction: column; max-height: calc(100vh - 112px); }
.stage-toolbar { min-height: 64px; flex: 0 0 auto; padding: 12px 15px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 14px; }
.stage-toolbar b { display: block; font-size: 13px; }
.stage-toolbar span { display: block; color: var(--muted); font-size: 11px; margin-top: 3px; }
.toolbar-actions { display: flex; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.canvas-wrap { position: relative; flex: 1; min-height: 540px; overflow: auto; display: grid; place-items: center; padding: 24px; background-color: #edf1f7; background-image: linear-gradient(45deg,#e5eaf1 25%,transparent 25%),linear-gradient(-45deg,#e5eaf1 25%,transparent 25%),linear-gradient(45deg,transparent 75%,#e5eaf1 75%),linear-gradient(-45deg,transparent 75%,#e5eaf1 75%); background-size: 22px 22px; background-position: 0 0,0 11px,11px -11px,-11px 0; }
.canvas-wrap.protect-mode { cursor: crosshair; box-shadow: inset 0 0 0 3px rgba(20,149,120,.22); }
#previewCanvas { max-width: 100%; max-height: calc(100vh - 225px); box-shadow: 0 16px 45px rgba(25,35,54,.23); background: white; touch-action: none; user-select: none; }
.empty-state { text-align: center; max-width: 510px; padding: 32px; }
.empty-visual { display: inline-flex; padding: 14px 20px; border-radius: 16px; background: rgba(255,255,255,.85); box-shadow: 0 10px 28px rgba(35,50,80,.08); font-size: 25px; font-weight: 900; color: #4566c7; }
.empty-state h2 { margin: 18px 0 8px; font-size: 20px; }
.empty-state p { margin: 0; font-size: 12px; line-height: 1.75; color: var(--muted); }
.editor-heading { display:flex; justify-content:space-between; align-items:flex-start; gap:8px; }
.editor-hint { color:var(--muted); font-size:10px; margin-top:4px; }
.editor-empty { margin-top: 12px; padding: 20px 12px; background: #f8fafc; color: var(--muted); border-radius: 12px; font-size: 12px; line-height: 1.6; }
.text-editor { margin-top: 10px; display: grid; gap: 10px; }
.text-item { padding: 11px; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.text-item .meta { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 6px; color: var(--muted); font-size: 10px; }
.text-item .src { font-size: 11px; font-weight:650; color: #536078; line-height: 1.45; margin-bottom: 7px; padding:7px 8px; border-radius:8px; background:#f7f9fc; }
.text-item textarea { width: 100%; resize: vertical; min-height: 64px; border: 1px solid var(--line); border-radius: 9px; padding: 9px; outline: none; line-height: 1.45; }
.toggle-row { margin:7px 0 8px; font-size:10.5px; color:#67758a; }
.toggle-row input { vertical-align:middle; }
.style-grid { display:grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap:7px; }
.style-grid label { min-width:0; }
.style-grid input[type=color] { width:100%; height:34px; border:1px solid var(--line); padding:2px; background:#fff; border-radius:8px; }
.style-grid input[type=number], .style-grid select { padding:7px 6px; border-radius:8px; font-size:10.5px; }
.queue { display: grid; gap: 7px; margin-top: 9px; }
.queue-item { display: grid; grid-template-columns: 38px 1fr auto; align-items: center; gap: 8px; padding: 7px; border-radius: 10px; background: #f8fafc; cursor: pointer; border: 1px solid transparent; }
.queue-item.active { border-color: #9db3ff; background: #f1f5ff; }
.queue-thumb { width: 38px; height: 38px; border-radius: 7px; object-fit: cover; background: #e9edf4; }
.queue-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; max-width:185px; }
.queue-status { color: var(--muted); font-size: 10px; }
.spinner { width: 14px; height: 14px; border: 2px solid #d8e0ed; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; right: 22px; bottom: 22px; z-index:9999; background: #1e293b; color: white; padding: 11px 14px; border-radius: 10px; font-size: 12px; box-shadow: 0 10px 24px rgba(0,0,0,.18); opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }
@media (max-width: 1260px) { .workspace { grid-template-columns: 290px minmax(0, 1fr); } .editor { grid-column: 1 / -1; max-height: none; } }
@media (max-width: 760px) { .app-shell { padding: 10px; } .top-actions { display: none; } .workspace { grid-template-columns: 1fr; } .sidebar, .editor, .stage { max-height: none; } .stage { min-height: 620px; } .stage-toolbar { align-items: flex-start; height: auto; flex-direction: column; } .toolbar-actions { justify-content:flex-start; } .canvas-wrap { min-height: 500px; padding: 12px; } .style-grid { grid-template-columns: repeat(2,minmax(0,1fr)); } .form-stack { grid-template-columns:1fr; } }

/* V2.1: per-text confirm + font picker */
.text-item { transition: border-color .18s ease, box-shadow .18s ease, background .18s ease; }
.text-item.dirty { border-color: #9db3ff; box-shadow: 0 0 0 3px rgba(47,107,255,.06); background: #fbfdff; }
.item-actions { display:flex; align-items:center; justify-content:space-between; gap:10px; margin-top:10px; padding-top:9px; border-top:1px dashed var(--line); }
.dirty-hint { color:var(--muted); font-size:9.5px; line-height:1.35; }
.text-item.dirty .dirty-hint { color:#4367c7; font-weight:700; }
.apply-item { flex:0 0 auto; border:0; border-radius:9px; padding:8px 12px; background:#2474ff; color:#fff; font-size:10.5px; font-weight:850; box-shadow:0 5px 14px rgba(36,116,255,.18); }
.apply-item:hover { filter:brightness(.97); }
.apply-item.applied { background:#149578; }
.style-grid .fontFamily { min-width:0; }
@media (max-width: 760px) { .item-actions { align-items:flex-start; flex-direction:column; } .apply-item { width:100%; } }

/* V2.2: cache-safe editor, isolated font confirmation, translation error guard */
.translation-warning {
  margin: 0 0 8px;
  padding: 8px 9px;
  border: 1px solid #f4cf8d;
  border-radius: 8px;
  background: #fff9ea;
  color: #8a5a00;
  font-size: 10px;
  line-height: 1.45;
}
.font-action-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 96px;
  gap: 8px;
  align-items: end;
  margin: 8px 0 9px;
  padding: 9px;
  border: 1px solid #dbe5f5;
  border-radius: 10px;
  background: #f8fbff;
}
.font-picker { min-width: 0; }
.font-picker > span {
  display: block;
  margin-bottom: 5px;
  color: #5e6d86;
  font-size: 10.5px;
  font-weight: 750;
}
.font-action-row select {
  width: 100%;
  min-width: 0;
  padding: 8px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 10.5px;
}
.apply-font {
  height: 35px;
  border: 0;
  border-radius: 8px;
  background: #173f76;
  color: #fff;
  font-size: 10.5px;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 5px 12px rgba(23,63,118,.14);
}
.apply-font.pending { background: #2474ff; }
.apply-font.applied { background: #149578; }
.item-actions {
  align-items: center;
  margin-top: 11px;
}
.apply-item {
  min-width: 122px;
  padding: 10px 13px;
  font-size: 11px;
  cursor: pointer;
}
@media (max-width: 760px) {
  .font-action-row { grid-template-columns: 1fr; }
  .apply-font { width: 100%; }
}

/* V2.3: per-text retranslation */
.single-translate-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 7px 0 8px;
  padding: 7px 8px;
  border: 1px solid #dfe8f7;
  border-radius: 9px;
  background: #f7faff;
}
.single-translate-hint {
  min-width: 0;
  color: #71819a;
  font-size: 9.5px;
  line-height: 1.35;
}
.retranslate-item {
  flex: 0 0 auto;
  min-width: 98px;
  height: 32px;
  padding: 0 10px;
  border: 1px solid #8fb0ee;
  border-radius: 8px;
  background: #eef4ff;
  color: #245bb5;
  font-size: 10.5px;
  font-weight: 850;
  cursor: pointer;
  transition: .15s ease;
}
.retranslate-item:hover:not(:disabled) {
  background: #e1ecff;
  border-color: #6d98e6;
}
.retranslate-item:disabled { cursor: wait; opacity: .72; }
.retranslate-item.loading { background: #eef1f6; color: #637086; border-color: #d4dce8; }
.retranslate-item.applied { background: #e9f8f3; color: #11745d; border-color: #9fd9c8; }
@media (max-width: 760px) {
  .single-translate-row { align-items: stretch; flex-direction: column; }
  .retranslate-item { width: 100%; }
}


/* V2.6: draggable text movement */
.canvas-wrap.move-mode { cursor: move; box-shadow: inset 0 0 0 3px rgba(36,116,255,.18); }
.text-item.selected { border-color: #7ea4ff; box-shadow: 0 0 0 3px rgba(47,107,255,.08); background: #f9fbff; }
.text-item.selected .src { background: #eef4ff; color: #264a93; }
.move-help { margin-top: 6px; padding: 7px 8px; border-radius: 8px; background: #eef4ff; color: #3257b8; font-size: 10px; line-height: 1.45; }


/* V2.7: keyboard nudge + snap guides */
.move-help strong { color:#173f76; }
.move-snap-badge { display:inline-flex; align-items:center; gap:5px; margin-left:6px; padding:2px 6px; border-radius:999px; background:#e8f8f2; color:#12725c; font-size:9px; font-weight:800; }


/* V2.8: reliable drag hit area + explicit per-item movement */
.move-help { display:flex; align-items:center; justify-content:space-between; gap:8px; }
.move-help > div { min-width:0; }
.move-this-item { flex:0 0 auto; border:1px solid #7ea4ff; background:#fff; color:#245bb5; border-radius:7px; padding:6px 9px; font-size:10px; font-weight:800; cursor:pointer; }
.move-this-item:hover { background:#eaf2ff; }
.canvas-wrap.move-mode #previewCanvas { cursor: grab; }
.canvas-wrap.move-mode #previewCanvas:active { cursor: grabbing; }


/* V2.9: translation provider status */
.provider-status {
  display:block;
  margin-top:5px;
  font-size:9.5px;
  line-height:1.4;
  font-weight:700;
}
.provider-status.checking { color:#7b879c; }
.provider-status.online { color:#11745d; }
.provider-status.offline { color:#b66a00; }
