:root {
  --bg: #f5f6fa;
  --card: #ffffff;
  --text: #1f2330;
  --muted: #6b7180;
  --line: #e3e5ec;
  --primary: #3b5bdb;
  --primary-soft: #edf1ff;
  --danger: #d6336c;
  --ok: #2b8a3e;
  --radius: 10px;
}

* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.55 system-ui, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); display: flex; min-height: 100vh; }
h1 { font-size: 24px; margin: 4px 0 0; }
h3 { margin: 0 0 6px; font-size: 16px; }
a { color: var(--primary); text-decoration: none; }
.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

/* Sidebar */
#sidebar { width: 220px; background: #161a26; color: #fff; padding: 20px 14px; display: flex; flex-direction: column; gap: 24px; position: sticky; top: 0; height: 100vh; }
#sidebar .brand { font-weight: 700; font-size: 17px; padding: 0 8px; }
#sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
#sidebar nav a { color: #c9cdd8; padding: 9px 10px; border-radius: 8px; }
#sidebar nav a.active, #sidebar nav a:hover { background: #262c3d; color: #fff; }
#sidebar .user { display: flex; flex-direction: column; gap: 8px; padding: 0 8px; font-size: 13px; color: #c9cdd8; }
body.auth #sidebar { display: none; }

#view { flex: 1; padding: 28px 32px; max-width: 1200px; min-width: 0; }
body.auth #view { display: flex; align-items: center; justify-content: center; max-width: none; }

/* Controls */
input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; }
textarea { min-height: 80px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 500; margin-bottom: 12px; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; margin: 4px 0; }
label.check input { width: auto; }
button { background: var(--primary); color: #fff; border: 0; border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .55; cursor: wait; }
button.ghost { background: transparent; color: var(--primary); border: 1px solid var(--line); }
button.danger { color: var(--danger); }
button.small { padding: 5px 10px; font-size: 13px; }

/* Layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.grid3 .card { display: flex; flex-direction: column; gap: 10px; margin: 0; }
.grid3 .card button { align-self: flex-start; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 18px; gap: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.product-bar { margin-bottom: 18px; }
.product-bar select { min-width: 280px; }

/* Auth */
.auth-card { width: 380px; }
.auth-card h1 { margin-bottom: 16px; }

/* Lists */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; }
td.title { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; background: var(--primary-soft); color: var(--primary); font-size: 12px; }
.project-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.project-list a.card { color: inherit; margin: 0; }
.project-list a.card:hover { border-color: var(--primary); }
.tree, .tree ul { list-style: none; padding-left: 18px; margin: 0; }
.tree { padding-left: 0; max-height: 320px; overflow: auto; }
.scroll { max-height: 320px; overflow: auto; }
.flash { padding: 10px 14px; border-radius: 8px; background: var(--primary-soft); margin-bottom: 18px; font-size: 14px; }
.flash ul { margin: 6px 0 0; padding-left: 18px; color: var(--danger); }

/* Create */
.tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.tools button { background: #fff; color: var(--text); border: 1px solid var(--line); }
.tools button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.create-layout { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }
.output img { max-width: 100%; border-radius: 8px; }

/* Hình ảnh sản phẩm */
a.button { display: inline-block; padding: 9px 16px; border-radius: 8px; font-weight: 600; border: 1px solid var(--line); }
button, a.button { white-space: nowrap; }
.row > select { width: auto; flex: none; }
.row input[type=file] { flex: 1; min-width: 0; }
.checker { background: repeating-conic-gradient(#b9c0c8 0% 25%, #dde1e6 0% 50%) 0 0 / 16px 16px; }  /* đủ tối để thấy logo trắng */
.brand-grid { display: grid; grid-template-columns: 240px 1fr; gap: 24px; margin-top: 10px; }
.brand-grid > div { display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
.logo-preview { width: 200px; height: 120px; object-fit: contain; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.logo-preview.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.row .logo-preview { width: 120px; height: 72px; }
.colors { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.colors input[type=color], .color-field input[type=color] { width: 44px; height: 38px; padding: 2px; flex: none; }
.color-field { margin-bottom: 12px; }
.gift-box { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.swatch { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); display: inline-block; }
.badge.ok { background: #ebfbee; color: var(--ok); }
.badge.warn { background: #fff4e6; color: #d9480f; }
.slots { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.slots .card { margin: 0; }
.slot-head { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.slot-head .badge { white-space: nowrap; }
.outputs figure { margin: 0; text-align: center; }
.outputs { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-top: 12px; }
.outputs img { width: 100%; border-radius: 6px; border: 1px solid var(--line); display: block; }
.outputs figcaption { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 4px; font-size: 13px; }
details summary { cursor: pointer; margin-top: 8px; }
.photo-grid { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px; }
.photo-grid figure { margin: 0; width: 110px; }
.photo-grid img { width: 110px; height: 110px; object-fit: contain; border-radius: 6px; border: 1px solid var(--line); display: block; }
.photo-grid figcaption { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.slot img.result, .thumb-layout img.result { width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; margin-bottom: 10px; }
.placeholder { aspect-ratio: 1 / 1; display: flex; align-items: center; justify-content: center; background: #f2f3f7; border-radius: 8px; margin-bottom: 10px; }
.error-text { color: var(--danger); }
.thumb-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; margin-top: 12px; }
.template-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.template-card { margin: 0; display: flex; flex-direction: column; gap: 4px; }
.template-card img.result { width: 100%; border-radius: 8px; border: 1px solid var(--line); display: block; margin-bottom: 6px; cursor: pointer; }
.field-title { font-weight: 500; margin-bottom: 5px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }

/* Settings */
.task { display: grid; grid-template-columns: 200px 140px 1fr; gap: 10px; align-items: center; margin-bottom: 10px; }
.note { background: #fff8e6; border: 1px solid #f5e1a4; border-radius: 8px; padding: 10px 14px; font-size: 14px; margin-bottom: 14px; }

/* Markdown */
.md table { margin: 10px 0; }
.md td, .md th { border: 1px solid var(--line); padding: 6px 8px; }
.md pre { background: #f2f3f7; padding: 10px; border-radius: 8px; overflow: auto; }
.pre { white-space: pre-wrap; font-size: 13px; max-height: 60vh; overflow: auto; background: #f7f8fb; padding: 12px; border-radius: 8px; }

/* Modal & toast */
.modal { position: fixed; inset: 0; background: rgba(15, 18, 30, .45); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 10; }
.modal-box { background: #fff; border-radius: var(--radius); width: min(900px, 100%); max-height: 90vh; overflow: auto; padding: 18px 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.toast { position: fixed; bottom: 22px; right: 22px; background: #161a26; color: #fff; padding: 11px 16px; border-radius: 8px; max-width: 420px; z-index: 20; }
.toast.error { background: var(--danger); }

@media (max-width: 900px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; }
  #sidebar nav { flex-direction: row; }
  #view { padding: 18px 16px; }
  .grid3, .create-layout, .task, .slots, .brand-grid, .colors, .grid-2, .grid-3, .thumb-layout { grid-template-columns: 1fr; }
}
