/* ========== Global reset & base ========== */
* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont,
               "Segoe UI", Roboto, Arial, sans-serif;
  background: #f3f4f6;
}

/* ========== Chat app layout ========== */
body.chat {
  overflow: hidden; /* prevent keyboard scroll issues */
}

.app {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}

.header {
  position: relative;
  padding: 10px 12px;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  max-height: 52px;
}

.header-title {
  font-weight: 600;
  font-size: 18px;
  flex: 0 0 auto;
}

.header-logo {
  height: 32px;
  width: auto;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

.qr-icon-btn {
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-icon-btn:hover {
  background: #f3f4f6;
}

.qr-icon-btn:active {
  background: #e5e7eb;
}

.qr-icon {
  width: 28px;
  height: 28px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  background: #f3f4f6;
  display: flex;
  flex-direction: column;
  gap: 6px;
  justify-content: flex-end;
}

.row { display: flex; }

.bubble {
  padding: 8px 12px;
  border-radius: 18px;
  max-width: 80%;
  font-size: 15px;
  line-height: 1.4;
}

.ai {
  background: #e5e7eb;
  color: #111827;
  border-bottom-left-radius: 4px;
}

.user {
  margin-left: auto;
  background: #e5f2ff;
  color: #111827;
  border-bottom-right-radius: 4px;
}

.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px 10px;
  border-top: 1px solid #e5e7eb;
  background: #ffffff;
}

.input-bar textarea {
  flex: 1;
  min-width: 0;
  appearance: none;
  -webkit-appearance: none;
  border-radius: 20px;
  border: 1px solid #d1d5db;
  padding: 10px 14px;
  font: inherit;
  font-size: 16px;
  line-height: 1.4;
  background: #ffffff;
  outline: none;
  resize: none;
  overflow-y: hidden;
  max-height: 140px;
}

.input-bar button {
  flex-shrink: 0;
  align-self: flex-end;
  border-radius: 20px;
  border: 1px solid #d1d5db;
  padding: 9px 14px;
  background: #ffffff;
  font-size: 16px;
  cursor: pointer;
}

/* ========== QR Overlay Modal ========== */
body.overlay-open {
  overflow: hidden;
}

.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-overlay[hidden] {
  display: none;
}

.qr-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: none;
  border: none;
  color: #ffffff;
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
}

.qr-close-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.qr-overlay-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
}

.qr-overlay-img {
  width: 260px;
  height: 260px;
  background: #ffffff;
  border-radius: 16px;
  padding: 16px;
}

.qr-overlay-hint {
  margin-top: 20px;
  color: #ffffff;
  font-size: 16px;
  text-align: center;
}

/* ========== Doctor / admin pages ========== */
.wrap {
  max-width: 520px;
  margin: 0 auto;
  padding: 24px;
}

.card {
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 18px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
}

h1 {
  margin: 0 0 10px;
  font-size: 20px;
}

p {
  margin: 0 0 14px;
  color: #374151;
}

label {
  display: block;
  margin: 12px 0 6px;
  font-weight: 600;
}

input[type="email"],
input[type="text"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  font-size: 16px;
}

button.primary {
  margin-top: 14px;
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: none;
  background: #111827;
  color: #ffffff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.small {
  font-size: 13px;
  color: #6b7280;
}

a {
  color: #2563eb;
  text-decoration: none;
}
a:hover { text-decoration: underline; }

