/* Thumb Studio — design tokens + shared components. Page-specific styles live in generate.css / pages.css / editor.css. */

:root {
  --bg: #f5f6f8;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #f1f3f7;
  --panel-3: #e6e9f0;
  --border: #dfe3ea;
  --border-2: #c9cfda;
  --border-3: #b4bbc9;
  --text: #1b2230;
  --text-2: #3d4657;
  --muted: #667085;
  --placeholder: #98a2b3;
  --accent: #1f5fd1;
  --accent-hover: #1a52b8;
  --accent-2: #1f5fd1;
  --accent-soft: rgba(31, 95, 209, 0.10);
  --accent-contrast: #ffffff;
  --ok: #1e8e4e;
  --warn: #a86a00;
  --err: #c0392b;
  --info: #1f5fd1;
  --check-a: #eceef2;
  --check-b: #e2e5eb;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 10px 28px rgba(27, 34, 48, 0.14);
  --font: Inter, 'Be Vietnam Pro', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  --sidebar-w: 236px;
  --focus: 0 0 0 3px rgba(31, 95, 209, 0.28);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --bg-2: #161a22;
    --panel: #1b2029;
    --panel-2: #222835;
    --panel-3: #2a3140;
    --border: #2e3542;
    --border-2: #3a4252;
    --border-3: #4a5264;
    --text: #e6e9ef;
    --text-2: #c4c9d5;
    --muted: #98a2b3;
    --placeholder: #667085;
    --accent: #6ea2ff;
    --accent-hover: #8ab4ff;
    --accent-2: #6ea2ff;
    --accent-soft: rgba(110, 162, 255, 0.16);
    --accent-contrast: #0e1a33;
    --ok: #58c98a;
    --warn: #e2b04a;
    --err: #ff8474;
    --info: #6ea2ff;
    --check-a: #171b23;
    --check-b: #12151c;
    --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    --focus: 0 0 0 3px rgba(110, 162, 255, 0.35);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

body.has-modal { overflow: hidden; }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 700; }
p { margin: 0 0 8px; }
hr, .divider { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
::selection { background: var(--accent-soft); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

.icon { flex-shrink: 0; }

/* ---------- app shell ---------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--text); padding: 2px 6px; }
.brand:hover { text-decoration: none; }
.brand-logo { color: var(--accent); display: flex; }
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-weight: 800; font-size: 16px; letter-spacing: 0.2px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.sidebar-channel { display: flex; flex-direction: column; gap: 6px; padding: 0 4px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; position: relative;
}
.nav a:hover { background: var(--panel); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--text); }
.nav a.active .icon { color: var(--accent); }
.nav-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); margin-left: auto; }

.sidebar-footer { margin-top: auto; padding: 0 6px; }

.main { overflow-y: auto; min-width: 0; outline: none; }

.page { padding: 24px 28px 40px; max-width: 1600px; margin: 0 auto; }
.page-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-title { font-size: 22px; font-weight: 800; }
.page-subtitle { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.page-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.page-loading { display: grid; place-items: center; min-height: 60vh; }

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

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-nowrap { flex-wrap: nowrap; }
.col, .stack { display: flex; flex-direction: column; gap: 10px; }
.stack-sm { gap: 6px; }
.stack-lg { gap: 18px; }
.spacer { flex: 1; }
.grid-auto { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.strong { font-weight: 600; }
.mono { font-family: ui-monospace, 'Cascadia Code', Consolas, monospace; font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll-y { overflow-y: auto; }
.hidden { display: none !important; }
.sticky-bottom {
  position: sticky; bottom: 0; z-index: 5;
  background: linear-gradient(to top, var(--bg) 70%, transparent);
  padding: 14px 0 6px;
}

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--panel-2);
  color: var(--text);
  font: inherit; font-weight: 600; font-size: 13.5px;
  cursor: pointer; white-space: nowrap; user-select: none;
  transition: background 0.12s, border-color 0.12s, color 0.12s, transform 0.05s;
}
.btn:hover { background: var(--panel-3); border-color: var(--border-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--panel-2); border-color: var(--border); color: var(--text); }
.btn-danger { background: transparent; border-color: rgba(248, 113, 113, 0.45); color: var(--err); }
.btn-danger:hover { background: rgba(248, 113, 113, 0.12); border-color: var(--err); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; gap: 6px; }
.btn-lg { height: 48px; padding: 0 22px; font-size: 15.5px; border-radius: var(--radius); }
.btn-block { width: 100%; }
.btn-icon { width: 36px; padding: 0; }
.btn-icon.btn-sm { width: 30px; }
.btn.is-busy { position: relative; color: transparent !important; }
.btn.is-busy > * { visibility: hidden; }
.btn.is-busy::after {
  content: ''; position: absolute; width: 16px; height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.35); border-top-color: #fff;
  border-radius: 50%; animation: spin 0.7s linear infinite;
}

/* ---------- cards ---------- */

.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); }
.card-header { display: flex; align-items: center; gap: 10px; padding: 14px 16px 0; }
.card-title { font-size: 14.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-title .icon { color: var(--accent); }
.card-body { padding: 14px 16px 16px; }
.card-actions { margin-left: auto; display: flex; gap: 6px; }

/* ---------- forms ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--muted); }

.input, .textarea, .select {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit; font-size: 13.5px;
  padding: 8px 11px;
  transition: border-color 0.12s, box-shadow 0.12s;
}
.input, .select { height: 36px; }
.textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input::placeholder, .textarea::placeholder { color: var(--placeholder); }
.input:disabled, .textarea:disabled, .select:disabled { opacity: 0.55; }
.select {
  appearance: none; padding-right: 30px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a92a3' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 16px;
}
.select option, .select optgroup { background: var(--panel); color: var(--text); }

.checkbox { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 36px; height: 20px; border-radius: 20px; background: var(--panel-3);
  border: 1px solid var(--border-2); position: relative; transition: background 0.15s;
}
.switch-track::after {
  content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--text-2); transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .switch-track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: #fff; }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }

/* ---------- chips, badges, tabs, segmented ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 28px; padding: 0 11px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--border-2);
  color: var(--text-2); font: inherit; font-size: 12.5px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
}
.chip:hover { border-color: var(--border-3); color: var(--text); }
.chip-active, .chip.active { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  height: 20px; padding: 0 8px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--panel-3); color: var(--text-2);
}
.badge-ok { background: rgba(52, 211, 153, 0.15); color: var(--ok); }
.badge-warn { background: rgba(251, 191, 36, 0.15); color: var(--warn); }
.badge-err { background: rgba(248, 113, 113, 0.15); color: var(--err); }
.badge-muted { background: var(--panel-2); color: var(--muted); }
.badge-accent { background: var(--accent-soft); color: var(--accent); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border: 0; background: none; color: var(--muted);
  font: inherit; font-weight: 600; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab-active, .tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .badge { height: 18px; }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: var(--radius-sm);
}
.segmented-btn {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 5px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.segmented-btn:hover { color: var(--text); }
.segmented-btn.active { background: var(--panel-3); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3); }

.kbd {
  display: inline-block; padding: 1px 6px; border-radius: 5px;
  background: var(--panel-3); border: 1px solid var(--border-2);
  font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; color: var(--text-2);
}

/* ---------- images ---------- */

.thumb-16x9, .thumb-square {
  position: relative; overflow: hidden; border-radius: var(--radius-sm);
  background: var(--bg-2) repeating-conic-gradient(var(--check-a) 0 25%, var(--check-b) 0 50%) 50% / 16px 16px;
}
.thumb-16x9 { aspect-ratio: 16 / 9; }
.thumb-square { aspect-ratio: 1 / 1; }
.thumb-16x9 > img, .thumb-square > img { width: 100%; height: 100%; object-fit: cover; }
.thumb-contain > img { object-fit: contain; }

/* ---------- dropzone ---------- */

.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  padding: 22px 16px; text-align: center; cursor: pointer;
  border: 1.5px dashed var(--border-2); border-radius: var(--radius);
  background: var(--bg-2); color: var(--muted);
  transition: border-color 0.12s, background 0.12s, color 0.12s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone-over {
  outline: none; border-color: var(--accent); background: var(--accent-soft); color: var(--text);
}
.dropzone-label { font-weight: 600; color: var(--text-2); }
.dropzone-hint { font-size: 12px; }
.dropzone-compact { flex-direction: row; padding: 10px 12px; gap: 8px; }

/* ---------- empty / spinner ---------- */

.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 40px 20px; text-align: center; color: var(--muted);
}
.empty-icon {
  width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center;
  background: var(--panel-2); color: var(--muted); margin-bottom: 4px;
}
.empty-title { font-size: 15px; font-weight: 700; color: var(--text); }
.empty-text { max-width: 440px; white-space: pre-line; }
.empty .btn { margin-top: 8px; }

