/* Giao diện trang quản trị. Màu và bo góc lấy từ tokens.css — không chép hex vào đây (ui-guidelines R1). */

body.admin {
  background: var(--bg);
  font-size: 14px;
}

/* ===== Shell quản trị: topbar dính + rail điều hướng + vùng nội dung ===== */

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 30;
  background: var(--paper);
  color: var(--red-dark);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-weight: 700;
  transition: top 0.15s ease;
}

.skip-link:focus {
  top: 12px;
}

.admin-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.admin-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 20px;
  background: linear-gradient(120deg, var(--red-dark), var(--red));
  color: #fff;
  box-shadow: var(--shadow-md);
}

.admin-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.admin-brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: #fff;
  color: var(--red-dark);
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.03em;
  flex-shrink: 0;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--red) 22%, transparent);
}

.admin-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}

.admin-brand-text b {
  font-size: 14.5px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.admin-brand-text small {
  font-size: 11.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: color-mix(in srgb, #fff 82%, var(--red));
}

/* Menu tài khoản — <details> gốc, không cần JS. */
.user-menu {
  position: relative;
}

.user-menu > summary {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  list-style: none;
  padding: 6px 10px 6px 6px;
  border-radius: 999px;
  background: rgb(255 255 255 / 12%);
  border: 1px solid rgb(255 255 255 / 26%);
  color: #fff;
}

.user-menu > summary::-webkit-details-marker {
  display: none;
}

.user-menu[open] > summary {
  background: rgb(255 255 255 / 20%);
}

.user-avatar {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  color: var(--red-dark);
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  max-width: 30vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-caret {
  font-size: 11px;
  opacity: 0.85;
}

.user-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 240px;
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.user-pop .user-email {
  margin: 0;
  padding: 4px 8px 8px;
  font-size: 12.5px;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--border);
  word-break: break-all;
}

.user-pop a {
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
}

.user-pop a:hover {
  background: var(--surface-sunk);
}

.user-pop form {
  margin: 0;
}

.admin-body {
  flex: 1;
  display: flex;
  align-items: flex-start;
  gap: 0;
}

.admin-rail {
  flex-shrink: 0;
  width: 256px;
  align-self: stretch;
  position: sticky;
  top: 58px;
  max-height: calc(100vh - 58px);
  overflow-y: auto;
  background: var(--paper);
  border-right: 1px solid var(--border);
}

.rail-inner {
  padding: 18px 14px 26px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.rail-heading {
  margin: 4px 8px 10px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-soft);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.rail-sub {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--red-dark);
}

.rail-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 2px 4px 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  background: var(--red);
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  box-shadow: var(--shadow-sm);
}

.rail-cta:hover {
  background: var(--red-dark);
}

.rail-cta span {
  font-size: 18px;
  line-height: 1;
}

.rail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink);
  font-weight: 600;
  border: 1px solid transparent;
}

.rail-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border);
  flex-shrink: 0;
  transition: background 0.12s ease, transform 0.12s ease;
}

.rail-link:hover {
  background: var(--surface-sunk);
}

.rail-link:hover .rail-dot {
  background: var(--ink-soft);
}

/* Mục đang mở: nền đỏ nhạt + thanh đỏ bên trái như thẻ đánh dấu của một cuốn sổ tay. */
.rail-link.is-active {
  background: var(--red-soft);
  color: var(--red-dark);
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--red);
}

.rail-link.is-active .rail-dot {
  background: var(--red);
  transform: scale(1.15);
}

.rail-back {
  margin: 12px 4px 0;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  border: 1px dashed var(--border);
  text-align: center;
}

.rail-back:hover {
  color: var(--red-dark);
  border-color: var(--red-border);
}

.admin-main {
  flex: 1;
  min-width: 0;
  padding: 24px 28px 48px;
}

/* Bề rộng đọc thoải mái cho cột nội dung quản trị — bảng rộng vẫn tự tràn ngang khi cần. */
.admin-main > * {
  max-width: 1080px;
}

/* Vòng focus rõ ràng, thống nhất — đặt sớm để mọi thành phần tương tác kế thừa (R4). */
.admin a:focus-visible,
.admin button:focus-visible,
.admin summary:focus-visible,
.admin input:focus-visible,
.admin select:focus-visible,
.admin textarea:focus-visible,
.admin [tabindex]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 32%, transparent);
  border-radius: var(--radius-sm);
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--paper);
  color: var(--ink);
  padding: 9px 16px;
  min-height: 40px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

button:hover {
  border-color: var(--ink-soft);
  background: var(--surface-sunk);
}

button.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-weight: 700;
}

button.primary:hover {
  background: var(--red-dark);
  border-color: var(--red-dark);
}

