:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --ink: #1b1a17;
  --ink-2: #57534c;
  --ink-3: #8c877e;
  --line: #e8e5df;
  --line-2: #d9d5cd;
  --accent: #ff5a1f;
  --accent-ink: #ffffff;
  --accent-soft: #fff1ea;
  --ok: #1f8a4c;
  --ok-soft: #e8f6ee;
  --warn: #b26a00;
  --warn-soft: #fff5e0;
  --bad: #c4321f;
  --bad-soft: #fdecea;
  --side: #17161a;
  --side-ink: #b9b5c2;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(20, 18, 14, .04), 0 4px 16px rgba(20, 18, 14, .05);
  --f-title: #ff5a1f; --f-content: #2f6bff; --f-image: #12a36b; --f-video: #a23bdb; --f-excerpt: #d99a00; --f-link: #ff5a1f; --f-remove: #d03030;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14.5px/1.55 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: .9em; }

/* ---------- khung ---------- */
.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.shell > div { min-width: 0; }
.side { background: var(--side); color: var(--side-ink); padding: 22px 14px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 16px; padding: 0 10px 22px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: var(--side-ink); letter-spacing: .02em; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 9px; text-decoration: none; font-weight: 500; transition: background .15s, color .15s; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.on { background: rgba(255,90,31,.14); color: #fff; }
.nav a.on svg { color: var(--accent); }
.nav svg { width: 18px; height: 18px; flex: none; }
.side-foot { margin-top: auto; padding: 12px; font-size: 12px; border-top: 1px solid rgba(255,255,255,.08); }
.side-foot button { background: none; border: 0; color: var(--side-ink); padding: 0; cursor: pointer; font: inherit; text-decoration: underline; }

.main { min-width: 0; padding: 28px 36px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--ink-2); }
.topbar { display: none; }

/* ---------- thành phần ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px 22px; }
.card h2 { font-size: 16px; font-weight: 600; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.muted { color: var(--ink-3); }
.small { font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; border-radius: 9px;
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink); font: 600 13.5px/1 inherit; font-family: inherit; cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s; }
.btn:hover { background: var(--surface-2); border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: #ec4a10; }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn.icon { width: 34px; padding: 0; }

label.field { display: grid; gap: 6px; font-weight: 500; font-size: 13px; color: var(--ink-2); }
label.field .hint { font-weight: 400; color: var(--ink-3); font-size: 12px; }
input[type=text], input[type=url], input[type=password], input[type=number], select, textarea {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 9px; background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; outline: none; transition: border-color .15s, box-shadow .15s; }
textarea { height: auto; min-height: 120px; padding: 10px 12px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,90,31,.15); }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin-top: 2px; flex: none; }
.check small { display: block; color: var(--ink-3); }

.seg { display: inline-flex; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 7px 14px; border-radius: 7px; font: 600 13px inherit; font-family: inherit; color: var(--ink-2); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

.badge { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); border: 1px solid var(--line); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.live { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .25; } }

.stat { padding: 18px 20px; }
.stat .label { color: var(--ink-3); font-size: 12.5px; font-weight: 500; }
.stat .value { font-size: 30px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { color: var(--ink-3); font-size: 12px; }

.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: 10px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars i { display: block; width: 100%; max-width: 28px; background: var(--accent); border-radius: 5px 5px 2px 2px; min-height: 3px; opacity: .85; }
.bars i.zero { background: var(--line); }
.bars span { font-size: 10.5px; color: var(--ink-3); }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); padding: 10px 22px; border-bottom: 1px solid var(--line); }
td { padding: 12px 22px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td .title { font-weight: 600; }
.tbl-wrap { overflow-x: auto; }

.empty { text-align: center; padding: 48px 24px; color: var(--ink-2); }
.empty .ico { width: 54px; height: 54px; border-radius: 14px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 14px; }
.empty .ico svg { width: 26px; height: 26px; }
.empty h3 { font-size: 16px; margin-bottom: 4px; color: var(--ink); }

.recipe-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.recipe { padding: 18px 20px; display: grid; gap: 12px; }
.recipe h3 { font-size: 15.5px; }
.recipe .src { font-size: 12.5px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe .meta { display: flex; gap: 14px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.recipe .meta b { color: var(--ink); }
.recipe .actions { display: flex; gap: 8px; border-top: 1px solid var(--line); padding-top: 12px; }

.logs { background: #141317; color: #d7d3df; border-radius: 10px; padding: 14px 16px; font: 12px/1.65 ui-monospace, Consolas, monospace; max-height: 380px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.logs .ok { color: #6fdc9b; } .logs .bad { color: #ff8a7a; } .logs .warn { color: #ffcf6e; }
details.run { border-bottom: 1px solid var(--line); }
details.run:last-child { border-bottom: 0; }
details.run summary { list-style: none; cursor: pointer; padding: 14px 22px; display: grid; grid-template-columns: 1fr auto auto; gap: 14px; align-items: center; }
details.run summary::-webkit-details-marker { display: none; }
details.run summary:hover { background: var(--surface-2); }
details.run .body { padding: 0 22px 18px; }
.counts { display: flex; gap: 12px; font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- trình soạn quy trình ---------- */
.editor { display: grid; grid-template-columns: minmax(340px, 400px) 1fr; gap: 20px; align-items: start; }
.editor-form { display: grid; gap: 16px; }
.step-title { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14.5px; }
.step-num { width: 24px; height: 24px; border-radius: 7px; background: var(--ink); color: #fff; display: grid; place-items: center; font-size: 12px; flex: none; }
.picker { position: sticky; top: 20px; display: grid; grid-template-rows: auto auto 1fr; height: calc(100vh - 40px); min-height: 560px; overflow: hidden; }
.picker-bar { display: flex; gap: 8px; padding: 12px; border-bottom: 1px solid var(--line); align-items: center; }
.picker-bar input { height: 36px; }
.picker-tools { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; align-items: center; background: var(--surface-2); }
.chip { --c: var(--ink-2); display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px; border-radius: 99px; border: 1.5px solid var(--line-2);
  background: var(--surface); font: 600 12.5px inherit; font-family: inherit; color: var(--ink); cursor: pointer; transition: all .12s; }
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.chip.set::after { content: "✓"; color: var(--c); font-weight: 700; }
.chip.on { border-color: var(--c); background: color-mix(in srgb, var(--c) 10%, white); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent); }
.picker-frame { position: relative; background: #fff; }
.use-bar { flex-basis: 100%; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 4px; padding: 8px 10px; border-radius: 9px; background: #eef3ff; color: #1f3d8a; font-size: 12.5px; }
.use-bar > span { flex: 1 1 220px; }
.picker-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.picker-empty { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 30px; color: var(--ink-2); background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 12px, var(--surface) 12px, var(--surface) 24px); }
.picker-empty > div { max-width: 380px; }
.picker-hint { position: absolute; left: 12px; right: 12px; bottom: 12px; background: rgba(23,22,26,.92); color: #fff; border-radius: 10px; padding: 10px 14px; font-size: 12.5px; display: flex; gap: 10px; align-items: center; pointer-events: none; }
.picker-hint kbd { background: rgba(255,255,255,.15); border-radius: 4px; padding: 1px 6px; font: 600 11px ui-monospace, monospace; }
.loading-bar { position: absolute; top: 0; left: 0; height: 3px; background: var(--accent); animation: load 1.2s ease-in-out infinite; z-index: 2; }
@keyframes load { 0% { left: 0; width: 0; } 50% { left: 20%; width: 60%; } 100% { left: 100%; width: 0; } }

.sel-row { display: grid; grid-template-columns: 110px 1fr auto; gap: 8px; align-items: center; }
.sel-row .name { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; }
.sel-row .name::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c); flex: none; }
.sel-row input { height: 34px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.sample { font-size: 12px; color: var(--ink-3); margin: -4px 0 0 118px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.preview-article { border: 1px solid var(--line); border-radius: 10px; padding: 16px; max-height: 520px; overflow: auto; background: var(--surface); }
.preview-article h3 { font-size: 18px; margin-bottom: 8px; }
.preview-article img, .preview-article video, .preview-article iframe { max-width: 100%; height: auto; border-radius: 6px; }
.media-strip { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.media-strip > * { flex: none; width: 92px; height: 66px; border-radius: 7px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 11px; color: var(--ink-2); text-align: center; padding: 4px; word-break: break-all; overflow: hidden; }
.media-strip .vid { background: #1b1a1f; color: #fff; }

.notice { display: flex; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: #6b4300; font-size: 13px; }
.notice.info { background: #eef3ff; color: #1f3d8a; }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 8px 16px; font-size: 13.5px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; word-break: break-all; }
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }

/* ---------- đăng nhập ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { background: var(--side); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art h1 { font-size: 40px; line-height: 1.15; font-weight: 700; max-width: 460px; letter-spacing: -.02em; }
.login-art h1 em { font-style: normal; color: var(--accent); }
.login-art p { color: var(--side-ink); max-width: 420px; font-size: 15px; }
.flow { display: flex; gap: 10px; align-items: center; margin-top: 28px; flex-wrap: wrap; }
.flow span { padding: 8px 14px; border: 1px solid rgba(255,255,255,.14); border-radius: 99px; font-size: 13px; background: rgba(255,255,255,.04); }
.flow b { color: var(--accent); }
.login-form { display: grid; place-items: center; padding: 40px 24px; }
.login-form form { width: 100%; max-width: 360px; display: grid; gap: 16px; }
.login-form h2 { font-size: 24px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }

/* ---------- hộp thoại, thông báo ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20,18,16,.45); display: grid; place-items: center; z-index: 50; padding: 20px; animation: fade .15s; }
.modal { width: 100%; max-width: 620px; max-height: calc(100vh - 40px); overflow: auto; background: var(--surface); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal .card-head { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--surface); }
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 10px; font-size: 13.5px; box-shadow: 0 8px 24px rgba(0,0,0,.2); max-width: 380px; animation: slide .2s; }
.toast.bad { background: var(--bad); }
.toast.ok { background: var(--ok); }
@keyframes slide { from { transform: translateY(10px); opacity: 0; } }

/* ---------- điện thoại / máy tính bảng ---------- */
@media (max-width: 1100px) {
  .editor { grid-template-columns: 1fr; }
  .picker { position: relative; top: 0; height: 75vh; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 250px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .shell.menu-open .side { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .topbar { display: flex; align-items: center; gap: 12px; padding: 12px 16px; background: var(--side); color: #fff; position: sticky; top: 0; z-index: 30; font-weight: 700; }
  .topbar button { background: none; border: 0; color: #fff; padding: 4px; cursor: pointer; display: grid; }
  .topbar svg { width: 22px; height: 22px; }
  .main { padding: 20px 16px 48px; }
  .grid-2 { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-art { padding: 32px 24px; }
  .login-art h1 { font-size: 28px; }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: 8px; }
  .sel-row { grid-template-columns: 90px 1fr auto; }
  .picker-bar { flex-wrap: wrap; }
  .picker-bar .seg { width: 100%; }
  .picker-bar .seg button { flex: 1; }
  .picker-hint { font-size: 11.5px; padding: 8px 10px; }
  .picker-hint > span:last-child:has(kbd) { display: none; }
  .sample { margin-left: 98px; }
  th, td { padding: 10px 14px; }
}
@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat .value { font-size: 24px; }
  .page-head h1 { font-size: 22px; }
}
