/* HT Việt Nam – trang quản trị. Phiên bản 1.0.5 */
body.admin { background: #F4F6F9; }
[hidden] { display: none !important; }
code { background: #EEF1F4; padding: 1px 6px; border-radius: 4px; font-size: .92em; }

/* Đăng nhập */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 36px 32px; display: flex; flex-direction: column; gap: 18px; box-shadow: 0 12px 32px rgba(14,27,44,.06); }
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand strong, .side-brand strong { display: block; color: var(--green); font-size: 17px; letter-spacing: .4px; }
.login-brand small, .side-brand small { font-size: 12px; color: var(--muted); }
.login-card h1 { font-size: 24px; }
.login-back { font-size: 14px; text-align: center; text-decoration: none; }
.login-ver { font-size: 12px; color: var(--muted); text-align: center; margin: 0; }
.btn-block { width: 100%; }

/* Bố cục */
.app { display: flex; min-height: 100vh; }
.side { width: 248px; flex: 0 0 248px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 20px 20px 16px; border-bottom: 1px solid var(--line); }
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 12px; flex: 1; }
.side-nav a { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 8px; color: #33404F; text-decoration: none; font-size: 15px; font-weight: 500; }
.side-nav a:hover { background: var(--surface); color: var(--ink); }
.side-nav a.active { background: var(--green-soft); color: var(--green-text); font-weight: 600; }
.side-foot { padding: 16px 20px 20px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; font-size: 13px; }
.side-link { font-weight: 600; text-decoration: none; }
.side-user { display: flex; flex-direction: column; gap: 4px; color: var(--muted); word-break: break-all; }
.side-ver { margin: 0; color: var(--muted); font-size: 12px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--green-text); font-weight: 600; cursor: pointer; text-align: left; min-height: 28px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: #B42318; }

.main { flex: 1; min-width: 0; padding: 32px 40px 96px; outline: none; }
.page-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; margin-bottom: 24px; }
.page-top h1 { font-size: 26px; }
.page-top .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.toolbar-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.back { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; text-decoration: none; margin-bottom: 12px; }

.panel { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 24px; }
.panel + .panel { margin-top: 20px; }
.panel h2 { font-size: 18px; margin-bottom: 16px; }
.panel .hint { font-size: 13px; color: var(--muted); margin-top: -8px; margin-bottom: 16px; }