.spinner {
  display: inline-block; border-radius: 50%;
  border: 2px solid var(--panel-3); border-top-color: var(--accent);
  animation: spin 0.75s linear infinite; vertical-align: middle;
}
.spinner-sm { width: 14px; height: 14px; }
.spinner-md { width: 20px; height: 20px; }
.spinner-lg { width: 34px; height: 34px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(5, 6, 10, 0.72); backdrop-filter: blur(3px);
  display: grid; place-items: center; padding: 24px;
  animation: fade-in 0.14s ease-out;
}
.modal-backdrop.modal-closing { animation: fade-out 0.16s ease-in forwards; }
.modal {
  width: 100%; max-height: calc(100vh - 48px);
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border-2);
  border-radius: 16px; box-shadow: var(--shadow);
  animation: pop-in 0.16s ease-out; outline: none;
}
.modal-sm { max-width: 440px; }
.modal-md { max-width: 620px; }
.modal-lg { max-width: 900px; }
.modal-xl { max-width: 1240px; }
.modal-full { max-width: none; width: calc(100vw - 32px); height: calc(100vh - 32px); max-height: none; }
.modal-backdrop:has(.modal-full) { padding: 16px; }
.modal-header { display: flex; align-items: center; gap: 12px; padding: 16px 18px 10px; }
.modal-title { font-size: 17px; font-weight: 700; flex: 1; min-width: 0; }
.modal-body { padding: 8px 18px 18px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 18px; border-top: 1px solid var(--border);
}
.confirm-text { white-space: pre-line; color: var(--text-2); }
@keyframes fade-in { from { opacity: 0; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* ---------- lightbox ---------- */

.lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.92);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 24px; animation: fade-in 0.14s ease-out;
}
.lightbox img { max-width: 100%; max-height: calc(100vh - 110px); object-fit: contain; border-radius: 8px; cursor: zoom-out; }
.lightbox-bar { display: flex; align-items: center; gap: 10px; }
.lightbox-caption { color: var(--text-2); margin-right: 8px; }

