/* ============================================================
   DHP Report System - Global Stylesheet
   โทนสีฟ้า/น้ำเงิน Digital Health Dashboard
   ============================================================ */

:root {
  --sidebar-width: 250px;
  --navbar-height: 56px;
  --primary:   #0d6efd;
  --primary-dark: #0a58ca;
  --success:   #198754;
  --warning:   #ffc107;
  --danger:    #dc3545;
  --info:      #0dcaf0;
  --purple:    #8b5cf6;
  --orange:    #f97316;
  --bg-body:   #f0f4f8;
  --card-bg:   #ffffff;
  --text-muted:#6c757d;
  --border:    #dee2e6;
}

/* ============================================================
   Base
   ============================================================ */
.text-orange  { color: var(--orange)  !important; }
.text-purple  { color: var(--purple)  !important; }
* { box-sizing: border-box; }
body {
  font-family: 'Kanit', sans-serif;
  font-size: 0.92rem;
  background: var(--bg-body);
  color: #212529;
  padding-top: var(--navbar-height);
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  position: fixed;
  top: var(--navbar-height);
  left: 0;
  width: var(--sidebar-width);
  height: calc(100vh - var(--navbar-height));
  background: linear-gradient(180deg, #0d1b3e 0%, #0a2852 60%, #0d3d7a 100%);
  overflow-y: auto;
  z-index: 1040;
  transition: transform 0.3s ease;
  display: flex;
  flex-direction: column;
}
.sidebar-inner { flex: 1; display: flex; flex-direction: column; }
.sidebar-nav   { flex: 1; padding: 0.5rem 0; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.1); }

.sidebar-group-label {
  margin-top: 0.9rem;
  padding: 0.9rem 1.25rem 0.5rem;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7dd3fc;
  white-space: nowrap;
}
.sidebar-nav > .sidebar-group-label:first-child {
  margin-top: 0.35rem;
  padding-top: 0;
  border-top: none;
}

.sidebar-link {
  display: flex;
  align-items: center;
  padding: 0.62rem 1.25rem;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  font-weight: 400;
  border-left: 3px solid transparent;
  transition: all 0.2s;
  white-space: nowrap;
}
.sidebar-link:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border-left-color: var(--info);
}
.sidebar-link.active {
  background: rgba(13,110,253,0.25);
  color: #fff;
  border-left-color: var(--info);
  font-weight: 500;
}
.sidebar-link i { font-size: 1.05rem; min-width: 1.5rem; }

/* Desktop: sidebar always visible */
@media (min-width: 992px) {
  .sidebar { transform: translateX(0) !important; }
  .main-content { margin-left: var(--sidebar-width); }
}

/* Mobile: sidebar hidden by default */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-left: 0; }
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1039;
}
.sidebar-overlay.show { display: block; }

/* ============================================================
   Main content
   ============================================================ */
.main-content {
  min-height: calc(100vh - var(--navbar-height));
  padding-bottom: 2rem;
}
.content-wrapper { padding: 1.5rem; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--primary);
}
.page-header h4 {
  font-weight: 600;
  color: var(--primary-dark);
  margin: 0;
}
.page-breadcrumb { font-size: 0.82rem; color: var(--text-muted); }

/* ============================================================
   KPI Cards
   ============================================================ */
.kpi-card {
  border: none;
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  transition: transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
}
.kpi-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.12);
}
.kpi-card .card-body { padding: 1.5rem 1.75rem; }
.kpi-icon {
  width: 64px; height: 64px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.9rem;
  opacity: 0.9;
}
.kpi-value { font-size: 2.8rem; font-weight: 700; line-height: 1.1; }
.kpi-label { font-size: 1rem; color: var(--text-muted); font-weight: 600; }
.kpi-sub   { font-size: 0.9rem; margin-top: 0.3rem; }

