

/* =====================================================
   ROOT VIEW
===================================================== */

.hd-document-view {

  position: fixed;

  inset: 0;

  z-index: 2100;

  display: flex;

  flex-direction: column;

  width: 100vw;
  height: 100dvh;

  min-width: 0;
  min-height: 0;

  background: #eef1f5;

  overflow: hidden;

}


/* =====================================================
   TOOLBAR
===================================================== */

.hd-document-toolbar {

  flex: 0 0 56px;

  display: flex;

  align-items: center;

  justify-content: space-between;

  min-width: 0;

  padding:
    0
    16px;

  background: #ffffff;

  border-bottom:
    1px solid #dfe3e8;

  box-sizing: border-box;

  z-index: 2;

}


/* =====================================================
   TOOLBAR LEFT
===================================================== */

.hd-document-toolbar-left {

  display: flex;

  align-items: center;

  min-width: 0;

  gap: 12px;

}


/* =====================================================
   CLOSE BUTTON
===================================================== */

.hd-document-close {

  flex:
    0 0 auto;

  width: 38px;
  height: 38px;

  display: flex;

  align-items: center;
  justify-content: center;

  padding: 0;

  border: none;

  border-radius: 8px;

  background: transparent;

  color: #333;

  font-size: 28px;

  line-height: 1;

  cursor: pointer;

}


.hd-document-close:hover {

  background: #f1f3f5;

}


.hd-document-close:active {

  background: #e5e7eb;

}


/* =====================================================
   TITLE
===================================================== */

.hd-document-title {

  min-width: 0;

  overflow: hidden;

  white-space: nowrap;

  text-overflow: ellipsis;

  font-size: 16px;

  font-weight: 600;

  color: #202124;

}


/* =====================================================
   TOOLBAR ACTIONS
===================================================== */

.hd-document-toolbar-actions {

  display: flex;

  align-items: center;

  gap: 8px;

  flex:
    0 0 auto;

}


/* =====================================================
   DOCUMENT VIEWPORT
===================================================== */

.hd-document-viewport {

  flex:
    1 1 auto;

  min-width: 0;
  min-height: 0;

  width: 100%;

  overflow-x: auto;
  overflow-y: auto;

  box-sizing: border-box;

  -webkit-overflow-scrolling: touch;

  overscroll-behavior: contain;

}


/* =====================================================
   DOCUMENT CANVAS
===================================================== */

.hd-document-pages {

  display: flex;

  flex-direction: column;

  align-items: center;

  gap: 24px;

  width: max-content;

  min-width: 100%;

  box-sizing: border-box;

  padding:
    24px
    24px
    40px;

}


/* =====================================================
   A4 PAGE
===================================================== */

.hd-document-page {

  flex:
    0 0 auto;

  width: 210mm;

  height: 297mm;

  box-sizing: border-box;

  background: #ffffff;

  overflow: hidden;

  box-shadow:
    0 2px 12px
    rgba(0, 0, 0, .14);

}


/* =====================================================
   A4 CONTENT
===================================================== */

.hd-document-page-content {

  width: 100%;

  height: 100%;

  box-sizing: border-box;

  padding:
    20mm
    18mm
    20mm
    22mm;

  overflow: hidden;

}


/* =====================================================
   DOCUMENT BLOCK
===================================================== */

.hd-document-block {

  box-sizing: border-box;

}


/* =====================================================
   PAGINATION DEBUG
===================================================== */

.hd-document-block-oversize {

  outline:
    1px dashed #999;

}


.hd-document-block-splittable {

  outline:
    1px dashed #999;

}


/* =====================================================
   EMPTY DOCUMENT
===================================================== */

.hd-document-empty {

  display: flex;

  align-items: center;

  justify-content: center;

  width: 210mm;

  min-height: 120mm;

  padding: 40px;

  box-sizing: border-box;

  color: #777;

  font-size: 15px;

}


/* =====================================================
   MOBILE
===================================================== */

@media (max-width: 767px) {

  .hd-document-toolbar {

    flex-basis: 52px;

    padding:
      0
      10px;

  }


  .hd-document-title {

    font-size: 15px;

  }


  .hd-document-viewport {

    overflow-x: auto;
    overflow-y: auto;

  }


  .hd-document-pages {

    align-items: flex-start;

    padding:
      16px
      16px
      32px;

    gap: 16px;

  }


  /*
    KHÔNG thay đổi width A4.

    Mobile sẽ scroll ngang.
  */

  .hd-document-page {

    width: 210mm;

    height: 297mm;

  }

}