/* ---------- toasts ---------- */

.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 300;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
  pointer-events: none;
}
.toast {
  pointer-events: auto; cursor: pointer;
  display: flex; align-items: flex-start; gap: 10px;
  max-width: 460px; padding: 11px 14px;
  background: var(--panel-2); border: 1px solid var(--border-2); border-left: 3px solid var(--info);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}
.toast-text { white-space: pre-line; word-break: break-word; }
.toast-success { border-left-color: var(--ok); } .toast-success .icon { color: var(--ok); }
.toast-error { border-left-color: var(--err); } .toast-error .icon { color: var(--err); }
.toast-warn { border-left-color: var(--warn); } .toast-warn .icon { color: var(--warn); }
.toast-info .icon { color: var(--info); }
.toast-out { opacity: 0; transform: translateX(12px); transition: all 0.2s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand-sub, .sidebar-footer { display: none; }
  .sidebar-channel { flex-direction: row; align-items: center; }
  .sidebar-channel .field-label { display: none; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a { padding: 8px 10px; }
  .main { overflow: visible; }
  .page { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ---------- Bigup: đăng nhập và tài khoản ---------- */
.login-screen { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px; background: var(--bg); z-index: 50; }
.login-card { width: min(380px, 100%); display: grid; gap: 8px; padding: 28px; border-radius: 16px; background: var(--panel); border: 1px solid var(--border); box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; color: var(--accent); }
.login-brand .brand-name { color: var(--text); }
.login-card .btn { margin-top: 8px; }
.login-error { color: var(--err); font-size: 13px; min-height: 18px; white-space: pre-line; }
.user-box { display: grid; gap: 4px; padding-bottom: 8px; }
.user-name { font-weight: 600; }
.user-actions { display: flex; flex-wrap: wrap; gap: 4px; }
