:root {
  --primary: #93195e;
  --primary-dark: #5e1040;
  --primary-light: #fdf1f7;
  --accent: #e0932e;
  --accent-light: #f2c94c;
  --bg: #f6f5f8;
  --card: #ffffff;
  --text: #1c1526;
  --muted: #726b7d;
  --border: #ece8f0;
  --danger: #c0392b;
  --danger-light: #fdedec;
  --success: #1e8e5a;
  --success-light: #e9f9f1;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(28,21,38,0.05);
  --shadow-md: 0 4px 16px rgba(28,21,38,0.06), 0 1px 3px rgba(28,21,38,0.05);
  --shadow-lg: 0 20px 50px rgba(28,21,38,0.16), 0 4px 12px rgba(28,21,38,0.08);
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { letter-spacing: -0.01em; }

/* ============ TOPBAR ============ */

.topbar {
  background: linear-gradient(120deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
  padding: 14px 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  box-shadow: 0 2px 12px rgba(94,16,64,0.18);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; display: flex; align-items: center; gap: 10px; }
.topbar .brand-logo { height: 42px; width: auto; background: #fdf9f2; border-radius: 8px; padding: 4px 8px; }
.topbar .brand span { color: var(--accent-light); font-weight: 600; }
.topbar .user-info { font-size: 0.88rem; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.topbar .user-info a.logout {
  background: rgba(255,255,255,0.14);
  padding: 7px 16px;
  border-radius: 100px;
  color: #fff;
  font-weight: 500;
  transition: background .15s ease;
}
.topbar .user-info a.logout:hover { background: rgba(255,255,255,0.26); }

.impersonation-bar {
  background: var(--accent-light);
  color: #4a3300;
  padding: 9px 28px;
  font-size: 0.85rem;
  text-align: center;
  font-weight: 600;
}
.impersonation-bar a {
  color: #4a3300;
  text-decoration: underline;
  margin-left: 10px;
}

.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 48px; }

/* ============ NAV TABS ============ */

.nav-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 5px;
  width: fit-content;
  box-shadow: var(--shadow-sm);
}
.nav-tabs a {
  background: transparent;
  padding: 9px 18px;
  border-radius: 100px;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.88rem;
  transition: background .15s ease, color .15s ease;
}
.nav-tabs a.active { background: var(--primary); color: #fff; }
.nav-tabs a:not(.active):hover { background: var(--primary-light); color: var(--primary-dark); }

/* ============ CARDS ============ */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-md);
}

.card h2, .card h3 { margin-top: 0; color: var(--primary-dark); font-weight: 700; }
.card h2 { font-size: 1.25rem; }
.card h3 { font-size: 1.05rem; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 800px) {
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
}

/* ============ FORMS ============ */

label { display: block; font-size: 0.83rem; font-weight: 600; margin-bottom: 6px; color: var(--muted); }

input[type=text], input[type=number], input[type=email], input[type=password],
input[type=date], input[type=time], input[type=tel], select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  background: #fbfafc;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(147,25,94,0.1);
  background: #fff;
}

.field { margin-bottom: 14px; }

/* ============ BUTTONS ============ */

button, .btn {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-block;
  transition: background .15s ease, transform .1s ease, box-shadow .15s ease;
  box-shadow: 0 1px 2px rgba(28,21,38,0.08);
}
button:hover, .btn:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 10px rgba(94,16,64,0.25); }
button:active, .btn:active { transform: translateY(0); }
.btn.secondary { background: #fff; color: var(--primary); border: 1.5px solid var(--border); box-shadow: none; }
.btn.secondary:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary-dark); box-shadow: none; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #a5321f; box-shadow: 0 4px 10px rgba(192,57,43,0.25); }
.btn.small { padding: 6px 14px; font-size: 0.8rem; border-radius: 7px; }

/* ============ TABLES ============ */

table { width: 100%; border-collapse: collapse; margin-top: 10px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--muted); font-weight: 600; text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.5px; background: #fbfafc; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--primary-light); }

/* ============ BADGES ============ */