/* Nút */
.btn-md { min-height: 42px; padding: 0 18px; font-size: 15px; }
.btn-light { background: #fff; border-color: #CBD3DD; color: var(--ink); }
.btn-light:hover { border-color: var(--green); color: var(--green-text); }
.btn-danger { background: #fff; border-color: #F1B4AE; color: #B42318; }
.btn-danger:hover { background: #FEF3F2; color: #912018; }
.btn-danger-solid { background: #B42318; color: #fff; }
.btn-danger-solid:hover { background: #912018; color: #fff; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: #33404F; cursor: pointer; }
.icon-btn:hover { border-color: var(--green); color: var(--green-text); }
.icon-btn.danger:hover { border-color: #F1B4AE; color: #B42318; }
.icon-btn[disabled] { opacity: .35; cursor: not-allowed; }

/* Trường nhập */
.fgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px 20px; }
.fgrid .full { grid-column: 1 / -1; }
.field small.help { font-size: 12px; color: var(--muted); }
.field textarea { min-height: 88px; }
.field input[type=color] { padding: 4px; height: 46px; width: 88px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 500; cursor: pointer; min-height: 32px; }
.check input { width: 18px; height: 18px; accent-color: var(--green); }
.inline-err { color: #B42318; font-size: 13px; }

/* Bảng */
.tbl-wrap { background: #fff; border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); background: #F8FAFB; padding: 12px 16px; white-space: nowrap; border-bottom: 1px solid var(--line); }
.tbl td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .t-title { font-weight: 600; color: var(--ink); }
.tbl .t-sub { font-size: 12px; color: var(--muted); margin-top: 2px; word-break: break-all; }
.tbl .t-actions { white-space: nowrap; text-align: right; }
.tbl .t-actions > * + * { margin-left: 6px; }
.tbl-empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; white-space: nowrap; }
.badge-pub { background: #E7F4EA; color: #1F6B32; }
.badge-draft { background: #EEF1F4; color: #475467; }
.badge-sched { background: #FFF4E5; color: #93510F; }
.badge-hidden { background: #FEF3F2; color: #B42318; }
.thumb { width: 64px; height: 44px; object-fit: cover; border-radius: 6px; background: var(--ph); display: block; }
.thumb-ph { width: 64px; height: 44px; border-radius: 6px; background: var(--ph); }

/* Lưới sửa danh mục */
.grid-edit td { padding: 8px 8px; }
.grid-edit td:first-child { padding-left: 16px; color: var(--muted); width: 40px; }
.grid-edit input[type=text] { width: 100%; min-width: 140px; font: inherit; font-size: 14px; padding: 9px 10px; border: 1px solid #D5DBE3; border-radius: 6px; background: #fff; }
.grid-edit input[type=text]:focus { outline: 2px solid var(--green); border-color: var(--green); }
.grid-edit tr.is-new td { background: #F6FBF3; }
.grid-edit .col-title { min-width: 260px; }

/* Danh sách khóa */
.list { display: flex; flex-direction: column; gap: 10px; }
.row-card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; align-items: center; gap: 16px; }
.row-card .rc-main { flex: 1; min-width: 0; }
.row-card .rc-title { font-weight: 600; }
.row-card .rc-sub { font-size: 13px; color: var(--muted); margin-top: 4px; }
.row-card .rc-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-card.is-hidden { opacity: .7; }

/* Soạn bài */
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.editor-side { display: flex; flex-direction: column; gap: 20px; position: sticky; top: 24px; }
.title-input { width: 100%; font: inherit; font-size: 26px; font-weight: 700; border: 0; border-bottom: 1px solid var(--line); padding: 4px 0 12px; background: transparent; color: var(--ink); }
.title-input:focus { outline: none; border-bottom-color: var(--green); }
.rte { border: 1px solid #CBD3DD; border-radius: 10px; background: #fff; }
.rte:focus-within { border-color: var(--green); box-shadow: 0 0 0 1px var(--green); }
.rte-bar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fff; border-radius: 10px 10px 0 0; z-index: 2; }
.rte-bar button { min-width: 36px; height: 36px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: none; border-radius: 6px; cursor: pointer; color: #33404F; font: inherit; font-size: 14px; font-weight: 600; }
.rte-bar button:hover { background: var(--surface); color: var(--ink); }
.rte-bar .sep { width: 1px; background: var(--line); margin: 6px 4px; }
.rte-body { min-height: 420px; padding: 20px 24px; outline: none; }
.rte-body:empty::before { content: attr(data-placeholder); color: #98A2B3; }
.status-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 14px; }
.cover-box { display: flex; flex-direction: column; gap: 10px; }
.cover-box img { width: 100%; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.cover-empty { aspect-ratio: 16 / 9; border: 1px dashed #CBD3DD; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; background: #FAFBFC; }
.img-field { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.img-field img { width: 160px; height: 90px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.img-field .cover-empty { width: 160px; aspect-ratio: auto; height: 90px; }
.save-bar { position: sticky; bottom: 0; margin: 24px -40px -96px; padding: 14px 40px; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); display: flex; justify-content: flex-end; align-items: center; gap: 12px; backdrop-filter: blur(6px); z-index: 5; }
.save-bar .dirty-note { margin-right: auto; font-size: 14px; color: #93510F; }

/* Thông báo */
.alert { font-size: 14px; padding: 10px 14px; border-radius: 8px; margin: 0; }
.alert-err { background: #FEF3F2; color: #912018; border: 1px solid #FDA29B; }
.alert-warn { background: #FFF4E5; color: #7A4510; border: 1px solid #F5C58B; }
.alert-info { background: #EFF6FF; color: #1E40AF; border: 1px solid #BFDBFE; }
.toasts { position: fixed; right: 20px; bottom: 84px; display: flex; flex-direction: column; gap: 10px; z-index: 200; max-width: min(440px, calc(100vw - 40px)); }
.toast { background: #0E1B2C; color: #fff; padding: 14px 16px; border-radius: 10px; font-size: 14px; line-height: 1.5; box-shadow: 0 12px 28px rgba(0,0,0,.2); white-space: pre-line; animation: tin .2s ease-out; }
.toast.ok { border-left: 4px solid #4CAF50; }
.toast.err { border-left: 4px solid #F04438; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* Hộp thoại */
.modal-back { position: fixed; inset: 0; background: rgba(14,27,44,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 150; }
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 24px 48px rgba(0,0,0,.2); display: flex; flex-direction: column; }
.modal-head { padding: 20px 24px 0; }
.modal-head h2 { font-size: 19px; }
.modal-body { padding: 16px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-body p { color: #33404F; line-height: 1.6; }
.modal-foot { padding: 12px 24px 20px; display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }

.loading-box { padding: 48px 0; text-align: center; color: var(--muted); }
.spinner { width: 18px; height: 18px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; display: inline-block; animation: spin .7s linear infinite; vertical-align: -3px; }

/* Điện thoại / máy tính bảng */
@media (max-width: 1100px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr); }
  .editor-side { position: static; }
}
@media (max-width: 860px) {
  .app { flex-direction: column; }
  .side { width: auto; flex: none; height: auto; position: sticky; top: 0; z-index: 20; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-brand { padding: 10px 16px; border-bottom: 0; }
  .side-brand small { display: none; }
  .side-nav { flex-direction: row; overflow-x: auto; padding: 0 8px 8px; gap: 4px; }
  .side-nav a { flex: 0 0 auto; padding: 9px 12px; font-size: 14px; }
  .side-nav a svg { display: none; }
  .side-foot { display: none; }
  .main { padding: 20px 16px 96px; }
  .save-bar { margin: 24px -16px -96px; padding: 12px 16px; }
  .mobile-foot { display: flex !important; }
  .tbl-cards thead { display: none; }
  .tbl-cards, .tbl-cards tbody, .tbl-cards tr, .tbl-cards td { display: block; width: 100%; }
  .tbl-cards tr { border-bottom: 1px solid var(--line); padding: 12px 16px; }
  .tbl-cards td { border: 0; padding: 4px 0; }
  .tbl-cards .t-actions { text-align: left; padding-top: 8px; }
  .row-card { flex-wrap: wrap; }
  .row-card .rc-actions { width: 100%; justify-content: flex-start; }
}
.mobile-foot { display: none; flex-direction: column; gap: 8px; margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }

/* 1.0.5: Thống kê */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.stat strong { font-size: 30px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.stat-sub { font-size: 12px; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 4px; height: 220px; padding-bottom: 26px; overflow-x: auto; }
.bar-col { flex: 1 0 18px; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; position: relative; }
.bar { width: 100%; max-width: 28px; background: #CFE3C4; border-radius: 4px 4px 0 0; display: flex; align-items: flex-end; min-height: 2px; }
.bar-in { width: 100%; background: var(--green); border-radius: 4px 4px 0 0; }
.bar-x { position: absolute; bottom: -22px; font-size: 10px; color: var(--muted); white-space: nowrap; }
.bar-col:nth-child(odd) .bar-x { visibility: hidden; }
.lg-box { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: -1px; }
.lg-out { background: #CFE3C4; } .lg-in { background: var(--green); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; margin-top: 20px; }
.two-col .panel + .panel { margin-top: 0; }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #22C55E; display: inline-block; }
.stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 860px) { .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .stat strong { font-size: 24px; } }
.main > .hint { font-size: 13px; color: var(--muted); line-height: 1.6; }
