:root {
  --primary: #1a4d8f;
  --primary-dark: #0f3565;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --border: #dde3ea;
  --text: #263140;
  --text-muted: #6b7684;
  --green: #1a8f5a;
  --orange: #c9781f;
  --red: #c0392b;
  --blue: #2565c7;
  --purple: #7c4dbf;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  background: var(--primary-dark);
  color: #fff;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 58px;
}
.topbar .brand { font-weight: 600; font-size: 17px; color: #fff; }
.topbar .brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 18px; align-items: center; }
.topbar nav a { color: #dbe6f5; font-size: 14px; }
.topbar nav a.active { color: #fff; font-weight: 600; }
.topbar .user-info { font-size: 13px; color: #b9cbe6; display: flex; align-items: center; gap: 12px; }
.topbar form { margin: 0; }
.topbar button.link-btn {
  background: none; border: none; color: #dbe6f5; cursor: pointer; font-size: 13px; padding: 0;
}
.topbar button.link-btn:hover { text-decoration: underline; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

h1 { font-size: clamp(18px, 5.2vw, 22px); margin: 0 0 16px; line-height: 1.3; }
h2 { font-size: clamp(16px, 4.2vw, 18px); margin: 0 0 12px; line-height: 1.3; }

details.card > summary {
  font-size: 18px; font-weight: 700; cursor: pointer; list-style: revert; user-select: none;
}
details.card[open] > summary { margin-bottom: 12px; }
details.card > summary:hover { color: var(--primary); }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}
.stat-grid.stat-grid-5 { grid-template-columns: repeat(5, 1fr); }
.stat-card {
  display: block;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}
a.stat-card { cursor: pointer; transition: box-shadow 0.15s, border-color 0.15s; }
a.stat-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.08); border-color: var(--primary); }
.stat-card .num { font-size: 28px; font-weight: 700; }
.stat-card .label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }
.stat-card.moi .num { color: var(--blue); }
.stat-card.dang_xu_ly .num { color: var(--orange); }
.stat-card.cho_y_kien .num { color: var(--red); }
.stat-card.hoan_thanh .num { color: var(--green); }
.stat-card.qua_han { background: #fdeceb; border-color: #f0c4be; }
.stat-card.qua_han .num { color: var(--red); }
.overdue-text { color: var(--red); font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); font-size: 14px; }
th { color: var(--text-muted); font-weight: 600; font-size: 13px; }
tr:hover td { background: #fafbfd; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 600;
}
.badge.moi { background: #e5eefb; color: var(--blue); }
.badge.dang_xu_ly { background: #fbf0e0; color: var(--orange); }
.badge.cho_y_kien { background: #fbe4e1; color: var(--red); }
.badge.hoan_thanh { background: #e2f5ea; color: var(--green); }

.badge.type-tag { background: #eef0f3; color: var(--text-muted); }
.badge.lead-tag { background: #fdeecb; color: #8a5a00; font-weight: 700; }

.dept-role-table { margin-bottom: 4px; }
.dept-role-table th:last-child, .dept-role-table td:last-child { width: 140px; }

.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  text-decoration: none;
}
.btn:hover { background: var(--primary-dark); text-decoration: none; }
.btn.secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
.btn.secondary:hover { background: #eef4fc; }

form.filter-bar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; align-items: end; }
form.filter-bar .field { display: flex; flex-direction: column; gap: 4px; }
form.filter-bar label { font-size: 12px; color: var(--text-muted); }

input[type=text], input[type=date], input[type=password], select, textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 14px; }
.form-group .hint { color: var(--text-muted); font-size: 12px; margin-top: 4px; }
.form-group input[type=text], .form-group input[type=date], .form-group textarea, .form-group select {
  width: 100%;
}
.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
}
.checkbox-grid label { display: flex; align-items: center; gap: 8px; font-weight: normal; font-size: 14px; }

.dept-select-table { border: 1px solid var(--border); border-radius: 6px; }
.dept-select-table th, .dept-select-table td { padding: 8px 12px; }
.dept-select-table th:first-child, .dept-select-table td:first-child { width: 70px; text-align: center; }
.dept-select-table th:last-child, .dept-select-table td:last-child { width: 70px; text-align: center; }

.error-box { background: #fbe4e1; color: var(--red); padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.success-box { background: #e2f5ea; color: var(--green); padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }

.login-page {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
}
.login-box {
  background: #fff; padding: 36px; border-radius: 10px; width: 360px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.2);
}
.login-box h1 { text-align: center; color: var(--primary-dark); }
.login-box .subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.login-box .form-group { margin-bottom: 14px; }
.login-box .btn { width: 100%; padding: 11px; margin-top: 8px; }

.timeline { display: flex; flex-direction: column; gap: 14px; margin-top: 16px; }
.event {
  border-left: 3px solid var(--border);
  padding: 8px 0 8px 16px;
}
.event.chi_dao { border-color: var(--red); }
.event.xin_y_kien { border-color: var(--orange); }
.event.cap_nhat { border-color: var(--blue); }
.event.thao_luan { border-color: var(--purple); }
.event.ket_qua { border-color: var(--green); }
.event.ghi_chu { border-color: #b7bdc6; }
.event .meta { font-size: 12px; color: var(--text-muted); margin-bottom: 4px; }
.event .meta .tag { font-weight: 700; text-transform: uppercase; font-size: 11px; letter-spacing: 0.3px; }
.event.chi_dao .tag { color: var(--red); }
.event.xin_y_kien .tag { color: var(--orange); }
.event.cap_nhat .tag { color: var(--blue); }
.event.thao_luan .tag { color: var(--purple); }
.event.ket_qua .tag { color: var(--green); }
.event.ghi_chu .tag { color: var(--text-muted); }
.event .content { white-space: pre-wrap; line-height: 1.5; }
.event .files { margin-top: 6px; font-size: 13px; }
.event-deadline { margin-top: 6px; font-size: 13px; color: var(--red); }

.task-meta-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 24px; margin-bottom: 16px; font-size: 14px; }
.task-meta-grid dt { color: var(--text-muted); font-size: 12px; }
.task-meta-grid dd { margin: 0 0 8px; }

.doc-attachments { display: flex; flex-wrap: wrap; gap: 14px; }
.doc-thumb {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  width: 160px; text-decoration: none; color: var(--text);
  background: none; border: none; padding: 0; font-family: inherit; cursor: pointer;
}
.doc-thumb img {
  width: 160px; height: 200px; object-fit: contain;
  border: 1px solid var(--border); border-radius: 6px; background: #f4f6f9;
  transition: transform 0.15s;
}
.doc-thumb span { font-size: 12px; text-align: center; word-break: break-word; }
.doc-thumb:hover img { border-color: var(--primary); }
.doc-thumb.doc-thumb-sm { width: 90px; }
.doc-thumb.doc-thumb-sm img { width: 90px; height: 110px; }
.doc-thumb.doc-thumb-sm span { font-size: 11px; }
.doc-file {
  display: flex; align-items: center; gap: 6px; padding: 10px 14px;
  border: 1px solid var(--border); border-radius: 6px; font-size: 14px; height: fit-content;
}

.doc-attachment-item { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.doc-delete-btn {
  background: none; border: none; color: var(--red); font-size: 12px; cursor: pointer;
  padding: 2px 4px;
}
.doc-delete-btn:hover { text-decoration: underline; }

.qlvb-lightbox-overlay {
  position: fixed; inset: 0; background: rgba(10, 15, 25, 0.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 1200; padding: 8px;
}
.qlvb-lightbox { display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 100%; height: 100%; }
.qlvb-lightbox-img-wrap {
  position: relative;
  max-width: 98vw; max-height: 88vh; flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;
}
.qlvb-lightbox-img-wrap.zoomed { cursor: grab; }
.qlvb-lightbox-img-wrap.zoomed:active { cursor: grabbing; }
.qlvb-lightbox-img { max-width: 98vw; max-height: 88vh; transition: transform 0.2s; border-radius: 4px; touch-action: pan-y; }
.qlvb-lightbox-img.rot-90, .qlvb-lightbox-img.rot-270 { max-width: 88vh; max-height: 98vw; }
.qlvb-lightbox-caption { color: #fff; font-size: 13px; text-align: center; }
.qlvb-lightbox-counter { color: rgba(255,255,255,0.7); font-size: 12px; text-align: center; margin-top: -6px; }
.qlvb-lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  background: rgba(0,0,0,0.4); color: #fff; border: none; border-radius: 50%;
  width: 44px; height: 44px; font-size: 26px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center; z-index: 2;
}
.qlvb-lightbox-nav:hover { background: rgba(0,0,0,0.65); }
.qlvb-lightbox-nav.prev { left: 6px; }
.qlvb-lightbox-nav.next { right: 6px; }
@media (max-width: 700px) {
  .qlvb-lightbox-nav { width: 38px; height: 38px; font-size: 22px; }
}
.qlvb-lightbox-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.qlvb-lightbox-actions .btn, .qlvb-lightbox-actions .btn.secondary {
  background: rgba(255,255,255,0.12); color: #fff; border: 1px solid rgba(255,255,255,0.4);
}
.qlvb-lightbox-actions .btn:hover { background: rgba(255,255,255,0.22); }

.dept-list { display: flex; flex-wrap: wrap; gap: 8px; }
.dept-pill { background: #eef2f7; border-radius: 14px; padding: 4px 12px; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.dept-pill.hoan_thanh { background: #e2f5ea; color: var(--green); }

.reply-form { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 16px; }
.type-choice { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.type-choice label {
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; font-size: 13px; cursor: pointer;
}
.type-choice input { margin-right: 6px; }

.empty-state { text-align: center; color: var(--text-muted); padding: 40px 0; }

.notif-link { position: relative; display: flex; align-items: center; gap: 4px; }
.notif-badge {
  background: var(--red); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700;
  padding: 1px 6px; line-height: 1.4;
}

.notif-list { display: flex; flex-direction: column; }
.notif-item {
  display: block; padding: 12px 10px; border-bottom: 1px solid var(--border); color: var(--text);
}
.notif-item:hover { background: #fafbfd; text-decoration: none; }
.notif-item.unread { background: #eef4fc; }
.notif-item.unread .notif-message { font-weight: 700; }
.notif-item:last-child { border-bottom: none; }
.notif-message { font-size: 14px; }
.notif-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.notif-item.notif-overdue .notif-message { color: var(--red); }
.notif-item.notif-deadline_soon .notif-message { color: var(--orange); }
.notif-item.notif-ket_qua .notif-message { color: var(--green); }
.notif-item.notif-thao_luan .notif-message { color: var(--purple); }
.notif-item.notif-cap_nhat .notif-message { color: var(--blue); }

.qlvb-toast {
  position: fixed; right: 20px; bottom: 20px; z-index: 1000;
  background: var(--primary-dark); color: #fff;
  border-radius: 10px; padding: 16px 18px; max-width: 320px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
  animation: qlvb-toast-in 0.25s ease-out;
}
.qlvb-toast-msg { font-size: 14px; margin-bottom: 12px; line-height: 1.4; }
.qlvb-toast-actions { display: flex; gap: 8px; }
.qlvb-toast-actions .btn { background: #fff; color: var(--primary-dark); font-size: 13px; padding: 6px 12px; }
.qlvb-toast-actions .btn.secondary { background: transparent; color: #fff; border-color: rgba(255,255,255,0.5); }

.qlvb-notif-permission {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 999;
  background: var(--primary-dark); color: #fff;
  padding: 12px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; font-size: 13px; box-shadow: 0 -4px 16px rgba(0,0,0,0.2);
}
.qlvb-notif-permission-actions { display: flex; gap: 8px; flex-shrink: 0; }
.qlvb-notif-permission-actions .btn { background: #fff; color: var(--primary-dark); font-size: 13px; padding: 6px 12px; }
.qlvb-notif-permission-actions .btn.secondary { background: transparent; color: #fff; border-color: rgba(255,255,255,0.5); }
@keyframes qlvb-toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 700px) {
  .qlvb-toast { left: 16px; right: 16px; max-width: none; }
}

.qlvb-modal-overlay {
  position: fixed; inset: 0; background: rgba(20, 30, 45, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 1100;
  padding: 16px;
}
.qlvb-modal {
  background: #fff; border-radius: 10px; padding: 22px; max-width: 380px; width: 100%;
  box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.qlvb-modal-msg { font-size: 15px; line-height: 1.5; margin-bottom: 18px; color: var(--text); }
.qlvb-modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-chart-row { display: grid; grid-template-columns: 180px 1fr 90px; align-items: center; gap: 10px; }
.bar-chart-label { font-size: 13px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-chart-track { background: var(--bg); border-radius: 4px; height: 16px; overflow: hidden; }
.bar-chart-fill { height: 100%; border-radius: 4px; min-width: 2px; }
.bar-chart-fill.lead { background: var(--primary); }
.bar-chart-fill.late { background: var(--red); }
.bar-chart-value { font-size: 13px; color: var(--text-muted); text-align: right; white-space: nowrap; }

@media (max-width: 700px) {
  .stat-grid, .stat-grid.stat-grid-5 { grid-template-columns: repeat(2, 1fr); }
  .task-meta-grid { grid-template-columns: 1fr; }
  .checkbox-grid { grid-template-columns: 1fr; }
  .bar-chart-row { grid-template-columns: 100px 1fr 70px; }
  .bar-chart-label { font-size: 12px; }

  .container { padding: 12px; }
  .card { padding: 14px; }

  .topbar { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  .topbar nav { flex-wrap: wrap; gap: 10px; row-gap: 8px; width: 100%; }
  .topbar .user-info { width: 100%; justify-content: space-between; padding-top: 8px; border-top: 1px solid rgba(255,255,255,0.15); }

  /* Bang du lieu cuon ngang thay vi bi bop met chu tren man hinh nho */
  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  thead, tbody, tr { display: table; width: 100%; table-layout: auto; }

  /* Bang nhieu cot (danh sach cong viec...) chuyen thanh tung the xep doc,
     de doc hon la cuon ngang. */
  table.table-cards { display: block; overflow-x: visible; white-space: normal; }
  table.table-cards thead { display: none; }
  table.table-cards tbody { display: block; }
  table.table-cards tr {
    display: block; width: auto; table-layout: auto;
    border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; padding: 12px 14px;
  }
  table.table-cards td {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    padding: 7px 0; border-bottom: 1px dashed var(--border); text-align: right;
  }
  table.table-cards td:last-child { border-bottom: none; }
  table.table-cards td::before {
    content: attr(data-label); font-weight: 600; color: var(--text-muted); font-size: 12px;
    text-align: left; flex-shrink: 0;
  }
  table.table-cards td[data-label="Tiêu đề"] {
    flex-direction: column; align-items: stretch; text-align: left; gap: 4px;
  }
  table.table-cards td[data-label="Tiêu đề"]::before { margin-bottom: 2px; }
  table.table-cards td[data-label="Tiêu đề"] a { font-weight: 600; font-size: 15px; }

  form.filter-bar { flex-direction: column; align-items: stretch; }
  form.filter-bar .field { width: 100%; }
  form.filter-bar select, form.filter-bar input[type=text] { width: 100%; }

  .login-box { width: 100%; max-width: 360px; padding: 24px; }

  .doc-thumb, .doc-thumb img { width: 120px; }
  .doc-thumb img { height: 150px; }
}
