/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
               Arial, "Noto Sans", "Liberation Sans", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  color: #1f2937;
  background: #f5f7fa;
}
h1, h2, h3, h4 { margin: 0 0 0.5em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; }
code { background: #eef2f7; padding: 1px 6px; border-radius: 4px; font-size: 0.9em; }

/* ============================================================
   Login page
   ============================================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 16px;
}
.login-container { width: 100%; max-width: 420px; }
.login-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.15);
  padding: 32px 28px;
}
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .logo { font-size: 48px; margin-bottom: 8px; }
.login-brand h1 { font-size: 1.4rem; margin: 0 0 4px; }
.login-brand .subtitle { color: #6b7280; margin: 0; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-hint {
  margin-top: 24px;
  padding: 14px;
  background: #f9fafb;
  border-radius: 8px;
  font-size: 13.5px;
  color: #4b5563;
}
.login-hint ul { margin: 6px 0 0; padding-left: 18px; }

/* ============================================================
   App shell: sidebar + main
   ============================================================ */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px;
  background: #1f2937;
  color: #d1d5db;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width 0.2s;
}
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .nav-label,
.sidebar.collapsed .brand-title,
.sidebar.collapsed .brand-sub,
.sidebar.collapsed .sidebar-footer { display: none; }
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px;
  border-bottom: 1px solid #374151;
}
.sidebar-brand .logo { font-size: 26px; }
.brand-title { font-weight: 700; color: #fff; font-size: 19px; line-height: 1.2; }
.brand-sub { font-size: 13px; color: #9ca3af; }

.nav-menu { flex: 1; padding: 8px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  border-radius: 6px;
  cursor: pointer;
  color: #d1d5db;
  user-select: none;
  font-size: 15.5px;
}
.nav-item:hover { background: #374151; }
.nav-item.active { background: #2563eb; color: #fff; }
.nav-icon { width: 20px; text-align: center; }

.sidebar-footer { padding: 12px; border-top: 1px solid #374151; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  position: sticky; top: 0; z-index: 10;
}
.topbar h1 { margin: 0; font-size: 1.3rem; flex: 1; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.icon-btn {
  background: none; border: 1px solid #e5e7eb; border-radius: 6px;
  padding: 6px 10px; cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: #f3f4f6; }

/* Dropdown năm học cố định trên topbar */
.topbar-select {
  width: auto;
  padding: 7px 14px;
  font-size: 15.5px;
  font-weight: 500;
  background: #eff6ff;
  border: 1px solid #93c5fd;
  color: #1e40af;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.topbar-select:hover { background: #dbeafe; border-color: #2563eb; }
.topbar-select:focus { outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,0.2); }

.page-content { padding: 20px; flex: 1; }
.loading { padding: 40px; text-align: center; color: #6b7280; }

/* ============================================================
   Form
   ============================================================ */
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-weight: 500; font-size: 14px; color: #374151; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
input, select, textarea {
  font-family: inherit; font-size: 15px;
  padding: 11px 14px; border: 1px solid #d1d5db; border-radius: 6px;
  background: #fff; outline: none;
  width: 100%;
}

/* Input ngày dd/mm/yyyy (thay cho <input type="date"> để hiển thị đúng locale VN) */
input.date-vi {
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px;
  min-width: 130px;
  width: auto;
}
input.date-vi::placeholder { color: #9ca3af; }

/* ============================================================
   Date picker VN — input dd/mm/yyyy + mini calendar popup
   ============================================================ */
.date-picker-vi {
  position: relative;
  display: inline-block;
}
.cal-popup {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 200;
  background: #fff;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 10px;
  width: 280px;
  user-select: none;
}
.cal-header {
  display: flex; align-items: center; gap: 4px;
  margin-bottom: 8px;
}
.cal-header select {
  flex: 1; padding: 4px 6px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 4px; background: #fff;
}
.cal-nav {
  padding: 4px 10px; font-size: 16px; font-weight: bold;
  border: 1px solid #d1d5db; border-radius: 4px; background: #fff;
  cursor: pointer; color: #374151;
}
.cal-nav:hover { background: #f3f4f6; }

.cal-weekdays {
  display: grid; grid-template-columns: repeat(7, 1fr);
  text-align: center; font-size: 12.5px; color: #6b7280;
  font-weight: 500; margin-bottom: 4px;
}
.cal-weekdays > div { padding: 2px 0; }

.cal-days {
  display: grid; grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-day {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px; color: #1f2937;
}
.cal-day:hover { background: #dbeafe; }
.cal-day.today {
  border: 1px solid #2563eb;
  font-weight: 600;
}
.cal-day.selected {
  background: #2563eb; color: #fff; font-weight: 600;
}
.cal-day.selected.today { background: #1d4ed8; border-color: #fff; }
.cal-day.cal-empty { visibility: hidden; pointer-events: none; }

.cal-footer {
  display: flex; gap: 6px; margin-top: 10px;
  padding-top: 8px; border-top: 1px solid #f3f4f6;
}
.cal-btn {
  flex: 1; padding: 6px 8px; font-size: 14px;
  border: 1px solid #d1d5db; border-radius: 4px;
  background: #fff; cursor: pointer; color: #374151;
}
.cal-btn:hover { background: #f3f4f6; }
.cal-today { color: #2563eb; border-color: #2563eb; }
.cal-clear { color: #6b7280; }
input:focus, select:focus, textarea:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
textarea { min-height: 70px; resize: vertical; }

/* ============================================================
   Button
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 10px 18px;
  border: 1px solid transparent; border-radius: 6px;
  background: #fff; color: #1f2937;
  cursor: pointer; font-weight: 500; font-size: 15px;
  transition: background 0.15s, border 0.15s;
}
.btn:hover { background: #f3f4f6; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: #2563eb; color: #fff; border-color: #2563eb; }
.btn-primary:hover { background: #1d4ed8; }
.btn-success { background: #16a34a; color: #fff; border-color: #16a34a; }
.btn-success:hover { background: #15803d; }
.btn-danger  { background: #dc2626; color: #fff; border-color: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost   { background: transparent; color: #d1d5db; border: 1px solid #4b5563; }
.btn-ghost:hover { background: #374151; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: 14px; }

/* ============================================================
   Card / panel
   ============================================================ */
.card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px; gap: 8px;
  flex-wrap: wrap;
}
.card-header h2, .card-header h3 { margin: 0; }

/* ============================================================
   Grid stats
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 16px;
}
.stat-card .label { color: #6b7280; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; }
.stat-card .value { font-size: 30px; font-weight: 700; color: #1f2937; margin-top: 4px; }
.stat-card .sub { color: #6b7280; font-size: 13px; margin-top: 4px; }
.stat-card.primary { border-left: 4px solid #2563eb; }
.stat-card.success { border-left: 4px solid #16a34a; }
.stat-card.warn    { border-left: 4px solid #f59e0b; }
.stat-card.danger  { border-left: 4px solid #dc2626; }

/* ============================================================
   Table
   ============================================================ */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%; border-collapse: collapse; font-size: 15px;
  background: #fff;
}
table.data th, table.data td {
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
  text-align: left;
}
table.data th { background: #f9fafb; font-weight: 600; color: #374151; white-space: nowrap; }
table.data td strong { font-size: 1.08em; }
table.data tr:hover td { background: #f9fafb; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td.center, table.data th.center { text-align: center; }

/* ============================================================
   Badge / status
   ============================================================ */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 500;
  background: #e5e7eb; color: #374151;
}
/* Badge chức vụ ở góc phải topbar — to hơn badge trong bảng */
#userBadge { font-size: 14.5px; padding: 5px 14px; }
.badge.blue   { background: #dbeafe; color: #1e40af; }
.badge.green  { background: #dcfce7; color: #166534; }
.badge.yellow { background: #fef3c7; color: #92400e; }
.badge.red    { background: #fee2e2; color: #991b1b; }
.badge.gray   { background: #e5e7eb; color: #374151; }

/* ============================================================
   Alert
   ============================================================ */
.alert {
  padding: 11px 14px; border-radius: 6px; font-size: 14px;
  border: 1px solid transparent;
}
.alert-error   { background: #fee2e2; border-color: #fca5a5; color: #991b1b; }
.alert-success { background: #dcfce7; border-color: #86efac; color: #166534; }
.alert-info    { background: #dbeafe; border-color: #93c5fd; color: #1e40af; }
.alert-warning { background: #fef3c7; border-color: #fcd34d; color: #92400e; }

/* ============================================================
   Modal
   ============================================================ */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 16px;
}
.modal {
  background: #fff; border-radius: 10px;
  max-width: 600px; width: 100%;
  max-height: 90vh; overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.modal-header { padding: 14px 18px; border-bottom: 1px solid #e5e7eb; display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 18px; }

/* Combobox chọn thiết bị (trong form tự do Đăng ký mượn) */
.mf-combobox .mf-list {
  position: absolute;
  top: 100%; left: 0; right: 0;
  max-height: 380px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #d1d5db;
  border-top: none;
  border-radius: 0 0 6px 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 100;
}
.mf-combobox .mf-item {
  padding: 10px 12px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
}
.mf-combobox .mf-item:last-child { border-bottom: none; }
.mf-combobox .mf-item:hover { background: #eff6ff; }
.mf-combobox .mf-item-row1 {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px;
}
.mf-combobox .mf-item-row1 strong { flex: 1; }
.mf-combobox .mf-conlai {
  font-size: 13px;
  color: #16a34a;
  font-weight: 500;
  white-space: nowrap;
}
.mf-combobox .mf-conlai.mf-het { color: #dc2626; }
.mf-combobox .mf-item-row2 {
  margin-top: 4px;
  font-size: 13px;
  color: #4b5563;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.mf-combobox .mf-empty {
  padding: 14px;
  color: #9ca3af;
  text-align: center;
  font-size: 14px;
}

/* Card hiển thị thiết bị đã chọn (dưới input search) */
.mf-selected-card {
  background: #ecfdf5;
  border-left: 4px solid #16a34a;
  border-radius: 6px;
  padding: 12px 14px;
  margin-top: 4px;
}
.mf-selected-header {
  display: flex; justify-content: space-between; align-items: start;
  gap: 8px;
  margin-bottom: 6px;
}
.mf-selected-title {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  font-size: 15px;
  flex: 1;
}
.mf-selected-title strong { font-size: 16px; }
.mf-selected-title .badge { font-size: 12.5px; }
.mf-selected-title .mf-ma {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  color: #4b5563;
}
.mf-selected-meta {
  font-size: 13.5px;
  margin-bottom: 8px;
  display: flex; flex-wrap: wrap; gap: 6px;
  align-items: center;
}
.mf-selected-mota {
  font-size: 13.5px;
  line-height: 1.6;
  color: #374151;
  white-space: pre-wrap;
  max-height: 200px;
  overflow-y: auto;
  background: #fff;
  padding: 8px 10px;
  border-radius: 4px;
  border: 1px solid #d1fae5;
}
.mf-selected-card .mf-change {
  font-size: 13px;
  padding: 5px 10px;
}
.modal-footer { padding: 12px 18px; border-top: 1px solid #e5e7eb; display: flex; gap: 8px; justify-content: flex-end; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: #6b7280; }

/* ============================================================
   Toast
   ============================================================ */
.toast-root {
  position: fixed; top: 16px; right: 16px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
}
.toast {
  background: #1f2937; color: #fff;
  padding: 12px 16px; border-radius: 6px;
  min-width: 240px; max-width: 360px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  font-size: 14.5px;
  animation: slideIn 0.2s ease-out;
}
.toast.success { background: #16a34a; }
.toast.error   { background: #dc2626; }
.toast.info    { background: #2563eb; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ============================================================
   Utility
   ============================================================ */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; } .mb-3 { margin-bottom: 12px; } .mb-4 { margin-bottom: 16px; }
.text-muted { color: #6b7280; }
.text-sm { font-size: 13px; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ============================================================
   Picker tuần học / năm học
   ============================================================ */
.tuan-hoc-picker {
  padding: 8px 10px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
}
.tuan-hoc-picker select { width: auto; min-width: 100px; }
.tuan-hoc-picker #pLabel {
  font-weight: 500; color: #2563eb;
  background: #fff; padding: 4px 8px; border-radius: 4px;
  border: 1px solid #dbeafe;
}

/* ============================================================
   Checklist tuần (cho nhân viên)
   ============================================================ */
.day-block {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 8px;
  margin-bottom: 12px; overflow: hidden;
}
.day-header {
  background: #f3f4f6; padding: 8px 14px;
  display: flex; align-items: center; justify-content: space-between;
  font-weight: 600;
}
.day-list { padding: 4px 0; }

.checklist-item {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px; border-top: 1px solid #f3f4f6;
  min-height: 44px;
}
.checklist-item:first-child { border-top: none; }
.checklist-item:hover { background: #fafbfc; }

/* Phần meta (trái) — chiếm phần còn lại, cho phép truncate */
.checklist-item .meta {
  flex: 1; min-width: 0;        /* min-width:0 quan trọng để ellipsis hoạt động */
  display: flex; flex-direction: column; gap: 1px;
}
.checklist-item .meta .ten {
  display: flex; align-items: center; gap: 6px;
  font-size: 15px; line-height: 1.4;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.checklist-item .meta .ten .badge { flex-shrink: 0; }
.checklist-item .meta .sub {
  color: #4b5563; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.checklist-item .meta .sub em { font-style: italic; }

/* Cụm bên phải: checkbox + các nút hành động — cố định, không bị co */
.checklist-item .right {
  flex-shrink: 0;
  display: flex; align-items: center; gap: 6px;
  min-width: 230px; justify-content: flex-end;
}
.checklist-item .right .row-check {
  width: 16px; height: 16px; margin: 0;
  cursor: pointer; accent-color: #2563eb;
  flex-shrink: 0;
}
.checklist-item .right .btn { padding: 4px 10px; font-size: 14px; }

/* Trên màn hình nhỏ: cụm bên phải tự wrap xuống dòng dưới */
@media (max-width: 900px) {
  .checklist-item { flex-wrap: wrap; }
  .checklist-item .right {
    width: 100%; min-width: 0;
    border-top: 1px dashed #f3f4f6; padding-top: 6px; margin-top: 4px;
    justify-content: flex-end;
  }
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .page-content { padding: 12px; }
  .topbar h1 { font-size: 1rem; }
}
