:root {
  --bg: #faf7f2; --panel: #ffffff; --ink: #1f2937; --muted: #6b7280; --line: #e7e3dc;
  --brand: #c2410c; --brand-ink: #fff7ed; --brand-soft: #fdebdd; --sage: #6b8f71; --navy: #1e3a5f;
  --danger: #b91c1c; --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(31,41,55,.06);
  --r: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #16130f; --panel: #211d18; --ink: #ece7df; --muted: #a39d93; --line: #352f27;
    --brand: #ea7a3f; --brand-ink: #1b1007; --brand-soft: #3a2416; --danger: #f87171; --shadow: none; }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 24px;
  border-bottom: 1px solid var(--line); background: var(--panel); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { font-size: 17px; display: block; line-height: 1.2; }
.brand small { color: var(--muted); font-size: 12px; }
.logo svg { width: 34px; height: 34px; display: block; }
.logo rect { fill: var(--brand); } .logo path, .logo circle { fill: var(--brand-ink); }
.pills { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.pill { font-size: 12.5px; padding: 3px 10px; border-radius: 99px; background: var(--brand-soft); color: var(--brand); white-space: nowrap; }
.pill.warn { background: #fee2e2; color: var(--danger); }

.layout { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; gap: 24px; padding: 24px; max-width: 1600px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 10px; align-self: start; position: sticky; top: 82px; max-height: calc(100vh - 100px); overflow: auto; }
.lbl { font-weight: 600; font-size: 13.5px; display: block; margin-top: 4px; }
.lbl small, .check small { font-weight: 400; color: var(--muted); }
textarea, select, input[type=search] { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 9px 11px; outline: none; }
textarea { resize: vertical; min-height: 80px; }
textarea:focus, select:focus, input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.check input { margin-top: 4px; accent-color: var(--brand); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { border: 1px solid var(--line); background: var(--bg); border-radius: 99px; padding: 5px 11px; font-size: 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px; }
.chips button:hover { border-color: var(--brand); }
.chips button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.goi-y button { font-size: 12.5px; color: var(--muted); }
.r { display: inline-block; width: calc(var(--w) / max(var(--w), var(--h)) * 14px); height: calc(var(--h) / max(var(--w), var(--h)) * 14px);
  border: 1.5px solid currentColor; border-radius: 2px; }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 14px; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { padding: 12px; font-size: 16px; margin-top: 6px; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger.confirm { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn:disabled { opacity: .55; cursor: wait; }
kbd { font: 11px ui-monospace, Consolas, monospace; opacity: .75; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; }
.link { background: none; border: 0; color: var(--brand); cursor: pointer; padding: 2px 0; font-size: 13px; text-align: left; }
.note { color: var(--danger); font-size: 13.5px; margin: 0; min-height: 0; }
.note:empty { display: none; }
.hint { color: var(--muted); font-size: 12.5px; margin: 0; }

.right { min-width: 0; }
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 12px; }
.lib-head h2 { font-size: 18px; margin: 0; white-space: nowrap; }
.lib-head h2 span { color: var(--muted); font-weight: 400; font-size: 14px; }
.lib-head input { max-width: 280px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; }
.card { position: relative; border-radius: 12px; overflow: hidden; background: var(--panel); border: 1px solid var(--line); cursor: zoom-in;
  aspect-ratio: var(--ar, 3/2); }
.card img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .25s; }
.card:hover img { transform: scale(1.03); }
.card .cap { position: absolute; inset: auto 0 0 0; padding: 22px 10px 8px; font-size: 12.5px; color: #fff;
  background: linear-gradient(transparent, rgba(0,0,0,.65)); opacity: 0; transition: opacity .2s;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card:hover .cap, .card:focus-visible .cap { opacity: 1; }
.empty { color: var(--muted); text-align: center; padding: 40px 0; }
#them { margin: 16px auto; display: flex; }

.job { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 16px; box-shadow: var(--shadow); }
.job-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 10px; }
.job-head b { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-head span { color: var(--muted); font-size: 13px; white-space: nowrap; }
.job .en { color: var(--muted); font-size: 12.5px; margin: -4px 0 10px; font-style: italic; }
.job .err { color: var(--danger); font-size: 13px; margin: 8px 0 0; }
.job .warn { color: #b45309; font-size: 13px; margin: 8px 0 0; }
.job .grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.ske { aspect-ratio: var(--ar, 3/2); border-radius: 12px; background: linear-gradient(100deg, var(--line) 30%, var(--bg) 50%, var(--line) 70%);
  background-size: 300% 100%; animation: sh 1.4s infinite linear; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
@keyframes sh { from { background-position: 100% 0; } to { background-position: 0 0; } }

.modal { position: fixed; inset: 0; background: rgba(15,12,8,.72); z-index: 20; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border-radius: 16px; width: min(1280px, 100%); max-height: calc(100vh - 40px); display: grid;
  grid-template-columns: 1fr 340px; overflow: hidden; position: relative; }
.modal-img { background: #0d0b09; display: grid; place-items: center; min-height: 300px; }
.modal-img img { max-width: 100%; max-height: calc(100vh - 40px); display: block; object-fit: contain; }
.modal-info { padding: 18px; overflow: auto; max-height: calc(100vh - 40px); }
.modal-info h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 4px; }
.modal-info p { margin: 0; font-size: 14px; word-break: break-word; }
.mono { font: 12.5px/1.5 ui-monospace, Consolas, monospace; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; padding-right: 30px; }
.meta span { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 99px; padding: 2px 9px; }
.acts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 18px; }
.acts .primary { grid-column: 1 / -1; }
.x { position: absolute; top: 8px; right: 10px; z-index: 2; border: 0; background: var(--bg); width: 32px; height: 32px; border-radius: 99px;
  font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg);
  padding: 9px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 30; max-width: calc(100vw - 32px); }
.toast.on { opacity: 1; transform: translateX(-50%); }

@media (max-width: 900px) {
  .top { padding: 10px 16px; }
  .layout { grid-template-columns: 1fr; padding: 16px; gap: 16px; }
  .panel { position: static; max-height: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .modal { padding: 0; }
  .modal-box { grid-template-columns: 1fr; border-radius: 0; max-height: 100vh; height: 100vh; overflow: auto; }
  .modal-img img { max-height: 60vh; }
  .modal-info { max-height: none; }
  .lib-head input { max-width: 160px; }
}

/* ---- dùng chung: thanh trên, menu, hộp thoại ---- */
.brand { text-decoration: none; color: inherit; }
.nav { display: flex; gap: 4px; flex: 1; margin-left: 18px; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 12px; border-radius: 99px; font-size: 14px; font-weight: 600; }
.nav a:hover { color: var(--ink); background: var(--bg); }
.nav a.on { color: var(--brand); background: var(--brand-soft); }
.pills { align-items: center; }
.menu-u { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; min-width: 170px; padding: 4px; z-index: 10; }
.menu[hidden] { display: none; }
.menu button { background: none; border: 0; text-align: left; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.menu button:hover { background: var(--bg); }
.dlg { background: var(--panel); border-radius: 16px; padding: 20px; width: min(440px, 100%); display: flex; flex-direction: column; gap: 10px; }
.dlg h3 { margin: 0; }
.dlg input, .ngan-box input, .admin input, .ct-head input, .khung-sua input, .row-gap input { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 8px 10px; outline: none; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.row-gap { display: flex; gap: 8px; align-items: center; }
.row-gap.wrap { flex-wrap: wrap; }
.muted { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.lbl.sm { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 99px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.t-admin, .t-ve, .t-kich-ban, .t-dung-trang { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.t-xong { background: #dcfce7; color: #166534; border-color: transparent; }
.t-khoa, .t-loi { background: #fee2e2; color: var(--danger); border-color: transparent; }
.t-het, .t-dung { background: #fef3c7; color: #92400e; border-color: transparent; }
.bar { height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 6px; min-width: 80px; }
.bar.sm { height: 4px; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .4s; }

/* ---- đăng nhập ---- */
.trang-dn { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.dn-wrap { width: min(400px, 100%); }
.panel.dn { position: static; max-height: none; gap: 12px; padding: 26px; }
.panel.dn input { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 10px 12px; }
.panel.dn .brand { margin-bottom: 8px; }
.mk { position: relative; display: block; }
.mk .link { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }

/* ---- truyện tranh ---- */
.truyen-grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.card-truyen { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; }
.card-truyen:hover { border-color: var(--brand); }
.card-truyen .bia { aspect-ratio: 1240/1754; background: var(--bg); display: grid; place-items: center; color: var(--muted); font-size: 13px; overflow: hidden; }
.card-truyen .bia img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-truyen .tt { padding: 10px; display: flex; flex-direction: column; gap: 4px; }
.card-truyen .tt b { font-size: 14px; line-height: 1.3; }
.card-truyen small { color: var(--muted); font-size: 12px; }
.ct-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.ct-head h2 { margin: 0; font-size: 20px; flex: 1; min-width: 200px; }
.acts-row { display: flex; gap: 8px; flex-wrap: wrap; }
.ct-status { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 14px; margin-bottom: 8px; }
.ct-status .bar { flex-basis: 100%; }
.nv-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 8px 0; }
.nv { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; max-width: 360px; display: flex; flex-direction: column; gap: 2px; }
.nv small { color: var(--muted); font-size: 12px; }
.sec { font-size: 15px; margin: 22px 0 10px; }
.trang-row { display: grid; grid-template-columns: minmax(200px, 340px) 1fr; gap: 16px; align-items: start; }
.trang-anh img { width: 100%; display: block; border-radius: 8px; border: 1px solid var(--line); cursor: zoom-in; }
.trang-anh .ske { aspect-ratio: 1240/1754; }
.mini-khung { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mini-khung img, .mini-khung .ske { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 6px; }
.khung-ds { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.khung-ds details { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.khung-ds summary { display: flex; gap: 10px; align-items: center; padding: 8px; cursor: pointer; font-size: 13.5px; list-style: none; }
.khung-ds summary::-webkit-details-marker { display: none; }
.khung-ds summary img, .ske-mini { width: 56px; height: 42px; object-fit: cover; border-radius: 6px; flex: none; background: var(--line); }
.khung-ds summary span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.khung-sua { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 6px; }
.tieu-de-sua { display: flex; flex-direction: column; gap: 6px; }
.modal.zoom { cursor: zoom-out; }
.modal.zoom img { max-width: 100%; max-height: calc(100vh - 40px); border-radius: 8px; }

/* ---- admin ---- */
.admin { max-width: 1400px; margin: 0 auto; padding: 20px 24px 40px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--brand); border-color: var(--brand); }
.admin .lib-head input, .admin .lib-head select { max-width: 240px; }
.bang-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; }
.bang { width: 100%; border-collapse: collapse; font-size: 14px; }
.bang th { text-align: left; font-size: 12.5px; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.bang td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.bang tr:last-child td { border-bottom: 0; }
.bang tbody tr[data-id] { cursor: pointer; }
.bang tbody tr[data-id]:hover { background: var(--bg); }
.tr-khoa, .tr-het { opacity: .62; }
.ngan { position: fixed; inset: 0; background: rgba(15,12,8,.5); z-index: 20; display: flex; justify-content: flex-end; }
.ngan[hidden] { display: none; }
.ngan-box { background: var(--panel); width: min(480px, 100%); height: 100%; overflow: auto; padding: 18px 20px 30px; display: flex; flex-direction: column; gap: 10px; }
.ngan-head { display: flex; align-items: center; justify-content: space-between; }
.ngan-head h3 { margin: 0; }
.ngan-head .x { position: static; }
.ngan-box select, .admin select { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); padding: 8px 10px; }
.tn-ds { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.tt-gui { white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 13.5px/1.5 ui-monospace, Consolas, monospace; margin: 0; }
.the-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.the { background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 10px; padding: 12px 14px; display: flex; flex-direction: column; }
.the small { color: var(--muted); font-size: 12.5px; }
.the b { font-size: 22px; }
.cot-bd { display: flex; align-items: flex-end; gap: 4px; height: 180px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px 26px; }
.cot { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; }
.cot i { display: block; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 1px; }
.cot small { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: 10.5px; color: var(--muted); white-space: nowrap; }

@media (max-width: 900px) {
  .top { flex-wrap: wrap; }
  .nav { order: 3; flex-basis: 100%; margin: 6px 0 0; overflow-x: auto; }
  .trang-row { grid-template-columns: 1fr; }
  .trang-anh { max-width: 360px; }
  .admin { padding: 16px; }
  .admin .lib-head { flex-wrap: wrap; }
  .grid2, .tn-ds { grid-template-columns: 1fr; }
}

.ngan-box .check input, .admin .check input, .dlg .check input { width: auto; padding: 0; flex: none; }
.tn-ds .check { align-items: center; }
#them[hidden] { display: none; }
