/* =====================================================
   Sách Tây Bắc – Admin Panel Styles
   ===================================================== */
:root {
  --brand: #1f3a6e;
  --brand-light: #2a4f99;
  --moss: #2f6b3f;
  --rice: #e3a72f;
  --red: #c23b2e;
  --bg: #f0f2f7;
  --surface: #ffffff;
  --ink: #1a2035;
  --muted: #64748b;
  --line: #e2e8f0;
  --shadow: 0 4px 16px rgba(30,58,110,.1);
  --sidebar-w: 240px;
  --header-h: 64px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font: 400 15px/1.6 system-ui, 'Segoe UI', sans-serif; background: var(--bg); color: var(--ink); }
h1, h2, h3 { line-height: 1.3; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select, textarea { font: inherit; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--rice); outline-offset: 2px; }

/* ---- Login ---- */
.login-page { display: grid; place-items: center; min-height: 100vh; background: linear-gradient(135deg, var(--brand), #0e1f47); }
.login-box { background: var(--surface); border-radius: 20px; padding: 40px; width: min(400px, 92vw); box-shadow: 0 24px 64px rgba(0,0,0,.25); }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo h1 { font-size: 22px; font-weight: 700; margin-top: 10px; }
.login-logo p { color: var(--muted); font-size: 14px; }
.login-box .field { margin-bottom: 16px; }
.login-box label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.login-box input { width: 100%; height: 46px; border: 1.5px solid var(--line); border-radius: 10px; padding: 0 14px; transition: border-color .2s; }
.login-box input:focus { border-color: var(--brand); outline: none; }
.error-msg { background: #fee2e2; color: #b91c1c; padding: 10px 14px; border-radius: 8px; font-size: 14px; margin-bottom: 14px; }
.btn-primary { width: 100%; height: 48px; background: var(--brand); color: #fff; border-radius: 10px; font-weight: 600; font-size: 16px; transition: .2s; }
.btn-primary:hover { background: var(--brand-light); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }
.login-back { text-align: center; margin-top: 16px; color: var(--muted); font-size: 14px; }

/* ---- Layout ---- */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0; width: var(--sidebar-w);
  background: var(--brand); color: #fff; display: flex; flex-direction: column;
  z-index: 100; transition: transform .3s;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; font-weight: 700; font-size: 16px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 11px 18px; color: rgba(255,255,255,.75); font-weight: 500; font-size: 14px; transition: .15s; border-radius: 0; position: relative; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.12); color: #fff; text-decoration: none; }
.nav-item.active { border-left: 3px solid var(--rice); }
.nav-icon { font-size: 17px; flex: none; }
.nav-badge { background: var(--red); color: #fff; border-radius: 50%; width: 18px; height: 18px; font-size: 11px; display: grid; place-items: center; margin-left: auto; }
.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.1); display: flex; flex-direction: column; gap: 8px; }
.user-info { font-size: 13px; color: rgba(255,255,255,.7); }
.btn-logout { background: rgba(255,255,255,.1); color: #fff; border-radius: 8px; padding: 8px; font-size: 14px; transition: .2s; }
.btn-logout:hover { background: var(--red); }
.btn-site { font-size: 13px; color: rgba(255,255,255,.6); text-align: center; }
.btn-site:hover { color: #fff; text-decoration: none; }

.admin-main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.admin-header { height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 0 24px; position: sticky; top: 0; z-index: 10; }
.page-title { font-size: 20px; font-weight: 700; flex: 1; }
.menu-toggle { display: none; font-size: 22px; }
.header-actions { display: flex; gap: 10px; }
.admin-content { flex: 1; padding: 24px; }

/* ---- Responsive Sidebar ---- */
@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 4px 0 24px rgba(0,0,0,.25); }
  .admin-main { margin-left: 0; }
  .menu-toggle { display: block; }
}

/* ---- Cards & Tables ---- */
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); }
.stat-card .label { color: var(--muted); font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 32px; font-weight: 800; margin-top: 4px; }
.stat-card .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }

