/* ==========================================================================
   VĂN SỚ ĐIỆN TỬ - STYLESHEET (PHONG CÁCH PHẬT GIÁO HIỆN ĐẠI & TRUYỀN THỐNG)
   ========================================================================== */

:root {
  --primary: #991b1b;        /* Đỏ son lễ hội */
  --primary-hover: #7f1d1d;
  --secondary: #b45309;      /* Vàng đồng / Hoàng thổ */
  --secondary-light: #fef3c7;
  --accent: #047857;         /* Xanh ngọc lục bảo */
  --bg-main: #fbf9f4;        /* Nền hoàng chỉ trang nhã */
  --bg-card: #ffffff;
  --border-color: #e5dfd3;
  --border-gold: #d4af37;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --text-gold: #92400e;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  --font-serif: "NomKhai", "HanNomTimes", "Noto Serif TC", "Songti SC", "SimSun", "Times New Roman", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

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

/* Header */
.app-header {
  background: linear-gradient(135deg, #7f1d1d 0%, #991b1b 50%, #b45309 100%);
  color: #fff;
  padding: 12px 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-icon {
  font-size: 28px;
  line-height: 1;
}

.brand-title h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  font-family: var(--font-serif);
}

.brand-title p {
  font-size: 11px;
  opacity: 0.85;
}

.header-stats {
  display: flex;
  gap: 16px;
  align-items: center;
}

.stat-badge {
  background: rgba(255, 255, 255, 0.15);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.stat-badge strong {
  color: #fef08a;
}

/* Nav Tabs */
.app-nav {
  background: #ffffff;
  border-bottom: 2px solid var(--border-gold);
  display: flex;
  padding: 0 24px;
  gap: 8px;
  box-shadow: var(--shadow-sm);
}

.nav-tab {
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-tab:hover {
  color: var(--primary);
  background: #fff8f8;
}

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: #fdf2f2;
}

/* Layout Container */
.app-container {
  flex: 1;
  max-width: 1440px;
  width: 100%;
  margin: 20px auto;
  padding: 0 20px;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* Card Container */
.card {
  background: var(--bg-card);
  border-radius: 8px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
}

.card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-serif);
}

/* Actions & Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: #fff;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background: #f9fafb;
  border-color: #cbd5e1;
}

.btn-gold {
  background: var(--secondary);
  color: #fff;
}

.btn-gold:hover {
  background: #92400e;
}

.btn-accent {
  background: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  background: #065f46;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

/* Search and Filter bar */
.search-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  flex: 1;
  min-width: 250px;
  position: relative;
}

.search-input input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 14px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

/* Tables */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  text-align: left;
}

.data-table th {
  background: #f8fafc;
  color: #475569;
  font-weight: 600;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.data-table tr:hover {
  background: #fefce8;
}

.data-table tr.selected {
  background: #fef3c7;
  font-weight: 500;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge-nam {
  background: #dbeafe;
  color: #1e40af;
}

.badge-nu {
  background: #fce7f3;
  color: #9d174d;
}

.badge-sao {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.badge-cung {
  background: #e0e7ff;
  color: #3730a3;
}

.badge-tuoi {
  background: #f3f4f6;
  color: #374151;
}

/* Master-Detail Split Grid */
.split-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 992px) {
  .split-grid {
    grid-template-columns: 1fr;
  }
}

/* Form Controls */
.form-group {
  margin-bottom: 14px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 5px;
  color: #374151;
}

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 14px;
}

.form-control:focus {
  outline: none;
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

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

.form-col {
  flex: 1;
}

/* Hán Nôm View & Typography */
.han-nom-text {
  font-family: var(--font-serif);
  font-size: 17px;
  color: #7f1d1d;
  font-weight: 600;
  letter-spacing: 1px;
}

/* Modal Popup */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-backdrop.show {
  display: flex;
}

.modal-content {
  background: #fff;
  border-radius: 8px;
  width: 90%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border-top: 4px solid var(--primary);
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  font-size: 18px;
  color: var(--primary);
  font-family: var(--font-serif);
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
}

/* Print Toolbar & Preview */
.print-toolbar {
  background: #f8fafc;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.print-options {
  display: flex;
  gap: 16px;
  align-items: center;
  flex-wrap: wrap;
}

.print-options label {
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

/* The Ritual Petition Canvas (Sớ Canvas) */
.so-paper-wrapper {
  display: flex;
  justify-content: center;
  padding: 20px;
  background: #e2e8f0;
  border-radius: 8px;
  overflow-x: auto;
}

.so-sheet {
  background: #fffdf5; /* Nền giấy điệp vàng nhạt */
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  border: 4px double #b45309;
  padding: 40px;
  position: relative;
  min-height: 500px;
  color: #1a1a1a;
  transition: all 0.3s ease;
}

.so-sheet.a3-landscape {
  width: 1050px;
  min-height: 650px;
}

.so-sheet.a4-portrait {
  width: 720px;
  min-height: 960px;
}

.so-sheet.vo-so {
  width: 450px;
  min-height: 700px;
}

/* Sớ Header */
.so-header {
  text-align: center;
  margin-bottom: 25px;
  border-bottom: 2px solid #b45309;
  padding-bottom: 15px;
}

.so-temple-title {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 700;
  color: #991b1b;
  letter-spacing: 4px;
}

.so-doc-title {
  font-family: var(--font-serif);
  font-size: 20px;
  color: #b45309;
  margin-top: 6px;
  letter-spacing: 2px;
}

/* Sớ Body: Dọc (Vertical) vs Ngang (Horizontal) */
.so-body-vertical {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: var(--font-serif);
  font-size: 20px;
  line-height: 2.2;
  letter-spacing: 2px;
  height: 500px;
  overflow-x: auto;
  white-space: pre-wrap;
  text-align: start;
}

.so-body-horizontal {
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.8;
  white-space: pre-wrap;
  text-align: justify;
}

/* Footer Note */
.app-footer {
  text-align: center;
  padding: 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-top: 1px solid var(--border-color);
  margin-top: auto;
  background: #fff;
}

/* ==========================================================================
   PRINT MEDIA STYLES (window.print())
   ========================================================================== */
@media print {
  body {
    background: #fff !important;
    color: #000 !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  .app-header,
  .app-nav,
  .print-toolbar,
  .card-header,
  .btn,
  .app-footer,
  .modal-backdrop,
  .non-printable {
    display: none !important;
  }

  .app-container {
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .so-paper-wrapper {
    background: transparent !important;
    padding: 0 !important;
  }

  .so-sheet {
    box-shadow: none !important;
    border: 3px double #000 !important;
    margin: 0 auto !important;
    background: transparent !important;
    page-break-after: always;
  }

  .so-sheet.a3-landscape {
    width: 100% !important;
    min-height: auto !important;
  }

  @page {
    margin: 10mm;
  }
}
