/* ============================================================
   APP SHELL + thành phần dùng chung (sidebar, topbar, card,
   bảng, badge, modal, toast, kanban, calendar...)
   Dùng kèm css/style.css (design tokens).
   ============================================================ */

.app-shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px; flex-shrink: 0; background: var(--card);
  border-right: 1px solid var(--border); padding: 18px 14px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.sidebar .brand { margin: 6px 8px 18px; }
.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 10px 12px;
  border-radius: 10px; font-size: 14px; font-weight: 500; color: var(--muted);
  cursor: pointer; border: none; background: transparent; width: 100%; text-align: left; font-family: inherit;
}
.nav-item .ic { width: 20px; text-align: center; font-size: 15px; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: #eef2ff; color: var(--primary-dark); font-weight: 600; }
.nav-item .nav-badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px;
}
.nav-item.logout { color: var(--danger); margin-top: 6px; }
.nav-item.logout:hover { background: #fee2e2; }

/* ---------- Main + Topbar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 12px 24px; display: flex; align-items: center; gap: 16px;
  position: sticky; top: 0; z-index: 20;
}
.hamburger { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.search { position: relative; flex: 1; max-width: 440px; display: flex; align-items: center;
  gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 0 12px; }
.search input { border: none; background: transparent; padding: 10px 0; box-shadow: none !important; }
.search-results {
  position: absolute; top: 110%; left: 0; right: 0; background: #fff;
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  overflow: hidden; display: none; z-index: 30;
}
.search-results.show { display: block; }
.sr-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; font-size: 13px; border-bottom: 1px solid var(--border); }
.sr-item:last-child { border-bottom: none; }
.sr-item:hover { background: var(--bg); }
.sr-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sr-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-status { color: var(--muted); font-size: 12px; }
.sr-empty { padding: 14px; color: var(--muted); font-size: 13px; text-align: center; }

.topbar-right { display: flex; align-items: center; gap: 16px; margin-left: auto; }
.bell { position: relative; font-size: 18px; }
.dot-badge { position: absolute; top: -6px; right: -10px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; }
.user { display: flex; align-items: center; gap: 9px; }
.user .avatar { width: 34px; height: 34px; border-radius: 50%; color: #fff;
  display: grid; place-items: center; font-weight: 700; }
.user .uname { font-size: 14px; font-weight: 600; }

.content { padding: 26px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; }
.page-head p { color: var(--muted); font-size: 14px; margin-top: 2px; }
.page-head .actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- Cards / grid ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px; cursor: pointer; transition: box-shadow .15s, transform .05s; }
.stat:hover { box-shadow: var(--shadow); }
.stat .top { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.stat .top .dot { width: 10px; height: 10px; border-radius: 50%; }
.stat b { font-size: 30px; display: block; margin-top: 6px; }

/* ---------- Badges ---------- */
.badge { font-size: 11px; padding: 3px 9px; border-radius: 7px; font-weight: 600; display: inline-flex; align-items: center; gap: 4px; }
.pill { font-size: 12px; padding: 3px 10px; border-radius: 20px; font-weight: 600; color: #fff; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 6px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

/* ---------- Avatars ---------- */
.av { width: 26px; height: 26px; border-radius: 50%; color: #fff; display: inline-grid; place-items: center;
  font-size: 11px; font-weight: 700; border: 2px solid #fff; }
.av-stack { display: inline-flex; }
.av-stack .av:not(:first-child) { margin-left: -8px; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: 14px; overflow: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 760px; }
table.tbl th, table.tbl td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
table.tbl th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 700; cursor: pointer; user-select: none; white-space: nowrap; }
table.tbl tbody tr:hover { background: var(--bg); }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl select { padding: 5px 8px; font-size: 13px; border-radius: 7px; }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 18px; }
.toolbar select, .toolbar input { width: auto; }
.chip { background: var(--card); border: 1px solid var(--border); color: var(--muted); padding: 7px 15px;
  border-radius: 20px; cursor: pointer; font-size: 13px; font-weight: 500; }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; align-items: start; }
.kcol { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 12px; min-height: 200px; transition: background .15s, border-color .15s; }
.kcol.drag-over { background: #eef2ff; border-color: var(--primary); }
.kcol h3 { font-size: 13px; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.kcol h3 .dot { width: 10px; height: 10px; border-radius: 50%; }
.kcol h3 .count { margin-left: auto; background: var(--bg); color: var(--muted); font-size: 12px; padding: 1px 9px; border-radius: 10px; }
.kcard { background: #fff; border: 1px solid var(--border); border-radius: 11px; padding: 12px; margin-bottom: 10px; cursor: grab; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.kcard:active { cursor: grabbing; }
.kcard .ktitle { font-weight: 600; font-size: 14px; margin-bottom: 8px; }
.kcard .kmeta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kcard .kfoot { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; }
.kcard .ktime { font-size: 11px; color: var(--muted); }
.kcard .ktime.over { color: var(--danger); font-weight: 600; }
.kadd { width: 100%; border: 1px dashed var(--border); background: transparent; color: var(--muted);
  padding: 9px; border-radius: 9px; cursor: pointer; font-size: 13px; font-weight: 600; font-family: inherit; }
.kadd:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Modal ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(17,24,39,.5); display: grid; place-items: center;
  z-index: 100; opacity: 0; transition: opacity .2s; padding: 20px; }
.modal-back.show { opacity: 1; }
.modal { background: #fff; border-radius: 16px; width: 100%; padding: 24px; max-height: 90vh; overflow: auto;
  transform: translateY(12px); transition: transform .2s; }
.modal-back.show .modal { transform: none; }
.modal h2 { font-size: 19px; margin-bottom: 4px; }
.modal .modal-sub { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.form-row { display: flex; gap: 12px; }
.form-row > .field { flex: 1; }

/* ---------- Toast ---------- */
#toast-host { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: .25s; max-width: 320px; }
.toast.show { opacity: 1; transform: none; }
.toast-ok { background: #15803d; }
.toast-error { background: #b91c1c; }
.toast-info { background: #1f2937; }

/* ---------- Member picker ---------- */
.member-picks { display: flex; flex-wrap: wrap; gap: 8px; }
.member-pick { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px 6px 8px;
  border: 1px solid var(--border); border-radius: 20px; font-size: 13px; cursor: pointer; }
.member-pick input { width: auto; }
textarea { resize: vertical; font-family: inherit; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; color: var(--muted); padding: 50px 20px; }
.empty-state .ico { font-size: 40px; margin-bottom: 10px; }
.muted { color: var(--muted); }
.checkline { display: flex; align-items: center; gap: 10px; padding: 9px 0; }
.checkline input { width: auto; }
.progress { height: 7px; background: var(--bg); border-radius: 10px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); }

/* ---------- Responsive ---------- */
@media (max-width: 980px) { .stat-grid, .kanban { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 820px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .hamburger { display: block; }
  .user .uname { display: none; }
}
@media (max-width: 620px) { .stat-grid, .kanban { grid-template-columns: 1fr; } .form-row { flex-direction: column; } }
