/* ================================================
   CliniFlow Design System — Premium Clinical UI
   ================================================ */

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

:root {
  --primary:        #0d9488;
  --primary-hover:  #0f766e;
  --primary-light:  #ccfbf1;
  --primary-dark:   #134e4a;

  --secondary:      #3b82f6;
  --accent:         #f59e0b;
  --danger:         #ef4444;
  --danger-light:   #fee2e2;
  --success:        #10b981;
  --success-light:  #d1fae5;
  --warning:        #f59e0b;
  --warning-light:  #fef3c7;
  --info:           #6366f1;
  --info-light:     #e0e7ff;

  --bg:             #f0f4f8;
  --surface:        #ffffff;
  --surface-2:      #f8fafc;
  --surface-hover:  #f1f5f9;
  --border:         #e2e8f0;
  --border-strong:  #cbd5e1;

  --text:           #0f172a;
  --text-muted:     #64748b;
  --text-light:     #94a3b8;

  --shadow-xs:  0 1px 2px rgb(0 0 0/0.04);
  --shadow-sm:  0 1px 3px rgb(0 0 0/0.08), 0 1px 2px rgb(0 0 0/0.04);
  --shadow-md:  0 4px 6px rgb(0 0 0/0.07), 0 2px 4px rgb(0 0 0/0.05);
  --shadow-lg:  0 10px 15px rgb(0 0 0/0.08), 0 4px 6px rgb(0 0 0/0.04);
  --shadow-xl:  0 20px 25px rgb(0 0 0/0.08), 0 10px 10px rgb(0 0 0/0.03);

  --sidebar-w:  260px;
  --header-h:   64px;
  --radius-sm:  6px;
  --radius:     10px;
  --radius-lg:  16px;
  --radius-xl:  20px;

  --transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
}

[data-theme="dark"] {
  --bg:            #0f172a;
  --surface:       #1e293b;
  --surface-2:     #162032;
  --surface-hover: #263548;
  --border:        #334155;
  --border-strong: #475569;
  --text:          #f1f5f9;
  --text-muted:    #94a3b8;
  --text-light:    #64748b;
  --shadow-sm:  0 1px 3px rgb(0 0 0/0.4);
  --shadow-md:  0 4px 6px rgb(0 0 0/0.3);
  --shadow-lg:  0 10px 15px rgb(0 0 0/0.3);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow: hidden;
}

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

/* ─── Loader ─── */
.loader-wrap {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100vh; width: 100vw; gap: 1rem;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── App Shell ─── */
#app-root { display: flex; height: 100vh; width: 100vw; overflow: hidden; }

/* ─── Sidebar ─── */
.app-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 20;
  transition: var(--transition);
}

.sidebar-brand {
  height: var(--header-h);
  display: flex; align-items: center; gap: 0.625rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-brand .brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: white; font-size: 1.1rem;
}
.sidebar-brand .brand-text {
  font-size: 1.125rem; font-weight: 700; color: var(--primary);
  letter-spacing: -0.02em;
}
.sidebar-brand .brand-sub {
  font-size: 0.625rem; color: var(--text-muted);
  font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase;
}

.sidebar-section-label {
  font-size: 0.6875rem; font-weight: 600; color: var(--text-light);
  letter-spacing: 0.08em; text-transform: uppercase;
  padding: 1rem 1.25rem 0.375rem;
}

.sidebar-nav { flex: 1; overflow-y: auto; padding: 0.5rem 0 1rem; }
.sidebar-nav::-webkit-scrollbar { width: 4px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.nav-item { padding: 0 0.625rem; }

.nav-link {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.5625rem 0.875rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 0.875rem; font-weight: 500;
  cursor: pointer; transition: var(--transition);
  margin-bottom: 1px;
}
.nav-link .material-icons-round { font-size: 1.125rem; }
.nav-link:hover { background: var(--surface-hover); color: var(--text); }
.nav-link.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
[data-theme="dark"] .nav-link.active {
  background: rgba(13,148,136,0.15);
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-user {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.625rem; border-radius: var(--radius-sm);
}
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 0.875rem; flex-shrink: 0;
}
.user-info .user-name { font-size: 0.875rem; font-weight: 600; }
.user-info .user-role { font-size: 0.75rem; color: var(--text-muted); }

/* ─── Main Area ─── */
.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: hidden; }