.badge {
  display: inline-block; padding: 4px 12px; border-radius: 100px; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.2px;
}
.badge.registered { background: #e5f0fd; color: #1257b8; }
.badge.consultation { background: #fff2e2; color: #c5690a; }
.badge.discharged { background: var(--success-light); color: var(--success); }

/* ============ ALERTS ============ */

.alert { padding: 13px 18px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: 0.9rem; border: 1px solid transparent; }
.alert.error { background: var(--danger-light); color: var(--danger); border-color: #f4cbc4; }
.alert.success { background: var(--success-light); color: var(--success); border-color: #c3e9d5; }

/* ============ LOGIN PAGES ============ */

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(135deg, rgba(94,16,64,0.85), rgba(147,25,94,0.78)),
    url('../images/bg.webp');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  padding: 20px;
}
.login-card {
  background: #fff;
  width: 100%;
  max-width: 400px;
  padding: 40px 34px;
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { margin: 0 0 4px; font-size: 1.4rem; font-weight: 800; color: var(--primary-dark); text-align: center; letter-spacing: -0.02em; }
.login-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.login-logo img { height: 110px; width: auto; }
.login-card p.sub { text-align: center; color: var(--muted); margin-bottom: 26px; font-size: 0.86rem; line-height: 1.4; }
.role-tabs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px; background: #f3f1f5; border-radius: 12px; padding: 5px; margin-bottom: 22px; }
.role-tabs button {
  background: transparent; color: var(--muted); font-weight: 600; font-size: 0.82rem; padding: 10px 4px; border-radius: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; box-shadow: none; transform: none;
}
.role-tabs button:hover { background: rgba(255,255,255,0.6); transform: none; box-shadow: none; }
.role-tabs button.active { background: #fff; color: var(--primary); box-shadow: 0 2px 6px rgba(28,21,38,0.1); }
.captcha-code { letter-spacing: 4px; color: var(--primary); font-weight: 700; }
.patient-portal-link { text-align: center; font-size: 0.85rem; color: var(--muted); margin-top: 18px; line-height: 1.5; }
.demo-creds { margin-top: 18px; font-size: 0.78rem; color: var(--muted); background: #f9f8fa; border-radius: var(--radius-sm); padding: 12px 14px; line-height: 1.7; }

/* ============ MISC COMPONENTS ============ */

.stat-box { text-align: center; padding: 20px 16px; }
.stat-box .num { font-size: 2.1rem; font-weight: 800; color: var(--primary); letter-spacing: -0.02em; }
.stat-box .label { color: var(--muted); font-size: 0.83rem; margin-top: 6px; font-weight: 500; }

.section-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; gap: 12px; }

.invoice-box { border: 1.5px dashed var(--border); padding: 22px; border-radius: var(--radius); background: #fbfafc; }
.invoice-box table td:last-child, .invoice-box table th:last-child { text-align: right; }

details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details > summary::marker { content: ''; }

@media print {
  .no-print { display: none !important; }
  .card { box-shadow: none; border: none; }
}

/* ============ RESPONSIVE ============ */

@media (max-width: 900px) {
  .container { padding: 20px 16px 40px; }
  .card { padding: 20px; }
  .grid.cols-4 { grid-template-columns: 1fr 1fr; }
}

/* Any table wider than the screen becomes horizontally scrollable instead of
   squeezing columns unreadably thin or breaking the page layout. */
@media (max-width: 700px) {
  table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
}

@media (max-width: 640px) {
  html { font-size: 15px; }
  .container { padding: 14px 12px 32px; }
  .card { padding: 18px; border-radius: 12px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; gap: 12px; }

  .topbar { padding: 10px 14px; }
  .topbar .brand { font-size: 1.02rem; gap: 8px; }
  .topbar .brand-logo { height: 32px; padding: 3px 6px; }
  .topbar .brand span { display: block; }
  .topbar .user-info { font-size: 0.8rem; gap: 8px; width: 100%; justify-content: space-between; }

  .nav-tabs { gap: 4px; margin-bottom: 18px; width: 100%; border-radius: 12px; }
  .nav-tabs a { padding: 9px 12px; font-size: 0.83rem; flex: 1 1 auto; text-align: center; border-radius: 8px; }

  .section-title { flex-direction: column; align-items: flex-start; gap: 8px; }
  .section-title .btn, .section-title a.btn { width: 100%; text-align: center; }

  button, .btn { padding: 12px 18px; font-size: 0.92rem; width: 100%; text-align: center; }
  .small { width: auto; padding: 8px 12px; }
  /* Buttons inside table action cells stay compact so the horizontal-scroll table works;
     everything else (form submit buttons, footer nav buttons) goes full-width for easy tapping. */
  td .btn, td button, td .small { width: auto; }

  .stat-box .num { font-size: 1.6rem; }

  .login-wrapper { padding: 12px; }
  .login-card { padding: 28px 22px; border-radius: 16px; }
  .login-logo img { height: 85px; }
  .role-tabs { grid-template-columns: repeat(2, 1fr); }
  .role-tabs button { font-size: 0.8rem; padding: 10px 6px; }

  input[type=text], input[type=number], input[type=email], input[type=password],
  input[type=date], input[type=time], input[type=tel], select, textarea {
    font-size: 16px; /* prevents iOS Safari auto-zoom on focus */
  }
}
