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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #1a1a1a;
  background: #f0f2f5;
  min-height: 100vh;
}

/* ── Screen visibility ───────────────────────────────────────────────────── */
.screen  { width: 100%; min-height: 100vh; }
.hidden  { display: none !important; }

/* ── Login / Access denied ───────────────────────────────────────────────── */
#screen-login,
#screen-denied,
#screen-patient {
  display: flex;
  align-items: center;
  justify-content: center;
}

.patient-welcome {
  text-align: center;
  max-width: 460px;
  width: 90%;
  padding: 40px 24px;
}
.patient-welcome .logo { font-size: 56px; margin-bottom: 16px; color: #22c55e; }
.patient-welcome h1   { font-size: 26px; font-weight: 700; margin-bottom: 12px; }
.patient-welcome p    { color: #555; line-height: 1.6; margin-bottom: 12px; font-size: 15px; }

.center-card {
  background: #fff;
  border-radius: 12px;
  padding: 48px 40px;
  text-align: center;
  box-shadow: 0 2px 16px rgba(0,0,0,.08);
  max-width: 420px;
  width: 90%;
}
.center-card .logo { font-size: 40px; margin-bottom: 16px; }
.center-card h1    { font-size: 22px; font-weight: 700; margin-bottom: 10px; }
.center-card p     { color: #666; line-height: 1.5; margin-bottom: 24px; }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  height: 52px;
  background: #fff;
  border-bottom: 1px solid #e0e4ea;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title { font-weight: 700; font-size: 15px; flex: 1; }
.topbar-email { font-size: 13px; color: #666; }

/* ── Tab nav ─────────────────────────────────────────────────────────────── */
.tab-nav {
  display: flex;
  background: #fff;
  border-bottom: 1px solid #e0e4ea;
  padding: 0 24px;
}
.tab-btn {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 13px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: #666;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab-btn:hover  { color: #1a1a1a; }
.tab-btn.active { border-bottom-color: #0066cc; color: #0066cc; }

/* ── Tab body ────────────────────────────────────────────────────────────── */
.tab-body { padding: 24px; }
.tab-pane { animation: fadein .12s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── Section header ──────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.section-header h2 { font-size: 18px; font-weight: 600; }

/* ── Card (add-mapping form) ─────────────────────────────────────────────── */
.card {
  background: #fff;
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  border: 1px solid #e8eaed;
}
.card h3 { font-size: 14px; font-weight: 600; margin-bottom: 14px; color: #444; }

.form-row {
  display: flex;
  gap: 16px;
  align-items: flex-end;
  flex-wrap: wrap;
}
.form-row label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-row select {
  padding: 7px 10px;
  border: 1px solid #d0d4da;
  border-radius: 6px;
  font-size: 13px;
  min-width: 220px;
  background: #fff;
  color: #1a1a1a;
}
.form-row select:focus { outline: none; border-color: #0066cc; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  border: 1px solid #e8eaed;
}
thead th {
  background: #f8f9fb;
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #666;
  border-bottom: 1px solid #e0e4ea;
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid #f0f2f5;
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }

.role-cell  { display: flex; gap: 8px; align-items: center; }
.mono       { font-family: ui-monospace, monospace; font-size: 12px; color: #555; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 16px;
  transition: opacity .1s, background .1s;
  white-space: nowrap;
}
button:hover   { opacity: .88; }
button:active  { opacity: .75; }
button.small   { padding: 5px 10px; font-size: 12px; }

.btn-primary   { background: #0066cc; color: #fff; }
.btn-secondary { background: #eaecf0; color: #1a1a1a; }
.btn-danger    { background: #fde8e8; color: #c0392b; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.badge-admin   { background: #fef3e2; color: #b45309; }
.badge-dealer  { background: #ede9fe; color: #6d28d9; }
.badge-viewer  { background: #dbeafe; color: #1d4ed8; }
.badge-patient { background: #dcfce7; color: #15803d; }
.badge-active  { background: #dcfce7; color: #15803d; }
.badge-pending { background: #fef9c3; color: #854d0e; }
.badge-pdf     { background: #ffe4e6; color: #be123c; }
.badge-zip     { background: #e0f2fe; color: #0369a1; }
.badge-json    { background: #fef9c3; color: #854d0e; }

/* ── Status dot ──────────────────────────────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}
.status-dot.active   { background: #22c55e; }
.status-dot.inactive { background: #9ca3af; }

/* ── State messages ──────────────────────────────────────────────────────── */
.loading { color: #888; padding: 24px 0; }
.empty   { color: #888; padding: 24px 0; }
.error   { color: #c0392b; }
.muted   { color: #aaa; }

/* ── Notice banner ───────────────────────────────────────────────────────── */
.notice-banner {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  padding: 12px 16px;
  color: #1d4ed8;
  font-size: 13px;
  margin-bottom: 20px;
  line-height: 1.5;
}

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

.modal {
  background: #fff;
  border-radius: 12px;
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, .18);
  padding: 28px 32px;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: 18px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  color: #888;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  border-radius: 4px;
}
.modal-close:hover { background: #f0f2f5; color: #333; }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ── Form grid (2-column layout inside modals) ───────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.form-field.span-2 { grid-column: span 2; }

.form-field input,
.form-field select {
  padding: 8px 10px;
  border: 1px solid #d0d4da;
  border-radius: 6px;
  font-size: 13px;
  background: #fff;
  color: #1a1a1a;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
}
.form-field input:focus,
.form-field select:focus { outline: none; border-color: #0066cc; }

.field-hint  { font-size: 11px; color: #888; font-weight: 400; text-transform: none; letter-spacing: 0; }
.required    { color: #c0392b; font-weight: 700; }
.optional    { color: #aaa; font-weight: 400; text-transform: none; letter-spacing: 0; }

@media (max-width: 520px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-field.span-2 { grid-column: span 1; }
  .modal { padding: 20px 18px; }
}

/* ── Breadcrumb ──────────────────────────────────────────────────────────── */
.breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 20px;
  font-size: 13px;
  color: #888;
}
.bc-link  { color: #0066cc; }
.bc-link:hover { text-decoration: underline; }
.bc-sep   { color: #ccc; }
.bc-current { color: #333; font-weight: 600; }

/* ── View hint ───────────────────────────────────────────────────────────── */
.view-hint { color: #888; font-size: 13px; margin-bottom: 16px; }

/* ── Profile card ────────────────────────────────────────────────────────── */
.profile-card {
  background: #fff;
  border: 1px solid #e8eaed;
  border-radius: 8px;
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.profile-card-row {
  display: flex;
  gap: 32px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.profile-card-row:last-child { margin-bottom: 0; }
.profile-field {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 160px;
}
.profile-field.span-2 { flex: 2; }
.profile-field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #888;
}
.profile-field span  { font-size: 14px; color: #1a1a1a; }

/* ── Report events list ──────────────────────────────────────────────────── */
.report-events-list { display: flex; flex-direction: column; gap: 8px; }
.report-event {
  background: #fff;
  border: 1px solid #e8eaed;
  border-radius: 8px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.report-event-header { display: flex; align-items: center; gap: 10px; }
.report-event-date   { font-size: 14px; font-weight: 500; color: #333; }
.small-badge { font-size: 11px; padding: 2px 7px; }
.report-event-actions { display: flex; gap: 8px; }

/* ── Dashboard summary cards ─────────────────────────────────────────────── */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.summary-card {
  background: #fff;
  border: 1px solid #e8eaed;
  border-radius: 10px;
  padding: 16px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.summary-card .sc-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: #888; margin-bottom: 6px; }
.summary-card .sc-value { font-size: 26px; font-weight: 700; color: #1a1a1a; line-height: 1; }
.summary-card .sc-sub   { font-size: 12px; color: #aaa; margin-top: 4px; }
.summary-card.sc-warn   { border-color: #fca5a5; background: #fff5f5; }
.summary-card.sc-good   { border-color: #86efac; background: #f0fdf4; }

/* ── Charts row ──────────────────────────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card {
  background: #fff;
  border: 1px solid #e8eaed;
  border-radius: 10px;
  padding: 16px 20px;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
}
.chart-card h4 { font-size: 13px; font-weight: 600; color: #444; margin-bottom: 12px; }
.chart-card canvas { width: 100% !important; height: 240px !important; }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 12px 16px;
  background: #f8f9fb;
  border: 1px solid #e8eaed;
  border-radius: 8px;
}
.filter-bar .fb-group   { display: flex; gap: 6px; align-items: center; }
.filter-bar label       { font-size: 12px; font-weight: 600; color: #666; white-space: nowrap; }
.filter-bar input[type=date] { padding: 5px 8px; border: 1px solid #d0d4da; border-radius: 5px; font-size: 12px; }
.filter-bar select      { padding: 5px 8px; border: 1px solid #d0d4da; border-radius: 5px; font-size: 12px; background: #fff; }
.filter-bar .fb-spacer  { flex: 1; }
.quick-btn { background: #eaecf0; color: #1a1a1a; padding: 4px 10px; border-radius: 4px; font-size: 12px; border: none; cursor: pointer; }
.quick-btn.active { background: #0066cc; color: #fff; }

/* ── Metrics table ───────────────────────────────────────────────────────── */
.metrics-table-wrap { overflow-x: auto; }
.metrics-table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  border: 1px solid #e8eaed;
  font-size: 13px;
}
.metrics-table thead th {
  background: #f8f9fb;
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: #666;
  border-bottom: 1px solid #e0e4ea;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.metrics-table thead th:hover { background: #eef0f3; }
.metrics-table thead th .sort-arrow { margin-left: 4px; color: #aaa; }
.metrics-table tbody td { padding: 9px 12px; border-bottom: 1px solid #f0f2f5; vertical-align: middle; }
.metrics-table tbody tr:last-child td { border-bottom: none; }
.metrics-table tbody tr:hover { background: #fafbfc; }
.metrics-table tbody tr.expanded { background: #f0f7ff; }
.compliant   { color: #15803d; font-weight: 600; }
.noncompliant { color: #c0392b; font-weight: 600; }
.ahi-high    { color: #c0392b; font-weight: 600; }

/* ── Expanded detail row ─────────────────────────────────────────────────── */
.detail-row td { padding: 0 !important; }
.detail-panel {
  padding: 16px 20px;
  background: #f8faff;
  border-top: 1px solid #d0e4ff;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px 24px;
}
.detail-field { display: flex; flex-direction: column; gap: 2px; }
.detail-field .df-label { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: #888; }
.detail-field .df-value { font-size: 13px; color: #1a1a1a; }
.detail-actions { grid-column: span 4; display: flex; gap: 8px; margin-top: 4px; padding-top: 12px; border-top: 1px solid #dce8ff; }

@media (max-width: 900px) {
  .summary-cards  { grid-template-columns: 1fr 1fr; }
  .charts-row     { grid-template-columns: 1fr; }
  .detail-panel   { grid-template-columns: 1fr 1fr; }
}
