/* ============================================================
   Patient Bed Management System – style.css
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:          #f5f5f4;
  --color-surface:     #ffffff;
  --color-surface-alt: #f5f5f4;
  --color-border:      rgba(0,0,0,.10);
  --color-border-md:   rgba(0,0,0,.18);
  --color-text:        #1c1c1b;
  --color-text-muted:  #6b6b68;
  --color-text-hint:   #9e9e9a;

  --color-available:   #1D9E75;
  --color-occupied:    #D85A30;
  --color-reserved:    #BA7517;
  --color-maintenance: #888780;

  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08);

  --font: 'Sarabun', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg:          #1a1a18;
    --color-surface:     #242422;
    --color-surface-alt: #2e2e2b;
    --color-border:      rgba(255,255,255,.10);
    --color-border-md:   rgba(255,255,255,.18);
    --color-text:        #f0eeeb;
    --color-text-muted:  #a8a8a4;
    --color-text-hint:   #6e6e6a;
  }
}

html { font-size: 16px; }
body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ---------- Header ---------- */
.app-header {
  background: var(--color-surface);
  border-bottom: 0.5px solid var(--color-border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 500;
}
.header-left .ti { font-size: 20px; color: var(--color-available); }
.header-right { font-size: 13px; color: var(--color-text-muted); }

/* ---------- Nav ---------- */
.nav {
  background: var(--color-surface);
  border-bottom: 0.5px solid var(--color-border);
  display: flex;
  gap: 2px;
  padding: 0 1.5rem;
  position: sticky;
  top: 56px;
  z-index: 40;
}
.nav-btn {
  font-family: var(--font);
  font-size: 13px;
  padding: 10px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--color-text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: color .15s;
}
.nav-btn.active { color: var(--color-text); border-bottom-color: var(--color-text); font-weight: 500; }
.nav-btn:hover:not(.active) { color: var(--color-text); }

/* ---------- Main ---------- */
.main-content { max-width: 960px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }

/* ---------- Pages ---------- */
.page { display: none; }
.page.active { display: block; }
.page-title {
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Stats Row ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 1.25rem;
}
.sc {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.sc-label { font-size: 11px; color: var(--color-text-muted); margin-bottom: 3px; }
.sc-val { font-size: 22px; font-weight: 500; }
.sc-val.t  { color: var(--color-text); }
.sc-val.a  { color: var(--color-available); }
.sc-val.o  { color: var(--color-occupied); }
.sc-val.r  { color: var(--color-reserved); }
.sc-val.m  { color: var(--color-maintenance); }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  flex: 1;
  min-width: 180px;
}
.search-box .ti { color: var(--color-text-muted); font-size: 15px; }
.search-box input {
  border: none;
  background: transparent;
  font-family: var(--font);
  font-size: 13px;
  color: var(--color-text);
  outline: none;
  width: 100%;
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 14px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--color-border-md);
  background: transparent;
  color: var(--color-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--color-surface-alt); }
.btn.primary {
  background: var(--color-text);
  color: var(--color-surface);
  border-color: transparent;
}
.btn.primary:hover { opacity: .85; }
.btn.danger { border-color: #F0997B; color: #993C1D; }
.btn.danger:hover { background: #FAECE7; }
.icon-btn {
  font-family: var(--font);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 18px;
  display: flex;
  align-items: center;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: background .15s;
}
.icon-btn:hover { background: var(--color-surface-alt); }

select {
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-text);
  cursor: pointer;
  outline: none;
}

/* ---------- Legend ---------- */
.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.leg {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--color-text-muted);
}
.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.available  { background: var(--color-available); }
.dot.occupied   { background: var(--color-occupied); }
.dot.reserved   { background: var(--color-reserved); }
.dot.maintenance{ background: var(--color-maintenance); }

/* ---------- Ward ---------- */
.ward-section { margin-bottom: 1.25rem; }
.ward-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  margin-bottom: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  transition: background .15s;
}
.ward-header:hover { background: var(--color-surface-alt); }
.ward-name {
  font-size: 14px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
}
.ward-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--color-text-muted);
}
.ward-toggle { transition: transform .2s; }
.ward-toggle.open { transform: rotate(180deg); }