.card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.card-header h2 { font-size: 16px; font-weight: 700; }
.card-body { padding: 20px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--bg); text-align: left; padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
td { padding: 12px 14px; border-top: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
tr:hover td { background: #f8faff; }
.cover-thumb { width: 40px; height: 53px; border-radius: 2px 6px 6px 2px; object-fit: cover; }
.cover-thumb-div { width: 40px; height: 53px; border-radius: 2px 6px 6px 2px; }

/* ---- Buttons ---- */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 9px 18px; border-radius: 9px; font-weight: 600; font-size: 14px; transition: .2s; cursor: pointer; border: 0; }
.btn-brand { background: var(--brand); color: #fff; }
.btn-brand:hover { background: var(--brand-light); }
.btn-moss { background: var(--moss); color: #fff; }
.btn-moss:hover { opacity: .9; }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { opacity: .9; }
.btn-ghost { background: transparent; color: var(--brand); border: 1.5px solid var(--brand); }
.btn-ghost:hover { background: var(--brand); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- Status badges ---- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.badge-published { background: #d1fae5; color: #065f46; }
.badge-draft { background: #fef3c7; color: #92400e; }
.badge-archived { background: #f1f5f9; color: #64748b; }
.badge-open { background: #dbeafe; color: #1e40af; }
.badge-closed { background: #f1f5f9; color: #64748b; }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid.full { grid-template-columns: 1fr; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-weight: 600; font-size: 14px; }
.form-group input,
.form-group select,
.form-group textarea { height: 42px; border: 1.5px solid var(--line); border-radius: 9px; padding: 0 12px; transition: border-color .2s; background: var(--surface); color: var(--ink); }
.form-group textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 100px; }
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(31,58,110,.1); }
.form-group .hint { font-size: 12px; color: var(--muted); }
.form-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---- Search & Filter bar ---- */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.search-input { height: 40px; border: 1.5px solid var(--line); border-radius: 9px; padding: 0 14px; min-width: 220px; flex: 1; }
.search-input:focus { border-color: var(--brand); outline: none; }
.filter-select { height: 40px; border: 1.5px solid var(--line); border-radius: 9px; padding: 0 10px; background: var(--surface); }

/* ---- Modal ---- */
.modal { position: fixed; inset: 0; z-index: 200; display: grid; place-items: center; padding: 20px; }
.modal[hidden] { display: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(10,20,50,.5); }
.modal-box { position: relative; background: var(--surface); border-radius: 18px; width: min(640px, 100%); max-height: 90vh; overflow-y: auto; box-shadow: 0 24px 64px rgba(0,0,0,.25); }
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-title { font-size: 18px; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; background: var(--bg); font-size: 16px; }
.modal-close:hover { background: var(--red); color: #fff; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; }

/* ---- Chat ---- */
.chat-layout { display: grid; grid-template-columns: 280px 1fr; gap: 0; height: calc(100vh - var(--header-h) - 48px); }
.conv-list { background: var(--surface); border-radius: 14px 0 0 14px; border: 1px solid var(--line); overflow-y: auto; }
.conv-item { padding: 14px 16px; border-bottom: 1px solid var(--line); cursor: pointer; transition: .15s; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: #eef4ff; border-left: 3px solid var(--brand); }
.conv-item .conv-name { font-weight: 600; font-size: 14px; }
.conv-item .conv-last { color: var(--muted); font-size: 13px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item .conv-time { font-size: 11px; color: var(--muted); float: right; }
.chat-panel { display: flex; flex-direction: column; background: var(--surface); border-radius: 0 14px 14px 0; border: 1px solid var(--line); border-left: 0; }
.chat-panel-header { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; }
.chat-panel-msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.admin-msg { max-width: 80%; padding: 10px 14px; border-radius: 14px; font-size: 14px; }
.admin-msg.visitor { align-self: flex-start; background: var(--line); }
.admin-msg.admin { align-self: flex-end; background: var(--brand); color: #fff; }
.admin-msg-time { font-size: 11px; opacity: .6; margin-top: 3px; }
.admin-msg.admin .admin-msg-time { text-align: right; }
.chat-panel-input { padding: 14px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.chat-panel-input textarea { flex: 1; height: 72px; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; resize: none; font: inherit; }
.chat-panel-input textarea:focus { border-color: var(--brand); outline: none; }
.chat-empty-state { flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 15px; }

/* ---- Toast ---- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 120px); background: #1a2035; color: #fff; padding: 12px 22px; border-radius: 99px; font-weight: 500; z-index: 300; transition: .35s; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 92vw; white-space: nowrap; }
.toast.show { transform: translate(-50%, 0); }
.toast.error { background: var(--red); }
.toast.success { background: var(--moss); }

/* ---- File Upload ---- */
.upload-box { border: 2px dashed var(--line); border-radius: 12px; padding: 24px; text-align: center; cursor: pointer; transition: .2s; }
.upload-box:hover { border-color: var(--brand); }
.upload-box input[type=file] { display: none; }
.upload-preview { width: 80px; height: 107px; border-radius: 4px 10px 10px 4px; object-fit: cover; margin: 10px auto; display: block; }

/* ---- Confirm dialog ---- */
.confirm-dialog { padding: 8px 0 0; }
.confirm-dialog p { color: var(--muted); margin-bottom: 16px; }

/* ---- Loading ---- */
.loading-screen { display: grid; place-items: center; min-height: 300px; color: var(--muted); font-size: 16px; }
.spinner { width: 40px; height: 40px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Settings page ---- */
.settings-section { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 24px; margin-bottom: 20px; }
.settings-section h2 { font-size: 16px; font-weight: 700; margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }

/* ---- Responsive ---- */
@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .chat-layout { grid-template-columns: 1fr; grid-template-rows: 200px 1fr; }
  .conv-list { border-radius: 14px 14px 0 0; }
  .chat-panel { border-radius: 0 0 14px 14px; border-left: 1px solid var(--line); }
}