/* Nút phụ, ít nhấn mạnh — dùng cho thao tác thứ cấp trong hàng nút. */
button.ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--ink-soft);
}

button.ghost:hover {
  color: var(--ink);
  background: var(--surface-sunk);
}

button.block {
  width: 100%;
  justify-content: center;
}

input,
textarea {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  transition: border-color 0.12s ease;
}

input:hover,
textarea:hover,
select:hover {
  border-color: var(--ink-soft);
}

label {
  display: block;
  margin-bottom: 12px;
}

label span {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
}

.hint {
  color: var(--ink-soft);
  font-size: 12.5px;
  margin: 4px 0 0;
}

.error {
  color: var(--red-dark);
  background: var(--red-soft);
  border: 1px solid var(--red-border);
  border-left: 4px solid var(--red);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  margin-bottom: 12px;
  font-weight: 600;
}

.panel {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 22px;
  margin: 0 0 18px;
  box-shadow: var(--shadow-sm);
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

/* ===== Đầu trang: tiêu đề lớn + mô tả + hàng thao tác (dùng cho các trang hệ thống) ===== */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 0 20px;
}

.page-head .page-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
}

.page-head .page-desc {
  margin: 6px 0 0;
  color: var(--ink-soft);
  max-width: 62ch;
}

.page-head .page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* Dải "vụn đường" nhỏ phía trên tiêu đề — cho biết đang ở khu vực nào. */
.page-eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--red);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  font-weight: 700;
}

thead th {
  border-bottom: 2px solid var(--border);
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--surface-sunk) 65%, transparent);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.55;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.7;
  flex-shrink: 0;
}

.badge.active {
  background: var(--success-bg);
  color: var(--success);
}

.badge.draft {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge.suspended,
.badge.archived {
  background: var(--border);
  color: var(--ink-soft);
}

.state {
  padding: 34px 18px;
  color: var(--ink-soft);
  text-align: center;
  background: var(--surface-sunk);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
}

.login-card h2 {
  margin-top: 0;
}

.form-card {
  margin-bottom: 16px;
  border-left: 7px solid var(--red);
}

.form-card h3 {
  margin-top: 0;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ===== Wizard tạo đơn vị ===== */
.wizard-steps {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
}

.wizard-steps li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--ink-soft);
  font-size: 13px;
}

.wizard-steps li.current {
  border-color: var(--red);
  color: var(--red-dark);
  font-weight: 700;
}

.wizard-steps li.done {
  color: var(--success);
  border-color: var(--success-bg);
}

.wizard-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--bg);
  font-size: 12px;
  font-weight: 700;
}

.choice-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 12px;
}

.choice-group legend {
  font-weight: 600;
  padding: 0 6px;
}

.choice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.choice input {
  width: auto;
  margin-top: 3px;
}

select {
  font: inherit;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--paper);
}

/* ===== Trang chi tiết đơn vị ===== */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px 24px;
  margin: 0;
}

.detail-grid dt {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-soft);
  margin-bottom: 4px;
}

.detail-grid dd {
  margin: 0;
  font-weight: 600;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.action-row form {
  margin: 0;
  display: flex;
  gap: 8px;
  align-items: center;
}

.panel-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--ink);
  min-height: 40px;
  font-weight: 600;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn-link:hover {
  border-color: var(--ink-soft);
  background: var(--surface-sunk);
}

.btn-link.primary {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
  font-weight: 700;
}

.btn-link.primary:hover {
  background: var(--red-dark);
  border-color: var(--red-dark);
  color: #fff;
}

.link-muted {
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
}

/* Nút thao tác trong ô bảng: mỗi nút là một form POST riêng (sắp xếp, xóa) nên phải nằm ngang nhau. */
/* Danh sách tệp PDF đính kèm ở màn quản trị văn bản / đất đai. */
.file-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
}

.file-list li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border, #e7e4e0);
}

form.inline {
  display: inline;
  margin: 0;
}

.nowrap {
  white-space: nowrap;
}

/* Một nhóm liên kết trong màn quản trị trang cổng. */
.group-block {
  padding: 12px 0;
  border-top: 1px solid var(--border);
}

.group-block:first-of-type {
  border-top: 0;
}

.danger-zone {
  border-color: var(--red-border);
}

button.danger {
  background: var(--red-dark);
  border-color: var(--red-dark);
  color: #fff;
  font-weight: 700;
}

button.danger:hover {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}

.delete-form input {
  width: auto;
  min-width: 220px;
}

.ok {
  color: var(--success);
  font-weight: 700;
}

.badge.job-done { background: var(--success-bg); color: var(--success); }
.badge.job-failed { background: var(--red-soft); color: var(--red-dark); }
.badge.job-running { background: var(--warn-bg); color: var(--warn); }
.badge.job-pending { background: var(--border); color: var(--ink-soft); }

