/* ─── Reset & variables ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:    #2563eb;
  --blue-dk: #1d4ed8;
  --blue-lt: #eff6ff;
  --green:   #16a34a;
  --green-lt:#f0fdf4;
  --amber:   #d97706;
  --amber-lt:#fffbeb;
  --red:     #dc2626;
  --red-lt:  #fef2f2;
  --gray-50: #f9fafb;
  --gray-100:#f3f4f6;
  --gray-200:#e5e7eb;
  --gray-400:#9ca3af;
  --gray-600:#4b5563;
  --gray-800:#1f2937;
  --radius:  10px;
  --shadow:  0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md:0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  font-size: 15px;
  line-height: 1.5;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */
.header {
  background: var(--blue);
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-md);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 1.1rem; font-weight: 700; }
.header .subtitle { font-size: .78rem; opacity: .85; margin-top: 1px; }
.header-right { text-align: right; font-size: .78rem; opacity: .85; }
.live-dot {
  display: inline-block; width: 8px; height: 8px;
  background: #4ade80; border-radius: 50%;
  animation: pulse 2s infinite;
  margin-right: 4px;
  vertical-align: middle;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ─── Nav tabs ───────────────────────────────────────────────────────────── */
.tabs {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  position: sticky;
  top: 57px;
  z-index: 99;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  flex: none;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: .82rem;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab-btn:hover { color: var(--blue); }
.tab-btn.active { color: var(--blue); border-bottom-color: var(--blue); }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.content { max-width: 900px; margin: 0 auto; padding: 16px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}
.card-title {
  font-size: .8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--gray-400);
  margin-bottom: 10px;
}
.card h3 { font-size: 1rem; font-weight: 600; margin-bottom: 4px; }

/* ─── Stats row ──────────────────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 12px;
  text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .72rem; color: var(--gray-600); margin-top: 4px; }
.stat.green .stat-value { color: var(--green); }
.stat.amber .stat-value { color: var(--amber); }
.stat.red   .stat-value { color: var(--red); }

/* ─── Badges ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
}
.badge-green  { background: var(--green-lt); color: var(--green); }
.badge-amber  { background: var(--amber-lt); color: var(--amber); }
.badge-red    { background: var(--red-lt);   color: var(--red); }
.badge-blue   { background: var(--blue-lt);  color: var(--blue); }
.badge-gray   { background: var(--gray-100); color: var(--gray-600); }
.badge-weekly { background: #fef9c3; color: #854d0e; }

/* ─── Medication list ────────────────────────────────────────────────────── */
.med-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--gray-100);
}
.med-item:last-child { border-bottom: none; }
.med-icon { font-size: 1.3rem; flex-shrink: 0; }
.med-info { flex: 1; min-width: 0; }
.med-name { font-weight: 600; font-size: .92rem; }
.med-detail { font-size: .78rem; color: var(--gray-600); }
.med-time { font-size: .8rem; font-weight: 600; color: var(--gray-600); flex-shrink: 0; }
.med-nurse { font-size: .72rem; color: var(--gray-400); margin-top: 1px; }

/* ─── Vitals grid ────────────────────────────────────────────────────────── */
.vitals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}
.vital-item {
  background: var(--gray-50);
  border-radius: 8px;
  padding: 12px;
  text-align: center;
  border: 1px solid var(--gray-200);
}
.vital-icon { font-size: 1.4rem; margin-bottom: 4px; }
.vital-value { font-size: 1.15rem; font-weight: 700; color: var(--blue); }
.vital-label { font-size: .7rem; color: var(--gray-600); margin-top: 2px; }

/* ─── Forms ──────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group label { font-size: .78rem; font-weight: 600; color: var(--gray-600); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  font-size: .88rem;
  font-family: inherit;
  background: #fff;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.form-group textarea { resize: vertical; min-height: 70px; }
.form-full { grid-column: 1 / -1; }

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  border: none;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dk); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger  { background: var(--red);   color: #fff; }
.btn-ghost   { background: var(--gray-100); color: var(--gray-800); }
.btn-ghost:hover { background: var(--gray-200); }
.btn-sm { padding: 5px 10px; font-size: .78rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Table-like list ────────────────────────────────────────────────────── */
.list-item {
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-100);
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.list-item:last-child { border-bottom: none; }
.list-body { flex: 1; min-width: 0; }
.list-title { font-weight: 600; font-size: .92rem; margin-bottom: 2px; }
.list-meta  { font-size: .78rem; color: var(--gray-600); }
.list-actions { display: flex; gap: 6px; flex-shrink: 0; align-items: center; }

/* ─── Upload area ────────────────────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--gray-200);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color .2s, background .2s;
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--blue);
  background: var(--blue-lt);
}
.upload-area input[type=file] { display: none; }
.upload-icon { font-size: 2rem; margin-bottom: 8px; }
.upload-text { font-size: .85rem; color: var(--gray-600); }
.upload-text strong { color: var(--blue); }

/* ─── AI summary box ─────────────────────────────────────────────────────── */
.ai-summary {
  background: var(--blue-lt);
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 12px;
  font-size: .85rem;
  line-height: 1.6;
  margin-top: 8px;
  white-space: pre-wrap;
}
.ai-label { font-size: .72rem; font-weight: 700; color: var(--blue); margin-bottom: 4px; text-transform: uppercase; }

