/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #64748b;
  --accent: #0d9488;
  --accent-light: #ccfbf1;
  --accent-dark: #0f766e;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #0d9488;
  --sidebar-hover: rgba(255,255,255,.07);
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.12);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 16px;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-mark {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #14b8a6, #0d9488);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(13,148,136,.4);
}

.brand-mark svg { width: 22px; height: 22px; }

.brand strong { display: block; color: #fff; font-size: 14px; }
.brand small { color: var(--sidebar-text); font-size: 11px; }

.nav {
  flex: 1;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  text-decoration: none;
  transition: background .15s, color .15s;
  -webkit-tap-highlight-color: transparent;
}

.nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .7; }

.nav a:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}

.nav a:hover svg { opacity: 1; }

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

.nav a.active svg { opacity: 1; }

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--sidebar-active);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-name {
  color: #d1d5db;
  font-size: 12.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-button {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  color: var(--sidebar-text);
  padding: 0;
  white-space: nowrap;
}

.link-button:hover { color: #fff; text-decoration: underline; }

/* ── Main content ────────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  padding: 32px 36px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

/* ── Page header ─────────────────────────────────────────────── */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--accent);
  margin-bottom: 4px;
}

h1 { font-size: 24px; font-weight: 700; color: var(--text); }
h2 { font-size: 16px; font-weight: 600; color: var(--text); }

/* ── Buttons ─────────────────────────────────────────────────── */
.button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, border-color .15s, box-shadow .15s, transform .1s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.button:hover { background: #f9fafb; text-decoration: none; }
.button:active { transform: scale(.98); }

.button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(109,40,217,.25);
}

.button.primary:hover {
  background: linear-gradient(135deg, var(--accent-dark), #4c1d95);
  border-color: var(--accent-dark);
  box-shadow: 0 4px 16px rgba(109,40,217,.35);
}

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ── Metrics ─────────────────────────────────────────────────── */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow .2s, transform .2s;
}

.metric-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.metric-icon svg { width: 22px; height: 22px; }

