/* ==========================================================================
   Trình Soạn Thảo & Mẫu Biên Bản Họp Phụ Huynh - TCT.VN
   Tối ưu màn hình hiển thị & Chuẩn in A4 sư phạm 100% Offline
   ========================================================================== */

:root {
  --primary: #1e3a8a;
  --primary-hover: #172554;
  --primary-light: #eff6ff;
  --accent: #2563eb;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --border: #e2e8f0;
  --card-bg: #ffffff;
  --bg-page: #f8fafc;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --font-ui: 'Be Vietnam Pro', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-print: 'Tinos', 'Times New Roman', Times, serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  background-color: var(--bg-page);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------------- HEADER BAR ---------------- */
.app-header {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.btn-back {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.85rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 0.5rem;
  text-decoration: none;
  transition: all 0.2s ease;
  border: 1px solid #bfdbfe;
}

.btn-back:hover {
  background: #dbeafe;
  color: var(--primary-hover);
}

.header-icon {
  background: linear-gradient(135deg, #1e3a8a, #3b82f6);
  color: #ffffff;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(30, 58, 138, 0.25);
}

.app-header h1 {
  font-size: 1.2rem;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.25;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

/* Header Action Buttons */
.btn-action {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 0.95rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 0.5rem;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-sample {
  background: #f1f5f9;
  color: #1e293b;
  border: 1px solid #cbd5e1;
}

.btn-sample:hover {
  background: #e2e8f0;
}

.btn-outline {
  background: #ffffff;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.btn-outline:hover {
  background: #f8fafc;
  border-color: #94a3b8;
}

.btn-danger {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.btn-danger:hover {
  background: #fee2e2;
  color: #b91c1c;
}

.btn-primary {
  background: #1e3a8a;
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(30, 58, 138, 0.2);
}

.btn-primary:hover {
  background: #1e40af;
}

.dropdown-wrapper {
  position: relative;
  display: inline-block;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  background: #ffffff;
  min-width: 330px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.12);
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: 0.5rem;
  z-index: 200;
}

.dropdown-menu.active {
  display: block;
}

.dropdown-item {
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.85rem;
  background: none;
  border: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: #334155;
  cursor: pointer;
  transition: background 0.15s;
  line-height: 1.4;
}

.dropdown-item:hover {
  background: #f1f5f9;
  color: var(--primary);
  font-weight: 600;
}

/* ---------------- ONBOARDING BANNER ---------------- */
.onboarding-banner {
  background: linear-gradient(90deg, #1e3a8a 0%, #2563eb 100%);
  color: #ffffff;
  padding: 1rem 1.5rem;
  box-shadow: 0 2px 8px rgba(30, 58, 138, 0.15);
  animation: slideDown 0.3s ease;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.banner-content {
  max-width: 1400px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.banner-icon {
  background: rgba(255, 255, 255, 0.15);
  padding: 0.5rem;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.banner-text {
  flex: 1;
  min-width: 280px;
}

.banner-text h3 {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 0.2rem;
}

.banner-text p {
  font-size: 0.85rem;
  color: #e0e7ff;
}

.banner-actions {
  display: flex;
  gap: 0.6rem;
  align-items: center;
}

.btn-banner {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

.btn-banner-secondary {
  background: rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.4);
}

.btn-banner-secondary:hover {
  background: rgba(255, 255, 255, 0.3);
}

.btn-banner-primary {
  background: #ffffff;
  color: #1e3a8a;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.btn-banner-primary:hover {
  background: #f8fafc;
  transform: translateY(-1px);
}

/* ---------------- MAIN LAYOUT ---------------- */
.app-main {
  display: grid;
  grid-template-columns: 550px 1fr;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 65px);
}

/* Left: Editor Panel */
.editor-panel {
  background: #ffffff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.panel-header {
  padding: 0.85rem 1.25rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 10;
}

.panel-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.autosave-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--success);
  background: #f0fdf4;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid #bbf7d0;
}

.form-body {
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.form-section {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.section-title-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.section-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e3a8a;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.badge-num {
  background: #1e3a8a;
  color: #ffffff;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
}

.section-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.form-group {
  margin-bottom: 0.75rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 0.3rem;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-family: inherit;
  font-size: 0.85rem;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background-color: #ffffff;
  color: #0f172a;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.75rem;
}

.form-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}

/* Dynamic Cards in Form */
.dynamic-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.dynamic-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem;
  position: relative;
  transition: all 0.2s;
}

.dynamic-card:hover {
  border-color: #cbd5e1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.card-header-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.card-order-tag {
  font-size: 0.75rem;
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
}

.btn-del {
  background: none;
  border: none;
  color: #ef4444;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  transition: background 0.15s;
}

.btn-del:hover {
  background: #fee2e2;
}

.btn-subaction {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: #2563eb;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-subaction:hover {
  background: #dbeafe;
}

.btn-subaction-sm {
  margin-top: 0.6rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
}

.committee-box {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px dashed #cbd5e1;
}

.subheading {
  font-size: 0.85rem;
  font-weight: 700;
  color: #334155;
  margin-bottom: 0.5rem;
}

/* ---------------- RIGHT: PREVIEW PANEL ---------------- */
.preview-panel {
  background: #525659;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.preview-toolbar {
  background: #323639;
  color: #f1f5f9;
  padding: 0.5rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.preview-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
}

.btn-subtool {
  background: #4a4d51;
  color: #ffffff;
  border: 1px solid #606368;
  padding: 0.35rem 0.75rem;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.btn-subtool:hover {
  background: #5f6368;
}

.paper-container {
  padding: 2.5rem 1rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  min-height: 100%;
}

/* ==========================================================================
   A4 DOCUMENT STYLING (Chuẩn thể thức văn bản hành chính Việt Nam)
   ========================================================================== */
.a4-document {
  width: 210mm;
  min-height: 297mm;
  background: #ffffff;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
  padding: 20mm 20mm 20mm 25mm; /* Chuẩn lề văn bản: Trái 25-30mm, Phải 15-20mm, Trên 20-25mm, Dưới 20-25mm */
  box-sizing: border-box;
  font-family: var(--font-print);
  font-size: 13pt;
  line-height: 1.35;
  color: #000000;
  transition: transform 0.2s ease;
}

.a4-document.zoom-out {
  transform: scale(0.85);
  transform-origin: top center;
}

/* Header Quốc hiệu / Đơn vị */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14pt;
}

.doc-header-left {
  text-align: center;
  width: 45%;
}

.unit-agency {
  font-size: 11pt;
  text-transform: uppercase;
  color: #000000;
}

.unit-school {
  font-size: 12pt;
  font-weight: bold;
  text-transform: uppercase;
  color: #000000;
}

.unit-class {
  font-size: 11pt;
  font-weight: bold;
  color: #000000;
  margin-top: 2pt;
}

.header-divider-left {
  width: 90px;
  height: 1px;
  background: #000000;
  margin: 4pt auto 0 auto;
}

.doc-header-right {
  text-align: center;
  width: 55%;
}

.nation-title {
  font-size: 11.5pt;
  font-weight: bold;
  text-transform: uppercase;
}

.nation-motto {
  font-size: 12pt;
  font-weight: bold;
  margin-top: 2pt;
}

.header-divider-right {
  width: 140px;
  height: 1.5px;
  background: #000000;
  margin: 4pt auto 0 auto;
}

/* Document Title */
.doc-title-block {
  text-align: center;
  margin: 18pt 0 16pt 0;
}

.doc-title {
  font-size: 16pt;
  font-weight: bold;
  text-transform: uppercase;
  margin-bottom: 4pt;
  color: #000000;
}

.doc-subtitle {
  font-size: 13pt;
  font-style: italic;
  font-weight: normal;
}

/* Document Body Sections */
.doc-part {
  margin-bottom: 12pt;
}

.doc-part-title {
  font-size: 13pt;
  font-weight: bold;
  text-transform: uppercase;
  margin-bottom: 5pt;
}

.doc-subpart-title {
  font-size: 13pt;
  font-weight: bold;
  margin: 6pt 0 4pt 0;
}

.doc-text {
  font-size: 13pt;
  text-align: justify;
  margin-bottom: 4pt;
  line-height: 1.35;
}

.doc-sublist {
  list-style-type: disc;
  margin-left: 24pt;
  margin-top: 3pt;
  margin-bottom: 4pt;
}

.doc-sublist li {
  margin-bottom: 2pt;
}

/* Dynamic Section in Preview */
.pv-report-item {
  margin-bottom: 8pt;
}

.pv-report-heading {
  font-weight: bold;
  margin-bottom: 2pt;
}

.pv-report-content {
  text-align: justify;
  white-space: pre-line;
}

/* Dynamic Opinion in Preview */
.pv-opinion-item {
  margin-bottom: 6pt;
  text-align: justify;
}

/* Tables in Preview */
.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin: 6pt 0 10pt 0;
  font-size: 12pt;
}

.doc-table th,
.doc-table td {
  border: 1px solid #000000;
  padding: 5pt 6pt;
  vertical-align: middle;
}

.doc-table th {
  font-weight: bold;
  text-align: center;
  background-color: #f9fafb;
}

.doc-table td.center {
  text-align: center;
}

/* Signatures */
.doc-signatures {
  margin-top: 20pt;
  page-break-inside: avoid;
}

.sign-meta-date {
  text-align: right;
  font-style: italic;
  font-size: 13pt;
  margin-bottom: 10pt;
}

.sign-grid {
  display: flex;
  justify-content: space-between;
  text-align: center;
}

.sign-col {
  flex: 1;
  padding: 0 4pt;
}

.sign-role {
  font-weight: bold;
  text-transform: uppercase;
  font-size: 12.5pt;
}

.sign-note {
  font-style: italic;
  font-size: 11pt;
  color: #333333;
  margin-top: 2pt;
}

.sign-spacer {
  height: 65pt; /* Chỗ để chữ ký tay & đóng dấu */
}

.sign-name {
  font-weight: bold;
  font-size: 13pt;
}

/* ---------------- TOAST NOTIFICATION ---------------- */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #1e293b;
  color: #ffffff;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.85rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

/* ---------------- MODAL OVERLAY ---------------- */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
}

.modal-card {
  background: #ffffff;
  border-radius: 12px;
  width: 90%;
  max-width: 480px;
  padding: 1.5rem;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
}

.modal-body {
  font-size: 0.9rem;
  color: #475569;
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}

.btn-modal {
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

.btn-cancel {
  background: #f1f5f9;
  color: #475569;
}

.btn-cancel:hover {
  background: #e2e8f0;
}

.btn-confirm-danger {
  background: #dc2626;
  color: #ffffff;
}

.btn-confirm-danger:hover {
  background: #b91c1c;
}

/* ==========================================================================
   PRINT MEDIA RULES (In chuẩn A4 sạch sẽ, giấu toàn bộ UI)
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 15mm 15mm 15mm 20mm;
  }

  body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 13pt;
  }

  .no-print,
  .app-header,
  .editor-panel,
  .preview-toolbar,
  .onboarding-banner,
  .toast,
  .modal-overlay {
    display: none !important;
  }

  .app-main {
    display: block !important;
    height: auto !important;
    overflow: visible !important;
  }

  .preview-panel {
    background: transparent !important;
    overflow: visible !important;
  }

  .paper-container {
    padding: 0 !important;
    margin: 0 !important;
    display: block !important;
  }

  .a4-document {
    width: 100% !important;
    min-height: auto !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    transform: none !important;
  }

  .doc-table th {
    background-color: transparent !important;
  }

  /* Đảm bảo trang ngắt tự nhiên không bị vỡ bảng */
  tr {
    page-break-inside: avoid;
  }

  .doc-part {
    page-break-inside: auto;
  }

  .doc-signatures {
    page-break-inside: avoid;
  }
}

/* Responsive for smaller screens */
@media (max-width: 1024px) {
  .app-main {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }
  .editor-panel {
    border-right: none;
    border-bottom: 2px solid var(--border);
    max-height: none;
  }
  .preview-panel {
    padding-bottom: 2rem;
  }
  .a4-document {
    width: 100%;
    max-width: 210mm;
    padding: 15mm;
  }
}
