/* ============================================================
   GoBranding · styles
   Dark-mode mặc định, accent đỏ thương hiệu (Thanh Wheel red).
   Mobile-first.
   ============================================================ */

:root {
  --bg: #0b0b0d;
  --bg-2: #131318;
  --bg-3: #1c1c24;
  --surface: #181820;
  --surface-2: #21212c;
  --border: #2a2a36;
  --text: #f4f4f7;
  --text-dim: #a4a4b0;
  --muted: #6c6c7a;
  --accent: #fb5a0c;       /* GoBranding orange */
  --accent-2: #ff9a1f;
  --accent-glow: rgba(255, 122, 16, 0.38);
  --danger: #f04438;
  --success: #16a34a;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-1: 0 6px 18px rgba(0,0,0,.35);
  --shadow-2: 0 12px 40px rgba(0,0,0,.55);
  --font-sans: 'Inter', 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: radial-gradient(1200px 600px at 80% -10%, rgba(255,138,21,.20), transparent 60%),
              radial-gradient(900px 500px at -10% 110%, rgba(248,80,11,.10), transparent 60%),
              var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

img { max-width: 100%; display: block; }
button { font-family: inherit; }
a { color: inherit; }

.muted { color: var(--text-dim); }
.muted.small { font-size: 12px; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(11, 11, 13, 0.75);
  backdrop-filter: saturate(160%) blur(12px);
  -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 700;
  letter-spacing: .2px;
}
.brand-logo {
  width: 34px;
  height: 34px;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px var(--accent-glow));
}
.brand-name { font-size: 16px; }
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Buttons ---------- */
.btn, .btn-ghost, .lang-toggle {
  appearance: none;
  border: 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 600;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease, color .15s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  box-shadow: 0 6px 18px var(--accent-glow);
}
.btn-primary:hover { filter: brightness(1.05); }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: #3a3a48; background: #262633; }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(240,68,56,.4);
}
.btn-danger:hover { background: rgba(240,68,56,.1); }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  padding: 8px 10px;
  border: 1px solid transparent;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border); }

.lang-toggle {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 8px 12px;
  font-size: 12.5px;
  letter-spacing: .4px;
}
.lang-toggle.is-en .vi { opacity: .45; }
.lang-toggle .sep { opacity: .35; margin: 0 4px; }

/* ---------- Forms ---------- */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--text-dim); }
.field > span { font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
.field > span em { font-style: normal; color: var(--text); font-weight: 600; font-size: 12px; }
.field input[type="email"],
.field input[type="password"],
.field input[type="text"],
.field input[type="number"],
.field select {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font: inherit;
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,122,16,.22);
}
.field input[type="color"] {
  width: 100%;
  height: 40px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}
.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.form-error {
  background: rgba(240,68,56,.1);
  border: 1px solid rgba(240,68,56,.35);
  color: #ffb4ad;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 13px;
}

/* ---------- Login ---------- */
.login-shell {
  min-height: calc(100% - 56px);
  display: grid;
  place-items: center;
  padding: 24px 18px 48px;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 22px;
  box-shadow: var(--shadow-2);
}
.login-card-head {
  text-align: center;
  margin-bottom: 20px;
}
.login-logo {
  width: 100%;
  max-width: 248px;
  height: auto;
  margin: 0 auto 14px;
  border-radius: 16px;
  filter: drop-shadow(0 10px 30px var(--accent-glow));
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
  letter-spacing: .2px;
}