.metric-icon.confirmed { background: #ecfdf5; color: #059669; }
.metric-icon.completed { background: #eef2ff; color: #4f46e5; }
.metric-icon.cancelled { background: #fef2f2; color: #dc2626; }
.metric-icon.services  { background: #eff6ff; color: #3b82f6; }
.metric-icon.doctors   { background: var(--accent-light); color: var(--accent); }

.metric-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.metric-card small {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
  display: block;
}

/* ── Animations ──────────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.animate-in {
  opacity: 0;
  animation: fadeInUp .4s ease forwards;
  animation-delay: calc(var(--delay, 0) * 60ms);
}

/* ── Split layout ────────────────────────────────────────────── */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.split > div {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-head a { font-size: 12.5px; color: var(--accent); }

/* ── Facts list ──────────────────────────────────────────────── */
.facts { display: grid; gap: 10px; }
.facts dt { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-2); }
.facts dd { font-size: 13.5px; color: var(--text); }
.facts.compact { grid-template-columns: auto 1fr; column-gap: 14px; }
.muted { color: var(--text-2); font-size: 12px; }

/* ── Health status ───────────────────────────────────────────── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.status-item {
  display: grid;
  grid-template-columns: 10px 1fr;
  gap: 2px 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}

.status-item > span {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  grid-row: span 2;
}

.status-item.ok > span { background: #059669; }
.status-item.bad > span { background: #dc2626; }
.status-item strong { font-size: 13px; }
.status-item small { color: var(--text-2); font-size: 11.5px; }

/* ── Row list ────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 4px; }

.row-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 7px;
  color: var(--text);
  text-decoration: none;
  transition: background .12s;
}

.row-link:hover { background: var(--bg); text-decoration: none; }
.row-link strong { font-size: 12.5px; color: var(--text-2); }

/* ── Table ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 2px solid var(--border); }
tbody tr { border-bottom: 1px solid #f3f4f6; transition: background .12s; }
tbody tr:hover { background: #fafafa; }
th { padding: 10px 14px; text-align: left; font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); white-space: nowrap; }
td { padding: 12px 14px; font-size: 13.5px; vertical-align: middle; }
td strong { display: block; }
td small { display: block; font-size: 11px; color: var(--text-2); margin-top: 2px; }
.empty { text-align: center; color: var(--text-2); padding: 32px; }

/* ── Pills ───────────────────────────────────────────────────── */
.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 99px;
  font-size: 11.5px;
  font-weight: 500;
  text-transform: capitalize;
  white-space: nowrap;
}

.pill.confirmed { background: #ecfdf5; color: #065f46; }
.pill.cancelled { background: #fef2f2; color: #991b1b; }
.pill.completed { background: #eff6ff; color: #1d4ed8; }
.pill.no_show   { background: #fffbeb; color: #92400e; }
.pill.finalized { background: #ecfdf5; color: #065f46; }
.pill.unknown { background: #f3f4f6; color: #374151; }

/* ── Form controls (base) ────────────────────────────────────── */
/* Applies to any raw form field (e.g. Django-rendered login inputs) so
   nothing renders as an unstyled browser default. Scoped rules below win. */
input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]):not([type=file]),
select,
textarea {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

input:not([type=checkbox]):not([type=radio]):not([type=submit]):not([type=button]):not([type=file]):focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

input::placeholder, textarea::placeholder { color: #94a3b8; }

/* ── Toolbar ─────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar input, .toolbar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 13.5px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.toolbar input:focus, .toolbar select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.toolbar input { min-width: 240px; }

/* ── Actions ─────────────────────────────────────────────────── */
.actions { display: flex; gap: 10px; align-items: center; }
.actions a { font-size: 12.5px; color: var(--accent); }

.danger-link {
  background: none;
  border: none;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  color: #dc2626;
  padding: 0;
}

.danger-link:hover { text-decoration: underline; }

/* ── Messages ────────────────────────────────────────────────── */
.messages { display: flex; flex-direction: column; gap: 8px; }

.message {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  border-radius: 8px;
  color: #065f46;
  font-size: 13.5px;
  animation: fadeInUp .3s ease;
}

.message svg { width: 18px; height: 18px; flex-shrink: 0; }

/* ── Edit form ───────────────────────────────────────────────── */
.form-card { max-width: 720px; }

.edit-form { display: grid; gap: 16px; }

.edit-form label { display: flex; flex-direction: column; gap: 5px; }

.edit-form label span {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.edit-form input,
.edit-form select,
.edit-form textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.edit-form input:focus,
.edit-form select:focus,
.edit-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.edit-form textarea { min-height: 100px; resize: vertical; }

.edit-form input[type=checkbox] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.field-error { font-size: 12px; color: #dc2626; }

.form-actions { display: flex; gap: 10px; padding-top: 8px; }

/* ═══════════════════════════════════════════════════════════════
   MOBILE TOPBAR & OVERLAY (hidden on desktop)
═══════════════════════════════════════════════════════════════ */
.topbar { display: none; }
.sidebar-overlay { display: none; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — tablet & mobile (≤ 900px)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 900px) {

  /* ── Topbar ── */
  .topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid rgba(255,255,255,.1);
    padding: 0 16px;
    z-index: 300;
  }

  .topbar-brand {
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
    letter-spacing: -.01em;
  }

  .hamburger {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--sidebar-text);
    border-radius: 8px;
    transition: background .15s, color .15s;
    -webkit-tap-highlight-color: transparent;
    flex-shrink: 0;
  }

  .hamburger:hover, .hamburger:focus-visible {
    background: var(--sidebar-hover);
    color: #fff;
    outline: none;
  }

  .hamburger svg { width: 22px; height: 22px; }

  /* ── Overlay backdrop ── */
  @keyframes overlay-fade-in { from { opacity: 0; } to { opacity: 1; } }

  body.sidebar-open .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    z-index: 200;
    animation: overlay-fade-in .2s ease;
  }

  /* ── Sidebar becomes slide-over ── */
  body { display: block; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%;
    z-index: 250;
    min-height: unset;
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4, 0, .2, 1),
                box-shadow .28s ease;
    will-change: transform;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
    box-shadow: 6px 0 40px rgba(0,0,0,.45);
  }

  /* ── Main content adjustments ── */
  .main {
    padding: 68px 20px 28px;
    gap: 20px;
  }

  /* ── Metrics: 2 columns ── */
  .metrics {
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }

  /* ── Split: single column ── */
  .split { grid-template-columns: 1fr; gap: 16px; }

  /* ── Page head: wraps ── */
  .page-head { flex-wrap: wrap; gap: 12px; }

  /* ── Toolbar: input shrinks ── */
  .toolbar input { min-width: 0; flex: 1; }

  /* ── Better touch targets ── */
  .nav a { min-height: 44px; }
  .button { min-height: 40px; padding: 10px 16px; }

  h1 { font-size: 20px; }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — small phone (≤ 480px)
═══════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {

  .main { padding: 60px 12px 24px; gap: 14px; }

  /* ── Smaller metric cards ── */
  .metrics { gap: 10px; }
  .metric-card { padding: 14px; gap: 10px; }
  .metric-icon { width: 38px; height: 38px; }
  .metric-icon svg { width: 18px; height: 18px; }
  .metric-value { font-size: 22px; }
  .metric-card small { font-size: 11px; }

  /* ── Cards ── */
  .split > div, .card { padding: 14px; }

  /* ── Table cells ── */
  td { padding: 10px; font-size: 12.5px; }
  th { padding: 8px 10px; }

  /* ── Toolbar stacks vertically ── */
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar input, .toolbar select { width: 100%; min-width: 0; }
  .toolbar .button { width: 100%; justify-content: center; }

  /* ── Form full-width ── */
  .form-card { max-width: 100%; }
  .form-actions { flex-direction: column; }
  .form-actions .button { width: 100%; justify-content: center; }

  /* ── Typography ── */
  h1 { font-size: 18px; }
  .page-head { flex-direction: column; align-items: flex-start; }
}

.message-action {
  border: 0;
  border-radius: 7px;
  color: #fff;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  padding: 7px 10px;
}

.message-action.whatsapp { background: #128c7e; }
.message-action.email { background: #2563eb; }
.message-action:disabled {
  cursor: not-allowed;
  opacity: .42;
}

.comms-panel { margin-top: 18px; }

.modal-backdrop {
  align-items: center;
  background: rgba(15, 23, 42, .58);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 500;
}

.modal-backdrop[hidden] { display: none; }

.modal-card {
  background: var(--card-bg, #fff);
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .35);
  max-width: 620px;
  padding: 22px;
  width: min(620px, 100%);
}

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  margin: 14px 0 6px;
  text-transform: uppercase;
}

.modal-card input,
.modal-card select,
.modal-card textarea {
  border: 1px solid var(--border, #d6dde8);
  border-radius: 7px;
  box-sizing: border-box;
  font: inherit;
  padding: 10px 12px;
  width: 100%;
}

.modal-card textarea { resize: vertical; }

.modal-actions {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 16px;
}

.message-status {
  color: var(--muted, #64748b);
  font-size: 13px;
}