.hd-document-status {
    width: 100%;
    height: 100%;

    display: flex;
    align-items: center;
    justify-content: center;

    box-sizing: border-box;

    font-size: 16px;
    color: #666;
}




/* LIST */

/* ==========================================================================
   1. BỐ CỤC KHUNG CĂN GIỮA (Đè hoàn toàn CSS Framework hệ thống)
   ========================================================================== */
.hdmlist-view-page {
  display: flex !important;
  justify-content: center !important;
  align-items: flex-start !important;
  width: 100% !important;
  padding: 24px 16px !important;
  box-sizing: border-box !important;
}

.hdmlist-card-container {
  width: 100% !important;
  max-width: 900px !important; /* Thu gọn vừa phải để căn giữa đẹp mắt */
  margin: 0 auto !important;
  background: #ffffff !important;
  border-radius: 12px !important;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06) !important;
  box-sizing: border-box !important;
}

/* ==========================================================================
   2. DESKTOP VIEW: HIỂN THỊ DẠNG CỘT (TABLE-LIKE GRID)
   ========================================================================== */
.hdmlist-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-top: 16px;
}

/* Header tiêu đề các cột */
.hdmlist-header {
  display: grid !important;
  grid-template-columns: 130px 1fr 130px 120px; /* Chia tỷ lệ 4 cột: Ký hiệu | Tên | Trạng thái | Thao tác */
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  background-color: #f8fafc;
  color: #475569;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  border-radius: 8px;
  margin-bottom: 8px;
}

/* Dòng dữ liệu item */
.hdmlist-item {
  display: grid !important;
  grid-template-columns: 130px 1fr 130px 120px;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  transition: background-color 0.2s;
}

.hdmlist-item:hover {
  background-color: #f8fafc;
}

.hdmlist-col .hdmlist-mobile-label {
  display: none !important; /* Ẩn nhãn mobile khi ở Desktop */
}

.hdmlist-col.col-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Badge trạng thái */
.hdmlist-badge-active {
  display: inline-block;
  padding: 4px 10px;
  background-color: #e6fffa;
  color: #0d9488;
  font-size: 12px;
  font-weight: 600;
  border-radius: 20px;
}

/* ==========================================================================
   3. MOBILE VIEW: HIỂN THỊ DẠNG CARD
   ========================================================================== */
@media (max-width: 768px) {
  .hdmlist-view-page {
    padding: 10px 8px !important;
  }

  /* Ẩn Header của bảng trên Mobile */
  .hdmlist-header {
    display: none !important;
  }

  .hdmlist-container {
    gap: 12px;
  }

  /* Chuyển dòng dữ liệu thành dạng khung Card */
  .hdmlist-item {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 10px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 14px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.03);
  }

  .hdmlist-col {
    display: flex !important;
    justify-content: space-between !important;
    width: 100% !important;
    font-size: 14px;
  }

  /* Hiện nhãn tiêu đề cột trên Mobile */
  .hdmlist-col .hdmlist-mobile-label {
    display: inline-block !important;
    font-weight: 600;
    color: #64748b;
  }

  .hdmlist-col.col-actions {
    justify-content: flex-end !important;
    width: 100% !important;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px dashed #e2e8f0;
  }
}

.hdmlist-item {
  cursor: pointer !important;
}



/* FORM */

/* =====================================================
   FORM TEMPLATE STYLES (DÙNG CHUNG CHO HỢP ĐỒNG & PHỤ LỤC)
   ===================================================== */

/* 1. Container Layout & Card Framing */
#hopDongMauFormView,
#phuLucMauFormView {
  padding: 16px;
  max-width: 900px;
  margin: 0 auto;
}

#hopDongMauFormView .hd-form-card,
#phuLucMauFormView .hd-form-card {
  background-color: #ffffff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
  padding: 24px;
  border: 1px solid #eef2f6;
}

/* 2. Header Section */
#hopDongMauFormView .view-header,
#phuLucMauFormView .view-header {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid #f0f4f8;
}

#hopDongMauFormView .view-title,
#phuLucMauFormView .view-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1e293b;
  letter-spacing: -0.01em;
}

/* 3. Form Sections & Titles */
.hd-form-section {
  margin-bottom: 28px;
}

.hd-section-title {
  font-size: 1rem;
  font-weight: 600;
  color: #334155;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hd-section-title::before {
  content: "";
  display: inline-block;
  width: 4px;
  height: 16px;
  background-color: #2563eb;
  border-radius: 2px;
}