/* ---------- Editor ---------- */
.editor-shell {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 12px;
  min-height: calc(100dvh - 56px);
}
.canvas-wrap {
  position: relative;
  background:
    linear-gradient(45deg, #15151c 25%, transparent 25%) 0 0 / 20px 20px,
    linear-gradient(-45deg, #15151c 25%, transparent 25%) 0 10px / 20px 20px,
    linear-gradient(45deg, transparent 75%, #15151c 75%) 10px -10px / 20px 20px,
    linear-gradient(-45deg, transparent 75%, #15151c 75%) -10px 0 / 20px 20px,
    var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 320px;
  padding: 8px;
}
#canvas {
  max-width: 100%;
  max-height: calc(100dvh - 220px);
  touch-action: none;
  user-select: none;
  cursor: grab;
  box-shadow: var(--shadow-1);
  border-radius: 6px;
  background: #000;
}
#canvas.is-dragging { cursor: grabbing; }

.canvas-empty {
  display: grid;
  justify-items: center;
  gap: 14px;
  text-align: center;
  padding: 24px;
}
.canvas-empty img { width: 110px; opacity: .85; filter: drop-shadow(0 8px 24px var(--accent-glow)); }
.canvas-empty p { color: var(--text-dim); margin: 0; }

/* Toolbar (mobile = bottom panel; desktop = right column) */
.toolbar {
  display: grid;
  gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.tool-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.tool-group.panel {
  display: grid;
  gap: 10px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
}
.tool-group .btn { flex: 1 1 auto; min-width: 120px; }

@media (min-width: 960px) {
  .editor-shell {
    grid-template-columns: minmax(0, 1fr) 320px;
    align-items: start;
  }
  .toolbar { position: sticky; top: 70px; max-height: calc(100dvh - 90px); overflow: auto; }
  #canvas { max-height: calc(100dvh - 100px); }
}

/* ---------- Admin ---------- */
.admin-shell {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px 64px;
  display: grid;
  gap: 16px;
}
.admin-head h1 { margin: 0 0 6px; font-size: 24px; }
.admin-head { display: grid; gap: 10px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; }

.admin-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: auto;
}
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  min-width: 720px;
}
.admin-table th, .admin-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table thead th {
  background: var(--bg-3);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .6px;
}
.admin-table tbody tr:hover { background: rgba(255,255,255,.02); }
.admin-table .pill {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .4px;
  text-transform: uppercase;
}
.pill-admin { background: rgba(255,122,16,.20); color: #ffb27a; }
.pill-user  { background: rgba(255,255,255,.08); color: var(--text-dim); }
.pill-on    { background: rgba(22,163,74,.18); color: #5be39b; }
.pill-off   { background: rgba(240,68,56,.18); color: #ffb4ad; }

.admin-table select, .admin-table input[type="checkbox"] {
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  font: inherit;
}
.admin-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-1);
  z-index: 50;
}
.toast.is-error { border-color: rgba(240,68,56,.45); color: #ffb4ad; }
.toast.is-ok { border-color: rgba(22,163,74,.45); color: #5be39b; }

/* ---------- Misc helpers ---------- */
[hidden] { display: none !important; }

::selection { background: rgba(255,122,16,.45); color: #fff; }

/* Focus outline */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* iOS safe areas */
@supports (padding: max(0px)) {
  .topbar { padding-left: max(14px, env(safe-area-inset-left)); padding-right: max(14px, env(safe-area-inset-right)); }
  .editor-shell, .admin-shell { padding-bottom: max(24px, env(safe-area-inset-bottom)); }
}

/* ============================================================
   v2 — mobile/iPad layout, núm kéo, bảng chọn logo
   ============================================================ */

/* Editor: khóa cuộn trang, để canvas + toolbar tự co giãn (mobile-first) */
.page-editor { height: 100dvh; overflow: hidden; overscroll-behavior: none; }
.editor-shell {
  height: calc(100dvh - 57px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
}
.canvas-wrap { flex: 1 1 auto; min-height: 0; touch-action: none; }
#canvas { max-width: 100%; max-height: 100%; }
.toolbar {
  flex: 0 0 auto;
  max-height: 46dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.tip-gesture { margin: 2px 0 0; line-height: 1.45; }

/* Nút đủ lớn để chạm trên điện thoại/iPad */
.btn { min-height: 46px; }
.tool-group .btn { min-width: 110px; }

@media (min-width: 960px) {
  .page-editor { overflow: hidden; }
  .editor-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    align-items: stretch;
    height: calc(100dvh - 57px);
    padding: 12px;
  }
  .toolbar {
    max-height: calc(100dvh - 81px);
    position: sticky;
    top: 73px;
  }
  .btn { min-height: 44px; }
}

/* ---------- Modal chọn logo ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 60;
  padding: 16px;
}
.modal {
  width: 100%;
  max-width: 560px;
  max-height: 86dvh;
  overflow: auto;
  background: linear-gradient(180deg, var(--surface), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-2);
  padding: 18px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 15px;
}
.modal-close:hover { border-color: var(--accent); }

.logo-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 12px;
}
@media (min-width: 520px) { .logo-grid { grid-template-columns: repeat(3, 1fr); } }

.logo-card {
  position: relative;
  display: grid;
  gap: 10px;
  justify-items: center;
  align-content: start;
  padding: 16px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--bg-2);
  cursor: pointer;
  text-align: center;
  font: inherit;
  color: var(--text);
  transition: border-color .15s ease, transform .08s ease, background .15s ease;
}
.logo-card:hover { border-color: var(--accent); background: #1d1d26; }
.logo-card:active { transform: translateY(1px); }
.logo-thumb {
  width: 76px;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.logo-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-thumb.placeholder {
  border-radius: 12px;
  background: repeating-linear-gradient(45deg, #1c1c24, #1c1c24 6px, #20202a 6px, #20202a 12px);
  font-size: 26px;
}
.logo-name { font-size: 13px; font-weight: 600; }
.logo-card.is-locked { cursor: not-allowed; opacity: .55; }
.logo-card.is-locked:hover { border-color: var(--border); background: var(--bg-2); transform: none; }
.logo-card.is-locked .logo-name { color: var(--text-dim); }
.lock-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0, 0, 0, .5);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: .3px;
  padding: 2px 8px;
  color: var(--text-dim);
}

/* ---------- Admin: tạo tài khoản + thao tác ---------- */
.admin-create {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.admin-create h2 { margin: 0 0 12px; font-size: 16px; }
.create-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
  align-items: end;
}
@media (min-width: 720px) {
  .create-grid { grid-template-columns: 2.2fr 2fr 1.1fr auto; }
}
.create-grid .btn { min-height: 46px; }
.admin-create .muted.small { margin: 10px 0 0; }

.admin-actions-bar { display: flex; flex-wrap: wrap; gap: 8px; }

.row-actions { display: flex; gap: 6px; white-space: nowrap; }
.btn-mini {
  padding: 7px 11px;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 8px;
  min-height: 36px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: border-color .15s ease, background .15s ease;
}
.btn-mini:hover { border-color: var(--accent); }
.btn-mini:disabled { opacity: .4; cursor: not-allowed; }
.btn-mini.danger { color: var(--danger); border-color: rgba(240,68,56,.4); background: transparent; }
.btn-mini.danger:hover { background: rgba(240,68,56,.1); }

/* ---------- Login: 2 tab Thành viên / Admin ---------- */
.login-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  margin-bottom: 16px;
}
.login-tab {
  flex: 1;
  padding: 10px 12px;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-weight: 600;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.login-tab.is-active {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: #fff;
  box-shadow: 0 4px 12px var(--accent-glow);
}

/* ---------- Modal copy tài khoản ---------- */
.cred-text {
  width: 100%;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font: inherit;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  resize: vertical;
}
.cred-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

/* ---------- CMS thương hiệu ---------- */
.brand-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
  margin-top: 14px;
}
@media (min-width: 640px) { .brand-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .brand-grid { grid-template-columns: repeat(3, 1fr); } }
.brand-card {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-2);
}
.brand-thumb {
  width: 56px; height: 56px;
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: #0d0d12;
  border-radius: 10px;
  overflow: hidden;
}
.brand-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brand-thumb.empty { color: var(--muted); font-size: 10px; text-align: center; }
.brand-info { flex: 1 1 auto; min-width: 0; }
.brand-cardname { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-status { font-size: 12px; color: var(--text-dim); }
.brand-status.locked { color: #ffb27a; }
.brand-card-actions { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Modal phân quyền ---------- */
.perm-row { display: flex; align-items: center; gap: 8px; margin: 10px 0; font-size: 14px; }
.perm-brands {
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 4px;
}
.perm-brand { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.perm-brands input[type="checkbox"], .perm-row input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--accent); flex: 0 0 auto;
}

/* ---------- Editor: nút tải logo cá nhân trong modal ---------- */
.logo-personal { margin: 6px 0 10px; }
.logo-personal .btn { width: 100%; }
