/* ============================================================
 * pims-mock/assets/style.css
 * ------------------------------------------------------------
 * ธีม: Modern Medical · Responsive (PC / แท็บเล็ต / มือถือ)
 * Design tokens + Components + Breakpoints
 * ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

/* ------------------------------------------------------------
 * 1. Design Tokens
 * ------------------------------------------------------------ */
:root{
  /* สีหลัก */
  --primary:#0D9488;
  --primary-d:#0F766E;
  --primary-l:#CCFBF1;
  --accent:#0EA5E9;
  --accent-l:#E0F2FE;

  /* สีสถานะ */
  --success:#16A34A;  --success-l:#DCFCE7;
  --warning:#F59E0B;  --warning-l:#FEF3C7;
  --danger:#DC2626;   --danger-l:#FEE2E2;
  --info:#0EA5E9;     --info-l:#E0F2FE;
  --slate-l:#EEF2F6;

  /* พื้น/ตัวอักษร */
  --bg:#F1F5F9;
  --surface:#FFFFFF;
  --line:#E2E8F0;
  --line-2:#CBD5E1;
  --ink:#0F172A;
  --muted:#64748B;

  /* รัศมี / เงา */
  --r-sm:8px; --r:12px; --r-lg:16px; --r-full:999px;
  --sh1:0 1px 2px rgba(15,23,42,.06);
  --sh2:0 6px 18px rgba(15,23,42,.08);
  --sh3:0 12px 32px rgba(15,23,42,.16);

  /* ขนาดโครง */
  --sidebar-w:260px;
  --bottomnav-h:64px;
  --maxw:1200px;
  --tap:44px;
}

/* ------------------------------------------------------------
 * 2. Base
 * ------------------------------------------------------------ */
*{ box-sizing:border-box; }
html, body{ margin:0; background:var(--bg); color:var(--ink); }
body{
  font-family:'Sarabun',-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;
  font-size:15px; line-height:1.5; -webkit-text-size-adjust:100%;
}
a{ color:inherit; }
h1,h2,h3,h4{ margin:0; }
img{ max-width:100%; }

