/*
 * PVKhanh Auto — the shell every app shares: colours, top bar, app switcher, menus,
 * mobile drawer, dialogs and toasts. Every rule is scoped to a .ux-* class, so it also
 * sits safely on top of Tailwind in Lương (React). Element defaults live in ui.css.
 */
:root {
  --brand: #4f46e5; --brand-hover: #4338ca; --brand-soft: #eef2ff; --brand-soft-2: #e0e7ff; --brand-ink: #3730a3;
  --bg: #f8fafc; --surface: #fff; --surface-2: #f1f5f9;
  --line: #e2e8f0; --line-strong: #cbd5e1;
  --text: #0f172a; --text-2: #334155; --muted: #64748b; --subtle: #94a3b8;
  --ok: #15803d; --ok-bg: #dcfce7; --ok-soft: #f0fdf4;
  --err: #dc2626; --err-ink: #b91c1c; --err-bg: #fee2e2; --err-soft: #fef2f2;
  --warn: #b45309; --warn-bg: #fef3c7; --warn-soft: #fffbeb;
  --info: #1d4ed8; --info-bg: #dbeafe; --info-soft: #eff6ff;
  --radius: 12px; --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 12px 32px -8px rgba(15, 23, 42, .22), 0 4px 10px -4px rgba(15, 23, 42, .1);
  --font: 'Be Vietnam Pro', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --top-h: 60px;
  --wrap: 1200px;
  --top-bg: rgba(255, 255, 255, .92); --row-hover: #fafbfd; --toast-bg: #0f172a; --backdrop: rgba(15, 23, 42, .45);
  --ok-line: #bbf7d0; --ok-ink: #14532d; --err-line: #fecaca; --err-ink-2: #7f1d1d; --warn-line: #fde68a; --warn-ink: #78350f;
  --brand-line: #c7d2fe; --glow-1: #e0e7ff; --glow-2: #ede9fe;
  color-scheme: light;
}

/* dark: chosen in the account menu (Sáng / Tối / Tự động), set on <html data-theme> before
   the page paints (partials/theme.blade.php), shared by every app through a cookie */
:root[data-theme="dark"] {
  --brand: #6366f1; --brand-hover: #818cf8; --brand-soft: rgba(99, 102, 241, .16); --brand-soft-2: rgba(99, 102, 241, .28); --brand-ink: #c7d2fe;
  --bg: #0b1120; --surface: #121a2a; --surface-2: #1a2436;
  --line: #243045; --line-strong: #33415a;
  --text: #e8edf5; --text-2: #c9d3e0; --muted: #8e9bb0; --subtle: #66748b;
  --ok: #4ade80; --ok-bg: rgba(34, 197, 94, .16); --ok-soft: rgba(34, 197, 94, .08);
  --err: #f87171; --err-ink: #fca5a5; --err-bg: rgba(239, 68, 68, .16); --err-soft: rgba(239, 68, 68, .08);
  --warn: #fbbf24; --warn-bg: rgba(245, 158, 11, .16); --warn-soft: rgba(245, 158, 11, .08);
  --info: #93c5fd; --info-bg: rgba(59, 130, 246, .18); --info-soft: rgba(59, 130, 246, .08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .6), 0 4px 12px -4px rgba(0, 0, 0, .4);
  --top-bg: rgba(18, 26, 42, .9); --row-hover: #162033; --toast-bg: #1e293b; --backdrop: rgba(2, 6, 23, .65);
  --ok-line: rgba(74, 222, 128, .3); --ok-ink: #bbf7d0; --err-line: rgba(248, 113, 113, .3); --err-ink-2: #fecaca; --warn-line: rgba(251, 191, 36, .3); --warn-ink: #fde68a;
  --brand-line: rgba(129, 140, 248, .5); --glow-1: rgba(99, 102, 241, .18); --glow-2: rgba(139, 92, 246, .12);
  color-scheme: dark;
}

/* ---------- top bar ---------- */
.ux-top { position: sticky; top: 0; z-index: 40; background: var(--top-bg); backdrop-filter: saturate(1.6) blur(10px);
  border-bottom: 1px solid var(--line); font-family: var(--font); color: var(--text); }
.ux-top-in { max-width: var(--wrap); margin: 0 auto; height: var(--top-h); padding: 0 max(1.25rem, env(safe-area-inset-right)) 0 max(1.25rem, env(safe-area-inset-left));
  display: flex; align-items: center; gap: .5rem; }