/* Badge */
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  font-weight: 500;
}
.badge.general   { background: #E6F1FB; color: #0C447C; }
.badge.icu       { background: #FCEBEB; color: #791F1F; }
.badge.pediatric { background: #FBEAF0; color: #72243E; }
.badge.surgical  { background: #FAEEDA; color: #633806; }
.badge.maternity { background: #EAF3DE; color: #27500A; }

/* ---------- Bed Grid ---------- */
.bed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(115px, 1fr));
  gap: 8px;
}
.bed-card {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
  transition: transform .1s, border-color .15s;
}
.bed-card:hover { transform: translateY(-1px); border-color: var(--color-border-md); }
.bed-card.available   { border-left: 3px solid var(--color-available); }
.bed-card.occupied    { border-left: 3px solid var(--color-occupied); }
.bed-card.reserved    { border-left: 3px solid var(--color-reserved); }
.bed-card.maintenance { border-left: 3px solid var(--color-maintenance); }
.bed-num { font-size: 13px; font-weight: 500; margin-bottom: 3px; }
.bed-stat { font-size: 11px; }
.bed-stat.available   { color: var(--color-available); }
.bed-stat.occupied    { color: var(--color-occupied); }
.bed-stat.reserved    { color: var(--color-reserved); }
.bed-stat.maintenance { color: var(--color-maintenance); }
.bed-pt {
  font-size: 11px;
  color: var(--color-text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.add-bed-card {
  background: transparent;
  border: 0.5px dashed var(--color-border-md);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 12px;
  color: var(--color-text-muted);
  min-height: 62px;
  transition: background .15s;
  font-family: var(--font);
}
.add-bed-card:hover { background: var(--color-surface-alt); }
.ward-collapsed { display: none; }

.divider { border: none; border-top: 0.5px solid var(--color-border); margin: 1.25rem 0; }
.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--color-text-muted);
  font-size: 14px;
}
.empty-state .ti { font-size: 36px; display: block; margin-bottom: 10px; opacity: .4; }

/* ---------- Modals ---------- */
.modal-wrap {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}
.modal-wrap.show { display: flex; }
.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--color-border);
  padding: 1.25rem;
  width: 380px;
  max-width: 100%;
  box-shadow: var(--shadow-sm);
  animation: modal-in .18s ease;
}
@keyframes modal-in { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-title {
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.frow { margin-bottom: 12px; }
.flabel { font-size: 12px; color: var(--color-text-muted); margin-bottom: 4px; display: block; }
.fval { font-size: 14px; }
.fval input,
.fval select {
  width: 100%;
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 10px;
  border-radius: var(--radius-md);
  border: 0.5px solid var(--color-border);
  background: var(--color-surface-alt);
  color: var(--color-text);
  outline: none;
  transition: border-color .15s;
}
.fval input:focus,
.fval select:focus { border-color: var(--color-border-md); }

/* Status buttons */
.sbrow { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.sbtn {
  font-family: var(--font);
  font-size: 12px;
  padding: 5px 12px;
  border-radius: 20px;
  border: 0.5px solid var(--color-border);
  background: var(--color-surface-alt);
  cursor: pointer;
  color: var(--color-text);
  transition: background .15s;
}
.sbtn.active-available  { background: #E1F5EE; color: #0F6E56; border-color: #5DCAA5; }
.sbtn.active-occupied   { background: #FAECE7; color: #993C1D; border-color: #F0997B; }
.sbtn.active-reserved   { background: #FAEEDA; color: #854F0B; border-color: #EF9F27; }
.sbtn.active-maintenance{ background: #F1EFE8; color: #5F5E5A; border-color: #B4B2A9; }

/* Modal actions */
.mactions { display: flex; gap: 8px; margin-top: 1rem; flex-wrap: wrap; }
.mbtn {
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 0.5px solid var(--color-border-md);
  flex: 1;
  transition: background .15s;
}
.mbtn.primary { background: var(--color-text); color: var(--color-surface); border-color: transparent; }
.mbtn.primary:hover { opacity: .85; }
.mbtn.secondary { background: transparent; color: var(--color-text); }
.mbtn.secondary:hover { background: var(--color-surface-alt); }
.mbtn.danger { color: #993C1D; border-color: #F0997B; background: transparent; }
.mbtn.danger:hover { background: #FAECE7; }

/* ---------- History ---------- */
.hist-list { display: flex; flex-direction: column; gap: 8px; }
.hist-item {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.hist-icon { font-size: 16px; margin-top: 2px; }
.hist-icon.add    { color: var(--color-available); }
.hist-icon.remove { color: var(--color-occupied); }
.hist-icon.status { color: var(--color-reserved); }
.hist-icon.admit  { color: #378ADD; }
.hist-time { font-size: 11px; color: var(--color-text-muted); margin-top: 2px; }
.hist-desc { font-size: 13px; }

/* ---------- Report ---------- */
.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 1.25rem;
}
.report-card {
  background: var(--color-surface);
  border: 0.5px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.rc-title { font-size: 12px; color: var(--color-text-muted); font-weight: 500; margin-bottom: 8px; }
.occ-pct { font-size: 22px; font-weight: 500; }
.occ-bar {
  height: 8px;
  border-radius: 4px;
  background: var(--color-border);
  margin: 6px 0;
  overflow: hidden;
}
.occ-fill { height: 8px; border-radius: 4px; background: var(--color-available); transition: width .5s ease; }
.occ-fill.hi { background: var(--color-occupied); }

.ward-report-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.wr-name { font-size: 13px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wr-bar { flex: 2; height: 6px; border-radius: 3px; background: var(--color-border); overflow: hidden; }
.wr-fill { height: 6px; border-radius: 3px; transition: width .5s ease; }
.wr-pct { font-size: 12px; color: var(--color-text-muted); min-width: 34px; text-align: right; }
.wr-count { font-size: 11px; color: var(--color-text-muted); min-width: 42px; text-align: right; }

.report-table { width: 100%; font-size: 12px; border-collapse: collapse; margin-top: 6px; }
.report-table th {
  text-align: left;
  padding: 6px 4px;
  font-weight: 500;
  color: var(--color-text-muted);
  border-bottom: 0.5px solid var(--color-border);
}
.report-table th:not(:first-child),
.report-table td:not(:first-child) { text-align: center; }
.report-table td { padding: 7px 4px; border-bottom: 0.5px solid var(--color-border); }
.report-table tr:last-child td { border-bottom: none; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .main-content { padding: 1rem .75rem 3rem; }
  .app-header { padding: 0 1rem; }
  .nav { padding: 0 1rem; }
  .modal { padding: 1rem; }
  .mactions { flex-direction: column; }
  .mbtn { flex: unset; width: 100%; }
}