::-webkit-scrollbar{ height:8px; width:8px; }
::-webkit-scrollbar-thumb{ background:#cbd5e1; border-radius:8px; }
::-webkit-scrollbar-track{ background:transparent; }

/* ------------------------------------------------------------
 * 3. Layout
 * ------------------------------------------------------------ */
.layout{ display:flex; min-height:100vh; }
.main{ flex:1; min-width:0; display:flex; flex-direction:column; }

/* ---------- Sidebar ---------- */
.sidebar{
  width:var(--sidebar-w); flex-shrink:0;
  background:linear-gradient(180deg,var(--primary-d),#0B5C57);
  color:#fff; display:flex; flex-direction:column;
  position:sticky; top:0; height:100vh; overflow-y:auto; z-index:400;
}
.brand{ padding:20px; border-bottom:1px solid rgba(255,255,255,.14); }
.brand h1{ font-size:17px; line-height:1.3; }
.brand p{ font-size:12px; margin:4px 0 0; opacity:.8; }
.nav{ padding:12px 10px; flex:1; }
.nav a{
  display:flex; align-items:center; gap:12px;
  padding:12px 14px; margin:3px 0; border-radius:var(--r);
  color:#e6fffb; text-decoration:none; font-size:15px;
  cursor:pointer; transition:.15s; border:1px solid transparent;
}
.nav a:hover{ background:rgba(255,255,255,.12); }
.nav a.active{ background:#fff; color:var(--primary-d); font-weight:700; box-shadow:var(--sh1); }
.nav .ico{ font-size:18px; width:22px; text-align:center; flex-shrink:0; }

/* ---------- Topbar ---------- */
.topbar{
  position:sticky; top:0; z-index:60;
  background:var(--surface); border-bottom:1px solid var(--line);
  padding:12px 24px; display:flex; align-items:center; justify-content:space-between;
  gap:16px; box-shadow:var(--sh1);
}
.topbar .tb-left{ display:flex; align-items:center; gap:12px; min-width:0; }
.topbar h2{ font-size:19px; color:var(--ink); white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.topbar .sub{ font-size:12px; color:var(--muted); margin-top:1px; }
.hamb{
  display:none; font-size:22px; line-height:1;
  background:var(--slate-l); border:1px solid var(--line); color:var(--primary-d);
  width:var(--tap); height:var(--tap); border-radius:var(--r); cursor:pointer; flex-shrink:0;
}
.backdrop{ display:none; position:fixed; inset:0; background:rgba(15,23,42,.45); z-index:150; }
.backdrop.show{ display:block; }

/* ---------- Content ---------- */
.content{
  padding:22px 24px 40px; width:100%;
  max-width:var(--maxw); margin:0 auto;
}
.page{ display:none; animation:fade .22s ease; }
.page.show{ display:block; }
@keyframes fade{ from{ opacity:0; transform:translateY(6px); } to{ opacity:1; transform:none; } }

/* ------------------------------------------------------------
 * 4. Buttons
 * ------------------------------------------------------------ */
button{ font-family:inherit; }
.btn-main,.rbtn,.pbtn,.refresh-btn,.logout-btn,.reset-btn,.btn-ghost,.icon-btn{
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  min-height:var(--tap); padding:10px 18px; border-radius:var(--r);
  font-size:15px; font-weight:700; cursor:pointer; transition:.15s; border:1px solid transparent;
}
.btn-main{ background:var(--primary); color:#fff; }
.btn-main:hover{ background:var(--primary-d); }
.panel .btn-main{ width:100%; }
.rbtn{ background:var(--success); color:#fff; }
.rbtn:hover{ filter:brightness(.94); }
.pbtn{ background:var(--surface); color:var(--primary-d); border-color:var(--line-2); }
.pbtn:hover{ background:var(--primary-l); border-color:var(--primary); }
.refresh-btn{ background:var(--slate-l); color:var(--primary-d); border-color:var(--line); }
.refresh-btn:hover{ background:#e2e8f0; }
.refresh-btn:disabled{ opacity:.6; cursor:wait; }
.logout-btn{ background:var(--danger-l); color:var(--danger); border-color:#f3c2c2; }
.logout-btn:hover{ background:var(--danger); color:#fff; border-color:var(--danger); }
.reset-btn{ background:#fff7ed; color:#b45309; border-color:#fed7aa; }
.reset-btn:hover{ background:#ffedd5; }
.btn-ghost{ background:var(--surface); border-color:var(--line); color:var(--ink); }
.btn-ghost:hover{ background:var(--slate-l); }
.icon-btn{
  min-height:34px; padding:6px 10px; font-size:13px; font-weight:600;
  background:var(--surface); border:1px solid var(--line); color:var(--ink); border-radius:var(--r-sm);
}
.icon-btn:hover{ background:var(--slate-l); }
.icon-btn.danger{ border-color:#f3c2c2; color:var(--danger); }
.icon-btn.danger:hover{ background:var(--danger-l); }

.top-actions{ display:flex; align-items:center; gap:8px; flex-shrink:0; }

/* ------------------------------------------------------------
 * 5. Panels / Cards
 * ------------------------------------------------------------ */
.panel{
  background:var(--surface); border:1px solid var(--line); border-radius:var(--r-lg);
  padding:20px; margin-bottom:18px; box-shadow:var(--sh1);
}
.panel h3{ font-size:16px; color:var(--primary-d); margin-bottom:14px; }

.dashboard{
  display:grid; grid-template-columns:repeat(auto-fit,minmax(150px,1fr));
  gap:14px; margin-bottom:18px;
}
.card{
  background:var(--surface); border:1px solid var(--line); border-left:5px solid var(--primary);
  border-radius:var(--r-lg); padding:16px 18px; box-shadow:var(--sh1);
  cursor:pointer; transition:.15s;
}
.card:hover{ transform:translateY(-2px); box-shadow:var(--sh2); }
.card .title{ font-size:13px; color:var(--muted); font-weight:600; }
.card .number{ font-size:34px; font-weight:800; margin-top:4px; line-height:1.1; }
.card.red{ border-left-color:var(--danger); }
.card.red .number{ color:var(--danger); }
.card.yellow{ border-left-color:var(--warning); }
.card.yellow .number{ color:#b45309; }
.card.blue{ border-left-color:var(--accent); }
.card.blue .number{ color:var(--accent); }
.card.gray{ border-left-color:#607d8b; }
.card.gray .number{ color:#455a64; }

/* แถบสถานะ READY / NOT READY */
.cart-status{
  display:flex; align-items:center; gap:16px; color:#fff;
  border-radius:var(--r-lg); padding:20px 22px; margin-bottom:18px; box-shadow:var(--sh2);
}
.cart-status .icon{ font-size:42px; line-height:1; }
.cart-status .big{ font-size:24px; font-weight:800; }
.cart-status .lbl{ font-size:13px; opacity:.92; margin-top:2px; }
.cart-status.ready{ background:linear-gradient(135deg,#16A34A,#15803d); }
.cart-status.notready{ background:linear-gradient(135deg,#DC2626,#991b1b); }

/* ------------------------------------------------------------
 * 6. Forms
 * ------------------------------------------------------------ */
.panel input, .panel select, .modal input, .modal select{
  width:100%; padding:11px 12px; margin-bottom:10px;
  border:1px solid var(--line-2); border-radius:var(--r-sm);
  font-size:15px; font-family:inherit; background:var(--surface); color:var(--ink);
}
.panel input:focus, .panel select:focus, .modal input:focus, .modal select:focus{
  outline:none; border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-l);
}
.toolbar{ display:flex; flex-wrap:wrap; gap:8px; align-items:center; margin-bottom:14px; }
.toolbar .grow{ flex:1; min-width:170px; margin-bottom:0; }
.toolbar > *{ margin-bottom:0 !important; }
.form-grid{ display:grid; grid-template-columns:repeat(auto-fit,minmax(140px,1fr)); gap:10px; }
.form-grid label, .lbl-sm{ font-size:12px; color:var(--muted); display:block; margin-bottom:4px; }

/* checkbox */
.panel label, .toolbar label{ font-size:13px; }

/* ------------------------------------------------------------
 * 7. Badges
 * ------------------------------------------------------------ */
.badge{
  display:inline-block; padding:3px 10px; border-radius:var(--r-full);
  font-size:12px; font-weight:700; white-space:nowrap;
}
.badge.normal,.badge.ok{ background:var(--success-l); color:#15803d; }
.badge.warning{ background:var(--warning-l); color:#b45309; }
.badge.critical{ background:#FFEDD5; color:#c2410c; }
.badge.expired{ background:var(--danger-l); color:var(--danger); }
.badge.missing{ background:var(--slate-l); color:#455a64; }
.badge.muted{ background:var(--slate-l); color:var(--muted); }

/* ------------------------------------------------------------
 * 8. Tables
 * ------------------------------------------------------------ */
.table-wrap{ overflow-x:auto; -webkit-overflow-scrolling:touch; }
table{ width:100%; border-collapse:collapse; font-size:14px; background:var(--surface); }
th,td{ border:1px solid var(--line); padding:9px 11px; text-align:left; vertical-align:middle; }
th{
  background:var(--slate-l); color:var(--primary-d); font-weight:800;
  position:sticky; top:0; z-index:1;
}
td.num, th.num{ text-align:center; }
tbody tr:nth-child(even){ background:#fafbfc; }
tbody tr:hover{ background:#f6fbfa; }
.table-actions{ display:flex; gap:6px; flex-wrap:wrap; }
.row-inactive{ opacity:.5; }
.row-missing td{ background:#fff5f5; }
table td .badge{ margin:1px 0; }

/* ---------- กลุ่มหมวดหมู่ ---------- */
.cat-group{ margin-bottom:18px; }
.cat-group:last-child{ margin-bottom:0; }
.cat-title{
  background:linear-gradient(180deg,#ecfeff,#f0fdfa);
  color:var(--primary-d); font-weight:800; font-size:14px;
  padding:10px 14px; border:1px solid var(--line); border-bottom:0;
  border-radius:var(--r) var(--r) 0 0;
}
.cat-group .table-wrap{ border:1px solid var(--line); border-radius:0 0 var(--r) var(--r); }
.cat-group table{ border:0; }
.cat-group th, .cat-group td{ border-left:0; border-right:0; }
.cat-group th:first-child, .cat-group td:first-child{ border-left:0; }
.cat-group th:last-child, .cat-group td:last-child{ border-right:0; }

/* ---------- toggle มี/ไม่มี ---------- */
.toggle{ display:inline-flex; border:1px solid var(--line-2); border-radius:var(--r-sm); overflow:hidden; }
.toggle button{ border:0; background:var(--surface); padding:8px 14px; cursor:pointer; font-size:13px; font-weight:700; color:var(--muted); }
.toggle button.on-yes{ background:var(--success); color:#fff; }
.toggle button.on-no{ background:var(--danger); color:#fff; }

/* ------------------------------------------------------------
 * 9. Tabs (ตั้งค่า)
 * ------------------------------------------------------------ */
.tabs{ display:flex; gap:6px; border-bottom:2px solid var(--line); margin-bottom:16px; flex-wrap:wrap; }
.tab{
  border:0; background:transparent; padding:10px 14px; cursor:pointer; font-size:14px;
  font-weight:700; color:var(--muted); border-bottom:3px solid transparent; margin-bottom:-2px;
}
.tab:hover{ color:var(--primary-d); }
.tab.active{ color:var(--primary-d); border-bottom-color:var(--primary); }
.stab{ display:none; }
.stab.show{ display:block; }

/* ------------------------------------------------------------
 * 10. Modal (desktop) / Bottom sheet (mobile)
 * ------------------------------------------------------------ */
.modal-overlay{
  position:fixed; inset:0; background:rgba(15,23,42,.5); z-index:900;
  display:none; align-items:center; justify-content:center; padding:16px;
}
.modal-overlay.show{ display:flex; }
.modal{
  background:var(--surface); border-radius:var(--r-lg); padding:22px;
  width:100%; max-width:520px; max-height:90vh; overflow:auto; box-shadow:var(--sh3);
  animation:pop .18s ease;
}
@keyframes pop{ from{ opacity:0; transform:translateY(10px) scale(.98); } to{ opacity:1; transform:none; } }
.modal h3{ color:var(--primary-d); margin-bottom:14px; }
.modal-actions{ display:flex; gap:8px; justify-content:flex-end; margin-top:14px; }
.modal-actions .btn-main{ width:auto; }

/* ------------------------------------------------------------
 * 11. Misc
 * ------------------------------------------------------------ */
.empty{ text-align:center; color:var(--muted); padding:28px 10px; }
.loading{ display:flex; align-items:center; justify-content:center; gap:8px; color:var(--muted); padding:26px 10px; }
.loading::before{
  content:""; width:16px; height:16px; border-radius:50%;
  border:2px solid var(--line-2); border-top-color:var(--primary);
  animation:spin .7s linear infinite;
}
@keyframes spin{ to{ transform:rotate(360deg); } }

.toast{
  position:fixed; left:50%; bottom:24px; transform:translateX(-50%);
  background:#0F172A; color:#fff; padding:12px 20px; border-radius:var(--r);
  z-index:1000; box-shadow:var(--sh3); display:none; font-size:14px; font-weight:600;
  max-width:calc(100% - 32px); text-align:center;
}
.toast.show{ display:block; animation:fade .2s ease; }
.toast.ok{ background:var(--success); }
.toast.err{ background:var(--danger); }

.log-list{ max-height:440px; overflow:auto; }
.log-item{ padding:11px 12px; border-bottom:1px solid var(--line); font-size:13px; }
.log-item:last-child{ border-bottom:0; }
.log-item .when{ color:var(--muted); font-size:12px; }
.log-item .who{ font-weight:700; color:var(--primary-d); }

.detail-row{ display:flex; justify-content:space-between; gap:10px; padding:9px 0; border-bottom:1px dashed var(--line); font-size:14px; }
.detail-row:last-child{ border-bottom:0; }

#detailBox{ background:var(--surface); border:1px solid var(--line); border-radius:var(--r-lg); padding:18px; margin:16px 0; box-shadow:var(--sh1); }
#detailBox .db-head{ display:flex; justify-content:space-between; align-items:center; margin-bottom:12px; gap:10px; }
#detailBox h3{ font-size:16px; color:var(--primary-d); }
#detailBox .db-close{ cursor:pointer; font-size:26px; line-height:1; color:var(--muted); background:none; border:0; }
#reportBox{ margin-top:12px; white-space:pre-line; font-size:14px; line-height:1.8; background:var(--slate-l); padding:16px; border-radius:var(--r); }
#pwMsg,#chkMsg,#cMsg{ margin-top:10px; font-size:14px; }

/* ------------------------------------------------------------
 * 12. Lock screen
 * ------------------------------------------------------------ */
.lock{
  position:fixed; inset:0; z-index:9999; display:flex; align-items:center; justify-content:center;
  background:linear-gradient(150deg,var(--primary-d),#0B5C57); padding:20px;
}
.lock-card{
  background:#fff; padding:36px 28px; border-radius:var(--r-lg); width:100%; max-width:320px;
  text-align:center; box-shadow:var(--sh3);
}
.lock-card .lock-icon{ font-size:44px; margin-bottom:8px; }
.lock-card h2{ color:var(--primary-d); margin-bottom:6px; font-size:20px; }
.lock-card .lock-unit{ font-size:13px; color:var(--muted); margin-bottom:18px; }
.password-wrap{ position:relative; width:100%; }
.password-wrap input{
  width:100%; padding:13px 48px 13px 14px; margin-bottom:12px;
  border:1px solid var(--line-2); border-radius:var(--r-sm); font-size:16px; font-family:inherit;
}
.password-wrap input:focus{ outline:none; border-color:var(--primary); box-shadow:0 0 0 3px var(--primary-l); }
.password-toggle{
  position:absolute; right:8px; top:50%; transform:translateY(-50%);
  width:36px; height:36px; border:0; background:transparent; color:var(--muted);
  font-size:19px; cursor:pointer; border-radius:var(--r-sm);
}
.password-toggle:hover{ background:var(--slate-l); }
#lockErr{ color:var(--danger); font-size:14px; margin-top:10px; min-height:18px; }

/* ------------------------------------------------------------
 * 13. Bottom navigation (มือถือ)
 * ------------------------------------------------------------ */
.bottomnav{
  display:none; position:fixed; left:0; right:0; bottom:0; z-index:300;
  height:var(--bottomnav-h); background:var(--surface); border-top:1px solid var(--line);
  box-shadow:0 -4px 16px rgba(15,23,42,.06);
  padding:4px 6px calc(4px + env(safe-area-inset-bottom,0px));
}
.bottomnav button{
  flex:1; border:0; background:none; cursor:pointer;
  display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px;
  color:var(--muted); font-size:11px; font-weight:600; padding:4px 2px; border-radius:var(--r);
}
.bottomnav button .bi{ font-size:20px; line-height:1; }
.bottomnav button.active{ color:var(--primary-d); }
.bottomnav button.active .bi{ transform:translateY(-1px); }

/* ============================================================
 * 14. Responsive
 * ============================================================ */

/* ---------- แท็บเล็ต : sidebar เป็น drawer ---------- */
@media (max-width:1023px){
  .sidebar{
    position:fixed; left:0; top:0; height:100vh;
    transform:translateX(-100%); transition:transform .25s ease;
    box-shadow:var(--sh3);
  }
  .sidebar.open{ transform:translateX(0); }
  .hamb{ display:inline-flex; align-items:center; justify-content:center; }
}

/* ---------- มือถือ : bottom nav + ตารางเป็นการ์ด ---------- */
@media (max-width:639px){
  .content{ padding:16px 14px calc(var(--bottomnav-h) + 24px); }
  .topbar{ padding:10px 14px; }
  .topbar h2{ font-size:17px; }
  .topbar .sub{ display:none; }
  .top-actions button{ min-height:40px; padding:8px 12px; font-size:13px; }
  .top-actions .txt{ display:none; }         /* ซ่อนข้อความปุ่ม เหลือ icon */

  .bottomnav{ display:flex; }

  .dashboard{ grid-template-columns:repeat(2,1fr); gap:10px; }
  .card{ padding:14px; }
  .card .number{ font-size:28px; }

  .panel{ padding:16px; border-radius:var(--r); }

  /* modal เป็น bottom sheet */
  .modal-overlay{ align-items:flex-end; padding:0; }
  .modal{
    max-width:100%; border-radius:var(--r-lg) var(--r-lg) 0 0;
    max-height:88vh; animation:sheet .22s ease;
  }
  @keyframes sheet{ from{ transform:translateY(100%); } to{ transform:none; } }
  .modal-actions{ position:sticky; bottom:0; background:#fff; padding-top:10px; }

  /* toast ลอยเหนือ bottom nav */
  .toast{ bottom:calc(var(--bottomnav-h) + 16px); }

  /* ---------- ตาราง → การ์ดซ้อน ---------- */
  .table-wrap{ overflow:visible; }
  table.responsive{ display:block; }
  table.responsive thead{ display:none; }
  table.responsive tbody{ display:block; }
  table.responsive tr{
    display:block; background:var(--surface); border:1px solid var(--line);
    border-radius:var(--r); margin-bottom:10px; padding:6px 12px; box-shadow:var(--sh1);
  }
  table.responsive tr:hover{ background:var(--surface); }
  table.responsive td{
    display:flex; justify-content:space-between; align-items:center; gap:12px;
    border:0; border-bottom:1px dashed var(--line); padding:9px 0; text-align:right;
  }
  table.responsive td:last-child{ border-bottom:0; }
  table.responsive td::before{
    content:attr(data-label); font-weight:700; color:var(--muted);
    font-size:12px; text-align:left; flex-shrink:0;
  }
  table.responsive td.num{ width:auto; text-align:right; }
  .cat-group .table-wrap{ border:0; border-radius:0; }
  .cat-group table.responsive tr:first-child{ margin-top:8px; }
  .cat-title{ border-radius:var(--r); }

  /* toolbar เรียงเต็มความกว้าง */
  .toolbar{ flex-direction:column; align-items:stretch; }
  .toolbar .grow{ width:100%; }
  .toolbar button{ width:100%; }
}

/* ---------- จอใหญ่มาก ---------- */
@media (min-width:1280px){
  :root{ --maxw:1240px; }
}