.ux-top.wide .ux-top-in { max-width: none; }
.ux-brand { display: inline-flex; align-items: center; gap: .6rem; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1rem; letter-spacing: -.01em; white-space: nowrap; }
.ux-brand:hover { text-decoration: none; color: var(--text); }
.ux-mark { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: .95rem; font-weight: 700;
  background: linear-gradient(135deg, #6366f1, #4338ca); box-shadow: 0 2px 6px rgba(79, 70, 229, .35); flex: none; }
.ux-brand b { color: var(--brand); font-weight: 700; }
.ux-slash { color: var(--line-strong); font-size: 1.3rem; font-weight: 300; margin: 0 .1rem; user-select: none; }

/* app switcher button */
.ux-app { display: inline-flex; align-items: center; gap: .45rem; height: 36px; padding: 0 .6rem 0 .5rem; border: 0; border-radius: var(--radius-sm);
  background: transparent; color: var(--text); font: 600 .95rem/1 var(--font); cursor: pointer; white-space: nowrap; }
.ux-app:hover, .ux-app[aria-expanded="true"] { background: var(--surface-2); }
.ux-app .ux-ico { color: var(--brand); }
.ux-app .ux-chev { color: var(--subtle); width: 16px; height: 16px; }

/* module navigation */
.ux-nav { display: flex; align-items: center; gap: .15rem; margin-left: .75rem; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.ux-nav::-webkit-scrollbar { display: none; }
.ux-nav a { position: relative; display: inline-flex; align-items: center; gap: .45rem; height: 36px; padding: 0 .75rem; border-radius: var(--radius-sm);
  color: var(--muted); font: 500 .9rem/1 var(--font); text-decoration: none; white-space: nowrap; transition: color .15s, background .15s; }
.ux-nav a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.ux-nav a.on { color: var(--brand-ink); background: var(--brand-soft); font-weight: 600; }
.ux-nav a .ux-ico { width: 17px; height: 17px; }

.ux-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; flex: none; }
.ux-user { display: inline-flex; align-items: center; gap: .55rem; height: 40px; padding: 0 .5rem 0 .25rem; border: 0; border-radius: 99px;
  background: transparent; color: var(--text-2); font: 500 .88rem/1 var(--font); cursor: pointer; }
.ux-user:hover, .ux-user[aria-expanded="true"] { background: var(--surface-2); }
.ux-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--brand-soft-2); color: var(--brand-ink);
  font: 700 .78rem/1 var(--font); letter-spacing: .02em; flex: none; }
.ux-user .ux-chev { width: 15px; height: 15px; color: var(--subtle); }
.ux-burger { display: none; width: 40px; height: 40px; margin-left: -.5rem; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); cursor: pointer;
  align-items: center; justify-content: center; }
.ux-burger:hover { background: var(--surface-2); }

.ux-ico { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: -.2em; }

/* light / dark switch: a button in the bar, and Sáng · Tối · Tự động in the account menu */
.ux-icon-btn { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; border: 0; border-radius: 50%;
  background: transparent; color: var(--muted); cursor: pointer; }
.ux-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.ux-icon-btn .ux-ico { width: 19px; height: 19px; }
.ux-theme-btn .ux-sun, :root[data-theme="dark"] .ux-theme-btn .ux-moon { display: none; }
:root[data-theme="dark"] .ux-theme-btn .ux-sun { display: inline-block; }
.ux-theme { padding: .45rem .65rem .55rem; }
.ux-theme > span { display: block; color: var(--muted); font: 500 .76rem/1 var(--font); margin-bottom: .45rem; }
.ux-theme-seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; padding: 3px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.ux-theme-seg button { display: inline-flex; align-items: center; justify-content: center; gap: .3rem; height: 30px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font: 500 .8rem/1 var(--font); cursor: pointer; }
.ux-theme-seg button:hover { color: var(--text); }
.ux-theme-seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow-sm); }
.ux-theme-seg .ux-ico { width: 14px; height: 14px; }

/* ---------- dropdown menus ---------- */
.ux-menu { position: relative; }
.ux-pop { position: absolute; top: calc(100% + 8px); left: 0; z-index: 60; min-width: 240px; padding: .4rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); font-family: var(--font); opacity: 0; transform: translateY(-4px); pointer-events: none;
  transition: opacity .12s, transform .12s; }
