:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --line: #e4e6ea;
  --accent: #2d6a4f;
  --accent-soft: #e3f1ea;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warn-soft: #fff4d6;
  --radius: 10px;
  --sidebar: 220px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15171c;
    --panel: #1e2128;
    --text: #e8eaef;
    --muted: #9aa1ad;
    --line: #2d313a;
    --accent: #6fcf97;
    --accent-soft: #1f3a2d;
    --danger: #f28b82;
    --danger-soft: #3a2220;
    --warn-soft: #3a3220;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.muted { color: var(--muted); font-size: 13px; }

.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 22px; }
.brand-mark { font-size: 26px; }
.brand-name { font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  padding: 9px 12px; border-radius: 8px; color: var(--text);
}
.nav a:hover { background: var(--bg); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }

.main { flex: 1; padding: 28px 32px; max-width: 1200px; min-width: 0; }
.app.login .sidebar { display: none; }
.app.login .main { max-width: none; display: grid; place-items: center; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px;
}
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
/* Trong một hàng, ô nhập/chọn chỉ rộng theo nội dung; muốn giãn thì đặt flex:1 riêng. */
.row > select, .row > input[type=text], .row > input[type=number] { width: auto; }
.row.between { justify-content: space-between; }
.grid { display: grid; gap: 14px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 900px) {
  .grid.cols-2, .grid.cols-4 { grid-template-columns: 1fr 1fr; }
  .main { padding: 18px; }
  .sidebar { width: 170px; flex-basis: 170px; }
}

.stat { text-align: left; }
.stat .num { font-size: 28px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 14px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
textarea { min-height: 120px; resize: vertical; }
textarea.editor { min-height: 55vh; font-family: "Times New Roman", "Noto Serif", Georgia, serif; font-size: 16px; line-height: 1.7; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text); cursor: pointer;
  font: inherit; font-size: 14px; white-space: nowrap;
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 9px; font-size: 13px; }
.btn-icon { padding: 4px 8px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--bg); }
td.actions { text-align: right; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--bg); color: var(--muted);
}
.badge.published { background: var(--accent-soft); color: var(--accent); }
.badge.draft { background: var(--warn-soft); color: #8a6d00; }
.badge.completed { background: var(--accent-soft); color: var(--accent); }
.badge.paused { background: var(--danger-soft); color: var(--danger); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; background: var(--bg); font-size: 12px; margin-right: 4px; }

.cover {
  width: 120px; aspect-ratio: 2/3; border-radius: 8px; background: var(--bg); object-fit: cover;
  border: 1px solid var(--line); display: block;
}
.cover.sm { width: 36px; border-radius: 4px; }
.cover-placeholder { display: grid; place-items: center; color: var(--muted); font-size: 12px; text-align: center; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; }
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent; padding: 8px 14px;
  font: inherit; color: var(--muted); cursor: pointer; margin-bottom: -1px;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

.login-box { width: min(380px, 92vw); }
.login-box h1 { text-align: center; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px;
  font-size: 14px; z-index: 50; box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}
.toast.error { background: var(--danger); color: #fff; }

.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: grid; place-items: center; z-index: 40;
  padding: 16px;
}
.modal {
  background: var(--panel); border-radius: var(--radius); padding: 20px; width: min(720px, 100%);
  max-height: 92vh; overflow: auto; border: 1px solid var(--line);
}
.modal.wide { width: min(960px, 100%); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.empty { color: var(--muted); padding: 24px; text-align: center; }
.drag-handle { cursor: grab; color: var(--muted); user-select: none; }
.file-drop {
  border: 1px dashed var(--line); border-radius: 8px; padding: 14px; text-align: center; color: var(--muted);
}
.file-drop input { display: block; margin: 8px auto 0; }
pre.preview { background: var(--bg); padding: 10px; border-radius: 8px; max-height: 240px; overflow: auto; font-size: 13px; }
