/* =====================================================================
   app.css — Aomkod Design System + Glassmorphism (CheckMate style)
   ===================================================================== */
* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Sarabun', sans-serif; }

:root {
  --color-primary: #a7f179; --color-secondary: #79f187; --color-tertiary: #e3f179;
  --color-quaternary: #afb1ef; --color-quinary: #dfafef;
  --orange: #79F187; --orange-light: #A7F179; --orange-dark: #2F6B34;
  --bg-page: #EFFBEA;
  --text-1: #1F2937; --text-2: #6B7280; --text-3: #9CA3AF;
}

body { background: var(--bg-page); min-height: 100vh; color: var(--text-1); }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }
.main-area { flex: 1; margin-left: 250px; display: flex; flex-direction: column; min-width: 0; }
.content { padding: 24px 28px; flex: 1; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 250px; position: fixed; inset: 0 auto 0 0; z-index: 40;
  background: rgba(255,255,255,.85); backdrop-filter: blur(14px);
  border-right: 1px solid rgba(121,241,135,.12);
  display: flex; flex-direction: column; transition: transform .25s;
}
.logo-area { display: flex; align-items: center; gap: 10px; padding: 16px; border-bottom: 1px solid #E2F7D9; }
.logo-icon { background: linear-gradient(135deg,#A7F179,#79F187); color:#fff; border-radius: 10px; width:40px; height:40px; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:1rem; box-shadow: 0 2px 8px rgba(121,241,135,.35); }
.app-name { font-weight: 700; font-size: .95rem; }
.tagline { font-size: .65rem; color: var(--text-3); }

.session-timer { text-align:center; padding: 10px 16px 4px; }
.session-timer .clock { font-weight: 700; font-size: 1.05rem; color: var(--orange-dark); }
.timer-bar-wrap { background:#F3F4F6; height:5px; border-radius:999px; margin:6px 16px 8px; overflow:hidden; }
.timer-bar { height:100%; border-radius:999px; background:linear-gradient(90deg,#A7F179,#79F187); transition: width 1s linear; }

.sidebar nav { flex: 1; padding: 8px 12px; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px; margin-bottom: 4px;
  border-radius: 12px; color: #374151; text-decoration: none; font-size: .9rem; cursor: pointer;
}
.nav-item .badge-num {
  margin-left: auto; background: #FEF3C7; color: #B45309; font-size: .7rem; font-weight: 700;
  padding: 1px 8px; border-radius: 999px; min-width: 26px; text-align: center;
}
.nav-item.active { background: linear-gradient(135deg,#A7F179,#79F187); color: #fff; font-weight: 600; box-shadow: 0 3px 10px rgba(121,241,135,.35); }
.nav-item.active .badge-num { background: rgba(255,255,255,.25); color: #fff; }
.nav-item:hover:not(.active) { background: #EFFBEA; color: var(--orange); }
.sidebar-footer { padding: 12px 16px; font-size: .7rem; color: var(--text-3); border-top: 1px solid #E2F7D9; }

/* ---------- Topbar ---------- */
.topbar {
  height: 56px; background: rgba(255,255,255,.8); backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
  border-bottom: 1px solid rgba(121,241,135,.1); position: sticky; top: 0; z-index: 30;
}
.topbar .unit-label { font-size: .85rem; color: var(--text-2); }
.topbar .unit-label b { color: var(--text-1); }
.user-chip { display:flex; align-items:center; gap:10px; cursor:pointer; padding:4px 8px; border-radius:12px; }
.user-chip:hover { background:#EFFBEA; }
.user-avatar { width:34px; height:34px; background:linear-gradient(135deg,#A7F179,#79F187); color:#fff; border-radius:50%; display:flex; align-items:center; justify-content:center; font-weight:700; overflow:hidden; }
.user-avatar img { width:100%; height:100%; object-fit:cover; }
.user-menu {
  position:absolute; right:16px; top:60px; background:rgba(255,255,255,.95); backdrop-filter:blur(14px);
  border-radius:16px; box-shadow:0 10px 40px rgba(0,0,0,.15); padding:10px; min-width:220px; display:none; z-index:60;
}
.user-menu.open { display:block; }
.user-menu a { display:flex; gap:10px; align-items:center; padding:9px 12px; border-radius:10px; color:#374151; text-decoration:none; font-size:.88rem; }
.user-menu a:hover { background:#EFFBEA; color:var(--orange); }

/* ---------- Cards ---------- */
.card {
  background: rgba(255,255,255,.85); backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: 18px; padding: 20px; box-shadow: 0 4px 20px rgba(47,107,52,.07);
}
.glass-panel { background: rgba(255,255,255,.6); backdrop-filter: blur(8px); border-radius: 16px; padding: 16px; border: 1px solid rgba(255,255,255,.7); }

.stats-card { border-radius: 16px; padding: 16px; color: var(--text-1); }
.stats-card .num { font-size: 1.9rem; font-weight: 700; }
.stats-card .lbl { font-size: .8rem; color: var(--text-2); display:flex; align-items:center; gap:6px; }
.sc-blue { background:#DBEAFE; } .sc-red { background:#FEE2E2; } .sc-amber { background:#FEF3C7; }
.sc-teal { background:#CCFBF1; } .sc-green { background:#D1FAE5; } .sc-gray { background:#F3F4F6; } .sc-purple { background:#EDE9FE; }

.page-title { font-size: 1.45rem; font-weight: 700; text-align: center; margin-bottom: 18px; }

/* ---------- Buttons ---------- */
.btn { border:none; border-radius: 10px; padding: 9px 18px; font-size: .88rem; font-weight: 600; cursor: pointer; font-family:'Sarabun'; display:inline-flex; align-items:center; gap:7px; transition: all .15s; text-decoration:none; }
.btn:disabled { opacity:.5; cursor:not-allowed; }
.btn-primary { background: linear-gradient(135deg,#A7F179,#79F187); color:#fff; box-shadow: 0 2px 8px rgba(121,241,135,.35); }
.btn-primary:hover:not(:disabled) { box-shadow: 0 4px 14px rgba(121,241,135,.5); transform: translateY(-1px); }
.btn-secondary { background:#4B5563; color:#fff; }
.btn-secondary:hover { background:#374151; }
.btn-danger { background:#DC2626; color:#fff; }
.btn-danger:hover { background:#B91C1C; }
.btn-blue { background:#2563EB; color:#fff; }
.btn-blue:hover { background:#1D4ED8; }
.btn-green { background:#059669; color:#fff; }
.btn-outline { background:#fff; border:1.5px solid #E5E7EB; color:#374151; }
.btn-outline:hover { border-color: var(--orange); color: var(--orange); }
.btn-sm { padding: 5px 12px; font-size:.8rem; border-radius:8px; }
.btn-icon { padding: 6px 9px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 12px 14px; }
.g2 { grid-template-columns: repeat(2,1fr); } .g3 { grid-template-columns: repeat(3,1fr); }
.g4 { grid-template-columns: repeat(4,1fr); } .g5 { grid-template-columns: repeat(5,1fr); } .g6 { grid-template-columns: repeat(6,1fr); }
label.fl { display:block; font-size:.8rem; font-weight:600; color:#374151; margin-bottom:4px; }
.inp, select.inp, textarea.inp {
  width:100%; border:1.5px solid #E5E7EB; border-radius:10px; padding:8px 12px; font-size:.88rem;
  font-family:'Sarabun'; background:#fff; color:var(--text-1); outline:none; transition: border .15s;
}
.inp:focus { border-color: var(--orange); box-shadow: 0 0 0 3px rgba(121,241,135,.12); }
.inp[readonly], .inp:disabled { background:#F3F4F6; color:#6B7280; }
textarea.inp { resize: vertical; min-height: 70px; }
.section-bar { background:#E2F7D9; border-radius:10px; padding:8px 14px; font-weight:700; font-size:.9rem; margin:14px 0 10px; }
.mic-btn { cursor:pointer; color:#6B7280; font-size:.95rem; margin-left:4px; }
.mic-btn.listening { color:#DC2626; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity:.4; } }

/* ---------- Tables ---------- */
.table-wrap { overflow-x:auto; border-radius: 14px; border:1px solid #D3F0BC; background:#fff; }
table.dt { width:100%; border-collapse: collapse; font-size:.85rem; min-width: 600px; }
table.dt thead th {
  background:#EFFBEA; padding:9px 12px; text-align:left; font-weight:700; color:#2F6B34;
  border-bottom:2px solid #D3F0BC; cursor:pointer; user-select:none; white-space:nowrap; position:sticky; top:0;
}
table.dt thead th .arrow { font-size:.65rem; color:#3F8F45; margin-left:3px; }
table.dt tbody td { padding:8px 12px; border-bottom:1px solid #E2F7D9; }
table.dt tbody tr { cursor:pointer; }
table.dt tbody tr:hover { background:#EFFBEA; }
table.dt tbody tr.selected { background:#E2F7D9; }
.no-data { text-align:center; padding:30px; color:#fff; background:#9CA3AF; font-weight:700; border-radius:8px; margin:8px; }
.table-footer { display:flex; justify-content:space-between; align-items:center; padding:10px 14px; font-size:.8rem; color:var(--text-2); flex-wrap:wrap; gap:8px; }
.pager { display:flex; gap:4px; }
.pager button { border:1px solid #E5E7EB; background:#fff; border-radius:7px; padding:3px 9px; font-size:.78rem; cursor:pointer; font-family:'Sarabun'; }
.pager button.cur { background:var(--orange); color:#fff; border-color:var(--orange); font-weight:700; }
.pager button:disabled { opacity:.4; cursor:default; }

/* ---------- Badges ---------- */
.badge { padding:2px 10px; border-radius:999px; font-size:.72rem; font-weight:600; display:inline-block; white-space:nowrap; }
.bg-green  { background:#D1FAE5; color:#059669; }
.bg-amber  { background:#FEF3C7; color:#D97706; }
.bg-red    { background:#FEE2E2; color:#DC2626; }
.bg-gray   { background:#F3F4F6; color:#6B7280; }
.bg-blue   { background:#DBEAFE; color:#1D4ED8; }
.bg-purple { background:#EDE9FE; color:#7C3AED; }
.bg-teal   { background:#CCFBF1; color:#0F766E; }
.bg-orange { background:#E2F7D9; color:#3F8F45; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position:fixed; inset:0; background:rgba(31,41,55,.45); backdrop-filter: blur(3px);
  display:none; align-items:flex-start; justify-content:center; z-index:100; overflow-y:auto; padding:30px 12px;
}
.modal-backdrop.open { display:flex; }
.modal {
  background:rgba(255,255,255,.97); backdrop-filter:blur(16px); border-radius:20px; width:100%; max-width:680px;
  box-shadow:0 20px 60px rgba(0,0,0,.25); padding:22px 24px; position:relative; animation: modalin .18s ease;
}
.modal.lg { max-width: 1050px; } .modal.sm { max-width: 430px; } .modal.xl { max-width: 1250px; }
@keyframes modalin { from { transform: translateY(14px); opacity:0; } to { transform:none; opacity:1; } }
.modal .close-x { position:absolute; top:14px; right:16px; border:none; background:none; font-size:1.3rem; cursor:pointer; color:#6B7280; }
.modal .close-x:hover { color:#DC2626; }
.modal h3 { text-align:center; font-size:1.05rem; margin-bottom:14px; }

/* ---------- Tabs ---------- */
.tabs { display:flex; flex-wrap:wrap; gap:4px; border-bottom:2px solid #D3F0BC; margin-bottom:14px; }
.tab {
  padding:8px 14px; border-radius:10px 10px 0 0; font-size:.85rem; font-weight:600; cursor:pointer;
  color:#4B5563; display:flex; align-items:center; gap:6px; border:none; background:none; font-family:'Sarabun';
}
.tab.active { background:linear-gradient(135deg,#A7F179,#79F187); color:#fff; }
.tab:hover:not(.active) { background:#EFFBEA; color:var(--orange); }
.tab-pane { display:none; } .tab-pane.active { display:block; }

/* ---------- Accordion ---------- */
.acc-item { border:1px solid #D3F0BC; border-radius:12px; margin-bottom:8px; overflow:hidden; background:#fff; }
.acc-head { padding:11px 16px; background:#EFFBEA; font-weight:700; font-size:.9rem; color:#2F6B34; cursor:pointer; display:flex; justify-content:space-between; align-items:center; }
.acc-body { padding:16px; display:none; }
.acc-item.open .acc-body { display:block; }
.acc-title-red { color:#DC2626; font-size:1.15rem; font-weight:600; border-bottom:2px solid #FCA5A5; padding-bottom:6px; margin-bottom:12px; }

/* ---------- Toast ---------- */
#toast-area { position:fixed; top:18px; right:18px; z-index:300; display:flex; flex-direction:column; gap:8px; }
.toast { padding:12px 18px; border-radius:12px; color:#fff; font-size:.88rem; font-weight:600; box-shadow:0 6px 20px rgba(0,0,0,.2); animation: toastin .25s ease; max-width:340px; }
.toast.ok { background:linear-gradient(135deg,#34D399,#059669); }
.toast.err { background:linear-gradient(135deg,#F87171,#DC2626); }
@keyframes toastin { from { transform:translateX(30px); opacity:0; } to { transform:none; opacity:1; } }

/* ---------- Patient action grid ---------- */
.pmenu-grid { display:grid; grid-template-columns:repeat(2,1fr); gap:10px; }
.pmenu-btn {
  border:1.5px solid #D3F0BC; background:#fff; border-radius:14px; padding:14px; text-align:left;
  cursor:pointer; display:flex; gap:12px; align-items:flex-start; font-family:'Sarabun'; transition:all .15s;
}
.pmenu-btn:hover { border-color:var(--orange); background:#EFFBEA; transform:translateY(-2px); }
.pmenu-btn .ic { font-size:1.4rem; }
.pmenu-btn b { font-size:.92rem; display:block; }
.pmenu-btn span { font-size:.75rem; color:var(--text-2); }

/* ---------- Exam room ---------- */
.exam-topbar { display:flex; flex-wrap:wrap; gap:6px; margin-bottom:10px; }
.patient-card {
  background:linear-gradient(135deg,#ECFDF5,#D1FAE5); border:1px solid #A7F3D0; border-radius:16px;
  padding:14px 18px; display:flex; gap:16px; margin-bottom:10px; font-size:.85rem;
}
.patient-card .avatar { width:74px; height:74px; border-radius:50%; background:#fff; flex-shrink:0; display:flex; align-items:center; justify-content:center; font-size:1.8rem; overflow:hidden; border:2px solid #fff; box-shadow:0 2px 8px rgba(0,0,0,.08); }
.patient-card .avatar img { width:100%; height:100%; object-fit:cover; }
.money-bar { text-align:center; font-size:.9rem; margin:8px 0 14px; line-height:1.9; }
.money-pill { background:#1F2937; color:#fff; padding:2px 12px; border-radius:999px; font-weight:700; }
.money-pill.orange { background:linear-gradient(135deg,#A7F179,#79F187); }
.money-pill.green { background:#059669; }

/* ---------- Login ---------- */
.login-page {
  min-height:100vh; display:flex; align-items:center; justify-content:center; padding:20px;
  background: linear-gradient(135deg,#EFFBEA 0%,#EFFBEA 40%,#E2F7D9 100%);
  position:relative; overflow:hidden;
}
.login-page::before, .login-page::after {
  content:''; position:absolute; border-radius:50%; filter:blur(60px); opacity:.5; z-index:0;
}
.login-page::before { width:420px; height:420px; background:#DFAFEF; top:-120px; right:-80px; }
.login-page::after { width:380px; height:380px; background:#AFB1EF; bottom:-120px; left:-80px; }
.login-card {
  position:relative; z-index:1; width:100%; max-width:430px;
  background:rgba(255,255,255,.65); backdrop-filter:blur(20px);
  border:1px solid rgba(255,255,255,.8); border-radius:24px; padding:34px 30px;
  box-shadow:0 25px 60px rgba(47,107,52,.18);
}

/* ---------- Calendar ---------- */
.cal-grid { display:grid; grid-template-columns:repeat(7,1fr); border:1px solid #D3F0BC; border-radius:12px; overflow:hidden; background:#fff; }
.cal-head { background:#EFFBEA; font-weight:700; text-align:center; padding:8px 4px; font-size:.8rem; color:#2F6B34; border-bottom:2px solid #D3F0BC; }
.cal-cell { min-height:92px; border:1px solid #E2F7D9; padding:4px 6px; font-size:.78rem; vertical-align:top; position:relative; cursor:pointer; background:#fff; }
.cal-cell:hover { background:#EFFBEA; }
.cal-cell.today { background:#FEF9C3; }
.cal-cell.weekend { background:#EFFBEA; }
.cal-cell.other { background:#FAFAFA; color:#C9CDD4; }
.cal-cell .dnum { font-weight:700; font-size:.85rem; text-align:right; }
.cal-event { background:linear-gradient(135deg,#A7F179,#79F187); color:#fff; border-radius:6px; padding:1px 6px; font-size:.68rem; margin-top:2px; overflow:hidden; white-space:nowrap; text-overflow:ellipsis; }

/* ---------- misc ---------- */
.flex { display:flex; } .items-center { align-items:center; } .justify-between { justify-content:space-between; }
.gap-2 { gap:8px; } .gap-3 { gap:12px; } .gap-4 { gap:16px; } .mb-2 { margin-bottom:8px; } .mb-3 { margin-bottom:12px; } .mb-4 { margin-bottom:16px; }
.mt-2 { margin-top:8px; } .mt-3 { margin-top:12px; } .mt-4 { margin-top:16px; }
.text-center { text-align:center; } .text-right { text-align:right; } .flex-wrap { flex-wrap:wrap; }
.text-sm { font-size:.82rem; } .text-xs { font-size:.72rem; } .text-muted { color:var(--text-2); }
.w-full { width:100%; } .hidden { display:none !important; }
.link-orange { color:var(--orange); cursor:pointer; text-decoration:none; font-weight:600; }
.link-orange:hover { text-decoration:underline; }
.hamburger { display:none; background:none; border:none; font-size:1.3rem; cursor:pointer; color:#374151; }
footer.app-footer { text-align:center; font-size:.75rem; color:var(--text-3); padding:14px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; box-shadow: 0 0 60px rgba(0,0,0,.3); }
  .main-area { margin-left: 0; }
  .hamburger { display:block; }
  .g3,.g4,.g5,.g6 { grid-template-columns: repeat(2,1fr); }
  .pmenu-grid { grid-template-columns:1fr; }
  .content { padding:16px 12px; }
  .modal { padding:18px 14px; }
}
@media (max-width: 560px) { .g2,.g3,.g4,.g5,.g6 { grid-template-columns: 1fr; } }

/* ---------- Print ---------- */
@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area { position: absolute; inset: 0; }
}
