:root {
  --bg: #eef2ff;
  --surface: #ffffff;
  --primary: #2f67ff;
  --primary-dark: #244ecc;
  --text: #0f172a;
  --muted: #6b7280;
  --border: #e4e7ee;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 16px;
  --shadow: 0 10px 40px rgba(27, 53, 160, 0.08);
  --font: "Poppins", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}
body {
  margin: 0;
  background: var(--bg);
  font-family: var(--font);
  color: var(--text);
  overflow-x: hidden;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
  position: relative;
}

.sidebar {
  background: #f6f7ff;
  border-right: 1px solid var(--border);
  padding: 24px 18px;
  width: 260px;
  transition:
    transform 0.25s ease,
    box-shadow 0.25s ease;
  will-change: transform;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}
.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--primary), #7aa2ff);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.brand-title {
  font-weight: 700;
}
.brand-sub {
  color: var(--muted);
  font-size: 12px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nav-item {
  text-decoration: none;
  color: var(--text);
  padding: 12px 14px;
  border-radius: 12px;
  display: block;
}
.nav-item:hover {
  background: #e8edff;
}
.nav-item.active {
  background: var(--primary);
  color: #fff;
}
.nav-item.muted {
  color: var(--muted);
}

.main {
  padding: 24px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}
.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
}
.page-title {
  font-weight: 700;
  font-size: 20px;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.search-box input {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  min-width: 220px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  padding: 8px 12px;
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.menu-toggle {
  display: none;
  width: 46px;
  height: 46px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-direction: column;
  border: none;
  appearance: none;
  background: var(--primary) !important;
  border-radius: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 10px 12px;
  color: #fff;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease;
}

.menu-toggle span {
  display: block;
  width: 22px;
  height: 3px;
  background: #fff;
  border-radius: 10px;
}

.menu-toggle .menu-label {
  display: none;
  font-weight: 700;
  font-size: 14px;
}

.nav-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.25);
  z-index: 55;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.nav-overlay.is-active {
  opacity: 1;
  pointer-events: auto;
}

body.nav-open {
  overflow: hidden;
}
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: #e0e7ff;
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--primary);
}
.user-name {
  font-weight: 600;
}
.user-role {
  color: var(--muted);
  font-size: 12px;
  text-transform: capitalize;
}

.content {
  display: grid;
  gap: 18px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.card-title {
  font-weight: 700;
  margin: 0 0 12px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Chart styling */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 22px;
  box-shadow: var(--shadow);
}

.chart-card h5 {
  margin: 0 0 12px 0;
  font-size: 20px;
  font-weight: 700;
}

.chart-area {
  position: relative;
  width: 100%;
  min-height: 320px;
}

.chart-area canvas {
  width: 100% !important;
  height: 320px !important;
}

/* Dashboard cards (Bootstrap assisted) */
.shadow-soft {
  box-shadow: 0 12px 32px rgba(59, 130, 246, 0.12) !important;
}

.patient-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px 16px;
  background: #fff;
}

.avatar-circle {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, #5aa0ff, #2f67ff);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.patient-name {
  font-size: 16px;
}

.label-intake {
  font-weight: 700;
  color: var(--muted);
}

.intake-value {
  font-size: 22px;
  font-weight: 700;
  color: #1d4ed8;
}

.badge-large {
  padding: 8px 12px;
  font-weight: 700;
  font-size: 13px;
  border-radius: 12px;
}

.badge-balance {
  padding: 6px 12px;
  font-weight: 700;
  border-radius: 10px;
  color: #fff;
}

.bg-outline {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
}

.progress-thin {
  height: 12px;
  background: #e5e7eb;
  border-radius: 999px;
}

