:root {
  --fb-blue: #1877f2;
  --fb-blue-hover: #166fe5;
  --fb-bg: #f0f2f5;
  --fb-gray: #e4e6eb;
  --fb-gray-hover: #d8dadf;
  --fb-hover: #f2f2f2;
  --ink: #050505;
  --muted: #65676b;
  --faint: #8a8d91;
  --line: #dddfe2;
  --danger: #e41e3f;
  --ok: #31a24c;
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--fb-bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
svg { display: block; }

/* ---------- Đăng nhập ---------- */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--fb-bg);
}
.login-card {
  background: #fff;
  width: 100%;
  max-width: 400px;
  border-radius: 12px;
  padding: 32px 28px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .15);
}
.login-logo {
  display: block;
  width: 100px; height: 100px;
  margin: 0 auto 16px;
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
}
.login-card h1 { font-size: 22px; font-weight: 700; margin: 0 0 6px; text-align: center; letter-spacing: -.4px; }
.login-org { text-align: center; color: var(--fb-blue); font-weight: 600; font-size: 12.5px; margin: 0 0 10px; }
.login-card p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.login-card .primary { font-size: 17px; padding: 12px; }

/* ---------- Bố cục chính (topbar + sidebar + main) ---------- */
.app {
  height: 100vh;
  display: grid;
  grid-template-columns: 300px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas: "top top" "side main";
}

/* Thanh trên cùng — xanh Facebook */
.topbar {
  grid-area: top;
  background: var(--fb-blue);
  color: #fff;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #fff; flex-shrink: 0; }
.topbar-title { font-size: 20px; font-weight: 700; letter-spacing: -.3px; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-right: 4px; }
.topbar-user b { color: #fff; font-weight: 600; }
.topbar .pill { background: rgba(255, 255, 255, .22); color: #fff; }
.top-ic {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: rgba(255, 255, 255, .18); color: #fff;
  display: grid; place-items: center; cursor: pointer; transition: background .12s;
}
.top-ic svg { width: 20px; height: 20px; }
.top-ic:hover { background: rgba(255, 255, 255, .3); }

/* Menu trái — trắng, icon tròn nhiều màu */
.sidebar {
  grid-area: side;
  background: #fff;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 12px 10px;
  display: flex; flex-direction: column;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 7px 10px; border-radius: 8px;
  border: none; background: none; width: 100%; text-align: left;
  cursor: pointer; font-family: inherit; font-size: 15px; font-weight: 500; color: var(--ink);
  transition: background .12s;
}
.nav-item:hover { background: var(--fb-hover); }
.nav-item.active { background: #e7f3ff; color: var(--fb-blue); font-weight: 600; }
.nav-ic {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; color: #fff;
}
.nav-ic svg { width: 20px; height: 20px; }
.ic-dashboard { background: #1877f2; }
.ic-households { background: #21a366; }
.ic-residents { background: #0ea5e9; }
.ic-party { background: #e41e3f; }
.ic-businesses { background: #f5860f; }
.ic-users { background: #7c3aed; }
.sidebar .spacer { flex: 1; }
.sidebar-foot { padding: 12px 10px 4px; font-size: 12px; color: var(--faint); }

.main { grid-area: main; overflow-y: auto; padding: 22px 26px; }
.page-title { font-size: 24px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.5px; }
.page-sub { color: var(--muted); margin: 0 0 18px; }

/* ---------- Thành phần ---------- */
.card { background: #fff; border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0, 0, 0, .1), 0 0 0 1px rgba(0, 0, 0, .04); }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }

input, select, textarea {
  font: inherit; color: var(--ink);
  padding: 10px 12px; border: 1px solid #ccced2; border-radius: 6px;
  background: #fff; width: 100%;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--fb-blue); box-shadow: 0 0 0 2px #e7f3ff; }
/* Ô tìm kiếm dạng viên thuốc, nền xám (kiểu thanh tìm kiếm Facebook) */
.toolbar input.grow { background: var(--fb-bg); border: 1px solid #ccced2; border-radius: 50px; padding: 10px 16px; }
.toolbar input.grow:focus { background: #fff; border-color: var(--fb-blue); box-shadow: 0 0 0 3px rgba(24, 119, 242, .15); }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; font-weight: 500; color: var(--muted); margin-bottom: 5px; }

button {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 6px; border: 1px solid transparent; padding: 9px 16px;
  transition: background .12s;
}
button.primary { background: var(--fb-blue); color: #fff; }
button.primary:hover { background: var(--fb-blue-hover); }
button.secondary { background: var(--fb-gray); color: var(--ink); }
button.secondary:hover { background: var(--fb-gray-hover); }
button.danger { background: var(--danger); color: #fff; }
button.danger:hover { background: #c9182f; }
button.ghost { background: transparent; color: var(--muted); border-color: transparent; }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted);
  padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
tbody td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--fb-bg); }
.table-wrap { overflow-x: auto; }
.badge { background: #e7f3ff; color: var(--fb-blue); padding: 3px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.pill { padding: 3px 9px; border-radius: 6px; font-size: 12px; background: var(--fb-gray); color: var(--muted); font-weight: 600; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.muted { color: var(--muted); }

/* ---------- Thẻ số liệu ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { padding: 18px 20px; }
.stat .n { font-size: 28px; font-weight: 700; letter-spacing: -.5px; color: var(--fb-blue); }
.stat .l { color: var(--muted); font-size: 13px; margin-top: 3px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ---------- Modal ---------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 10px; width: 100%; max-width: 700px;
  max-height: 90vh; overflow: auto; box-shadow: 0 12px 28px rgba(0, 0, 0, .25);
}
.modal header { padding: 16px 22px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 17px; text-align: center; position: sticky; top: 0; background: #fff; }
.modal .body { padding: 20px 22px; }
.modal .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.modal footer { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 10px; position: sticky; bottom: 0; background: #fff; }

/* ---------- Thông báo ---------- */
.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 100;
  background: #333; color: #fff; padding: 12px 16px; border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25); opacity: 0; transform: translateY(10px);
  transition: .2s; max-width: 340px; font-size: 14px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }
.error-text { color: var(--danger); font-size: 13px; margin: 6px 0 0; min-height: 18px; }
.section-head { display: flex; justify-content: space-between; align-items: center; padding: 15px 18px; border-bottom: 1px solid var(--line); font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 760px) {
  .app {
    height: auto; min-height: 100vh;
    grid-template-columns: 1fr;
    grid-template-rows: 52px auto 1fr;
    grid-template-areas: "top" "side" "main";
  }
  .topbar-title { font-size: 17px; }
  .topbar-user { display: none; }
  .sidebar { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); padding: 8px; }
  .nav { flex-direction: row; }
  .nav-label { display: none; }
  .sidebar .spacer, .sidebar-foot { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .main { padding: 16px; }
}