/* ===== Tên miền & kiểm tra ===== */
.add-domain {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 14px;
}

.add-domain input {
  max-width: 360px;
}

.domain-guide {
  margin-top: 14px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}

.domain-guide summary {
  cursor: pointer;
  font-weight: 600;
}

.domain-guide code {
  background: var(--bg);
  border-radius: 6px;
  padding: 1px 6px;
}

.check-card {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-left-width: 7px;
  border-radius: var(--radius);
  padding: 14px 16px;
}

.check-card.check-ok {
  border-left-color: var(--success);
}

.check-card.check-fail {
  border-left-color: var(--red);
}

.check-card h4 {
  margin: 0 0 10px;
}

.check-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.check-list li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.check-mark {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}

.check-ok .check-mark,
li.check-ok .check-mark {
  background: var(--success-bg);
  color: var(--success);
}

li.check-warn .check-mark {
  background: var(--warn-bg);
  color: var(--warn);
}

li.check-fail .check-mark {
  background: var(--red-soft);
  color: var(--red-dark);
}

.check-hint {
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--red-dark);
}

/* ── Nội dung TTHC (GĐ 6) ───────────────────────────────────────────────── */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.dept-form {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
  background: var(--bg);
}

.field {
  margin-bottom: 12px;
}

.field label {
  font-weight: 600;
  margin-bottom: 4px;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .field {
  flex: 1;
}

.reorder-cell {
  white-space: nowrap;
  width: 1%;
}

.reorder-cell button {
  padding: 6px 9px;
  min-width: 34px;
}

.drag-handle {
  cursor: grab;
  color: var(--ink-soft);
  margin-right: 6px;
  user-select: none;
}

.dept-table tr.dragging {
  opacity: 0.5;
}

.dept-table tr[draggable='true'] {
  cursor: grab;
}

/* Nền lấy từ màu phòng ban (dữ liệu địa phương — ngoại lệ duy nhất của R1); chữ do máy chủ
   tính theo độ tương phản thật, không mặc định trắng. */
.dept-chip {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 600;
  background: var(--border);
  color: var(--ink);
}

/* Danh sách + form thủ tục */

.muted {
  color: var(--ink-soft);
}

.proc-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.proc-filter input[name='q'] {
  flex: 1 1 320px;
}

.proc-filter select {
  flex: 0 1 200px;
}

.proc-table td .hint {
  display: block;
}

/* Ba sắc thái mức độ thực hiện. Ánh xạ giá trị → sắc thái khai báo tập trung ở
   `packages/shared/src/catalog.ts` (procedureLevelTone), không rải trong template. */
.badge.tone-success { background: var(--success-bg); color: var(--success); }
.badge.tone-warning { background: var(--warn-bg); color: var(--warn); }
.badge.tone-neutral { background: var(--border); color: var(--ink-soft); }

.pager {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
}

.pager a,
.pager-current {
  display: inline-block;
  min-width: 34px;
  padding: 6px 8px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.pager-current {
  background: var(--red);
  border-color: var(--red);
  color: var(--paper);
  font-weight: 700;
}

.qr-box {
  display: inline-block;
  padding: 10px;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.qr-box svg {
  display: block;
}

.qr-state {
  margin: 0;
  color: var(--ink-soft);
  font-size: 13px;
}

.qr-error {
  color: var(--red-dark);
}

input[readonly] {
  background: var(--bg);
  color: var(--ink-soft);
}

/* Bảng dò link — địa chỉ dài không được đẩy các cột khác ra khỏi màn hình */
.link-cell {
  max-width: 320px;
  overflow-wrap: anywhere;
}

/* Khung xem thử bản đồ ở màn quản trị. Trang công khai lấy quy tắc này từ `modules.css`, nhưng layout
   quản trị không nạp file đó — thiếu ở đây thì iframe rơi về 300×150px mặc định và cán bộ không xem
   thử được thứ mình vừa dán. */
.map-frame {
  aspect-ratio: 16 / 10;
  width: 100%;
  max-width: 720px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: var(--paper);
}

.map-frame iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

/* ===== Hub nội dung của đơn vị (cán bộ đơn vị) ===== */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
}

.hub-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--red);
  border-radius: 12px;
  text-decoration: none;
  color: var(--ink);
  min-height: 64px;
}

.hub-card:hover,
.hub-card:focus-visible {
  border-color: var(--red);
}

.hub-card small {
  color: var(--ink-soft);
}

/* Ô đặt lại mật khẩu trong bảng tài khoản: input + nút nằm ngang. */
.reset-form {
  display: flex;
  gap: 6px;
  margin: 0;
  align-items: center;
}

