/* ============================================================
   Clinic Referral System — Orange Glassmorphism Design System
   (อ้างอิงจาก CheckMate / orange-design skill)
   ============================================================ */

:root {
  --orange-primary: #F97316;
  --orange-light: #FB923C;
  --orange-dark: #EA580C;
  --bg-page: #FDF0E8;
  --bg-card: #FFFFFF;
  --text-primary: #1F2937;
  --text-secondary: #6B7280;
  --text-muted: #9CA3AF;
}

* { font-family: 'Sarabun', sans-serif; box-sizing: border-box; }

body {
  background-color: var(--bg-page);
  color: var(--text-primary);
  margin: 0;
}

a { color: inherit; text-decoration: none; }

/* ---------------- Layout ---------------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 260px;
  background: #fff;
  min-height: 100vh;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  border-right: 1px solid #F3F4F6;
  z-index: 40;
  transition: transform .2s ease;
}
.sidebar-logo { display: flex; align-items: center; gap: 10px; padding: 20px 18px 12px; }
.sidebar-logo .logo-icon {
  background: linear-gradient(135deg, var(--orange-light), var(--orange-primary));
  color: #fff; border-radius: 10px; width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1rem;
}
.sidebar-logo .app-name { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); }
.sidebar-logo .tagline { font-size: .68rem; color: var(--text-muted); }

.nav-group-title { font-size: .72rem; font-weight: 700; color: var(--text-muted); padding: 16px 18px 6px; text-transform: none; letter-spacing: .02em; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; margin: 2px 10px; border-radius: 10px;
  color: #374151; font-size: .88rem; font-weight: 500;
}
.nav-item .nav-ico { width: 18px; text-align: center; }
.nav-item.active { background: linear-gradient(135deg, var(--orange-light), var(--orange-primary)); color: #fff; font-weight: 600; box-shadow: 0 4px 10px rgba(249,115,22,.25); }
.nav-item:hover:not(.active) { background: #FEF3C7; color: var(--orange-dark); }

.sidebar-footer { padding: 16px 18px; margin-top: 12px; }
.sidebar-user-badge { background: #FDF0E8; border-radius: 12px; padding: 10px 12px; display: flex; align-items: center; gap: 8px; font-size: .78rem; }
.sidebar-user-badge .dot { width: 8px; height: 8px; border-radius: 50%; background: #22C55E; flex-shrink: 0; }

.main-area { margin-left: 260px; flex: 1; display: flex; flex-direction: column; min-height: 100vh; width: calc(100% - 260px); }

/* ---------------- Topbar ---------------- */
.topbar {
  background: #fff; border-bottom: 1px solid #F3F4F6;
  height: 64px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 30; gap: 12px;
}
.topbar-title-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-page-icon { width: 34px; height: 34px; border-radius: 9px; background: #FEF3C7; color: var(--orange-dark); display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.topbar-title { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.topbar-subtitle { font-size: .72rem; color: var(--text-muted); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.icon-btn {
  background: none; border: none; cursor: pointer; padding: 8px; border-radius: 10px;
  color: #6B7280; display:flex; align-items:center; justify-content:center; position: relative;
}
.icon-btn:hover { background: #FEF3C7; color: var(--orange-dark); }
.icon-btn.alert-btn { color: #F97316; }
.icon-btn .dot-badge { position:absolute; top:6px; right:6px; width:8px; height:8px; border-radius:50%; background:#EF4444; border:2px solid #fff; }
.topbar-clinic { display:flex; align-items:center; gap:8px; padding-left: 10px; border-left: 1px solid #F3F4F6; margin-left: 4px; }
.topbar-clinic .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--orange-primary); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:.85rem; flex-shrink:0; }
.topbar-clinic-text { line-height: 1.15; }
.topbar-clinic-text .name { font-size: .82rem; font-weight: 700; color: var(--text-primary); white-space:nowrap; }
.topbar-clinic-text .sub { font-size: .68rem; color: var(--text-muted); white-space:nowrap; }
.logout-link { display:flex; align-items:center; gap:6px; font-size:.82rem; font-weight:600; color:#6B7280; padding: 8px 10px; border-radius: 10px; }
.logout-link:hover { background:#FEE2E2; color:#DC2626; }

.page-content { padding: 24px 28px 60px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* ---------------- Popover (help / alert) ---------------- */
.popover-wrap { position: relative; }
.popover-card {
  position: absolute; top: calc(100% + 8px); z-index: 50;
  background: #fff; border-radius: 14px; box-shadow: 0 12px 30px rgba(0,0,0,.15);
  padding: 16px; font-size: .82rem; line-height: 1.5; color: var(--text-secondary);
  display: none;
}
.popover-card.open { display: block; }
.popover-card.help { width: 320px; left: -260px; }
.popover-card.alert { width: 320px; right: 0; border-top: 3px solid #F97316; background: #FFF7ED; }
.popover-card .popover-title { font-weight: 700; color: var(--text-primary); margin-bottom: 8px; display:flex; align-items:center; gap:6px; }
.popover-card .popover-num { background: var(--orange-primary); color:#fff; width:18px; height:18px; border-radius:50%; font-size:.65rem; display:inline-flex; align-items:center; justify-content:center; flex-shrink:0; margin-top:2px; }
.popover-card .popover-item { display:flex; gap:8px; margin-bottom:8px; }

/* ---------------- Cards / stats ---------------- */
.card { background: #fff; border-radius: 18px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.glass-card { background: rgba(255,255,255,.7); backdrop-filter: blur(10px); border: 1px solid rgba(255,255,255,.5); border-radius: 18px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px,1fr)); gap: 16px; margin-bottom: 24px; }
.stats-card { background: #fff; border-radius: 18px; padding: 18px 20px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.stats-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stats-icon { width: 42px; height: 42px; border-radius: 12px; display:flex; align-items:center; justify-content:center; font-size: 1.15rem; }
.stats-icon.blue { background:#DBEAFE; color:#1D4ED8; }
.stats-icon.green { background:#D1FAE5; color:#059669; }
.stats-icon.red { background:#FEE2E2; color:#DC2626; }
.stats-icon.purple { background:#EDE9FE; color:#7C3AED; }
.stats-icon.orange { background:#FFEDD5; color:#C2410C; }
.stats-icon.gray { background:#F3F4F6; color:#6B7280; }
.stats-number { font-size: 2.1rem; font-weight: 700; color: var(--text-primary); line-height:1.1; }
.stats-label { font-size: .8rem; color: var(--text-secondary); margin-top: 4px; }
.stats-pct { font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.stats-pct.up { background:#D1FAE5; color:#059669; }
.stats-pct.down { background:#FEE2E2; color:#DC2626; }
.stats-pct.neutral { background:#F3F4F6; color:#6B7280; }

/* ---------------- Badges ---------------- */
.badge { display:inline-flex; align-items:center; padding: 2px 10px; border-radius: 999px; font-size: .72rem; font-weight: 600; white-space:nowrap; }
.badge-gray { background:#F3F4F6; color:#6B7280; }
.badge-green { background:#D1FAE5; color:#059669; }
.badge-amber { background:#FEF3C7; color:#D97706; }
.badge-red { background:#FEE2E2; color:#DC2626; }
.badge-purple { background:#EDE9FE; color:#7C3AED; }
.badge-blue { background:#DBEAFE; color:#1D4ED8; }
.badge-orange { background:#FFEDD5; color:#C2410C; }

/* ---------------- Buttons ---------------- */
.btn { display:inline-flex; align-items:center; justify-content:center; gap:6px; border:none; border-radius: 10px; padding: 9px 18px; font-size: .85rem; font-weight: 600; cursor: pointer; font-family:'Sarabun',sans-serif; transition: all .15s ease; }
.btn-primary { background: linear-gradient(135deg, var(--orange-light), var(--orange-primary)); color:#fff; box-shadow: 0 2px 8px rgba(249,115,22,.35); }
.btn-primary:hover { box-shadow: 0 4px 14px rgba(249,115,22,.5); transform: translateY(-1px); }
.btn-primary:disabled { opacity:.55; cursor:not-allowed; transform:none; box-shadow:none; }
.btn-secondary { background:#F3F4F6; color:#374151; }
.btn-secondary:hover { background:#E5E7EB; }
.btn-danger { background:#FEE2E2; color:#DC2626; }
.btn-danger:hover { background:#FECACA; }
.btn-outline { background:#fff; color:var(--orange-dark); border:1px solid #FDBA74; }
.btn-outline:hover { background:#FFF7ED; }
.btn-sm { padding: 6px 12px; font-size: .78rem; border-radius: 8px; }
.btn-block { width:100%; }

/* ---------------- Forms ---------------- */
.form-label { font-size: .8rem; font-weight: 600; color: var(--text-primary); margin-bottom: 5px; display:block; }
.form-control {
  width: 100%; border: 1px solid #E5E7EB; border-radius: 10px; padding: 9px 12px;
  font-size: .85rem; font-family:'Sarabun',sans-serif; background:#fff; color: var(--text-primary);
}
.form-control:focus { outline:none; border-color: var(--orange-primary); box-shadow: 0 0 0 3px rgba(249,115,22,.15); }
.search-input-wrap { position:relative; flex:1; }
.search-input-wrap .search-ico { position:absolute; left:12px; top:50%; transform:translateY(-50%); color:var(--text-muted); }
.search-input-wrap input { padding-left: 36px; }

/* ---------------- Table ---------------- */
.table-wrap { overflow-x: auto; background:#fff; border-radius: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
table.data-table { width: 100%; border-collapse: collapse; font-size: .84rem; }
table.data-table th { text-align:left; padding: 12px 16px; font-size:.74rem; color:var(--text-muted); font-weight:700; border-bottom:1px solid #F3F4F6; white-space:nowrap; }
table.data-table td { padding: 12px 16px; border-bottom:1px solid #F9FAFB; vertical-align: middle; }
table.data-table tr:hover td { background: #FFFBF5; }
table.data-table input.form-control, table.data-table select.form-control { padding: 6px 10px; font-size:.8rem; }

/* ---------------- Progress bar ---------------- */
.progress-wrap { background:#F3F4F6; border-radius:999px; height:9px; overflow:hidden; }
.progress-fill { height:100%; border-radius:999px; background: linear-gradient(90deg, #FDBA74, var(--orange-primary)); }
.progress-fill.green { background: linear-gradient(90deg, #6EE7B7, #059669); }
.progress-fill.purple { background: linear-gradient(90deg, #C4B5FD, #7C3AED); }

/* ---------------- Kanban ---------------- */
.kanban-wrap { display:grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .kanban-wrap { grid-template-columns: 1fr; } }
.kanban-col { background:#F9FAFB; border-radius:18px; padding: 14px; min-height: 300px; }
.kanban-col-header { display:flex; align-items:center; justify-content:space-between; padding: 4px 6px 14px; }
.kanban-col-title { font-weight:700; font-size:.92rem; color:var(--text-primary); display:flex; align-items:center; gap:8px; }
.kanban-count { background:#fff; border-radius:999px; padding:2px 10px; font-size:.75rem; font-weight:700; color:var(--orange-dark); }
.kanban-card {
  background:#fff; border-radius:14px; padding:14px; margin-bottom:12px; box-shadow:0 1px 3px rgba(0,0,0,.07);
  cursor: grab; border: 1px solid transparent;
}
.kanban-card.dragging { opacity:.5; }
.kanban-card:hover { border-color:#FDBA74; }
.kanban-card .kc-name { font-weight:700; font-size:.9rem; color:var(--text-primary); }
.kanban-card .kc-meta { font-size:.75rem; color:var(--text-secondary); margin-top:2px; }
.kanban-card .kc-tags { display:flex; flex-wrap:wrap; gap:6px; margin: 8px 0; }
.kanban-card .kc-note { background:#FFF7ED; border-radius:10px; padding:8px 10px; font-size:.76rem; color:#9A3412; margin: 8px 0; }
.kanban-card .kc-actions { display:flex; gap:6px; margin-top:10px; flex-wrap:wrap; }
.kanban-empty { text-align:center; color:var(--text-muted); font-size:.85rem; padding: 40px 10px; }

/* ---------------- Card grid (OPD, opt-out lists) ---------------- */
.record-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(320px,1fr)); gap: 16px; }
.record-card { background:#fff; border-radius:16px; padding:16px; box-shadow:0 1px 4px rgba(0,0,0,.06); }
.record-card .rc-head { display:flex; align-items:flex-start; justify-content:space-between; margin-bottom:8px; gap:8px; }
.record-card .rc-name { font-weight:700; font-size:.95rem; color:var(--text-primary); }
.record-card .rc-sub { font-size:.72rem; color:var(--text-muted); }
.record-card .rc-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; font-size:.78rem; margin: 10px 0; }
.record-card .rc-grid .lbl { color:var(--text-muted); }
.record-card .rc-grid .val { color:var(--text-primary); font-weight:600; }
.rc-toggle-btn { width:100%; text-align:center; background:#FFF7ED; color:var(--orange-dark); border:1px dashed #FDBA74; border-radius:10px; padding:8px; font-size:.82rem; font-weight:600; cursor:pointer; }
.rc-form { margin-top:12px; display:none; }
.rc-form.open { display:block; }
.rc-form .fld { margin-bottom:10px; }

/* ---------------- Modal ---------------- */
.modal-overlay { position: fixed; inset:0; background: rgba(17,24,39,.45); display:none; align-items:center; justify-content:center; z-index: 100; padding: 20px; }
.modal-overlay.open { display:flex; }
.modal-box { background:rgba(255,255,255,.92); backdrop-filter: blur(14px); border:1px solid rgba(255,255,255,.6); border-radius: 20px; max-width: 640px; width:100%; max-height: 88vh; overflow-y:auto; box-shadow: 0 24px 60px rgba(0,0,0,.25); }
.modal-header { display:flex; align-items:center; justify-content:space-between; padding: 18px 22px; border-bottom:1px solid #F3F4F6; background: linear-gradient(135deg, var(--orange-light), var(--orange-primary)); color:#fff; border-radius: 20px 20px 0 0; }
.modal-header h3 { margin:0; font-size:1rem; }
.modal-close { background:rgba(255,255,255,.25); border:none; color:#fff; width:30px; height:30px; border-radius:50%; cursor:pointer; font-size:1rem; }
.modal-body { padding: 20px 22px; }
.modal-footer { padding: 14px 22px; border-top:1px solid #F3F4F6; display:flex; justify-content:flex-end; gap:8px; }
.detail-grid { display:grid; grid-template-columns:1fr 1fr; gap: 12px 20px; font-size:.85rem; }
.detail-grid .lbl { color:var(--text-muted); font-size:.72rem; }
.detail-grid .val { color:var(--text-primary); font-weight:600; margin-top:2px; }

/* ---------------- Toast ---------------- */
#toast-region { position: fixed; top: 20px; right: 20px; z-index: 200; display:flex; flex-direction:column; gap:10px; }
.toast { background:#fff; border-left: 4px solid var(--orange-primary); border-radius:10px; padding:12px 16px; box-shadow:0 8px 24px rgba(0,0,0,.15); font-size:.85rem; min-width:260px; animation: toast-in .2s ease; }
.toast.success { border-color:#059669; }
.toast.error { border-color:#DC2626; }
@keyframes toast-in { from { opacity:0; transform: translateY(-8px);} to { opacity:1; transform:translateY(0);} }

/* ---------------- Tabs ---------------- */
.tabs-row { display:flex; gap:6px; flex-wrap:wrap; margin-bottom:16px; }
.tab-btn { padding: 8px 16px; border-radius:10px; font-size:.82rem; font-weight:600; color:var(--text-secondary); background:#fff; border:1px solid #F3F4F6; cursor:pointer; }
.tab-btn.active { background: linear-gradient(135deg, var(--orange-light), var(--orange-primary)); color:#fff; border-color:transparent; }

/* ---------------- Accordion (manual/FAQ) ---------------- */
.accordion-item { background:#fff; border-radius:12px; margin-bottom:8px; overflow:hidden; box-shadow:0 1px 3px rgba(0,0,0,.05); }
.accordion-btn { width:100%; text-align:left; background:none; border:none; padding:14px 16px; font-size:.86rem; font-weight:600; color:var(--text-primary); cursor:pointer; display:flex; justify-content:space-between; align-items:center; gap:10px; }
.accordion-panel { max-height:0; overflow:hidden; transition: max-height .2s ease; padding: 0 16px; font-size:.82rem; color:var(--text-secondary); line-height:1.7; }
.accordion-item.open .accordion-panel { max-height: 800px; padding: 0 16px 16px; }
.accordion-item.open .accordion-btn .chev { transform: rotate(180deg); }

/* ---------------- Pagination ---------------- */
.pagination { display:flex; gap:6px; justify-content:center; margin-top: 18px; flex-wrap:wrap; }
.pagination a, .pagination span { padding:7px 13px; border-radius:8px; font-size:.8rem; background:#fff; color:var(--text-secondary); border:1px solid #F3F4F6; }
.pagination a:hover { background:#FEF3C7; }
.pagination .current { background: var(--orange-primary); color:#fff; border-color: var(--orange-primary); font-weight:700; }

/* ---------------- Utility ---------------- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.mt-0 { margin-top:0; }
.empty-state { text-align:center; padding: 60px 20px; color: var(--text-muted); }
.empty-state .ico { font-size:2.4rem; margin-bottom:10px; }

/* ---------------- Login page ---------------- */
.login-shell { min-height:100vh; display:flex; align-items:center; justify-content:center; background: linear-gradient(160deg, #FDF0E8, #FDE4CF); padding: 20px; }
.login-card { background:rgba(255,255,255,.85); backdrop-filter: blur(16px); border:1px solid rgba(255,255,255,.6); border-radius: 24px; padding: 40px 36px; width: 100%; max-width: 400px; box-shadow: 0 30px 70px rgba(234,88,12,.15); }
.login-logo { width:56px; height:56px; border-radius:16px; background: linear-gradient(135deg, var(--orange-light), var(--orange-primary)); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:1.3rem; margin: 0 auto 16px; }

#mobileMenuBtn { display: none; }

@media (max-width: 860px) {
  #mobileMenuBtn { display: flex; }
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 40px rgba(0,0,0,.2); }
  .sidebar.open { transform: translateX(0); }
  .main-area { margin-left: 0; width: 100%; }
  .stats-grid { grid-template-columns: repeat(2,1fr); }
  .topbar-clinic-text { display: none; }
  .topbar-title-wrap { flex: 1 1 auto; min-width: 0; }
  .topbar-subtitle { display: none; }
  .logout-link span { display: none; }
  .topbar-clinic { padding-left: 4px; border-left: none; margin-left: 0; }
  .topbar-actions { flex-shrink: 0; }
}
