:root {
  --brand-1: #087EA4;
  --brand-2: #12a8b9;
  --brand-dark: #0a5f78;
  --ink: #0b2b3a;
  --card-line: rgba(8, 126, 164, .12);
  --card-shadow: 0 8px 24px rgba(8, 126, 164, .10);
  --card-shadow-hover: 0 16px 36px rgba(8, 126, 164, .20);
  --radius: 18px;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Segoe UI', system-ui, -apple-system, Arial, sans-serif; }

body {
  background: linear-gradient(180deg, #eef7fb 0%, #f7fafc 100%);
  color: #0b2b3a;
  animation: pageFade .6s ease;
  transition: background .4s, color .4s;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main { flex: 1; }
.home-layout { flex: 1; }

@keyframes pageFade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Dark mode ---------- */
body.dark { background: #16181d; color: #e4e6eb; }
body.dark .stat-card, body.dark .doctor-card, body.dark .form-card, body.dark table {
  background: #22262e; color: #e4e6eb; box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
body.dark th { background: #2c323d; }
body.dark td { border-bottom: 1px solid #363d4a; }
body.dark .form-card input, body.dark .form-card select, body.dark textarea {
  background: #16181d; color: #e4e6eb; border-color: #363d4a;
}
body.dark .stat-card h3, body.dark .stat-card .stat-num, body.dark .doctor-card h3, body.dark .doctor-card h4 { color: #5aa9ff; }
body.dark .topbar { background: linear-gradient(135deg, #0b2833, #0e3c4b); }

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* ---------- Top navigation ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: nowrap;
  padding: 10px clamp(14px, 3vw, 30px);
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  color: #fff;
  box-shadow: 0 6px 22px rgba(5, 55, 72, .28);
  transition: box-shadow .3s ease;
}
.topbar.scrolled { box-shadow: 0 12px 34px rgba(5, 55, 72, .42); }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  text-decoration: none;
  white-space: nowrap;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: .3px;
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--brand-1);
  font-size: 1.5rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
  transition: transform .3s ease;
}
.brand:hover .brand-mark { transform: rotate(90deg) scale(1.06); }
.brand-text span { font-weight: 500; opacity: .9; }

.site-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-left: auto;
}

.nav-btn {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, .35);
  color: #fff;
  padding: 8px 13px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
  font-size: .88rem;
  line-height: 1.2;
  white-space: nowrap;
  transition: background .25s, transform .2s, box-shadow .25s, border-color .25s;
}
.nav-btn:hover { background: rgba(255, 255, 255, .18); transform: translateY(-2px); }
.nav-btn.active,
.nav-btn[aria-current="page"] {
  background: rgba(255, 255, 255, .24);
  border-color: rgba(255, 255, 255, .8);
  box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}
.nav-btn:focus-visible { outline: 3px solid #ffe27a; outline-offset: 2px; }

.nav-btn--quiet { border-color: transparent; background: rgba(255, 255, 255, .07); }
.nav-btn--quiet:hover { background: rgba(255, 255, 255, .2); }
.nav-btn--quiet.active,
.nav-btn--quiet[aria-current="page"] { background: rgba(255, 255, 255, .24); border-color: rgba(255, 255, 255, .6); }

.nav-btn--outline { border-color: rgba(255, 255, 255, .65); }
.nav-btn--solid { background: #fff; color: var(--brand-1); border-color: #fff; font-weight: 700; }
.nav-btn--solid:hover { background: #e9fbff; box-shadow: 0 6px 16px rgba(0, 0, 0, .25); }
.nav-btn--solid.active { background: #e9fbff; }

.nav-sep { width: 1px; height: 24px; background: rgba(255, 255, 255, .35); margin: 0 4px; }

.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* hamburger */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  margin-left: auto;
  padding: 10px;
  background: rgba(255, 255, 255, .08);
  border: 1px solid rgba(255, 255, 255, .35);
  border-radius: 10px;
  cursor: pointer;
}
.nav-toggle__bar { width: 22px; height: 2.5px; border-radius: 2px; background: #fff; transition: transform .25s ease, opacity .2s ease; }
.nav-toggle.open .nav-toggle__bar:nth-child(1) { transform: translateY(7.5px) rotate(45deg); }
.nav-toggle.open .nav-toggle__bar:nth-child(2) { opacity: 0; }
.nav-toggle.open .nav-toggle__bar:nth-child(3) { transform: translateY(-7.5px) rotate(-45deg); }

@keyframes navDrop { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Layout ---------- */
main { padding: clamp(18px, 4vw, 34px); max-width: 1200px; margin: auto; }
.view { display: none; }
.view.active { display: block; animation: fadeIn .5s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }

h2 { margin-bottom: 18px; font-size: 1.6rem; }
h3 { margin: 20px 0 10px; }

/* ---------- Cards & stats ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 18px;
}
.stat-card {
  background: #fff; border: 1px solid var(--card-line); border-radius: var(--radius); padding: 24px 20px; text-align: center;
  box-shadow: var(--card-shadow);
  transition: transform .3s, box-shadow .3s;
}
.stat-card:hover { transform: translateY(-6px); box-shadow: var(--card-shadow-hover); }
.stat-card h3, .stat-card .stat-num {
  display: block;
  color: var(--brand-1); font-size: 2.2rem; margin: 0;
  background: linear-gradient(135deg, var(--brand-1), var(--brand-2));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}

/* ---------- Forms ---------- */
.form-card {
  background: #fff; padding: 20px; border: 1px solid var(--card-line); border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 22px;
}
.form-card input, .form-card select, .form-card textarea {
  padding: 11px 14px; border: 1px solid #d5dbe7; border-radius: 10px;
  flex: 1 1 170px; font-size: .95rem; background: #fbfcff;
  transition: border-color .3s, box-shadow .3s;
}
.form-card input:focus, .form-card select:focus, .form-card textarea:focus {
  outline: none; border-color: #087EA4; box-shadow: 0 0 0 3px rgba(30,94,255,.15);
}

/* ---------- Buttons ---------- */
button {
  background: linear-gradient(135deg, #087EA4, #12a8b9);
  color: #fff; border: none; padding: 11px 20px; border-radius: 10px;
  cursor: pointer; font-size: .95rem; font-weight: 600;
  transition: transform .2s, box-shadow .3s, filter .2s;
}
button:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(30,94,255,.35); filter: brightness(1.05); }
button.secondary { background: #6c757d; }
button.danger { background: linear-gradient(135deg, #ff5a5a, #e03131); padding: 7px 13px; font-size: .85rem; }
button.edit { background: linear-gradient(135deg, #ffd43b, #f59f00); color: #333; padding: 7px 13px; font-size: .85rem; }

/* ---------- Tables ---------- */
table {
  width: 100%; border-collapse: collapse; background: #fff; border-radius: var(--radius);
  overflow: hidden; border: 1px solid var(--card-line);
  box-shadow: var(--card-shadow);
}
th, td { padding: 14px 16px; text-align: left; border-bottom: 1px solid #eef1f6; }
th { background: #eef4ff; color: var(--brand-1); font-weight: 700; }

/* ---------- Cards ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 18px;
}
.doctor-card {
  background: #fff; border: 1px solid var(--card-line); border-radius: var(--radius); padding: 20px;
  box-shadow: var(--card-shadow);
  transition: transform .3s, box-shadow .3s;
}
.doctor-card:hover { transform: translateY(-6px); box-shadow: var(--card-shadow-hover); }
.doctor-card h3, .doctor-card h4 { color: var(--brand-1); margin-bottom: 8px; }
.doctor-card__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* Appointments shown inside the Patients & Doctors views */
.appt-cell { font-size: .85rem; color: #4c6472; white-space: nowrap; }
.appt-line {
  font-size: .85rem; color: var(--brand-1); font-weight: 600;
  background: rgba(8,126,164,.08); border-radius: 8px; padding: 7px 10px; margin-top: 6px;
}
body.dark .appt-cell { color: #c7cdd6; }
body.dark .appt-line { color: #8fd3e6; background: rgba(18,168,185,.16); }

/* ---------- Doctors page: filters + profile cards ---------- */
.doctor-toolbar {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px; align-items: end; margin: 18px 0 4px;
}
.doctor-toolbar .field { display: flex; flex-direction: column; gap: 6px; }
.doctor-toolbar .field > span {
  font-size: .82rem; font-weight: 700; letter-spacing: .02em;
  text-transform: uppercase; color: var(--brand-1);
}
.doctor-toolbar input, .doctor-toolbar select {
  width: 100%; padding: 11px 13px; border: 1px solid var(--card-line); border-radius: 10px;
  background: #fff; color: #1b2b3a; font: inherit; font-size: .92rem;
  transition: border-color .2s, box-shadow .2s;
}
.doctor-toolbar input:focus, .doctor-toolbar select:focus {
  outline: none; border-color: var(--brand-1); box-shadow: 0 0 0 3px rgba(8,126,164,.16);
}
.doctor-count { grid-column: 1 / -1; margin: 0; font-size: .85rem; color: #4c6472; }

#doctorList { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }

.doctor-card { display: flex; flex-direction: column; }
.doctor-card__photo {
  position: relative; margin: -20px -20px 14px; border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden; background: #eef4ff;
}
.doctor-card__photo img { display: block; width: 100%; height: 195px; object-fit: cover; }
.doctor-card__badge {
  position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 24px);
  background: rgba(8,126,164,.94); color: #fff; padding: 5px 11px; border-radius: 999px;
  font-size: .72rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
}
.doctor-fields { display: grid; gap: 6px; margin: 12px 0 0; }
.doctor-fields > div { display: flex; gap: 8px; font-size: .86rem; }
.doctor-fields dt { flex: 0 0 86px; color: #6b7c8c; font-weight: 600; }
.doctor-fields dd { margin: 0; color: #23384a; }
.doctor-fields a { color: var(--brand-1); text-decoration: none; overflow-wrap: anywhere; }
.doctor-fields a:hover { text-decoration: underline; }
.doctor-card__bio { margin: 12px 0 0; font-size: .87rem; color: #4c6472; }
.doctor-card__rating { margin: 12px 0 0; font-size: .87rem; font-weight: 600; color: #b45309; }
.doctor-card__rate { margin: 8px 0 0; font-size: .82rem; color: #4c6472; }
.doctor-card__rate button { padding: 4px 7px; margin: 2px 4px 0 0; font-size: .78rem; }
.btn-book {
  display: block; margin-top: 16px; padding: 11px 18px; border-radius: 10px; text-align: center;
  background: linear-gradient(135deg, #087EA4, #12a8b9); color: #fff;
  font-weight: 600; text-decoration: none; transition: transform .2s, box-shadow .3s;
}
.btn-book:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(30,94,255,.35); }
.doctor-empty { grid-column: 1 / -1; padding: 24px; text-align: center; color: #4c6472; }

body.dark .doctor-toolbar input, body.dark .doctor-toolbar select { background: #16232e; color: #e8eef4; border-color: #2b3a48; }
body.dark .doctor-card__photo { background: #16232e; }
body.dark .doctor-fields dd { color: #cfd9e2; }
body.dark .doctor-fields dt, body.dark .doctor-card__bio, body.dark .doctor-count, body.dark .doctor-empty { color: #9fb0c0; }
body.dark .doctor-card__rating { color: #f0b429; }

/* ---------- Entrance animations ---------- */
.doctor-card, .stat-card, .form-card, table {
  animation: riseIn .5s ease both;
}
@keyframes riseIn {
  from { opacity: 0; transform: translateY(24px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.badge:not(:empty) {
  animation: badgePop .5s ease;
}

/* Staggered entrance for grid children */
.card-grid > *:nth-child(1), .stats-grid > *:nth-child(1) { animation-delay: .05s; }
.card-grid > *:nth-child(2), .stats-grid > *:nth-child(2) { animation-delay: .15s; }
.card-grid > *:nth-child(3), .stats-grid > *:nth-child(3) { animation-delay: .25s; }
.card-grid > *:nth-child(4), .stats-grid > *:nth-child(4) { animation-delay: .35s; }
.card-grid > *:nth-child(5), .stats-grid > *:nth-child(5) { animation-delay: .45s; }
.card-grid > *:nth-child(6), .stats-grid > *:nth-child(6) { animation-delay: .55s; }

/* Spinner */
.spinner {
  width: 40px; height: 40px;
  border: 4px solid rgba(30,94,255,.2);
  border-top-color: #087EA4;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Confetti */
.confetti-piece {
  position: fixed;
  width: 10px; height: 10px;
  top: -20px;
  z-index: 100;
  pointer-events: none;
  animation: confettiFall 1.6s ease-in forwards;
}
@keyframes confettiFall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0; }
}
@keyframes badgePop {
  0% { transform: scale(0); }
  70% { transform: scale(1.3); }
  100% { transform: scale(1); }
}

.stat-card:hover h3, .stat-card:hover .stat-num {
  display: inline-block;
  animation: heartbeat 1s ease-in-out infinite;
}
@keyframes heartbeat {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.badge {
  background: #ff4d6d;
  color: #fff;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: .7rem;
  margin-left: 4px;
  min-width: 20px;
  display: inline-block;
  text-align: center;
}
.badge:empty { display: none; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: linear-gradient(135deg, #087EA4, #12a8b9);
  color: #fff;
  padding: 14px 22px;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(30,94,255,.4);
  font-weight: 600;
  display: none;
  animation: slideUp .4s ease;
  z-index: 50;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.layout.collapsed .sidebar { display: none; }

/* ---------- Sidebar layout ---------- */
.layout {
  display: flex;
  align-items: stretch;
  min-height: calc(100vh - 64px);
  flex: 1;
}

.sidebar {
  width: 220px;
  background: linear-gradient(180deg, #087EA4, #0d5d74);
  color: #fff;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 4px 0 18px rgba(30,94,255,.25);
}

.sidebar .nav-btn {
  text-align: left;
  border-radius: 10px;
  padding: 10px 14px;
  width: 100%;
  font-size: .95rem;
}
.sidebar .nav-btn:hover, .sidebar .nav-btn.active {
  background: rgba(255,255,255,.22);
  box-shadow: inset 4px 0 0 #12a8b9;
}

.layout main { flex: 1; max-width: 100%; }

@media (max-width: 980px) {
  .nav-toggle { display: inline-flex; }
  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 16px 16px;
    background: linear-gradient(180deg, var(--brand-1), var(--brand-dark));
    box-shadow: 0 18px 34px rgba(0, 0, 0, .32);
    max-height: calc(100vh - 70px);
    overflow-y: auto;
  }
  .site-nav.open { display: flex; animation: navDrop .25s ease; }
  .site-nav .nav-btn { text-align: center; padding: 11px 14px; font-size: .95rem; }
  .nav-sep { display: none; }
}

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex-direction: row; flex-wrap: wrap; }
  .sidebar .nav-btn { width: auto; }
}

/* ---------- Help button & panel ---------- */
#helpBtn {
  position: fixed;
  bottom: 24px;
  left: 24px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, #087EA4, #12a8b9);
  color: #fff;
  font-size: 1.3rem;
  font-weight: bold;
  box-shadow: 0 8px 20px rgba(30,94,255,.4);
  z-index: 50;
  transition: transform .2s;
}
#helpBtn:hover { transform: scale(1.1); }

#helpPanel {
  position: fixed;
  bottom: 80px;
  left: 24px;
  max-width: 300px;
  background: #fff;
  color: #333;
  padding: 16px;
  border-radius: 14px;
  box-shadow: 0 12px 30px rgba(0,0,0,.18);
  display: none;
  z-index: 50;
  animation: slideUp .3s ease;
}
body.dark #helpPanel { background: #22262e; color: #e4e6eb; }

/* ---------- Morphing background slideshow ---------- */
.bg-slideshow {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
}

main, footer, header, .sidebar, .home-side {
  position: relative;
  z-index: 2;
}

.bg-slideshow img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  filter: brightness(.55) blur(1px);
  animation: morphFade 25s infinite;
}
.bg-slideshow img:nth-child(2) { animation-delay: 5s; }
.bg-slideshow img:nth-child(3) { animation-delay: 10s; }
.bg-slideshow img:nth-child(4) { animation-delay: 15s; }
.bg-slideshow img:nth-child(5) { animation-delay: 20s; }

@keyframes morphFade {
  0%   { opacity: 0; transform: translateY(40px) scale(.6) rotate(-1.5deg); }
  12%  { opacity: 1; transform: translateY(-12px) scale(1.08) rotate(1.5deg); }
  20%  { transform: translateY(6px) scale(.97) rotate(-1deg); }
  28%  { opacity: 1; transform: translateY(0) scale(1) rotate(.5deg); }
  30%  { opacity: 1; transform: translateY(-6px) scale(1.03) rotate(-1deg); }
  35%  { opacity: 0; transform: translateY(-20px) scale(.9) rotate(2deg); }
  100% { opacity: 0; transform: translateY(40px) scale(.6) rotate(-1.5deg); }
}

/* ---------- Reactions ---------- */
.reactions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  border-top: 1px solid #eee;
  padding-top: 8px;
}
.rx {
  background: #f1f5ff;
  color: #333;
  border: none;
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  font-size: .85rem;
  transition: transform .2s, background .2s;
}
.rx:hover { background: #dbe7ff; transform: translateY(-2px); }
.rx.pop { animation: badgePop .3s ease; }

/* ---------- Theme toggle ---------- */
.theme-btn, .dark-toggle {
  background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.5); color: #fff;
  padding: 8px 14px; border-radius: 999px; cursor: pointer; font-size: .95rem;
  transition: background .3s, transform .2s;
}
.theme-btn:hover, .dark-toggle:hover { background: rgba(255,255,255,.3); transform: scale(1.08); }


