:root {
  --blue: #1a73e8;
  --blue-dark: #1557b0;
  --blue-light: #e8f0fe;
  --green: #34a853;
  --red: #ea4335;
  --orange: #fb8c00;
  --gray-50: #f8f9fa;
  --gray-100: #f1f3f4;
  --gray-200: #e8eaed;
  --gray-400: #9aa0a6;
  --gray-600: #5f6368;
  --gray-800: #3c4043;
  --gray-900: #202124;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --radius: 12px;
  --radius-sm: 8px;
  font-size: 15px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  font-family: 'Google Sans', 'Segoe UI', system-ui, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100vh;
}

/* ── Login ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
  background: linear-gradient(135deg, #1a73e8 0%, #0d47a1 100%);
}

.login-card {
  background: white;
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  text-align: center;
}

.login-logo { height: 48px; margin-bottom: 16px; }
.login-card h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 8px; color: var(--gray-900); }
.login-card p { color: var(--gray-600); font-size: .9rem; margin-bottom: 28px; }

.login-card input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  margin-bottom: 12px;
  transition: border-color .2s;
  outline: none;
}
.login-card input:focus { border-color: var(--blue); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: .95rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:active { transform: scale(.98); }
.btn-primary:disabled { background: var(--gray-400); cursor: not-allowed; }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  color: var(--red);
  border: 1.5px solid var(--red);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-danger:hover { background: #fde8e6; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: transparent;
  color: var(--blue);
  border: 1.5px solid var(--blue-light);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s;
}
.btn-ghost:hover { background: var(--blue-light); }

.btn-sm {
  padding: 5px 11px;
  font-size: .8rem;
}

.login-card .btn-primary { width: 100%; justify-content: center; padding: 14px; font-size: 1rem; }

.error-msg {
  background: #fde8e6;
  color: var(--red);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: .85rem;
  margin-top: 12px;
  text-align: left;
  display: none;
}
.error-msg.visible { display: block; }

/* ── Header ── */
header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-logo { height: 32px; }
header h1 { font-size: 1.1rem; font-weight: 600; color: var(--blue); flex: 1; }

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .85rem;
  color: var(--gray-600);
}

#logout-btn {
  background: none;
  border: 1.5px solid var(--gray-200);
  border-radius: 20px;
  padding: 5px 14px;
  font-size: .85rem;
  color: var(--gray-600);
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
#logout-btn:hover { border-color: var(--red); color: var(--red); }

/* ── Main ── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 28px 20px 60px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.toolbar h2 { font-size: 1.2rem; font-weight: 600; color: var(--gray-800); }

/* ── Stats bar ── */
.stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.stat-pill {
  background: white;
  border: 1px solid var(--gray-200);
  border-radius: 20px;
  padding: 6px 16px;
  font-size: .85rem;
  color: var(--gray-600);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-pill strong { color: var(--gray-900); }

/* ── Doctor card ── */
.doctor-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  margin-bottom: 16px;
  overflow: hidden;
  transition: box-shadow .15s;
}
.doctor-card:hover { box-shadow: var(--shadow); }

.doctor-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 18px 20px;
}

.doctor-avatar {
  width: 44px;
  height: 44px;
  background: var(--blue-light);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.doctor-info { flex: 1; min-width: 0; }
.doctor-info h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-900);
  margin-bottom: 2px;
}
.doctor-meta {
  font-size: .82rem;
  color: var(--gray-600);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.doctor-meta span { display: flex; align-items: center; gap: 3px; }

.doctor-badge {
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 12px;
  padding: 3px 10px;
  font-size: .78rem;
  font-weight: 500;
  white-space: nowrap;
}

.doctor-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* ── Contacted by ── */
.contacted-by-row {
  padding: 0 20px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.contacted-label {
  font-size: .8rem;
  color: var(--gray-400);
  white-space: nowrap;
}
.contacted-value {
  flex: 1;
  font-size: .88rem;
  color: var(--gray-800);
  font-weight: 500;
}
.contacted-empty { color: var(--gray-400); font-style: italic; font-weight: 400; }

.inline-edit-form {
  display: flex;
  gap: 6px;
  flex: 1;
}
.inline-edit-form input {
  flex: 1;
  padding: 6px 10px;
  border: 1.5px solid var(--blue);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  outline: none;
  min-width: 0;
}

/* ── Divider ── */
.card-divider {
  height: 1px;
  background: var(--gray-100);
  margin: 0 20px;
}

/* ── Notes ── */
.notes-section {
  padding: 14px 20px 18px;
}

.notes-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: .85rem;
  color: var(--gray-600);
  font-weight: 500;
  user-select: none;
  margin-bottom: 0;
}
.notes-toggle .chevron {
  width: 18px;
  height: 18px;
  transition: transform .2s;
  color: var(--gray-400);
}
.notes-toggle.open .chevron { transform: rotate(180deg); }

.notes-body { margin-top: 14px; display: none; }
.notes-body.open { display: block; }

.note-item {
  background: var(--gray-50);
  border-left: 3px solid var(--blue-light);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 10px 14px;
  margin-bottom: 10px;
  position: relative;
}
.note-item:last-of-type { margin-bottom: 0; }

.note-text { font-size: .88rem; color: var(--gray-800); line-height: 1.5; white-space: pre-wrap; }
.note-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}
.note-meta-left { font-size: .75rem; color: var(--gray-400); }

.note-delete-btn {
  background: none;
  border: none;
  color: var(--gray-400);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: .75rem;
  transition: color .15s, background .15s;
}
.note-delete-btn:hover { color: var(--red); background: #fde8e6; }

.add-note-form { margin-top: 12px; }
.add-note-form textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: .88rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
  outline: none;
  transition: border-color .2s;
  color: var(--gray-800);
}
.add-note-form textarea:focus { border-color: var(--blue); }

.add-note-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 8px;
  gap: 6px;
}

.no-notes {
  text-align: center;
  color: var(--gray-400);
  font-size: .85rem;
  padding: 16px 0 4px;
}

/* ── Loading spinner ── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid var(--gray-200);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray-400);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }

.modal {
  background: white;
  border-radius: var(--radius);
  width: 100%;
  max-width: 480px;
  box-shadow: 0 24px 80px rgba(0,0,0,.25);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-100);
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--gray-400);
  line-height: 1;
  padding: 0 4px;
  transition: color .15s;
}
.modal-close:hover { color: var(--gray-900); }

.modal-body { padding: 20px 24px; }

.field-group { margin-bottom: 16px; }
.field-group label {
  display: block;
  font-size: .82rem;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.field-group input, .field-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  outline: none;
  transition: border-color .2s;
  font-family: inherit;
}
.field-group input:focus, .field-group select:focus { border-color: var(--blue); }
.field-required { color: var(--red); margin-left: 2px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--gray-100);
}

/* ── QR Modal ── */
.qr-modal .modal { max-width: 360px; }
.qr-body { text-align: center; padding: 24px; }
.qr-body img { width: 240px; height: 240px; border-radius: 8px; }
.qr-url {
  margin-top: 14px;
  font-size: .8rem;
  color: var(--blue);
  word-break: break-all;
  cursor: pointer;
}
.qr-url:hover { text-decoration: underline; }
.qr-actions { display: flex; gap: 8px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--gray-900);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: .88rem;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  z-index: 300;
  white-space: nowrap;
}
.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--gray-400);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: .95rem; }

/* ── Responsive ── */
@media (max-width: 600px) {
  .doctor-actions { gap: 4px; }
  .btn-sm { padding: 4px 8px; font-size: .75rem; }
}