.hd-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 4. Form Control Standardizing */
#hopDongMauFormView .form-group,
#phuLucMauFormView .form-group {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#hopDongMauFormView label,
#phuLucMauFormView label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #475569;
}

#hopDongMauFormView input[type="text"],
#hopDongMauFormView select,
#hopDongMauFormView textarea,
#phuLucMauFormView input[type="text"],
#phuLucMauFormView select,
#phuLucMauFormView textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.9rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  background-color: #ffffff;
  color: #1e293b;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
}

#hopDongMauFormView input[type="text"]:focus,
#hopDongMauFormView select:focus,
#hopDongMauFormView textarea:focus,
#phuLucMauFormView input[type="text"]:focus,
#phuLucMauFormView select:focus,
#phuLucMauFormView textarea:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

#hopDongMauFormView input[readonly],
#phuLucMauFormView input[readonly] {
  background-color: #f8fafc;
  color: #64748b;
  cursor: not-allowed;
}

/* 5. Informational / Party Cards (Bên A & Bên B) */
.hd-party-card {
  background-color: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 16px;
}

.hd-party-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #1e293b;
  margin-bottom: 12px;
}

.hd-system-block {
  background-color: #eff6ff;
  border-left: 3px solid #3b82f6;
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.hd-system-block-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: #1d4ed8;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.hd-system-block-text {
  font-size: 0.85rem;
  color: #2563eb;
  line-height: 1.4;
}

/* 6. Clauses List & Dynamic Cards */
.hd-clause-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 16px;
}

.hd-clause-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 18px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.02);
  transition: border-color 0.2s ease;
}

.hd-clause-card:hover {
  border-color: #cbd5e1;
}

.hd-clause-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid #f1f5f9;
}

.hd-clause-number {
  font-size: 0.95rem;
  font-weight: 700;
  color: #0f172a;
}

.hd-clause-delete {
  background: none;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  color: #94a3b8;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.hd-clause-delete:hover {
  background-color: #fee2e2;
  color: #ef4444;
}

.hd-dynamic-note {
  font-size: 0.825rem;
  color: #64748b;
  background-color: #f1f5f9;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-style: italic;
}

.hd-system-value {
  display: flex;
  align-items: center;
  gap: 8px;
  background-color: #f0fdf4;
  border: 1px dashed #4ade80;
  padding: 8px 12px;
  border-radius: 6px;
  margin: 12px 0;
  font-size: 0.85rem;
}

.hd-system-value span {
  color: #166534;
}

.hd-system-value strong {
  color: #15803d;
  font-weight: 600;
}

/* 7. Empty State */
.hd-empty-state {
  text-align: center;
  padding: 32px;
  background-color: #f8fafc;
  border: 2px dashed #e2e8f0;
  border-radius: 8px;
  color: #94a3b8;
  font-size: 0.9rem;
}

/* 8. Action Buttons */
.hd-clause-add {
  display: flex;
  justify-content: flex-start;
}

.hd-add-btn {
  background-color: #f1f5f9;
  color: #334155;
  border: 1px dashed #cbd5e1;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  width: 100%;
  transition: all 0.2s ease;
}

.hd-add-btn:hover {
  background-color: #e2e8f0;
  border-color: #94a3b8;
  color: #0f172a;
}

.hd-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 32px;
  padding-top: 20px;
  border-top: 1px solid #f0f4f8;
}

.hd-form-actions button {
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background-color 0.2s ease, transform 0.1s ease;
}

.hd-form-actions button:active {
  transform: scale(0.98);
}

.hd-form-actions button.secondary {
  background-color: #f1f5f9;
  color: #475569;
}

.hd-form-actions button.secondary:hover {
  background-color: #e2e8f0;
  color: #1e293b;
}

.hd-form-actions button.primary {
  background-color: #2563eb;
  color: #ffffff;
}

.hd-form-actions button.primary:hover {
  background-color: #1d4ed8;
}

/* 9. Mobile Responsive */
@media (max-width: 640px) {
  #hopDongMauFormView,
  #phuLucMauFormView {
    padding: 8px;
  }

  #hopDongMauFormView .hd-form-card,
  #phuLucMauFormView .hd-form-card {
    padding: 16px;
  }

  .hd-form-actions {
    flex-direction: column-reverse;
  }

  .hd-form-actions button {
    width: 100%;
  }
}