.kpi-blue   { background: linear-gradient(135deg,#e8f1ff,#f8fbff); }
.kpi-orange { background: linear-gradient(135deg,#fff3e8,#fffaf6); }
.kpi-purple { background: linear-gradient(135deg,#f3eeff,#faf7ff); }
.kpi-yellow { background: linear-gradient(135deg,#fff9e6,#fffdf5); }

.kpi-blue   .kpi-icon { background: #d0e4ff; color: var(--primary); }
.kpi-orange .kpi-icon { background: #ffe4cc; color: var(--orange); }
.kpi-purple .kpi-icon { background: #ede0ff; color: var(--purple); }
.kpi-yellow .kpi-icon { background: #fff3cd; color: #856404; }

.kpi-blue   .kpi-value { color: var(--primary); }
.kpi-orange .kpi-value { color: var(--orange); }
.kpi-purple .kpi-value { color: var(--purple); }
.kpi-yellow .kpi-value { color: #856404; }

/* ============================================================
   Hospital Cards
   ============================================================ */
.hos-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card-bg);
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  transition: box-shadow 0.2s;
}
.hos-card:hover { box-shadow: 0 4px 16px rgba(0,0,0,0.1); }
.hos-card .card-header {
  background: linear-gradient(135deg, #1565c0, #1e88e5);
  color: #fff;
  border-radius: 10px 10px 0 0 !important;
  padding: 0.75rem 1rem;
}
.hos-name-col {
  flex: 1;
  min-width: 0;
}
.hos-name {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.hos-badge-col {
  flex-shrink: 0;
}
.hos-stat { text-align: center; padding: 0.65rem 0.15rem; }
.hos-stat .stat-val { font-size: clamp(1.1rem, 1.6vw, 1.8rem); font-weight: 700; line-height: 1.15; white-space: nowrap; overflow: hidden; }
.hos-stat .stat-lbl { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.2rem; }

/* ============================================================
   Chart containers
   ============================================================ */
.chart-card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  padding: 1.25rem;
}
.chart-card .chart-title {
  font-size: 0.95rem; font-weight: 600; color: #1a3a6e; margin-bottom: 1rem;
}

/* ============================================================
   Tables
   ============================================================ */
.table-card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  padding: 1.25rem;
  overflow-x: auto;
}
/* Daily transposed table (รพ. = rows, วันที่ = columns) */
.dly-table { font-size: 0.78rem; table-layout: fixed; width: 100%; }
.dly-hos-col {
  width: 120px;
  min-width: 120px;
  max-width: 120px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dly-date-col {
  width: 32px;
  min-width: 28px;
  padding: 0 !important;
}
.dly-date-hdr {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  transform: rotate(180deg);
  white-space: nowrap;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 6px 0;
  margin: auto;
  line-height: 1;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dly-sum-col { min-width: 52px; width: 52px; }
.dly-val { padding: 4px 2px !important; font-size: 0.75rem; font-weight: 600; }
.dly-table tbody tr:hover td { background: #eef4ff !important; }
.dly-table tbody tr:hover .bk-sticky-col { background: #eef4ff !important; }

/* Breakdown table (3-metric tabs) */
.bk-table { font-size: 0.82rem; white-space: nowrap; }
.bk-table thead th {
  background: #1a3a6e;
  color: #fff;
  font-weight: 500;
  border-color: #2d4e8a;
  font-size: 0.75rem;
  line-height: 1.3;
  white-space: normal;
  vertical-align: middle;
}
.bk-sticky-col {
  position: sticky;
  left: 0;
  z-index: 3;
  min-width: 82px;
  background: #1a3a6e;
  color: #fff;
}
tbody .bk-sticky-col { background: #fff !important; color: #111827; }
.bk-total-col { background: #f0f4ff !important; font-weight: 700 !important; }
.bk-table thead .bk-total-col { background: #0f2d5e !important; color: #fff !important; }
.bk-foot { background: #eef2fb !important; border-top: 2px solid #93c5fd !important; }
.bk-table tbody tr:hover td { background: #eef4ff !important; }
.bk-table tbody tr:hover .bk-sticky-col { background: #eef4ff !important; }

.table { font-size: 0.87rem; }
.table thead th {
  background: #1a3a6e;
  color: #fff;
  font-weight: 500;
  border: none;
  white-space: nowrap;
}
.table tbody tr:hover { background: #eef4ff; }

/* ============================================================
   Badges / Status
   ============================================================ */
.badge-reported   { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.badge-pending    { background: #f3f4f6; color: #374151; border: 1px solid #d1d5db; }
.badge-error      { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.badge-synced     { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* Source-type badges — white bg + colored text ให้ contrast บน card header สีน้ำเงิน */
.src-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.5;
  white-space: nowrap;
  background: rgba(255,255,255,0.92);
  border: 1.5px solid rgba(255,255,255,0.6);
}
.src-api    { color: #0284c7; }  /* API Sync — blue */
.src-csv    { color: #b45309; }  /* CSV file — amber */
.src-excel  { color: #15803d; }  /* Excel xlsx — green */
.src-manual { color: #7c3aed; }  /* Manual entry — purple */

/* ============================================================
   Forms
   ============================================================ */
.form-card {
  background: var(--card-bg);
  border-radius: 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.07);
  padding: 1.5rem;
}
.form-label { font-weight: 500; font-size: 0.88rem; }
.form-control, .form-select {
  font-family: 'Kanit', sans-serif;
  font-size: 0.9rem;
  border-radius: 8px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 0.2rem rgba(13,110,253,0.15);
}

/* ============================================================
   Buttons
   ============================================================ */
.btn { font-family: 'Kanit', sans-serif; border-radius: 8px; }
.btn-primary { background: var(--primary); border-color: var(--primary); }

/* ============================================================
   Filter bar
   ============================================================ */
.filter-bar {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  box-shadow: 0 1px 6px rgba(0,0,0,0.06);
  margin-bottom: 1.25rem;
}

/* ============================================================
   Login page
   ============================================================ */
body.login-body {
  background: linear-gradient(135deg, #0d1b3e 0%, #1565c0 50%, #0d47a1 100%);
  min-height: 100vh;
  padding-top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  background: rgba(255,255,255,0.97);
  border-radius: 18px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.3);
  padding: 2.5rem 2rem;
  width: 100%; max-width: 420px;
}
.login-logo { text-align: center; margin-bottom: 1.5rem; }
.login-logo .logo-icon {
  width: 72px; height: 72px;
  background: linear-gradient(135deg,#1565c0,#42a5f5);
  border-radius: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 2rem; color: #fff; margin-bottom: 0.75rem;
}
/* ============================================================
   Site Footer
   ============================================================ */
/* ============================================================
   Site Footer — full width (outside #mainContent)
   ============================================================ */
.site-footer {
  background: linear-gradient(135deg, #0d1b3e 0%, #0a2852 60%, #0d3d7a 100%);
  color: rgba(255,255,255,0.85);
  padding: 1.4rem 2rem;
  width: 100%;
  box-sizing: border-box;
}
@media (min-width: 992px) {
  .site-footer { padding-left: calc(var(--sidebar-width) + 2rem); }
}
.footer-inner {
  display: flex; align-items: center; gap: 2rem;
  max-width: 1600px;
  flex-wrap: wrap;
}

/* Logo + laser wrapper */
.footer-logo-col { flex-shrink: 0; padding: 8px 4px; }
.footer-logo-wrap {
  position: relative;
  width: 68px; height: 68px;
  display: flex; align-items: center; justify-content: center;
}
.laser-ring {
  position: absolute;
  top: 50%; left: 50%;
  width: 108px; height: 108px;
  transform: translate(-50%, -50%);
  pointer-events: none;
  overflow: visible;
}
.footer-logo-img {
  width: 64px; height: 64px;
  object-fit: contain;
  border-radius: 50%;
  position: relative; z-index: 1;
  animation: logo-pulse 5s ease-in-out infinite;
}
@keyframes logo-pulse {
  0%,100% { filter: drop-shadow(0 0 3px rgba(0,229,255,0.3)); }
  50%      { filter: drop-shadow(0 0 8px rgba(0,229,255,0.65)) drop-shadow(0 0 16px rgba(0,100,255,0.3)); }
}

/* Footer text */
.footer-text-col { flex: 1; min-width: 200px; }
.footer-org  { font-size: .92rem; font-weight: 600; color: #fff; line-height: 1.4; }
.footer-dept { font-size: .8rem;  color: rgba(255,255,255,.72); margin-top: 2px; }
.footer-meta { font-size: .76rem; color: rgba(255,255,255,.55); margin-top: 3px; }
.footer-copy-col { text-align: right; flex-shrink: 0; }
.footer-copy     { font-size: .82rem; color: rgba(255,255,255,.8); font-weight: 500; }
.footer-copy-sub { font-size: .72rem; color: rgba(255,255,255,.4); margin-top: 3px; }

@media (max-width: 991.98px) {
  .site-footer { padding-left: 1.25rem; }
  .footer-logo-col { padding: 6px 2px; }
}
@media print { .site-footer { display: none; } }

/* ============================================================
   Login: back-home button
   ============================================================ */
.btn-back-home {
  display: inline-flex; align-items: center; gap: 6px;
  color: #6b7280; font-size: .85rem; text-decoration: none;
  padding: 6px 16px; border-radius: 20px;
  border: 1px solid #e5e7eb;
  transition: all .2s;
}
.btn-back-home:hover {
  background: #f3f4f6; color: #1565c0; border-color: #1565c0;
}

/* ============================================================
   Register / Privacy
   ============================================================ */
body.register-body {
  background: linear-gradient(135deg, #0d1b3e 0%, #1565c0 50%, #0d47a1 100%);
  min-height: 100vh;
  padding-top: 0;
}
.register-wrap { max-width: 680px; margin: 2rem auto; padding: 1rem; }
.register-card {
  background: rgba(255,255,255,0.97);
  border-radius: 18px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.3);
  padding: 2rem;
}
.privacy-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  max-height: 240px;
  overflow-y: auto;
  font-size: 0.85rem;
  line-height: 1.7;
}

/* ============================================================
   API status indicators
   ============================================================ */
.status-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 5px;
}
.status-dot.connected { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,0.2); }
.status-dot.failed    { background: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.2); }
.status-dot.pending   { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245,158,11,0.2); }

/* ============================================================
   Responsive tweaks
   ============================================================ */
@media (max-width: 767.98px) {
  .content-wrapper { padding: 1rem 0.75rem; }
  .kpi-value { font-size: 2rem; }
  .hos-stat .stat-val { font-size: 1.3rem; }
  .page-header { flex-direction: column; align-items: flex-start; }
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f1f1; }
::-webkit-scrollbar-thumb { background: #a0b4cc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #6b8cae; }

/* ============================================================
   Scroll Nav (Go-to-top / Go-to-bottom)
   ============================================================ */
.scroll-nav {
  position: fixed;
  right: 1.25rem;
  bottom: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  z-index: 1060;
}
.scroll-nav-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1565c0, #1e88e5);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 3px 12px rgba(21,101,192,0.35);
  opacity: 0;
  transform: scale(0.7) translateY(12px);
  transition: opacity 0.28s cubic-bezier(.34,1.56,.64,1),
              transform 0.28s cubic-bezier(.34,1.56,.64,1),
              background 0.15s, box-shadow 0.15s;
  pointer-events: none;
}
.scroll-nav-btn.visible {
  opacity: 1;
  transform: scale(1) translateY(0);
  pointer-events: auto;
}
.scroll-nav-btn:hover {
  background: linear-gradient(135deg, #0d47a1, #1565c0);
  box-shadow: 0 6px 18px rgba(21,101,192,0.45);
  transform: scale(1.12) translateY(-2px);
}
.scroll-nav-btn:active {
  transform: scale(0.95);
}