.ux-pop.right { left: auto; right: 0; }
.ux-apps .ux-pop { width: 320px; }
.ux-pop:has(.ux-theme) { min-width: 280px; }
.ux-theme-seg button { white-space: nowrap; }
.ux-menu.open > .ux-pop { opacity: 1; transform: none; pointer-events: auto; }
.ux-pop-label { padding: .45rem .65rem .3rem; color: var(--subtle); font: 600 .7rem/1 var(--font); letter-spacing: .06em; text-transform: uppercase; }
.ux-pop-head { padding: .55rem .65rem .65rem; border-bottom: 1px solid var(--line); margin-bottom: .35rem; }
.ux-pop-head strong { display: block; color: var(--text); font-size: .9rem; }
.ux-pop-head span { color: var(--muted); font-size: .8rem; }
.ux-item { display: flex; align-items: center; gap: .7rem; width: 100%; padding: .55rem .65rem; border: 0; border-radius: var(--radius-sm); background: none;
  color: var(--text-2); font: 500 .88rem/1.3 var(--font); text-align: left; text-decoration: none; cursor: pointer; }
.ux-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.ux-item.on { background: var(--brand-soft); color: var(--brand-ink); }
.ux-item .ux-ico { color: var(--muted); }
.ux-item.on .ux-ico { color: var(--brand); }
.ux-item.danger { color: var(--err-ink); }
.ux-item.danger .ux-ico { color: var(--err); }
.ux-item.danger:hover { background: var(--err-soft); }
.ux-item small { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; margin-top: .1rem; }
.ux-app-ico { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--surface-2); color: var(--text-2); }
.ux-app-ico .ux-ico { color: inherit; width: 19px; height: 19px; }
.ux-item.on .ux-app-ico { background: var(--brand); color: #fff; }
.ux-item.on .ux-app-ico .ux-ico { color: #fff; }
.ux-pop hr { border: 0; border-top: 1px solid var(--line); margin: .35rem 0; }
.ux-pop form { margin: 0; }

/* ---------- mobile drawer ---------- */
.ux-drawer { position: fixed; inset: 0; z-index: 80; font-family: var(--font); visibility: hidden; }
.ux-drawer.open { visibility: visible; }
.ux-drawer-bg { position: absolute; inset: 0; background: var(--backdrop); opacity: 0; transition: opacity .2s; }
.ux-drawer.open .ux-drawer-bg { opacity: 1; }
.ux-drawer-panel { position: absolute; top: 0; bottom: 0; left: 0; width: min(300px, 86vw); background: var(--surface); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; transform: translateX(-100%); transition: transform .22s ease-out; padding-bottom: env(safe-area-inset-bottom); }
.ux-drawer.open .ux-drawer-panel { transform: none; }
.ux-drawer-head { display: flex; align-items: center; justify-content: space-between; height: var(--top-h); padding: 0 .75rem 0 1rem; border-bottom: 1px solid var(--line); }
.ux-drawer-body { flex: 1; overflow-y: auto; padding: .5rem; }
.ux-drawer-foot { border-top: 1px solid var(--line); padding: .5rem; }
.ux-drawer .ux-item { padding: .7rem .7rem; font-size: .92rem; }

@media (max-width: 860px) {
  .ux-nav, .ux-slash, .ux-menu.ux-apps, .ux-user-name { display: none; }
  .ux-burger { display: inline-flex; }
  .ux-top-in { gap: .35rem; }
}
@media (max-width: 860px) {
  .ux-top-title { display: inline-flex; align-items: center; gap: .4rem; font: 600 .98rem/1 var(--font); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ux-top-title .ux-ico { color: var(--brand); }
  .ux-brand .ux-brand-name { display: none; }
}
@media (min-width: 861px) { .ux-top-title { display: none; } }

/* ---------- dialogs (replace alert / confirm / prompt) ---------- */
.ux-modal { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center; padding: 1rem; font-family: var(--font); }
.ux-modal-bg { position: absolute; inset: 0; background: var(--backdrop); animation: ux-fade .15s ease-out; }
.ux-modal-panel { position: relative; width: min(440px, 100%); max-height: calc(100dvh - 2rem); overflow: auto; background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-lg); padding: 1.4rem 1.4rem 1.2rem; animation: ux-pop .16s ease-out; color: var(--text); }
.ux-modal-panel.wide { width: min(640px, 100%); }
.ux-modal-top { display: flex; gap: .9rem; align-items: flex-start; }
.ux-modal-badge { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--brand-soft); color: var(--brand); }
.ux-modal-badge.danger { background: var(--err-bg); color: var(--err); }
.ux-modal-badge.warn { background: var(--warn-bg); color: var(--warn); }
.ux-modal-badge.ok { background: var(--ok-bg); color: var(--ok); }
.ux-modal-badge .ux-ico { width: 20px; height: 20px; }
.ux-modal-title { margin: .45rem 0 0; font: 600 1.05rem/1.35 var(--font); color: var(--text); }
.ux-modal-msg { margin: .45rem 0 0; color: var(--text-2); font-size: .92rem; line-height: 1.55; white-space: pre-line; }
.ux-modal-input { display: block; width: 100%; margin-top: .9rem; padding: .6rem .75rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: 400 .95rem/1.4 var(--font); }
.ux-modal-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79, 70, 229, .18); }
.ux-modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.3rem; }
.ux-modal-actions button { min-width: 88px; height: 40px; padding: 0 1rem; border-radius: var(--radius-sm); border: 1px solid var(--line-strong); background: var(--surface);
  color: var(--text-2); font: 600 .9rem/1 var(--font); cursor: pointer; }
