/* =====================================================================
 * styles.css — Giao diện ứng dụng + định dạng mẫu biểu in (A4)
 * ===================================================================== */
:root {
  --bg: #f2f5f8;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #5c6b7a;
  --line: #dde4ea;
  --primary: #0b6e4f;
  --primary-ink: #ffffff;
  --accent: #0e7490;
  --danger: #b91c1c;
  --warn-bg: #fff7ed;
  --warn-line: #fdba74;
  --ok-bg: #ecfdf5;
  --ok-line: #34d399;
  --bad-bg: #fef2f2;
  --bad-line: #fca5a5;
  --radius: 10px;
  font-size: 15px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
}
.hidden { display: none !important; }
.mt8 { margin-top: 8px; }
.center { text-align: center; }
.bold { font-weight: 700; }
.italic { font-style: italic; }
.u { text-decoration: underline; }
.small { font-size: 0.86rem; color: var(--muted); }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; }
.sidebar {
  width: 265px; flex: 0 0 265px; background: #0b3d33; color: #e7f3ee;
  display: flex; flex-direction: column; padding: 18px 14px; gap: 18px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand-icon {
  width: 40px; height: 40px; border-radius: 10px; background: #149d74;
  display: flex; align-items: center; justify-content: center; font-size: 22px; color: #fff;
}
.brand-title { font-weight: 700; line-height: 1.2; font-size: 0.98rem; }
.brand-sub { font-size: 0.72rem; opacity: 0.75; margin-top: 3px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  color: #d6e8e0; text-decoration: none; padding: 10px 12px; border-radius: 8px;
  font-size: 0.95rem; display: flex; gap: 10px; align-items: center;
}
.nav a:hover { background: rgba(255,255,255,0.08); }
.nav a.active { background: #149d74; color: #fff; font-weight: 600; }
.privacy {
  margin-top: auto; font-size: 0.78rem; line-height: 1.45; opacity: 0.85;
  background: rgba(255,255,255,0.06); padding: 10px; border-radius: 8px;
}
.about {
  font-size: 0.75rem; line-height: 1.6; opacity: 0.8;
  border-top: 1px solid rgba(255,255,255,0.14); padding-top: 10px;
}
.about .ver { font-weight: 600; letter-spacing: 0.02em; }
.about .owner b { color: #7dd3c0; }
.footer-note {
  text-align: center; color: var(--muted); font-size: 0.8rem;
  border-top: 1px solid var(--line); margin: 26px 0 4px; padding-top: 14px; line-height: 1.7;
}
.main { flex: 1; padding: 26px 30px; min-width: 0; }

/* ---------- Thành phần chung ---------- */
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
.page-sub { color: var(--muted); margin: 0 0 20px; font-size: 0.92rem; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { display: flex; align-items: center; gap: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 18px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px 18px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 18px; }
@media (max-width: 1100px) { .grid3, .grid4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 800px) { .grid2, .grid3, .grid4 { grid-template-columns: 1fr; } .sidebar { display: none; } }

.field label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
.field input[type=text], .field input[type=date], .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 0.92rem; background: #fbfdfe;
}
.field textarea { min-height: 74px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid #7dd3c0; border-color: var(--primary);
}
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 8px 14px; border-radius: 8px; font: inherit; font-size: 0.9rem;
  cursor: pointer; display: inline-flex; align-items: center; gap: 7px;
}
.btn:hover { border-color: #b9c6d1; background: #f6f9fb; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: #0a5d43; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-ghost { border-style: dashed; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th, table.data td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); }
table.data th { color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
table.data tr:hover td { background: #f6f9fb; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; border: 1px solid; }
.badge.ok { background: var(--ok-bg); border-color: var(--ok-line); color: #065f46; }
.badge.bad { background: var(--bad-bg); border-color: var(--bad-line); color: #991b1b; }
.badge.warn { background: var(--warn-bg); border-color: var(--warn-line); color: #9a3412; }
.badge.grey { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }

.notice {
  border: 1px solid var(--warn-line); background: var(--warn-bg); color: #7c2d12;
  padding: 10px 14px; border-radius: 8px; font-size: 0.9rem; line-height: 1.5; margin: 10px 0;
}
.notice.ok { border-color: var(--ok-line); background: var(--ok-bg); color: #065f46; }
.notice.bad { border-color: var(--bad-line); background: var(--bad-bg); color: #991b1b; }

.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
}
.stat .num { font-size: 1.6rem; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 0.82rem; }
@media (max-width: 900px) { .stat-row { grid-template-columns: 1fr 1fr; } }

/* ---------- Tabs của hồ sơ ---------- */
.case-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin: 18px 0 20px; flex-wrap: wrap; }
.tabs a {
  padding: 9px 16px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 0.92rem;
  border-radius: 8px 8px 0 0; border: 1px solid transparent; border-bottom: none;
}
.tabs a.active { color: var(--primary); background: #fff; border-color: var(--line); position: relative; top: 2px; }
.tabs a:hover { color: var(--ink); }

/* ---------- Ma trận ---------- */
.matrix-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
@media (max-width: 1150px) { .matrix-wrap { grid-template-columns: 1fr; } }
.sticky { position: sticky; top: 16px; }
.q-block { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 14px; overflow: hidden; }
.q-head {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
  padding: 12px 16px; background: #f8fafb; border-bottom: 1px solid var(--line); cursor: pointer;
}
.q-head .qn {
  background: var(--accent); color: #fff; border-radius: 8px; font-weight: 700;
  min-width: 58px; text-align: center; padding: 4px 8px; font-size: 0.85rem;
}
.q-head .qt { font-weight: 600; font-size: 0.95rem; line-height: 1.4; }
.q-body { padding: 14px 16px; }
.dauhieu { border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 10px; background: #fbfdfe; }
.dauhieu .dt { font-size: 0.9rem; line-height: 1.45; margin-bottom: 8px; }
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; }
.radio-row label { display: inline-flex; gap: 6px; align-items: center; font-size: 0.9rem; cursor: pointer; }
.harm-group { margin-bottom: 10px; }
.harm-group .hg-title { font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.checks label { display: inline-flex; gap: 6px; align-items: center; font-size: 0.88rem; cursor: pointer; }

table.matrix-board { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
table.matrix-board td, table.matrix-board th { border: 1px solid var(--line); padding: 7px 8px; }
table.matrix-board th { background: #f1f5f9; font-size: 0.72rem; text-transform: uppercase; color: var(--muted); }
.mcell { font-weight: 700; text-align: center; }
.mcell.co { color: #065f46; background: var(--ok-bg); }
.mcell.khong { color: #991b1b; background: var(--bad-bg); }
.mcell.chua { color: var(--muted); background: #f8fafc; font-weight: 400; }

/* ---------- Phiếu cai ---------- */
.pc-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; margin-bottom: 16px; overflow: hidden; }
.pc-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: #f8fafb; border-bottom: 1px solid var(--line); gap: 10px; flex-wrap: wrap; }
.pc-title { font-weight: 700; }
.pc-body { padding: 14px 16px; }
table.grid-edit { width: 100%; border-collapse: collapse; font-size: 0.85rem; margin-top: 8px; }
table.grid-edit th, table.grid-edit td { border: 1px solid var(--line); padding: 6px 8px; }
table.grid-edit th { background: #f1f5f9; }
table.grid-edit td.c { text-align: center; }
.pc-kq { border-radius: 8px; padding: 10px 14px; margin-top: 12px; font-size: 0.92rem; line-height: 1.5; }
.pc-kq.co { background: var(--ok-bg); border: 1px solid var(--ok-line); }
.pc-kq.khong { background: #f8fafc; border: 1px solid var(--line); }
.pc-kq .t { font-weight: 700; }

/* ---------- Overlay xem trước & in ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.55); z-index: 50;
  display: flex; align-items: stretch; justify-content: center; padding: 22px;
}
.ovl { background: #eef2f5; border-radius: 12px; width: min(860px, 96vw); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.35); }
.ovl-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); gap: 10px; flex-wrap: wrap; }
.ovl-title { font-weight: 700; }
.ovl-actions { display: flex; gap: 8px; }
.ovl-body { overflow: auto; padding: 18px; }

.modal { background: #fff; border-radius: 12px; padding: 22px; width: min(440px, 92vw); align-self: center; }
.modal-msg { line-height: 1.5; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 10px 20px; border-radius: 999px;
  font-size: 0.9rem; z-index: 80; box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}

/* =====================================================================
 * MẪU BIỂU IN — Times New Roman khổ A4 (mô phỏng văn bản hành chính)
 * ===================================================================== */
#print-root { display: none; }
.sheet {
  font-family: "Times New Roman", Times, serif;
  font-size: 13pt; line-height: 1.42; color: #000;
  background: #fff; width: 210mm; min-height: 290mm;
  padding: 14mm 16mm 12mm; margin: 0 auto 14px;
  box-shadow: 0 2px 14px rgba(0,0,0,0.15);
}
.ovl-body .sheet { box-shadow: 0 2px 10px rgba(0,0,0,0.18); }
.sheet p { margin: 3px 0; }
.sheet .formnum { text-align: right; font-weight: 700; font-style: italic; margin-bottom: 4px; }
.sheet .row-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.sheet .col-l { text-align: left; font-style: italic; }
.sheet .col-r { text-align: right; font-style: italic; }
.sheet .qoctieu-inline { text-align: center; font-style: normal; }
.sheet .underline-bar { border-bottom: 1px solid #000; width: 46mm; margin: 2px auto 0; }
.sheet .title { text-align: center; margin: 14px 0 10px; }
.sheet .title .bar { letter-spacing: 6px; margin-top: 2px; }
.sheet .w {
  display: inline-block; min-width: 60px; border-bottom: 1px dotted #000;
  padding: 0 6px; line-height: 1.15;
}
.sheet sup { font-size: 8pt; }
.sheet table.grid { width: 100%; border-collapse: collapse; font-size: 12pt; margin-top: 4px; }
.sheet table.grid th, .sheet table.grid td { border: 1px solid #000; padding: 3.5pt 5pt; vertical-align: middle; }
.sheet table.grid th { font-weight: 700; text-align: center; }
.sheet td.c, .sheet th.c { text-align: center; }
.sheet td.cell-w, .sheet th.cell-w { width: 34mm; }
.sheet table.plain { width: 100%; border-collapse: collapse; }
.sheet table.plain td { padding: 2px 0; vertical-align: top; }
.sheet .foot { font-size: 10.5pt; margin-top: 14px; padding-left: 18pt; }
.sheet .foot li { margin-bottom: 1pt; text-align: justify; }
.sheet .sig-row { display: flex; justify-content: space-between; gap: 14mm; page-break-inside: avoid; }
.sheet .sig { flex: 1; }
.sheet .sig-right { margin-left: 55%; }
.sheet .multiline {
  min-height: 68px; white-space: pre-wrap; border-bottom: 0;
  background-image: repeating-linear-gradient(to bottom, transparent 0 27px, #0000 27px);
}
.sheet .lylich-head { display: flex; gap: 10mm; align-items: flex-start; margin-top: 6mm; }
.sheet .photo-box {
  width: 30mm; height: 40mm; border: 1px solid #000; display: flex; align-items: center; justify-content: center;
  text-align: center; font-size: 11pt; font-style: italic; flex: 0 0 30mm;
}
.sheet .lylich-title { flex: 1; text-align: center; text-transform: uppercase; margin-top: 4mm; }

@media print {
  body.printing #app, body.printing .overlay, body.printing .toast { display: none !important; }
  body.printing #print-root { display: block; }
  #print-root .sheet { box-shadow: none; margin: 0; width: auto; min-height: 0; padding: 0; }
  .sheet { page-break-after: always; }
  .sheet:last-child { page-break-after: auto; }
  @page { size: A4; margin: 14mm 16mm 12mm; }
}
