:root {
  --primary: #1b4b8a;
  --primary-dark: #123463;
  --accent: #c0392b;
  --success: #1e7e4f;
  --warning: #b9770e;
  --bg: #eef2f6;
  --surface: #ffffff;
  --border: #d5dde8;
  --text: #1f2937;
  --muted: #5f6c7b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

/* KHU VỰC A: TOPBAR */
.topbar {
  background: var(--primary-dark);
  color: #fff;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  z-index: 20;
  flex-shrink: 0;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-badge {
  background: #f5b041;
  color: #123463;
  font-weight: 800;
  padding: 6px 9px;
  border-radius: 6px;
  font-size: 13px;
}
.brand-title { font-weight: 700; font-size: 14px; letter-spacing: 0.3px; }
.brand-sub { font-size: 11px; color: #c7d6ec; }

.toolbar-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-btn {
  background: transparent;
  color: #dbe7f7;
  border: 1px solid transparent;
  padding: 6px 11px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.nav-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }
.nav-btn.active { background: #fff; color: var(--primary-dark); font-weight: 700; }

.toolbar-actions { display: flex; gap: 6px; }
.action-btn {
  border: none;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
}
.btn-check { background: #2c7a7b; }
.btn-check:hover { background: #236162; }
.btn-docx { background: #2563eb; }
.btn-docx:hover { background: #1d4ed8; }
.btn-pdf { background: #c0392b; }
.btn-pdf:hover { background: #a93226; }

/* WORKSPACE: KHU VỰC B + C */
.editor-workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 480px;
  overflow: hidden;
}

/* KHU VỰC B: XEM TRƯỚC A4 */
.preview-pane {
  display: flex;
  flex-direction: column;
  background: #dfe5ee;
  border-right: 1px solid var(--border);
  overflow: hidden;
}
.preview-toolbar {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  padding: 8px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.preview-meta { display: flex; align-items: center; gap: 10px; }
.badge-type {
  background: #e0ecff;
  color: var(--primary);
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 12px;
  font-size: 12px;
}
.autosave-status { font-size: 12px; color: var(--muted); }
.preview-controls { display: flex; align-items: center; gap: 6px; }
.zoom-label { font-size: 12px; font-weight: 600; min-width: 40px; text-align: center; }
.toggle-inline { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; cursor: pointer; }

.preview-scroll {
  flex: 1;
  overflow: auto;
  padding: 20px;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.preview-scale-wrapper {
  transform-origin: top center;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* TRANG A4 CHUẨN NGHỊ ĐỊNH 30/2020/NĐ-CP */
.a4-page {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  box-shadow: 0 4px 20px rgba(0,0,0,0.16);
  padding: 20mm 15mm 20mm 30mm;
  font-family: "Times New Roman", Times, serif;
  color: #000;
  line-height: 1.3;
  position: relative;
}
.a4-page.show-guides .nd30-zone {
  outline: 1px dashed #2563eb;
  position: relative;
}
.a4-page.show-guides .nd30-zone::before {
  content: attr(data-zone);
  position: absolute;
  top: -13px;
  left: 0;
  background: #2563eb;
  color: #fff;
  font-family: "Segoe UI", sans-serif;
  font-size: 9px;
  padding: 1px 4px;
  border-radius: 2px;
}

.doc-header-grid {
  display: grid;
  grid-template-columns: 37% 63%;
  gap: 6px;
  margin-bottom: 12px;
}
.doc-agency-box { text-align: center; font-size: 12pt; line-height: 1.25; }
.doc-agency-parent { text-transform: uppercase; }
.doc-agency-main { text-transform: uppercase; font-weight: bold; }
.doc-rule { width: 42%; height: 1px; background: #000; margin: 3px auto 6px; }
.doc-rule-wide { width: 52%; height: 1px; background: #000; margin: 3px auto 6px; }
.doc-rule-center { width: 28%; height: 1px; background: #000; margin: 4px auto 10px; }

.doc-quochhieu-box { text-align: center; line-height: 1.25; }
.doc-qh { font-size: 12pt; font-weight: bold; text-transform: uppercase; }
.doc-tn { font-size: 13pt; font-weight: bold; }
.doc-so { text-align: center; font-size: 13pt; margin-top: 4px; }
.doc-vv { text-align: left; font-size: 12pt; margin-top: 6px; padding-right: 8px; }
.doc-date { text-align: center; font-size: 13pt; font-style: italic; margin-top: 4px; }

.doc-title-block { text-align: center; margin: 10px 0 8px; }
.doc-ten-loai { font-size: 14pt; font-weight: bold; text-transform: uppercase; }
.doc-trich-yeu { font-size: 14pt; font-weight: bold; margin-top: 2px; }
.doc-tham-quyen { text-align: center; font-size: 14pt; font-weight: bold; text-transform: uppercase; margin: 8px 0; }
.doc-kinh-gui { font-size: 14pt; margin: 8px 0 10px; }
.doc-kinh-gui.single { text-align: center; }
.doc-kinh-gui.multi { padding-left: 24mm; }

.doc-cancu p {
  font-style: italic;
  text-align: justify;
  text-indent: 12.7mm;
  margin: 0 0 5px;
}
.doc-qd-word { text-align: center; font-weight: bold; font-size: 14pt; margin: 10px 0 8px; }
.doc-body p {
  text-align: justify;
  text-indent: 12.7mm;
  margin: 0 0 6px;
}
.doc-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0 10px;
  font-size: 12.5pt;
}
.doc-body th, .doc-body td {
  border: 1px solid #000;
  padding: 5px 7px;
  vertical-align: middle;
}
.doc-body th { background: #eef2f7; text-align: center; font-weight: bold; }

.doc-footer-grid {
  display: grid;
  grid-template-columns: 48% 52%;
  margin-top: 16px;
  gap: 8px;
}
.doc-noinhan-title { font-size: 12pt; font-weight: bold; font-style: italic; }
.doc-noinhan-list { font-size: 11pt; line-height: 1.25; white-space: pre-line; margin-top: 2px; }
.doc-sig-box { text-align: center; font-size: 13pt; line-height: 1.25; }
.doc-sig-role { font-weight: bold; text-transform: uppercase; }
.doc-sig-space { height: 68px; }
.doc-sig-name { font-weight: bold; font-size: 14pt; }

/* KHU VỰC C: BẢNG NHẬP LIỆU 7 BƯỚC */
.input-pane {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.stepper {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.step-tab {
  border: none;
  background: transparent;
  padding: 8px 2px;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  border-bottom: 3px solid transparent;
}
.step-tab span {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #dce3ee;
  color: #334155;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 11px;
}
.step-tab.active {
  color: var(--primary);
  font-weight: 700;
  border-bottom-color: var(--primary);
  background: #fff;
}
.step-tab.active span { background: var(--primary); color: #fff; }

.step-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.step-panel { display: none; }
.step-panel.active { display: block; }
.step-panel h3 { margin: 0 0 12px; font-size: 15.5px; color: var(--primary-dark); }

.form-group { margin-bottom: 11px; }
.form-group label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 4px; color: #334155; }
.req { color: var(--accent); }
input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(27,75,138,0.12);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.inline-row { display: flex; gap: 8px; align-items: center; }
.inline-row > input, .inline-row > select { flex: 1; }

.step-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* BUTTONS */
.primary-btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 8px 14px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn {
  background: #eef2f7;
  color: var(--text);
  border: 1px solid #cbd5e1;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
}
.secondary-btn:hover { background: #e2e8f0; }
.danger-btn {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12px;
}
.mini-btn {
  background: #fff;
  border: 1px solid #cbd5e1;
  padding: 4px 9px;
  border-radius: 5px;
  font-size: 12px;
  cursor: pointer;
}
.primary-mini { background: var(--primary); color: #fff; border-color: var(--primary); }
.file-upload-label { display: inline-flex; align-items: center; cursor: pointer; }

/* AI BOX */
.ai-box {
  background: #f0f6ff;
  border: 1px solid #bfd7f8;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 14px;
}
.ai-box-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; font-size: 13px; }
.ai-pill { background: #1e7e4f; color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 10px; }
.ai-btn-grid { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.ai-btn {
  background: #fff;
  border: 1px solid #93c5fd;
  color: var(--primary-dark);
  padding: 4px 8px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
}
.ai-btn:hover { background: var(--primary); color: #fff; }
.ai-result {
  margin-top: 8px;
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 8px;
}
.ai-notice { font-size: 11.5px; color: var(--primary); margin-bottom: 6px; font-weight: 600; }
.ai-result pre {
  margin: 0 0 8px;
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 12.5px;
  max-height: 180px;
  overflow-y: auto;
  background: #f8fafc;
  padding: 6px;
  border-radius: 4px;
}
.ai-result-actions { display: flex; gap: 6px; }

/* CHECKER */
.check-summary {
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 600;
}
.check-summary.pass { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.check-summary.fail { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.issue-item {
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: 6px;
  padding: 9px 10px;
  margin-bottom: 8px;
  background: #fff;
  font-size: 12.5px;
}
.issue-item.error { border-left-color: #dc2626; }
.issue-item.warning { border-left-color: #d97706; }
.issue-item.info { border-left-color: #2563eb; }
.issue-loc { font-size: 11px; color: var(--muted); font-weight: 600; }
.issue-msg { font-weight: 600; margin: 2px 0; }
.issue-sug { color: #334155; margin-bottom: 6px; }

/* EXPORT CARDS */
.export-cards { display: grid; gap: 8px; }
.export-card {
  text-align: left;
  padding: 11px 14px;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
  background: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.export-card:hover { border-color: var(--primary); background: #f8fbff; }
.export-card.primary-card { background: var(--primary); color: #fff; border-color: var(--primary); }
.export-card.primary-card span { color: #dbeafe; }
.export-card span { font-size: 12px; color: var(--muted); }

/* OTHER VIEWS (HOME, TEMPLATES, DOCUMENTS, SETTINGS) */
.page-view { flex: 1; overflow-y: auto; padding: 24px; }
.home-container, .page-container { max-width: 1180px; margin: 0 auto; }
.home-hero {
  background: linear-gradient(135deg, #123463, #1e56a0);
  color: #fff;
  padding: 28px;
  border-radius: 12px;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 20px;
  align-items: center;
  margin-bottom: 24px;
}
.home-hero h1 { margin: 0 0 10px; font-size: 22px; }
.home-hero p { margin: 0 0 16px; font-size: 14px; color: #dbeafe; line-height: 1.5; }
.hero-btns { display: flex; gap: 10px; }
.home-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat-card { background: rgba(255,255,255,0.14); padding: 14px; border-radius: 10px; text-align: center; }
.stat-num { font-size: 24px; font-weight: 800; }
.stat-label { font-size: 12px; color: #dbeafe; margin-top: 4px; }

.section-heading { font-size: 16px; color: var(--primary-dark); margin: 0 0 12px; }
.doc-types-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.doc-type-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s;
}
.doc-type-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.doc-type-card strong { display: block; font-size: 13.5px; color: var(--primary-dark); }
.doc-type-card span { font-size: 11.5px; color: var(--muted); }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 12px; }
.page-header h2 { margin: 0 0 4px; color: var(--primary-dark); }
.page-header p { margin: 0; font-size: 13px; color: var(--muted); }
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; }
.filter-bar input { flex: 2; }
.filter-bar select { flex: 1; }

.cards-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.tpl-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 10px;
}
.tpl-card h4 { margin: 0 0 4px; font-size: 14px; color: var(--primary-dark); }
.tpl-card p { margin: 0; font-size: 12.5px; color: var(--muted); }
.tpl-meta { display: flex; gap: 6px; font-size: 11px; margin-top: 6px; }
.tag { background: #eef2f7; padding: 2px 7px; border-radius: 10px; color: #334155; }
.tpl-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.table-wrap { background: #fff; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { background: #f8fafc; font-weight: 700; color: var(--primary-dark); }

.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.settings-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 18px; }
.settings-card h3 { margin: 0 0 12px; color: var(--primary-dark); font-size: 15px; }
.warning-banner {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  color: #92400e;
  padding: 10px;
  border-radius: 6px;
  font-size: 12.5px;
  margin-bottom: 12px;
}
.sub-box { background: #f8fafc; border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-top: 10px; }
.hint-text { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.mini-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.mini-list-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 10px; background: #f8fafc; border: 1px solid var(--border); border-radius: 6px; font-size: 12.5px;
}

.toast {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  background: #111827;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  z-index: 100;
}
.toast.show { opacity: 1; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; overflow: visible; height: auto; }
  .editor-workspace { display: block; }
  .preview-pane, .preview-scroll { background: #fff; padding: 0; overflow: visible; }
  .preview-scale-wrapper { transform: none !important; }
  .a4-page { box-shadow: none; margin: 0; page-break-after: always; }
}

/* AUTH OVERLAY & ACCOUNT SYSTEM */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, rgba(18,52,99,0.96), rgba(30,86,160,0.94));
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.auth-card {
  background: #fff;
  width: 100%;
  max-width: 440px;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 14px; background: #eef2f7; padding: 4px; border-radius: 8px; }
.auth-tab { border: none; background: transparent; padding: 8px; border-radius: 6px; cursor: pointer; font-weight: 600; color: #475569; font-size: 13px; }
.auth-tab.active { background: #fff; color: var(--primary-dark); box-shadow: 0 1px 4px rgba(0,0,0,0.08); }
.auth-divider { text-align: center; margin: 12px 0; position: relative; font-size: 12px; color: #64748b; }
.auth-divider::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: #e2e8f0; }
.auth-divider span { background: #fff; padding: 0 10px; position: relative; }
.google-btn {
  width: 100%;
  padding: 9px 12px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1f2937;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.google-btn:hover { background: #f8fafc; border-color: #94a3b8; }
.google-btn strong { color: #db4437; font-size: 15px; }
.auth-alert { padding: 9px 11px; border-radius: 6px; font-size: 12.5px; margin-bottom: 12px; font-weight: 500; }
.auth-alert.err { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.auth-alert.ok { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.auth-hint { margin-top: 12px; font-size: 11.5px; color: #64748b; background: #f8fafc; padding: 8px; border-radius: 6px; border: 1px solid #e2e8f0; }

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255,255,255,0.14);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 12px;
}
.plan-pill {
  background: #f5b041;
  color: #123463;
  font-weight: 800;
  font-size: 10.5px;
  padding: 2px 6px;
  border-radius: 10px;
}
.plan-pill.free { background: #cbd5e1; color: #1e293b; }
.logout-btn {
  background: rgba(255,255,255,0.18);
  color: #fff;
  border: none;
  padding: 3px 7px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11.5px;
}
.logout-btn:hover { background: rgba(255,255,255,0.3); }
.status-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11.5px; font-weight: 700; }
.status-badge.pending { background: #fef3c7; color: #92400e; }
.status-badge.approved { background: #dcfce7; color: #166534; }
.status-badge.rejected, .status-badge.suspended { background: #fee2e2; color: #991b1b; }

/* THANH CÔNG CỤ ĐIỀU CHỈNH CỠ CHỮ TRỰC TIẾP */
.font-toolbar {
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
  padding: 6px 14px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
}
.font-toolbar .ft-label { font-weight: 700; color: var(--primary-dark); }
.font-toolbar select { width: auto; padding: 4px 6px; font-size: 12px; }
.font-toolbar input[type="text"] { width: 46px; padding: 4px 6px; font-size: 12px; text-align: center; }
.font-warn-badge {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #f59e0b;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}
