/* Patient Charting System — CareFlow palette & cards, sidebar layout */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap');

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

:root {
  --primary: #1565a8;
  --primary-dark: #0a3d6b;
  --primary-mid: #1e88c7;
  --primary-light: #e3f2fd;
  --primary-glow: rgba(21, 101, 168, 0.2);
  --accent: #42a5f5;
  --accent-dark: #1976d2;
  --surface: #ffffff;
  --bg: #f4f9fc;
  --bg-warm: #eef6fb;
  --text: #0d2137;
  --text-secondary: #1a3a5c;
  --text-muted: #5a7a9a;
  --border: #d4e4f0;
  --border-light: #e8f2f9;
  --danger: #c73e54;
  --success: #2d8a6e;
  --sidebar-bg: #0a3d6b;
  --sidebar-hover: #1565a8;
  --radius-sm: 10px;
  --radius: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-card: 0 0 0 1px var(--border-light), 0 6px 20px rgba(10, 61, 107, 0.07);
  --shadow-md: 0 8px 24px rgba(10, 61, 107, 0.1);
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'DM Sans', system-ui, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

/* ---- App shell (sidebar layout) ---- */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, #062a4a 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 1000;
  transition: transform 0.3s ease;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand {
  padding: 1.25rem 1.5rem;
  font-size: 1.15rem;
  font-weight: 600;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.sidebar-brand i {
  font-size: 1.5rem;
  color: var(--accent);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-section-label {
  padding: 0.75rem 1.5rem 0.25rem;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.6;
}

.sidebar .nav-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1.5rem;
  color: rgba(255, 255, 255, 0.85);
  transition: background 0.2s;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar .nav-link.active {
  border-left: 3px solid var(--accent);
  padding-left: calc(1.5rem - 3px);
}

.sidebar-footer {
  padding: 1rem 0;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar .nav-link.text-danger {
  color: #f5a8b8 !important;
}

.sidebar .nav-link.text-danger:hover {
  background: rgba(199, 62, 84, 0.25);
}

.main-content {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top-bar {
  background: var(--surface);
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 2px rgba(10, 61, 107, 0.06);
}

.page-heading {
  font-size: 1.25rem;
  margin: 0;
  flex: 1;
  font-weight: 600;
  color: var(--primary-dark);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-name {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.role-badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-full);
  font-weight: 600;
  text-transform: uppercase;
}

.role-admin { background: #ede7f6; color: #5e35b1; }
.role-nurse { background: var(--primary-light); color: var(--primary-dark); }
.role-doctor { background: #e8f5e9; color: var(--success); }

.content-area {
  padding: 1.5rem;
  flex: 1;
}

.app-footer {
  padding: 1rem 1.5rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.875rem;
}

.app-footer a {
  color: var(--primary);
  font-weight: 500;
}

.app-footer a:hover {
  text-decoration: underline;
}

/* ---- Cards (CareFlow style) ---- */
.stat-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-light);
  border-left: 4px solid var(--primary);
  height: 100%;
}

.stat-card .stat-icon {
  font-size: 2rem;
  color: var(--primary);
  opacity: 0.85;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary-dark);
}

.stat-card .stat-label {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.card-panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  border: 1px solid var(--border-light);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.card-panel .card-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 0.85rem 1.25rem;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.card-panel .card-header .badge {
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 0.78rem;
}

.card-panel .card-body {
  padding: 1.25rem;
}

.patient-banner {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary-mid));
  color: #fff;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow-md);
}

.patient-banner h2 {
  margin: 0 0 0.25rem;
}

.patient-banner-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.patient-banner-id {
  margin: 0;
  opacity: 0.88;
  font-size: 0.95rem;
}

.patient-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.patient-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem;
  margin-top: 1rem;
  font-size: 0.9rem;
  opacity: 0.95;
}

.patient-meta span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.chart-vitals-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.stat-card--compact {
  text-align: center;
  padding: 1rem;
  margin-bottom: 0;
}

.stat-card--compact .stat-card-label {
  display: block;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat-card--compact .stat-card-value {
  font-size: 1.25rem;
  font-weight: 700;
  display: block;
}

.chart-page-layout {
  margin: -0.75rem;
}

.chart-form-col {
  flex: 0 0 33.333%;
  max-width: 33.333%;
  padding: 0.75rem;
}

.chart-main-col {
  flex: 0 0 66.666%;
  max-width: 66.666%;
  padding: 0.75rem;
}

.history-list {
  padding: 0;
}

.history-item {
  padding: 1.25rem;
  border-bottom: 1px solid var(--border-light);
}

.history-item:last-child {
  border-bottom: none;
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.history-item-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.history-item p {
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  line-height: 1.6;
}

.history-item p:last-child {
  margin-bottom: 0;
}

.history-empty {
  padding: 2rem 1.25rem;
  text-align: center;
  color: var(--text-muted);
}

.form-range {
  width: 100%;
  accent-color: var(--primary);
}

.alert-warning {
  background: #fff8e6;
  color: #8a6d1d;
  border-color: #f5e0a8;
}

.border-bottom {
  border-bottom: 1px solid var(--border-light);
}

.card-panel .card-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-light);
}

/* ---- Tables ---- */
.table-responsive {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.table thead th {
  background: var(--primary-dark);
  color: #fff;
  padding: 0.85rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.table td {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-light);
  color: var(--text-secondary);
}

.table-hover tbody tr:hover {
  background: var(--primary-light);
}

.table-bordered td,
.table-bordered th {
  border: 1px solid var(--border);
}

.badge {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  padding: 0.3rem 0.75rem;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.8rem;
}

/* ---- Forms & buttons ---- */
.form-label {
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.35rem;
  display: block;
  font-size: 0.875rem;
}

.required::after,
.form-label.required::after {
  content: ' *';
  color: var(--danger);
}

.form-control,
.form-select,
input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="tel"],
select,
textarea {
  width: 100%;
  padding: 0.72rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg-warm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus,
.form-select:focus,
input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.9rem;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  box-shadow: 0 2px 8px var(--primary-glow);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-outline-primary {
  background: var(--surface);
  color: var(--primary);
  border: 1.5px solid rgba(21, 101, 168, 0.35);
}

.btn-outline-primary:hover {
  background: var(--primary-light);
}

.btn-outline-secondary {
  background: var(--surface);
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}

.btn-outline-secondary:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-outline-info {
  background: var(--surface);
  color: var(--accent-dark);
  border: 1.5px solid rgba(30, 136, 199, 0.35);
}

.btn-outline-success {
  background: var(--surface);
  color: var(--success);
  border: 1.5px solid rgba(45, 138, 110, 0.35);
}

.btn-outline-danger {
  background: var(--surface);
  color: var(--danger);
  border: 1.5px solid rgba(199, 62, 84, 0.35);
}

.btn-light {
  background: rgba(255, 255, 255, 0.95);
  color: var(--primary-dark);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.btn-link {
  background: none;
  border: none;
  color: var(--primary);
  padding: 0.35rem;
}

.w-100 { width: 100%; }

/* ---- Alerts ---- */
.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.925rem;
  border: 1px solid transparent;
}

.alert-success {
  background: #e8f5e9;
  color: #1f5c4d;
  border-color: #a8d9cc;
}

.alert-danger,
.alert-error {
  background: #fce8ec;
  color: #9b2c42;
  border-color: #f5c4ce;
}

.alert-info {
  background: #e1f5fe;
  color: var(--accent-dark);
  border-color: #b3e5fc;
}

/* ---- Vitals ---- */
.vital-normal { color: var(--success); font-weight: 600; }
.vital-abnormal {
  color: #b45309;
  font-weight: 600;
  background: #fef3c7;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}
.vital-critical {
  color: #fff;
  font-weight: 600;
  background: var(--danger);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.vital-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.8rem;
  margin-bottom: 1rem;
}

.pain-scale-display {
  display: inline-block;
  min-width: 2rem;
  text-align: center;
  font-weight: 700;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  background: var(--primary-light);
  color: var(--primary-dark);
}

/* ---- Login ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%);
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 420px;
  overflow: hidden;
  border: 1px solid var(--border-light);
}

.login-header {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  padding: 2rem;
  text-align: center;
}

.login-header i {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  display: block;
}

.login-body {
  padding: 2rem;
}

/* ---- Pagination & utilities ---- */
.pagination-nav { margin-top: 1rem; }
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  list-style: none;
}
.page-link {
  display: inline-flex;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.88rem;
}
.page-item.active .page-link {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.page-item.disabled .page-link {
  opacity: 0.45;
  pointer-events: none;
}

.row {
  display: flex;
  flex-wrap: wrap;
  margin: -0.75rem;
}
.row > [class*="col"] {
  padding: 0.75rem;
}
.col-sm-6 { flex: 0 0 50%; max-width: 50%; }
.col { flex: 1 1 0; min-width: 0; }
.col-lg-4 { flex: 0 0 33.333%; max-width: 33.333%; }
.col-lg-6 { flex: 0 0 50%; max-width: 50%; }
.col-lg-8 { flex: 0 0 66.666%; max-width: 66.666%; }
.col-xl-3 { flex: 0 0 25%; max-width: 25%; }
.col-md-3 { flex: 0 0 25%; max-width: 25%; }
.col-md-4 { flex: 0 0 33.333%; max-width: 33.333%; }
.col-md-6 { flex: 0 0 50%; max-width: 50%; }
.col-md-8 { flex: 0 0 66.666%; max-width: 66.666%; }
.col-12 { flex: 0 0 100%; max-width: 100%; }
.g-3 { margin: -0.75rem; }
.g-4 { margin: -0.75rem; }

.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.justify-content-between { justify-content: space-between; }
.align-items-center { align-items: center; }
.align-items-start { align-items: flex-start; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 1rem; }
.flex-grow-1 { flex: 1; }
.d-inline { display: inline; }
.d-lg-none { display: none; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.ms-2 { margin-left: 0.5rem; }
.mb-0 { margin-bottom: 0; }
.mb-3 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 1.5rem; }
.mt-4 { margin-top: 1.5rem; }
.ms-2 { margin-left: 0.5rem; }
.px-3 { padding-left: 1rem; padding-right: 1rem; }
.pt-2 { padding-top: 0.5rem; }
.border-top { border-top: 1px solid var(--border-light); }
.border { border: 1px solid var(--border); }
.p-2 { padding: 0.75rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1.5rem; padding-bottom: 1.5rem; }
.fs-5 { font-size: 1.15rem; }
.small { font-size: 0.85rem; }
.opacity-75 { opacity: 0.75; }
.search-bar { max-width: 320px; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.no-print { }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 999;
}

@media (max-width: 991.98px) {
  .d-lg-none { display: inline-flex; }
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.show {
    transform: translateX(0);
  }
  .sidebar-overlay.show {
    display: block;
  }
  .main-content {
    margin-left: 0;
  }
  .col-sm-6, .col-lg-4, .col-lg-6, .col-lg-8, .col-xl-3,
  .col-md-3, .col-md-4, .col-md-6, .col-md-8,
  .chart-form-col, .chart-main-col {
    flex: 0 0 100%;
    max-width: 100%;
  }

  .chart-vitals-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 480px) {
  .chart-vitals-grid {
    grid-template-columns: 1fr;
  }
}

@media print {
  .sidebar, .top-bar, .app-footer, .no-print, .btn, form {
    display: none !important;
  }
  .main-content {
    margin-left: 0 !important;
  }
  .card-panel {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
