:root {
  --bg: #f0f0f0;
  --panel: #ffffff;
  --text: #1d1f23;
  --muted: #7a7f88;
  --line: #c9ccd1;
  --accent: #1f6feb;
  --danger: #c00000;
  --ruler: #f6f6f6;
  /* Desktop: split.setSizes([855, 345]) - phong chu web rong hon Qt mot
     chut, nen mac dinh 380 de nhan khong gay nhieu dong. */
  --right-width: 380px;
}

* { box-sizing: border-box; }
/* Thuoc tinh hidden phai thang moi "display" khac (.row la flex) - neu
   khong, o "an" van hien. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text); background: var(--bg);
}
button, select, input { font: inherit; }

/* ---- cua so: trai | thanh keo | phai ---- */
.window { display: flex; height: 100%; padding: 8px; gap: 0; }
.left { flex: 1; min-width: 320px; display: flex; flex-direction: column; gap: 6px; padding-right: 4px; }
.right {
  width: var(--right-width); min-width: 300px; max-width: 620px; flex: none;
  display: flex; flex-direction: column; min-height: 0; padding-left: 4px;
}
.splitter { width: 6px; flex: none; cursor: col-resize; border-radius: 3px; }
.splitter:hover, .splitter.dragging { background: #d6dbe3; }

/* ---- ben trai: tieu de, thuoc, khung ve ---- */
.canvas-title {
  margin: 0; text-align: center; font-size: 22px; font-weight: 700;
  padding-left: 24px;            /* can giua theo VUNG VE, khong theo ca cot */
}
.canvas-grid {
  flex: 1; min-height: 0; display: grid;
  grid-template-columns: 24px minmax(0, 1fr); grid-template-rows: 24px minmax(0, 1fr);
  border: 1px solid var(--line); background: var(--panel);
}
/* Canvas nam TUYET DOI trong khung boc: co ve (width/height) cua canvas
   khong duoc keo gian o luoi - neu khong thuoc doc tran xuong duoi. */
.ruler { position: relative; overflow: hidden; background: var(--ruler); }
.ruler canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.ruler-origin { background: var(--ruler); border-right: 1px solid #aaa; border-bottom: 1px solid #aaa; }
.canvas-wrap { position: relative; min-width: 0; min-height: 0; overflow: hidden; }
.canvas { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
.canvas.dragging { cursor: grabbing; }
.canvas polyline { fill: none; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.fit-button { position: absolute; right: 10px; top: 10px; }
.busy {
  position: absolute; left: 10px; top: 10px; padding: 2px 8px;
  background: #fffbe6; border: 1px solid #f0d58a; border-radius: 4px;
}

.file-row { display: flex; gap: 12px; align-items: center; }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hover { min-width: 200px; text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.status { white-space: pre-line; max-height: 11em; overflow-y: auto; font-size: 13px; }
.status .warn { color: var(--danger); }
.button-row { display: flex; gap: 6px; }
.button-row > * { flex: 1; text-align: center; }

button, .button {
  padding: 6px 12px; border: 1px solid #adadad; border-radius: 3px;
  background: #e1e1e1; color: var(--text); cursor: pointer; white-space: nowrap;
}
button:hover:not(:disabled), .button:hover { background: #e5f1fb; border-color: #0078d7; }
button:disabled, .button.disabled {
  color: #9a9a9a; background: #ececec; border-color: #c8c8c8; cursor: default;
}
.button.disabled { pointer-events: none; }

/* ---- ben phai: logo, giai doan, tab ---- */
.logo { display: block; width: 100%; max-width: 420px; height: auto; margin: 0 auto 6px; }
.badge {
  margin: 0 0 6px; padding: 3px 8px; border-radius: 4px; font-size: 13px; text-align: center;
  background: #fff4d6; color: #7a5a00; border: 1px solid #f0d58a;
}
.stage-row { display: flex; align-items: center; gap: 8px; padding: 2px 2px 6px; }
.stage-row select { flex: 1; }
.tab-bar { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.tab-bar button {
  border: 1px solid transparent; border-bottom: none; border-radius: 3px 3px 0 0;
  background: none; padding: 5px 10px; color: var(--muted);
}
.tab-bar button[aria-selected="true"] {
  background: var(--panel); color: var(--text); border-color: var(--line);
  margin-bottom: -1px; padding-bottom: 6px;
}
.tab-pages {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden;
  padding: 8px 8px 16px; background: var(--panel);
  border: 1px solid var(--line); border-top: none;
}

fieldset { border: 1px solid var(--line); border-radius: 4px; margin: 0 0 10px; padding: 6px 10px 8px; }
legend { padding: 0 4px; font-weight: 600; }
.row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.row > label.caption { flex: 1; min-width: 0; }
.row input[type="number"] { width: 96px; text-align: right; }
.row input.int { width: 64px; }          /* so nguyen: so dao, feed, toc do */
.row .inline-label { white-space: nowrap; }
.row.disabled { opacity: .45; }
.row input:invalid { outline: 2px solid var(--danger); }
.toggle { display: flex; gap: 10px; }
.toggle.vertical { flex-direction: column; gap: 2px; }
.toggle label { white-space: nowrap; }
.info { color: #31527a; font-size: 13px; padding: 4px 0; }

/* bang vung */
.zones { width: 100%; border-collapse: collapse; }
.zones th { font-weight: 400; color: var(--muted); text-align: left; }
.zones td { padding: 2px 4px 2px 0; }
.zones td input { width: 100%; text-align: right; }
.zones .dim { color: #999999; }
.note { color: var(--muted); font-size: 13px; }

/* ---- trang chu: dang nhap + danh sach loai ---- */
body.home { display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; }
.home-box {
  width: min(440px, 100% - 32px); margin: 48px 16px; padding: 20px 24px 24px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
}
.home-title { margin: 4px 0 16px; text-align: center; font-size: 20px; }
.login { display: flex; flex-direction: column; gap: 10px; }
.login label { display: flex; flex-direction: column; gap: 3px; }
.login input { padding: 6px 8px; border: 1px solid #adadad; border-radius: 3px; }
.login .warn, .home .warn { color: var(--danger); min-height: 1.4em; }
.hello { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
button.link { margin-left: auto; padding: 2px 6px; background: none; border: none; color: var(--accent); }
button.link:hover:not(:disabled) { background: none; text-decoration: underline; }
.module-list { display: flex; flex-direction: column; gap: 8px; }
.module-card, .admin-card {
  display: flex; flex-direction: column; gap: 2px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 4px; color: var(--text); text-decoration: none;
}
a.module-card:hover, .admin-card:hover { border-color: #0078d7; background: #e5f1fb; }
.module-card.expired { color: var(--muted); background: #f6f6f6; }
.module-title { font-weight: 600; font-size: 16px; }
.module-plan { font-size: 13px; color: var(--muted); }
.module-card.expired .module-plan { color: var(--danger); }

.admin-card { margin-top: 8px; border-color: #9fb8d8; background: #f3f7fc; }
.form-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.done { color: #1a7f37; margin: 4px 0; }
button.primary { background: #0078d7; border-color: #0067b8; color: #fff; }
button.primary:hover:not(:disabled) { background: #0067b8; }
button.danger { color: var(--danger); }
button.danger:disabled { color: #9a9a9a; }

/* ---- trang quan tri ---- */
body.admin { overflow-y: auto; }
.admin .warn { color: var(--danger); }
.admin-box { width: min(1100px, 100% - 32px); margin: 16px auto 40px; }
.admin-head { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; }
.admin-head h1 { margin: 0; font-size: 20px; flex: 1; }
.admin-head .account-row { padding: 0; }
.admin-logo { width: 160px; margin: 0; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
  padding: 12px 16px 16px; margin-bottom: 14px;
}
.card h2 { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 10px; font-size: 16px; }
.card h2 input[type="search"] { margin-left: auto; width: 200px; font-weight: 400; }
.card input, .card select, dialog input, dialog select {
  padding: 5px 7px; border: 1px solid #adadad; border-radius: 3px;
}
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 14px; }
.grid-form label, dialog label { display: flex; flex-direction: column; gap: 3px; }
.grid-form label.check { flex-direction: row; align-items: center; gap: 6px; align-self: end; }
.grid-form .wide, .grant-fields { grid-column: 1 / -1; }
.grant-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px 14px; }
.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th { text-align: left; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); padding: 4px 8px 4px 0; }
table.list td { vertical-align: top; border-bottom: 1px solid #eceef1; padding: 6px 8px 6px 0; }
.nowrap { white-space: nowrap; }
.tags, .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.tag, .chip { padding: 1px 7px; border-radius: 10px; font-size: 12px; white-space: nowrap; border: 1px solid; }
.tag.admin { color: #1f4e8c; background: #e8f0fb; border-color: #b7cbe8; }
.tag.locked { color: var(--danger); background: #fdecec; border-color: #f0b7b7; }
.tag.pending { color: #7a5a00; background: #fff4d6; border-color: #f0d58a; }
.chip.ok { color: #1a7f37; background: #e9f7ee; border-color: #a8dbb7; }
.chip.expired { color: var(--danger); background: #fdecec; border-color: #f0b7b7; }
.actions { display: flex; flex-wrap: wrap; gap: 4px; justify-content: flex-end; }
.actions button { padding: 3px 8px; font-size: 13px; }
dialog { border: 1px solid var(--line); border-radius: 6px; padding: 16px 20px; width: min(420px, 100vw - 32px); }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog h3 { margin: 0 0 10px; font-size: 16px; }
.dialog-body { display: flex; flex-direction: column; gap: 10px; margin-bottom: 6px; }
.dialog-body p { margin: 0; }
.quick { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.card h2 .button { font-size: 14px; font-weight: 400; text-decoration: none; }
/* Nhat ky nhieu cot: giu be rong, cuon ngang TRONG khung (khong bop chu). */
#audit { min-width: 760px; }

/* dong tai khoan tren cot phai cua trang mot loai */
.account-row { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); padding: 0 2px 4px; }
.account-row a { color: var(--accent); text-decoration: none; }
.account-row .link { margin-left: auto; }

/* ---- man hep (dien thoai): xep doc, ca trang cuon ---- */
@media (max-width: 760px) {
  html, body { height: auto; }
  .window { flex-direction: column; height: auto; }
  .left { min-width: 0; padding-right: 0; }
  .canvas-grid { flex: none; height: 55vh; }
  .canvas-title { font-size: 16px; }
  .splitter { display: none; }
  .right { width: auto; max-width: none; min-width: 0; padding-left: 0; margin-top: 10px; }
  .tab-pages { max-height: 70vh; }
  .logo { max-width: 260px; }
  .hover { display: none; }
  .button-row { flex-wrap: wrap; }
  /* Bang tai khoan: moi tai khoan mot khoi doc, nut nam ngay duoi. */
  #users thead { display: none; }
  #users tr, #users td { display: block; }
  #users td { border: none; padding: 2px 0; }
  #users tr { border-bottom: 1px solid #eceef1; padding: 8px 0; }
  #users .actions { justify-content: flex-start; margin-top: 4px; }
  #users td:nth-child(3)::before { content: "Đăng nhập cuối: "; color: var(--muted); }
}
