* { box-sizing: border-box; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #f3f5f7; color: #1e2530; font-size: 14px;
}
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; background: #1c2733; color: #dbe4ee;
  display: flex; flex-direction: column; flex-shrink: 0;
}
.brand { font-size: 17px; font-weight: 700; padding: 18px 16px; color: #fff; }
.sidebar nav { display: flex; flex-direction: column; }
.sidebar nav a {
  color: #b8c5d3; text-decoration: none; padding: 11px 16px; border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: #263443; color: #fff; }
.sidebar nav a.active { background: #2c3e50; color: #fff; border-left-color: #4da3ff; }
.sidebar-footer { margin-top: auto; padding: 14px 16px; }
.sidebar-footer a { color: #7d8fa1; text-decoration: none; font-size: 13px; }
.content { flex: 1; padding: 22px 28px; max-width: 1500px; }

h1 { font-size: 20px; margin-bottom: 16px; }
h2 { font-size: 15px; margin: 18px 0 10px; }
.card {
  background: #fff; border: 1px solid #e1e6ec; border-radius: 8px;
  padding: 16px 18px; margin-bottom: 16px;
}
.flash {
  background: #e6f4ea; border: 1px solid #b7dfc2; color: #1d6b34;
  padding: 10px 14px; border-radius: 6px; margin-bottom: 14px;
}
label { display: block; font-weight: 600; margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; max-width: 640px; padding: 8px 10px; border: 1px solid #c8d1db;
  border-radius: 6px; font-size: 14px; font-family: inherit; background: #fff;
}
textarea { min-height: 120px; }
.btn {
  display: inline-block; border: none; border-radius: 6px; padding: 9px 18px;
  font-size: 14px; cursor: pointer; background: #3b8ef3; color: #fff;
  text-decoration: none; font-family: inherit;
}
.btn:hover { background: #2f7cd8; }
.btn.secondary { background: #64748b; }
.btn.danger { background: #d9534f; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.row { display: flex; gap: 18px; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 260px; }

table.grid { border-collapse: collapse; width: 100%; background: #fff; }
table.grid th, table.grid td {
  border: 1px solid #e1e6ec; padding: 6px 10px; text-align: left;
}
table.grid th { background: #f0f3f6; font-weight: 600; }
table.grid input { max-width: 110px; padding: 4px 6px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; }
.badge.done, .badge.csv_done { background: #e6f4ea; color: #1d6b34; }
.badge.running, .badge.pending { background: #fff4d6; color: #8a6100; }
.badge.failed, .badge.error { background: #fde8e8; color: #a03030; }
.badge.uploaded, .badge.composited, .badge.downloaded { background: #e3edff; color: #2456a6; }

.tpl-grid { display: flex; flex-wrap: wrap; gap: 14px; }
.tpl-card {
  width: 170px; background: #fff; border: 1px solid #e1e6ec; border-radius: 8px;
  padding: 8px; text-align: center;
}
.tpl-card img { width: 100%; height: 150px; object-fit: contain; background: #fafbfc; }
.tpl-card.inactive { opacity: 0.45; }
.tpl-card .meta { font-size: 12px; color: #5b6572; margin: 6px 0; }

#logbox {
  background: #10161d; color: #cfe3f5; font-family: Consolas, monospace;
  font-size: 12.5px; padding: 12px; border-radius: 6px; height: 320px;
  overflow-y: auto; white-space: pre-wrap;
}
#logbox .warn { color: #ffd479; }
#logbox .error { color: #ff8f8f; }

.editor-wrap { display: flex; gap: 14px; align-items: flex-start; }
.col-title { font-size: 12px; font-weight: 700; color: #5b6572; margin-bottom: 6px; text-transform: uppercase; }
.style-col, .color-col {
  flex-shrink: 0; max-height: 86vh; overflow-y: auto; padding-right: 2px;
}
.style-col { width: 112px; }
.color-col { width: 60px; }
.style-item {
  display: block; text-align: center; background: #fff; border: 2px solid #e1e6ec;
  border-radius: 8px; padding: 4px; margin-bottom: 8px; text-decoration: none;
  color: #1e2530; font-size: 11.5px; line-height: 1.25;
}
.style-item img { width: 100%; height: 74px; object-fit: cover; border-radius: 5px; }
.style-item.current { border-color: #3b8ef3; box-shadow: 0 0 0 1px #3b8ef3; }
.style-item:hover { border-color: #9db8d4; }
.color-item {
  display: block; border: 2px solid #e1e6ec; border-radius: 6px;
  margin-bottom: 6px; overflow: hidden;
}
.color-item img { width: 100%; height: 48px; object-fit: cover; display: block; }
.color-item.current { border-color: #e02020; box-shadow: 0 0 0 1px #e02020; }
.color-item:hover { border-color: #9db8d4; }
.color-item.inactive { opacity: 0.4; }
.region-inputs {
  display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 6px 8px;
  align-items: center;
}
.region-inputs span { font-size: 12px; color: #5b6572; font-weight: 600; }
.region-inputs input { width: 100%; max-width: none; padding: 5px 8px; }
#editor-canvas {
  border: 1px solid #cdd6df; background: #fff; cursor: crosshair;
  max-width: 100%; height: auto; /* co theo màn hình nhưng giữ đúng tỉ lệ */
}
.editor-side { width: 300px; flex-shrink: 0; }
.editor-side .card { position: sticky; top: 10px; }
#preview-img { max-width: 100%; border: 1px solid #cdd6df; border-radius: 6px; margin-top: 10px; }

.login-box {
  max-width: 360px; margin: 120px auto; background: #fff; padding: 28px;
  border-radius: 10px; border: 1px solid #e1e6ec;
}
.error-text { color: #a03030; margin-top: 8px; }
.muted { color: #6b7683; font-size: 13px; }
.progress { background: #e6ebf0; border-radius: 8px; height: 14px; overflow: hidden; max-width: 480px; }
.progress > div { background: #3b8ef3; height: 100%; transition: width .3s; }
.progress.big { height: 24px; position: relative; border: 1px solid #c8d1db; }
.progress.big > div { background: linear-gradient(90deg, #3b8ef3, #55b06a); }
.progress.big > span {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #1e2530; text-shadow: 0 0 3px #fff;
}

.set-chips { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.chip {
  border: 2px solid #c8d1db; background: #f6f8fa; border-radius: 18px;
  padding: 7px 16px; font-size: 14px; cursor: pointer; font-family: inherit;
  color: #1e2530;
}
.chip:hover { border-color: #9db8d4; }
.chip.active { border-color: #3b8ef3; background: #e3edff; font-weight: 700; }
.chip-count {
  background: #fff; border-radius: 10px; padding: 1px 8px; font-size: 12px;
  margin-left: 4px; color: #2456a6; border: 1px solid #c8d1db;
}
.chip.active .chip-count { background: #3b8ef3; color: #fff; border-color: #3b8ef3; }
.chip-new { display: flex; gap: 6px; align-items: center; margin-left: 8px; }
.chip-new input { max-width: 180px; padding: 6px 10px; }

.notice {
  background: #fff8e1; border: 1px solid #f0d47a; color: #7a5c00;
  padding: 12px 14px; border-radius: 8px; margin-top: 12px; font-size: 14px;
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
}
