/* QLNT - giao diện responsive, không phụ thuộc thư viện ngoài */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ec;
  --text: #17212b;
  --muted: #64717d;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #e6f4f2;
  --danger: #c2410c;
  --danger-soft: #fdeee6;
  --green: #15803d;  --green-soft: #e8f6ec;
  --blue: #1d4ed8;   --blue-soft: #e8eefc;
  --amber: #a16207;  --amber-soft: #fdf5dc;
  --red: #b91c1c;    --red-soft: #fdeaea;
  --gray: #52606d;   --gray-soft: #eef1f4;
  --sidebar: #12302d;
  --sidebar-ink: #cfe3df;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .5em; line-height: 1.3; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.ico { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- Khung ứng dụng ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; background: var(--sidebar); color: var(--sidebar-ink);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 600; font-size: 15px; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.brand-text strong { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { font-size: 12px; font-weight: 500; color: var(--sidebar-ink); opacity: .85; overflow: hidden; text-overflow: ellipsis; }
.nav { flex: 1; overflow-y: auto; padding: 6px 10px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--sidebar-ink); margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.13); color: #fff; font-weight: 600; }
.sidebar-foot { padding: 12px 18px; font-size: 12px; }
.sidebar-foot > div { opacity: .6; }
.lic-chip { display: block; margin-bottom: 8px; padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; text-decoration: none; color: #d1fae5; background: rgba(255,255,255,.08); }
.lic-chip:hover { background: rgba(255,255,255,.16); }
.lic-chip.lic-warn { background: #b45309; color: #fff; }
.lic-chip.lic-urgent, .lic-chip.lic-expired { background: #b91c1c; color: #fff; }
.sidebar-backdrop { display: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 18px; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-btn { display: none; }
.user-menu { display: flex; align-items: center; gap: 6px; }
.user-menu form { margin: 0; }
.user-chip { display: flex; align-items: center; gap: 8px; color: var(--text); padding: 4px 8px; border-radius: 8px; }
.user-chip:hover { background: var(--surface-2); text-decoration: none; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; }
.user-name { display: flex; flex-direction: column; line-height: 1.2; font-weight: 600; }
.user-name small { color: var(--muted); font-weight: 400; }
.icon-btn { background: none; border: 0; padding: 7px; border-radius: 8px; color: var(--muted); cursor: pointer; display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.content { padding: 20px 24px 40px; max-width: 1400px; width: 100%; }

/* ---------- Thẻ, lưới ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.card.narrow { max-width: 520px; }
.card-title { font-size: 15px; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid-side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.stack > * + * { margin-top: 16px; }

.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { color: var(--muted); font-size: 12.5px; }
.stat .value { font-size: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }
.stat.accent { border-left: 3px solid var(--primary); }

.bar { height: 10px; border-radius: 99px; background: var(--gray-soft); overflow: hidden; display: flex; }
.bar > span { display: block; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.bg-green { background: var(--green); } .bg-blue { background: var(--blue); }
.bg-amber { background: #d4a017; } .bg-red { background: var(--red); } .bg-gray { background: #9aa5b1; }

/* ---------- Toolbar, bộ lọc ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar h2 { font-size: 16px; margin: 0; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; margin-bottom: 14px; }
.filters .field { margin: 0; min-width: 140px; }
.filters .field.grow { flex: 1; min-width: 200px; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; line-height: 1.3;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #0d665f; }
.btn-danger { color: var(--danger); border-color: #f3c7b3; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; color: var(--primary); padding: 0; font: inherit; cursor: pointer; }
.btn-link.danger { color: var(--danger); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }

/* ---------- Biểu mẫu ---------- */
.form { display: block; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.field > span { font-weight: 600; font-size: 13px; }
.field small { color: var(--muted); font-size: 12px; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date],
input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #cfd7de; border-radius: 8px; background: #fff;
  font: inherit; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(15, 118, 110, .25); border-color: var(--primary); }
input:disabled { background: var(--surface-2); color: var(--muted); }
textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 16px; }
.span-2 { grid-column: span 2; }
.span-all { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.form-section { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid var(--border); }
.form-section:first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.check { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; cursor: pointer; }
.check input { margin-top: 3px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 2px 16px; }
.input-error { border-color: var(--red) !important; }

/* ---------- Bảng ---------- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
.table tbody tr:hover { background: #fbfcfd; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .empty { text-align: center; color: var(--muted); padding: 28px; }

.dl { display: grid; grid-template-columns: 160px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; word-break: break-word; }

/* ---------- Nhãn, thông báo ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-gray { background: var(--gray-soft); color: var(--gray); }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-success { background: var(--green-soft); color: #14532d; border-color: #c4e7cf; }
.alert-error { background: var(--red-soft); color: #7f1d1d; border-color: #f5c2c2; }
.alert-warning { background: var(--amber-soft); color: #713f12; border-color: #f1dea0; }
.alert-info { background: var(--blue-soft); color: #1e3a8a; border-color: #c9d6f8; }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

.empty-state { text-align: center; padding: 40px 20px; }
.error-code { font-size: 48px; font-weight: 800; color: var(--primary); }

.pager { display: flex; gap: 4px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.pager a, .pager span.current { min-width: 32px; padding: 5px 10px; border: 1px solid var(--border); border-radius: 6px; text-align: center; background: var(--surface); }
.pager span.current { background: var(--primary); color: #fff; border-color: var(--primary); }
.pager-total { margin-left: 8px; color: var(--muted); font-size: 13px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs a.active { color: var(--primary); border-color: var(--primary); }
.tabs a:hover { text-decoration: none; color: var(--text); }

/* ---------- Phòng dạng lưới ---------- */
.room-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.room-tile { display: block; border: 1px solid var(--border); border-left-width: 4px; border-radius: 8px; padding: 8px 10px; color: var(--text); background: var(--surface); }
.room-tile:hover { text-decoration: none; box-shadow: var(--shadow); }
.room-tile strong { display: block; }
.room-tile small { color: var(--muted); }
.room-tile.st-vacant { border-left-color: var(--green); }
.room-tile.st-occupied { border-left-color: var(--blue); }
.room-tile.st-reserved { border-left-color: #d4a017; }
.room-tile.st-maintenance { border-left-color: var(--red); }
.floor-row { display: grid; grid-template-columns: 90px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px dashed var(--border); }
.floor-row:last-child { border-bottom: 0; }
.floor-name { font-weight: 600; color: var(--muted); padding-top: 8px; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gallery figure { margin: 0; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.gallery img { width: 100%; height: 120px; object-fit: cover; display: block; }
.gallery figcaption { padding: 6px 8px; font-size: 12px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }

.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.list-plain li:last-child { border-bottom: 0; }

/* ---------- Đăng nhập ---------- */
.auth-body { background: linear-gradient(160deg, #e6f4f2 0%, #f4f6f8 55%); }
.auth-wrap { max-width: 400px; margin: 0 auto; padding: 8vh 16px 40px; }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.auth-brand strong { display: block; font-size: 17px; }
.auth-brand span { color: var(--muted); font-size: 13px; }
.auth-card { padding: 24px; }
.auth-title { font-size: 20px; }
.auth-links { text-align: center; margin: 14px 0 0; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s; z-index: 50; }
  body.sidebar-open .sidebar { transform: none; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
  .menu-btn { display: inline-flex; }
  .topbar { padding: 8px 12px; }
  .content { padding: 14px 16px 32px; }
  .grid-2, .grid-3, .grid-side, .form-grid, .form-grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .user-name { display: none; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .floor-row { grid-template-columns: 1fr; gap: 4px; }
  .floor-name { padding-top: 0; }
  .filters .field { min-width: calc(50% - 4px); flex: 1; }
  .card { padding: 14px; }
  .table-wrap { margin: 0 -14px; padding: 0 14px; }
  /* Bảng dạng thẻ trên điện thoại */
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; padding: 6px 10px; }
  .table.responsive td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--muted); font-weight: 600; text-align: left; }
  .table.responsive td.num { text-align: right; }
  .table.responsive td.empty::before { content: none; }
  .table.responsive td.empty { justify-content: center; }
}

/* ---------- In ấn ---------- */
@media print {
  .sidebar, .topbar, .no-print, .sidebar-backdrop { display: none !important; }
  body { background: #fff; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
}

/* ---------- Trợ lý AI ---------- */
.chat-log { display: flex; flex-direction: column; gap: 10px; max-height: 60vh; overflow-y: auto; padding: 4px 2px 10px; }
.msg { padding: 10px 14px; border-radius: 12px; max-width: 88%; line-height: 1.55; word-break: break-word; }
.msg-user { align-self: flex-end; background: var(--primary); color: #fff; border-bottom-right-radius: 4px; }
.msg-ai { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.chat-form textarea { min-height: 48px; }
.chart text { font-family: var(--font); }
tfoot td { background: var(--surface-2); }
.legend a { color: inherit; }

/* Hướng dẫn bắt đầu */
.setup-card { border-color: var(--primary); background: linear-gradient(var(--primary-soft), var(--surface) 90px); }
.setup-steps { list-style: none; margin: 8px 0 0; padding: 0; }
.setup-steps li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.setup-steps li:first-child { border-top: 0; }
.setup-num { flex: 0 0 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: var(--gray-soft); color: var(--gray); }
.setup-steps li.done .setup-num { background: var(--green-soft); color: var(--green); }
.setup-steps li.next .setup-num { background: var(--primary); color: var(--primary-ink); }
.setup-steps li.done .setup-body strong { color: var(--muted); font-weight: 600; }
.setup-body { flex: 1; min-width: 0; }
.setup-steps .btn { flex: 0 0 auto; }
@media (max-width: 560px) { .setup-steps li { flex-wrap: wrap; } .setup-body { flex-basis: calc(100% - 40px); } .setup-steps .btn { margin-left: 40px; } }
.card.danger-zone { border-color: #f3c7b3; }
.roomgen-preview { background: var(--primary-soft); color: var(--primary); border-radius: 8px; padding: 8px 12px; margin: 4px 0 0; }
/* Nhập Excel */
.import-table tr.row-error td { background: var(--red-soft); }
.import-msg { margin: 0; padding-left: 16px; font-size: 13px; }
.import-msg.err { color: var(--red); }
.import-msg.warn { color: var(--amber); margin-top: 4px; }
.import-table.only-errors tr:not([data-error]) { display: none; }
/* Mã QR thanh toán */
.qr-box { display: flex; gap: 18px; align-items: flex-start; flex-wrap: wrap; }
.qr-img { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 6px; line-height: 0; flex: 0 0 auto; }
.qr-img svg { display: block; max-width: 100%; height: auto; }
.qr-meta { flex: 1; min-width: 200px; }
.copy-row { display: flex; align-items: center; gap: 8px; }
.copy-row .btn { padding: 2px 8px; font-size: 12px; }
@media print { .qr-img { border: 0; } }

/* Bảng phân quyền */
.perm-matrix th.center, .perm-matrix td.center { text-align: center; }
.perm-matrix thead th { text-transform: none; letter-spacing: 0; white-space: nowrap; }
.perm-matrix .perm-group td { background: var(--surface-2); font-weight: 700; color: var(--text); }
.perm-matrix input[type=checkbox] { width: 18px; height: 18px; }
.perm-matrix tbody td:first-child { min-width: 260px; }
.link-btn { background: none; border: 0; padding: 0; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.link-btn:hover { color: var(--primary); text-decoration: underline; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; z-index: 5; }
.perm-count { white-space: nowrap; }

/* Bản quyền phần mềm */
.lic-hero { display: flex; gap: 24px; align-items: center; flex-wrap: wrap; }
.lic-days { font-size: 44px; font-weight: 800; line-height: 1; }
.lic-days small { font-size: 16px; font-weight: 600; color: var(--muted); }
.lic-ok .lic-days, .lic-unlimited .lic-days { color: var(--primary); }
.lic-warn .lic-days { color: #b45309; }
.lic-urgent .lic-days, .lic-expired .lic-days { color: #b91c1c; }
.lic-bar { height: 10px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.lic-bar span { display: block; height: 100%; background: var(--primary); }
.lic-warn .lic-bar span { background: #d97706; }
.lic-urgent .lic-bar span, .lic-expired .lic-bar span { background: #dc2626; }
.note-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 14px; margin-top: 8px; }