/* ─── Toast notification ─────────────────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--gray-800);
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: .85rem;
  font-weight: 500;
  z-index: 9999;
  transition: transform .3s ease;
  pointer-events: none;
  white-space: nowrap;
}
#toast.show { transform: translateX(-50%) translateY(0); }
#toast.success { background: var(--green); }
#toast.error   { background: var(--red); }

/* ─── Empty state ────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--gray-400);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 8px; }
.empty p { font-size: .88rem; }

/* ─── Loading ────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Section header ─────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.section-header h2 { font-size: 1rem; font-weight: 700; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 500px) {
  .stats { grid-template-columns: repeat(3, 1fr); }
  .stat-value { font-size: 1.6rem; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .vitals-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ─── Collapsible form ───────────────────────────────────────────────────── */
.collapsible { overflow: hidden; max-height: 0; transition: max-height .3s ease; }
.collapsible.open { max-height: 800px; }

/* ─── Timeline connector ─────────────────────────────────────────────────── */
.timeline-dot {
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}
.dot-green { background: var(--green); }
.dot-amber { background: var(--amber); }
.dot-red   { background: var(--red); }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.hidden { display: none !important; }
.modal {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 90%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}
.modal-header {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--gray-200);
}
.modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  display: flex;
  flex-direction: row;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--gray-200);
  flex-wrap: wrap;
}
.modal-close {
  border: none;
  background: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--gray-600);
  line-height: 1;
}
.confirm-msg {
  font-size: .9rem;
  color: var(--gray-600);
  line-height: 1.6;
}
.dot-gray  { background: var(--gray-200); }

/* ─── Settings tab toggles ───────────────────────────────────────────────── */
.config-section { margin-bottom: 28px; }
.config-section-title {
  font-weight: 700; font-size: .9rem; color: var(--gray-800);
  margin-bottom: 12px; padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-200);
}
.config-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; border-bottom: 1px solid var(--gray-100);
  cursor: default; gap: 16px;
}
.config-row:last-child { border-bottom: none; }
.config-row-info { flex: 1; }
.config-row-label { font-size: .88rem; font-weight: 600; color: var(--gray-800); }
.config-row-desc  { font-size: .78rem; color: var(--gray-600); margin-top: 2px; line-height: 1.4; }
.toggle-wrap { flex-shrink: 0; }
.toggle-input { display: none; }
.toggle-label {
  display: block; width: 44px; height: 24px; border-radius: 12px;
  background: var(--gray-300); cursor: pointer;
  position: relative; transition: background .2s;
}
.toggle-label::after {
  content: ''; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: left .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.toggle-input:checked + .toggle-label { background: var(--green); }
.toggle-input:checked + .toggle-label::after { left: 23px; }

/* ─── Vitais tab layout ────────────────────────────────────────────────────── */
.vitais-tab-panel { padding: 0 !important; }
.vitais-tab-panel.tab-panel.active { display: flex; flex-direction: column; }

.vitals-layout {
  display: flex;
  flex: 1;
  min-height: 0;
  gap: 0;
}

/* Sidebar */
.vitals-sidebar {
  width: 180px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--gray-200);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 105px;
  align-self: flex-start;
  min-height: calc(100vh - 110px);
}

.vsidebar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 11px 18px;
  border: none;
  background: none;
  text-align: left;
  font-size: .85rem;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  border-radius: 0;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.vsidebar-btn:hover  { background: var(--gray-50); color: var(--gray-800); }
.vsidebar-btn.active { background: var(--blue-lt); color: var(--blue); border-left-color: var(--blue); font-weight: 600; }

/* Content area */
.vitals-content {
  flex: 1;
  min-width: 0;
  padding: 16px;
  overflow-y: auto;
}

.vsec { display: block; }

/* Chart header */
.vitals-chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.chart-filters {
  display: flex;
  gap: 4px;
}
.chart-filter-btn {
  padding: 5px 12px;
  border: 1px solid var(--gray-200);
  background: #fff;
  border-radius: 6px;
  font-size: .78rem;
  font-weight: 500;
  color: var(--gray-600);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.chart-filter-btn:hover  { background: var(--gray-100); }
.chart-filter-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* Chart blocks */
.chart-block {
  margin-bottom: 20px;
}
.chart-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-600);
  margin-bottom: 6px;
}
.chart-scroll-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--gray-100);
  border-radius: var(--radius);
  background: #fff;
  padding: 8px 8px 4px;
}
.chart-scroll-wrap canvas {
  display: block;
}

/* Vitals history table */
.vitals-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .82rem;
}
.vitals-table th {
  background: var(--gray-50);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
  font-size: .78rem;
  color: var(--gray-600);
  border-bottom: 1px solid var(--gray-200);
  white-space: nowrap;
}
.vitals-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}
.vitals-table tr:last-child td { border-bottom: none; }
.vitals-table tr.vital-row-alert td { background: #fff5f5; }
.vitals-table tr.vital-row-alert:hover td { background: #fee2e2; }
.vitals-table tr:not(.vital-row-alert):hover td { background: var(--gray-50); }

/* Pagination */
.pagination-row { margin-top: 12px; }
.pagination-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

/* Responsive: stack sidebar on mobile */
@media (max-width: 640px) {
  .vitals-layout { flex-direction: column; }
  .vitals-sidebar {
    width: 100%;
    min-height: unset;
    flex-direction: row;
    overflow-x: auto;
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
    position: static;
  }
  .vsidebar-btn {
    flex-shrink: 0;
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 10px 14px;
  }
  .vsidebar-btn.active { border-left-color: transparent; border-bottom-color: var(--blue); }
  .vitals-content { padding: 12px; }
}