.ux-modal-actions button:hover { background: var(--surface-2); }
.ux-modal-actions button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.ux-modal-actions button.primary:hover { background: var(--brand-hover); }
.ux-modal-actions button.danger { background: var(--err); border-color: var(--err); color: #fff; }
.ux-modal-actions button.danger:hover { background: var(--err-ink); }
.ux-modal-actions button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
@media (max-width: 520px) {
  .ux-modal { align-items: flex-end; padding: 0; }
  .ux-modal-panel { width: 100%; border-radius: 18px 18px 0 0; padding-bottom: max(1.2rem, env(safe-area-inset-bottom)); animation-name: ux-rise; }
  .ux-modal-actions { flex-direction: column-reverse; }
  .ux-modal-actions button { width: 100%; height: 44px; }
}

/* ---------- toasts ---------- */
.ux-toasts { position: fixed; z-index: 110; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; align-items: flex-end; pointer-events: none; font-family: var(--font); }
.ux-toast { pointer-events: auto; display: flex; align-items: flex-start; gap: .6rem; max-width: min(380px, calc(100vw - 2rem)); padding: .75rem .9rem; border-radius: var(--radius);
  background: var(--toast-bg); color: #f8fafc; box-shadow: var(--shadow-lg); font-size: .88rem; line-height: 1.45; animation: ux-rise .18s ease-out; }
.ux-toast .ux-ico { margin-top: .1rem; }
.ux-toast.ok .ux-ico { color: #4ade80; }
.ux-toast.err .ux-ico { color: #f87171; }
.ux-toast.warn .ux-ico { color: #fbbf24; }
.ux-toast.info .ux-ico { color: #a5b4fc; }
.ux-toast.out { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
@media (max-width: 520px) { .ux-toasts { left: 1rem; right: 1rem; align-items: stretch; bottom: max(1rem, env(safe-area-inset-bottom)); } .ux-toast { max-width: none; } }

/* long jobs (a video export): title, text, bar, "Huỷ" */
.ux-progress { width: min(360px, calc(100vw - 2rem)); align-items: center; }
.ux-progress strong { display: block; font-weight: 600; }
.ux-progress-text { color: #cbd5e1; font-size: .8rem; margin-top: .15rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ux-progress-bar { height: 5px; margin-top: .5rem; border-radius: 99px; background: rgba(255, 255, 255, .15); overflow: hidden; }
.ux-progress-bar span { display: block; height: 100%; width: 0; background: #818cf8; border-radius: 99px; transition: width .2s; }
.ux-progress-cancel { flex: none; height: 30px; padding: 0 .7rem; border: 1px solid rgba(255, 255, 255, .25); border-radius: 7px; background: transparent;
  color: #f8fafc; font: 500 .8rem/1 var(--font); cursor: pointer; }
.ux-progress-cancel:hover { background: rgba(255, 255, 255, .1); }

@keyframes ux-fade { from { opacity: 0; } }
@keyframes ux-pop { from { opacity: 0; transform: scale(.96); } }
@keyframes ux-rise { from { opacity: 0; transform: translateY(12px); } }
@media (prefers-reduced-motion: reduce) {
  .ux-modal-bg, .ux-modal-panel, .ux-toast, .ux-pop, .ux-drawer-panel, .ux-drawer-bg { animation: none !important; transition: none !important; }
}