/* ========== Landing page ========== */
body.landing {
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.landing-card {
  max-width: 720px;
  padding: 28px 24px;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  box-shadow: 0 6px 24px rgba(0,0,0,.06);
  text-align: center;
  background: #fff;
}

.btn {
  display: inline-block;
  padding: 12px 16px;
  border-radius: 12px;
  text-decoration: none;
  border: 1px solid #d1d5db;
  background: #fff;
  font-size: 16px;
  cursor: pointer;
}

.btn:active { transform: translateY(1px); }

.disclaimer {
  margin-top: 14px;
  font-size: 12px;
  color: #6b7280;
}

/* ========== Doctor session view ========== */
.wrap-wide { max-width: 860px; margin: 0 auto; padding: 18px; }

.row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

button.btn2 {
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #d1d5db;
  background: #ffffff;
  cursor: pointer;
  font-size: 14px;
}

pre.summary {
  white-space: pre-wrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px;
}

/* ========== Scan list (doctor home) ========== */
.scan-list {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scan-card {
  display: block;
  background: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
  text-decoration: none;
  color: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.scan-card:hover {
  border-color: #2563eb;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.1);
  text-decoration: none;
}

.scan-card--expired {
  opacity: 0.6;
  background: #f9fafb;
}

.scan-card__title {
  font-weight: 600;
  font-size: 15px;
  color: #111827;
  margin-bottom: 4px;
}

.scan-card__meta {
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 4px;
}

.scan-card__brief {
  font-size: 13px;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-danger {
  color: #dc2626;
  border-color: #fecaca;
}

.btn-danger:hover {
  background: #fef2f2;
}

/* ========== Doctor home page ========== */
body.doctor-home {
  overflow: hidden;
}

body.doctor-scan {
  overflow: hidden;
}

.doctor-app {
  position: fixed;
  inset: 0;
  margin: 0 auto;
  max-width: 720px;
  display: flex;
  flex-direction: column;
  background: #ffffff;
}

.header-icon-btn {
  flex: 0 0 auto;
  background: none;
  border: none;
  padding: 6px;
  cursor: pointer;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #374151;
  text-decoration: none;
}

.header-icon-btn:hover {
  background: #f3f4f6;
}

.header-icon {
  width: 26px;
  height: 26px;
  max-width: 26px;
  max-height: 26px;
  flex-shrink: 0;
}

.doctor-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #f3f4f6;
}

.section-title {
  font-size: 15px;
  font-weight: 600;
  color: #6b7280;
  margin: 0 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: #6b7280;
}

.empty-state p {
  margin: 0 0 8px;
}

/* ========== Menu overlay ========== */
.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  justify-content: flex-start;
}

.menu-overlay[hidden] {
  display: none;
}

.menu-panel {
  width: 280px;
  max-width: 85vw;
  height: 100%;
  background: #ffffff;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  position: relative;
}

.menu-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: none;
  border: none;
  font-size: 28px;
  color: #6b7280;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 6px;
}

.menu-close-btn:hover {
  background: #f3f4f6;
}

.menu-header {
  padding: 24px 20px;
  border-bottom: 1px solid #e5e7eb;
  margin-top: 40px;
}

.menu-email {
  font-weight: 600;
  font-size: 15px;
  color: #111827;
  word-break: break-all;
}

.menu-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: 13px;
  padding: 4px 10px;
  border-radius: 20px;
}

.menu-badge.verified {
  background: #dcfce7;
  color: #166534;
}

.menu-badge.unverified {
  background: #fef3c7;
  color: #92400e;
}

.badge-icon {
  font-weight: 700;
}

.menu-items {
  flex: 1;
  padding: 12px 0;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 14px 20px;
  background: none;
  border: none;
  text-align: left;
  font-size: 15px;
  color: #374151;
  cursor: pointer;
  text-decoration: none;
}

.menu-item:hover {
  background: #f3f4f6;
}

.menu-item--danger {
  color: #dc2626;
}

.menu-form {
  display: contents;
}

/* ========== Summary structured display ========== */
.summary-structured {
  margin-top: 14px;
}

.summary-section {
  padding: 10px 0;
  border-bottom: 1px solid #f3f4f6;
}

.summary-section:last-child {
  border-bottom: none;
}

.summary-label {
  font-size: 12px;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 4px;
}

.summary-value {
  font-size: 14px;
  color: #111827;
  line-height: 1.5;
}

/* ========== QR Scanner page ========== */
.scan-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #000000;
  position: relative;
}

.scanner-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#scanner-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scanner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scanner-frame {
  width: 250px;
  height: 250px;
  border: 3px solid rgba(255, 255, 255, 0.8);
  border-radius: 20px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
}

.scanner-status {
  padding: 20px;
  text-align: center;
  background: #111827;
  color: #ffffff;
}

.scanner-status p {
  margin: 0;
  color: #ffffff;
}

.scanner-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #f3f4f6;
  padding: 24px;
  text-align: center;
}

.scanner-fallback[hidden] {
  display: none;
}

.fallback-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.scanner-fallback p {
  margin: 0 0 8px;
}