.reset-form input {
  width: auto;
  min-width: 150px;
}

/* ---- Trình soạn mẫu đơn (GĐ 9) ---- */

/* Khối chú thích lồng trong biểu mẫu — dùng cho phần căn cứ pháp lý, thứ quyết định mẫu có công bố được không. */
.panel-inset {
  background: var(--bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--red);
  border-radius: 10px;
  padding: 12px 16px 16px;
  margin: 16px 0;
}

/* Ô JSON: chữ đều để đếm được dấu ngoặc, và không bọc dòng để giữ cấu trúc thụt lề. */
.code-area {
  font-family: ui-monospace, 'Cascadia Mono', 'Consolas', monospace;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  overflow-wrap: normal;
  overflow-x: auto;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-weight: 600;
  margin: 8px 0;
}

.check-row input {
  width: auto;
  margin-top: 3px;
}

/* ===== Trang đăng nhập (ngoài shell) ===== */
.login-wrap {
  background: radial-gradient(120% 90% at 50% -10%, color-mix(in srgb, var(--red) 10%, transparent), transparent 62%);
}

.login-card {
  box-shadow: var(--shadow-md);
  border-top: 5px solid var(--red);
}

/* ===== CRUD phân loại danh mục TTHC gốc ===== */

.mono {
  font-family: ui-monospace, 'Cascadia Mono', 'Consolas', monospace;
  font-size: 12.5px;
  color: var(--ink-soft);
}

/* Nền lấy từ màu phòng ban (dữ liệu địa phương — ngoại lệ duy nhất của R1). */
.color-swatch {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, var(--ink) 16%, transparent);
  flex-shrink: 0;
}

.tax-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.tax-item {
  border-bottom: 1px solid var(--border);
}

.tax-item:last-child {
  border-bottom: 0;
}

.tax-item > summary.tax-summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  list-style: none;
  min-height: 54px;
}

.tax-item > summary.tax-summary::-webkit-details-marker {
  display: none;
}

.tax-summary:hover,
.tax-item[open] > summary.tax-summary {
  background: var(--surface-sunk);
}

.tax-name {
  font-weight: 700;
  flex: 1 1 auto;
  min-width: 0;
}

.tax-count {
  font-size: 12.5px;
  color: var(--ink-soft);
  white-space: nowrap;
}

.tax-edit-hint {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--red-dark);
  white-space: nowrap;
}

.tax-item[open] .tax-edit-hint {
  color: var(--ink-soft);
}

.tax-edit {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 16px;
  border-top: 1px dashed var(--border);
  background: color-mix(in srgb, var(--surface-sunk) 45%, var(--paper));
}

.tax-edit-form,
.add-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin: 0;
}

.tax-edit-form {
  flex: 1 1 auto;
}

.tax-del-form {
  margin: 0;
}

/* Hàng thêm mới — luôn hiện dưới mỗi bảng phân loại, dạng thẻ nét đứt cho khác với danh sách. */
.add-row {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface-sunk);
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.add-row .field,
.tax-edit-form .field {
  margin: 0;
  flex: 1 1 170px;
}

.add-row .field.grow,
.tax-edit-form .field.grow {
  flex: 3 1 240px;
}

.add-row .field.narrow,
.tax-edit-form .field.narrow {
  flex: 0 0 118px;
}

.add-row label,
.tax-edit-form label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  margin-bottom: 5px;
}

.add-row .field-actions {
  flex: 0 0 auto;
}

/* Ô chọn màu native — cao bằng ô nhập cho thẳng hàng. */
input[type='color'] {
  width: 100%;
  min-width: 64px;
  height: 42px;
  padding: 4px;
  cursor: pointer;
}

/* ===== Responsive: rail thành dải cuộn ngang, topbar gọn lại ===== */
@media (max-width: 900px) {
  .admin-body {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-rail {
    position: static;
    width: auto;
    max-height: none;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .rail-inner {
    padding: 12px 14px;
    gap: 10px;
  }

  .rail-cta {
    margin: 0;
  }

  .rail-list {
    flex-direction: row;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 4px;
  }

  .rail-link {
    white-space: nowrap;
    border: 1px solid var(--border);
  }

  .rail-link.is-active {
    box-shadow: none;
    border-color: var(--red);
  }

  .rail-back {
    align-self: flex-start;
  }

  .admin-main {
    padding: 18px 16px 40px;
  }

  .admin-main > * {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .field-row {
    flex-direction: column;
    gap: 0;
  }
}

@media (max-width: 560px) {
  .admin-topbar {
    padding: 8px 12px;
  }

  .admin-brand-text small,
  .user-name {
    display: none;
  }
}