.app-header {
  height: var(--header-h); flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  gap: 1rem;
}
.header-left { display: flex; align-items: center; gap: 1rem; }
.header-title { font-size: 1rem; font-weight: 600; color: var(--text); }
.header-breadcrumb { font-size: 0.75rem; color: var(--text-muted); margin-top: 1px; }
.header-right { display: flex; align-items: center; gap: 0.75rem; }

.header-search {
  display: flex; align-items: center; gap: 0.5rem;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 0.375rem 0.875rem;
  transition: var(--transition);
}
.header-search:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.header-search input {
  border: none; background: transparent; outline: none;
  font-size: 0.875rem; color: var(--text); width: 180px;
  font-family: inherit;
}
.header-search .material-icons-round { font-size: 1rem; color: var(--text-muted); }

.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: var(--transition); color: var(--text-muted);
  position: relative;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn .material-icons-round { font-size: 1.125rem; }
.badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); color: white;
  font-size: 0.625rem; font-weight: 700;
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}

.app-content { flex: 1; overflow-y: auto; padding: 1.5rem; }
.app-content::-webkit-scrollbar { width: 6px; }
.app-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ─── Page Header ─── */
.page-header {
  display: flex; align-items: flex-start;
  justify-content: space-between; gap: 1rem;
  margin-bottom: 1.5rem; flex-wrap: wrap;
}
.page-header h1 { font-size: 1.375rem; font-weight: 700; letter-spacing: -0.02em; }
.page-header p { font-size: 0.875rem; color: var(--text-muted); margin-top: 0.25rem; }
.page-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ─── Cards ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.card-title { font-size: 0.9375rem; font-weight: 600; }