.progress-thin .progress-bar {
  background: linear-gradient(90deg, #3b82f6, #7aa2ff);
  border-radius: 999px;
}

.badge.text-white {
  color: #fff !important;
}
.card-sub {
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.patient {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #fdfdff;
}
.patient-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.patient-name {
  font-weight: 700;
  font-size: 16px;
}
.patient-meta {
  color: var(--muted);
  font-size: 13px;
}
.badge {
  padding: 6px 10px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 12px;
}
.badge.normal {
  background: #ecfdf3;
  color: #15803d;
}
.badge.warning {
  background: #fff7ed;
  color: #c2410c;
}
.badge.critical {
  background: #fef2f2;
  color: #b91c1c;
}

.bar {
  height: 10px;
  background: #e5e7eb;
  border-radius: 999px;
  overflow: hidden;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--primary);
}

.progress-text {
  font-weight: 700;
  color: var(--primary-dark);
  margin-top: 6px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  table-layout: auto;
}
.table th,
.table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  white-space: normal;
  word-break: break-word;
}
.table th {
  color: var(--muted);
  font-weight: 600;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.table-responsive .table {
  min-width: 0;
}

.patients-table {
  min-width: 720px;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.label {
  font-weight: 600;
  margin-bottom: 6px;
  display: block;
}
.input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
}
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: none;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
.button.secondary {
  background: #e5e7eb;
  color: var(--text);
}

.flash {
  padding: 12px 14px;
  border-radius: 12px;
  background: #ecfdf3;
  color: #15803d;
  border: 1px solid #bbf7d0;
}
.flash.error {
  background: #fef2f2;
  color: #b91c1c;
  border-color: #fecdd3;
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 60;
    background: #fff;
    box-shadow: 0 14px 44px rgba(15, 23, 42, 0.16);
    border-right: 1px solid var(--border);
    width: min(320px, 86vw);
    height: 100vh;
    max-height: none;
    overflow-y: auto;
    transform: translateX(-110%);
    padding-top: 26px;
  }
  .sidebar.is-open {
    transform: translateX(0);
  }
  .menu-toggle {
    display: inline-flex;
  }
  .nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
  }
  .table {
    display: table;
    width: 100%;
  }
  .patients-table {
    min-width: 0;
    width: 100%;
    white-space: normal;
    border-collapse: separate;
  }
  .patients-table thead {
    display: none;
  }
  .patients-table tbody {
    display: grid;
    gap: 12px;
  }
  .patients-table tr {
    display: block;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fff;
    box-shadow: var(--shadow);
  }
  .patients-table td {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 0;
    border: 0;
    white-space: normal;
  }
  .patients-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    max-width: 40%;
  }
  .patients-table td:nth-child(1) {
    font-weight: 700;
    font-size: 15px;
  }
  .patients-table td:nth-child(6) {
    font-weight: 600;
  }
  .patients-table .cell-actions {
    display: flex;
    gap: 8px;
  }
  .patients-table .cell-actions::before {
    content: "";
  }
  .patients-table .cell-actions .button,
  .patients-table .cell-actions .button.secondary {
    flex: 1;
    min-width: 0;
    padding: 10px 12px;
    text-align: center;
    white-space: nowrap;
  }
  .table-responsive .table {
    min-width: 0;
  }
  .table th,
  .table td {
    padding: 10px 10px;
  }
  .table th {
    font-size: 13px;
  }
  .main {
    padding: 16px;
    margin-top: 8px;
  }
  .search-box input {
    min-width: 140px;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
  }
  .topbar-left {
    justify-content: space-between;
    width: 100%;
  }
  .topbar-right {
    width: 100%;
    flex-wrap: wrap;
  }
  .menu-toggle {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    gap: 4px;
    padding: 10px;
  }
  .menu-toggle span {
    width: 22px;
    height: 3px;
  }
  .menu-toggle .menu-label {
    display: none;
  }
}

@media (max-width: 640px) {
  .auth-card {
    padding: 22px;
  }
  .auth-title {
    font-size: 22px;
  }
  .grid {
    grid-template-columns: 1fr;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .button {
    width: 100%;
  }
  .table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}

@media (max-width: 768px) {
  .grid {
    grid-template-columns: 1fr;
  }
  .page-title {
    font-size: 22px;
  }
  .user-chip {
    width: 100%;
    justify-content: flex-start;
    gap: 12px;
  }
}

/* Auth layout */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  background:
    radial-gradient(
      120% 120% at 10% 20%,
      rgba(47, 103, 255, 0.18),
      transparent
    ),
    radial-gradient(120% 120% at 90% 10%, rgba(34, 197, 94, 0.12), transparent),
    linear-gradient(135deg, #eef2ff 0%, #f7f9ff 60%, #eef2ff 100%);
}

.auth-card {
  width: min(480px, 100%);
  background: #fff;
  border-radius: 18px;
  padding: 28px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: grid;
  gap: 14px;
}

.auth-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 6px;
}

.auth-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
}

.auth-sub {
  color: var(--muted);
  margin: 0;
}

.auth-form {
  display: grid;
  gap: 12px;
  margin-top: 6px;
}

.auth-footer {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}
