* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Microsoft YaHei", "Segoe UI", "Noto Sans Khmer", "Khmer UI",
    "DaunPenh", "Moul", Arial, sans-serif;
  color: #1f2937;
  background: #f3f5f8;
  font-size: 14px;
}
.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 24px;
  background: #14365d;
  color: #fff;
}
.brand { font-size: 17px; font-weight: 600; letter-spacing: 0.5px; }
.tenant-box { display: flex; align-items: center; gap: 8px; }
.tenant-box label { color: #c8d6e8; }
.tenant-box input {
  width: 120px;
  padding: 6px 8px;
  border: 1px solid #3a5a82;
  border-radius: 4px;
  background: #0f2a49;
  color: #fff;
}

.layout { display: flex; min-height: calc(100vh - 56px); }
.sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e2e7ee;
  padding: 16px;
}
.sidebar h2 { font-size: 14px; color: #64748b; margin: 0 0 12px; }
.filter-bar { margin-bottom: 12px; }
.filter-bar label {
  display: block;
  font-size: 12px;
  color: #64748b;
  margin-bottom: 4px;
}
.filter-bar select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #d4dde8;
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  color: #1f2d3d;
  box-sizing: border-box;
}
.filter-bar select:focus { outline: none; border-color: #14467a; }
.diagnosis-list { list-style: none; margin: 0; padding: 0; }
.diagnosis-list li {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  margin-bottom: 4px;
  border: 1px solid transparent;
}
.diagnosis-list li:hover { background: #eef3fa; }
.diagnosis-list li.active { background: #e3edfa; border-color: #b9d2f2; }
.diagnosis-list .di-id { font-weight: 600; }
.diagnosis-list .di-sub { color: #64748b; font-size: 12px; margin-top: 2px; }
.di-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.di-archive {
  border: 1px solid #d4dde8;
  background: #fff;
  border-radius: 5px;
  padding: 2px 8px;
  font-size: 12px;
  color: #14467a;
  cursor: pointer;
  white-space: nowrap;
}
.di-archive:hover { background: #eef3fa; }
.diagnosis-list li.archived { opacity: 0.6; }
.diagnosis-list li.archived .di-id { text-decoration: line-through; }
.archive-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 12px;
}
.archive-toggle label { font-size: 12px; color: #64748b; cursor: pointer; }

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 12px;
}
.pager button {
  border: 1px solid #cbd5e1;
  background: #fff;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.pager button:hover:not(:disabled) { background: #eef3fa; }
.pager button:disabled { opacity: 0.45; cursor: not-allowed; }
.pager-info { color: #64748b; font-size: 12px; white-space: nowrap; }

.content { flex: 1; padding: 24px; }
.empty { color: #64748b; padding: 60px; text-align: center; }

.detail-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}
.detail-head h1 { font-size: 20px; margin: 0 0 6px; }
.meta-line { color: #64748b; font-size: 13px; }
.status-badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #e5edf8;
  color: #1d4e89;
}
.status-badge.high { background: #fde8e8; color: #b91c1c; }

.actions-bar { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.btn {
  padding: 8px 16px;
  border: 1px solid #c4cfdd;
  border-radius: 5px;
  background: #fff;
  color: #1f2937;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { background: #f1f5fa; }
.btn.primary { background: #1d4e89; border-color: #1d4e89; color: #fff; }
.btn.primary:hover { background: #163d6b; }

.card {
  background: #fff;
  border: 1px solid #e2e7ee;
  border-radius: 8px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h2 { font-size: 15px; margin: 0 0 14px; }
.card h2 small { color: #64748b; font-weight: 400; margin-left: 8px; }
.headline { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.caveat { color: #9a6b1c; background: #fdf6e7; padding: 10px 12px; border-radius: 5px; margin: 12px 0 0; }

.narrative {
  border-left: 3px solid #1d4e89;
  padding: 8px 12px;
  background: #f7f9fc;
  border-radius: 0 5px 5px 0;
  margin-bottom: 10px;
}
.narrative .n-title { font-weight: 600; }
.narrative .n-sev { color: #b91c1c; font-size: 12px; margin-left: 6px; }
.narrative .n-hyp { color: #64748b; margin-top: 4px; }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.metric-item {
  border: 1px solid #e2e7ee;
  border-radius: 8px;
  padding: 14px;
  background: #f9fbfd;
}
.metric-item .m-code { font-size: 12px; color: #64748b; }
.metric-item .m-value { font-size: 22px; font-weight: 700; margin: 6px 0; }
.metric-item .m-unit { font-size: 12px; color: #94a3b8; }

.layers .layer { margin-bottom: 14px; }
.layers h3 { font-size: 13px; margin: 0 0 8px; color: #334155; }
.layers ul { margin: 0; padding-left: 20px; }
.layers li { margin-bottom: 6px; line-height: 1.5; }
.evidence-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.evidence-cols h4 { font-size: 12px; margin: 0 0 6px; color: #166534; }
.evidence-cols h4.contradict { color: #b91c1c; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid #e8edf3;
  font-size: 13px;
}
.data-table th { color: #64748b; font-weight: 600; background: #f8fafc; white-space: nowrap; }

.delta-up { color: #15803d; font-weight: 600; }
.delta-down { color: #b91c1c; font-weight: 600; }
.delta-flat { color: #64748b; }
.dir-tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
}
.dir-tag.delta-up { background: #e7f6ec; }
.dir-tag.delta-down { background: #fde8e8; }
.dir-tag.delta-flat { background: #eef1f5; }

.kv-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #eef1f5;
}
.kv-key { color: #64748b; }
.kv-value { font-weight: 600; }

.retest-date {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #64748b;
}
.retest-date input { padding: 6px 8px; border: 1px solid #c4cfdd; border-radius: 5px; }

.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-info { color: #d6e2f1; font-size: 13px; }

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 42, 73, 0.92);
}
.login-overlay.hidden { display: none; }
.login-card {
  width: 320px;
  background: #fff;
  border-radius: 10px;
  padding: 32px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}
.login-card h1 { margin: 0; font-size: 22px; color: #14365d; }
.login-sub { margin: 0; color: #64748b; font-size: 13px; }
.login-card input {
  padding: 10px 12px;
  border: 1px solid #c4cfdd;
  border-radius: 6px;
  font-size: 14px;
}
.login-card input:focus {
  outline: none;
  border-color: #1d4e89;
  box-shadow: 0 0 0 3px rgba(29, 78, 137, 0.12);
}
.login-card .btn { margin-top: 4px; padding: 10px; }
.login-error { color: #b91c1c; font-size: 13px; min-height: 16px; }

.system-bar {
  margin-bottom: 16px;
  padding: 10px 14px;
  border-radius: 6px;
  background: #eef1f5;
  border: 1px solid #dde3eb;
  color: #475569;
  font-size: 13px;
}
.system-bar.online {
  background: #e7f6ec;
  border-color: #bfe3cb;
  color: #166534;
}

.upload-form {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.upload-form input[type="file"] { flex: 1; min-width: 220px; }
.field-date {
  display: flex;
  align-items: center;
  gap: 6px;
  color: #64748b;
}
.field-date input {
  padding: 6px 8px;
  border: 1px solid #c4cfdd;
  border-radius: 5px;
}
.form-error {
  color: #b91c1c;
  font-size: 13px;
  margin-top: 10px;
  min-height: 16px;
}
.btn[disabled] {
  opacity: 0.6;
  cursor: not-allowed;
}

.toast-container {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  min-width: 240px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 8px;
  background: #14365d;
  color: #fff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  font-size: 13px;
}
.toast.success { background: #166534; }
.toast.error { background: #b91c1c; }

.review-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.review-form {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.review-form input {
  flex: 1;
  min-width: 160px;
  padding: 8px 10px;
  border: 1px solid #c4cfdd;
  border-radius: 6px;
  font-size: 13px;
}
.review-form input:focus {
  outline: none;
  border-color: #1d4e89;
  box-shadow: 0 0 0 3px rgba(29, 78, 137, 0.12);
}
.btn.danger {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}
.btn.danger:hover { background: #991717; }
.btn.success {
  background: #166534;
  border-color: #166534;
  color: #fff;
}
.btn.success:hover { background: #11522a; }

@media (max-width: 960px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid #e2e7ee;
  }
  .evidence-cols { grid-template-columns: 1fr; }
  .content { padding: 16px; }
}

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    height: auto;
    padding: 10px 14px;
    gap: 8px;
  }
  .tenant-box { display: none; }
  .card { overflow-x: auto; }
  .data-table { min-width: 560px; }
}