/* ─── Stat Cards ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex; flex-direction: column; gap: 0.75rem;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-top { display: flex; align-items: center; justify-content: space-between; }
.stat-icon {
  width: 44px; height: 44px; border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
}
.stat-icon .material-icons-round { font-size: 1.25rem; }
.stat-trend {
  font-size: 0.75rem; font-weight: 600;
  display: flex; align-items: center; gap: 2px;
}
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }
.stat-value { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.stat-label { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; }

/* ─── Table ─── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
  gap: 1rem; flex-wrap: wrap;
}
.table-title { font-size: 0.9375rem; font-weight: 600; }
.table-filters { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
thead th {
  padding: 0.75rem 1rem; text-align: left;
  font-size: 0.75rem; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: var(--surface-hover); }
tbody td { padding: 0.875rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
.table-empty { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.table-empty .material-icons-round { font-size: 2.5rem; display: block; margin-bottom: 0.75rem; opacity: 0.4; }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 0.4rem; padding: 0.5rem 1rem;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 0.875rem; font-weight: 500; font-family: inherit;
  cursor: pointer; transition: var(--transition); white-space: nowrap;
  line-height: 1.4;
}
.btn .material-icons-round { font-size: 1rem; }
.btn-sm { padding: 0.3125rem 0.625rem; font-size: 0.8125rem; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 2px 8px rgba(13,148,136,0.35); transform: translateY(-1px); }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-hover); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-ghost { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }

/* ─── Forms ─── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 1rem; }
.col-span-2 { grid-column: span 2; }
.col-span-3 { grid-column: span 3; }

.form-group { display: flex; flex-direction: column; gap: 0.3125rem; }
.form-label { font-size: 0.8125rem; font-weight: 500; color: var(--text); }
.form-label .required { color: var(--danger); }

.form-control {
  padding: 0.5rem 0.75rem;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 0.875rem; font-family: inherit;
  transition: var(--transition); outline: none;
}
.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
  background: var(--surface);
}
.form-control::placeholder { color: var(--text-light); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.input-group { display: flex; }
.input-group .form-control { border-radius: var(--radius-sm) 0 0 var(--radius-sm); flex: 1; }
.input-group .input-addon {
  padding: 0 0.75rem;
  background: var(--surface-hover); border: 1px solid var(--border);
  border-left: none; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  display: flex; align-items: center;
  color: var(--text-muted); font-size: 0.875rem;
}

/* ─── Badges / Pills ─── */
.pill {
  display: inline-flex; align-items: center; gap: 0.25rem;
  padding: 0.25rem 0.625rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600;
}
.pill-teal    { background: var(--primary-light); color: var(--primary); }
.pill-blue    { background: #dbeafe; color: var(--secondary); }
.pill-green   { background: var(--success-light); color: #065f46; }
.pill-amber   { background: var(--warning-light); color: #92400e; }
.pill-red     { background: var(--danger-light); color: #991b1b; }
.pill-gray    { background: var(--surface-hover); color: var(--text-muted); }
.pill-purple  { background: var(--info-light); color: var(--info); }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto;
  animation: slideUp 0.25s cubic-bezier(0.34,1.56,0.64,1);
}
.modal-lg { max-width: 720px; }
.modal-xl { max-width: 900px; }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal-title { font-size: 1.0625rem; font-weight: 700; }
.modal-body { padding: 1.5rem; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 0.75rem;
  padding: 1rem 1.5rem; border-top: 1px solid var(--border);
}
.modal-close {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: 0.25rem;
  border-radius: var(--radius-sm); transition: var(--transition);
  display: flex;
}
.modal-close:hover { background: var(--surface-hover); color: var(--text); }

/* ─── Section divider ─── */
.section-divider {
  font-size: 0.75rem; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
  padding: 0 0 0.75rem; margin: 1.5rem 0 1rem;
  border-bottom: 1px solid var(--border);
}

/* ─── Tabs ─── */
.tabs {
  display: flex; gap: 0; border-bottom: 1px solid var(--border);
  margin-bottom: 1.5rem; overflow-x: auto;
}
.tab-btn {
  padding: 0.75rem 1.25rem; font-size: 0.875rem; font-weight: 500;
  background: none; border: none; border-bottom: 2px solid transparent;
  cursor: pointer; color: var(--text-muted); white-space: nowrap;
  transition: var(--transition); font-family: inherit;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ─── Toast ─── */
#toast-container {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  z-index: 9999; display: flex; flex-direction: column; gap: 0.5rem;
}
.toast {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--surface); color: var(--text);
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius); box-shadow: var(--shadow-xl);
  border-left: 4px solid var(--primary);
  font-size: 0.875rem; font-weight: 500;
  min-width: 280px; max-width: 380px;
  animation: toastIn 0.3s cubic-bezier(0.34,1.56,0.64,1);
}
.toast.success { border-left-color: var(--success); }
.toast.error   { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast .material-icons-round { font-size: 1.1rem; }
.toast.success .material-icons-round { color: var(--success); }
.toast.error   .material-icons-round { color: var(--danger); }
.toast.warning .material-icons-round { color: var(--warning); }
@keyframes toastIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ─── Grid layouts ─── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.three-col { display: grid; grid-template-columns: repeat(3,1fr); gap: 1.25rem; }

/* ─── Vitals highlight ─── */
.vital-abnormal { color: var(--danger); font-weight: 700; }
.vital-normal   { color: var(--success); }

/* ─── EMR Timeline ─── */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before {
  content: ''; position: absolute; left: 0.5rem; top: 0; bottom: 0;
  width: 2px; background: var(--border);
}
.timeline-item { position: relative; margin-bottom: 1.5rem; }
.timeline-dot {
  position: absolute; left: -1.75rem; top: 0.375rem;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary); border: 2px solid var(--surface);
  box-shadow: 0 0 0 2px var(--primary-light);
}
.timeline-date { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 0.375rem; }
.timeline-card {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.timeline-type { font-size: 0.75rem; font-weight: 700; color: var(--primary); text-transform: uppercase; margin-bottom: 0.25rem; }
.timeline-content { font-size: 0.875rem; }

/* ─── Bed Grid ─── */
.bed-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px,1fr)); gap: 0.75rem; }
.bed-cell {
  aspect-ratio: 1; border-radius: var(--radius);
  border: 2px solid var(--border);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 0.25rem; cursor: pointer; transition: var(--transition);
  font-size: 0.75rem; font-weight: 600;
}
.bed-cell .material-icons-round { font-size: 1.5rem; }
.bed-cell.available { border-color: var(--success); color: var(--success); background: var(--success-light); }
.bed-cell.occupied  { border-color: var(--danger);  color: var(--danger);  background: var(--danger-light); }
.bed-cell.cleaning  { border-color: var(--warning); color: var(--warning); background: var(--warning-light); }
.bed-cell:hover { transform: scale(1.03); box-shadow: var(--shadow-md); }

/* ─── Chart placeholder ─── */
.chart-area {
  height: 220px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); display: flex;
  align-items: center; justify-content: center;
  color: var(--text-muted); flex-direction: column; gap: 0.5rem;
}
.chart-area .material-icons-round { font-size: 2rem; opacity: 0.4; }

/* ─── Responsive ─── */
@media (max-width: 900px) {
  .app-sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%); z-index: 200;
    box-shadow: var(--shadow-xl);
  }
  .app-sidebar.open { transform: translateX(0); }
  .form-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .app-content { padding: 1rem; }
  .modal { border-radius: var(--radius-lg); }
}
