:root {
  --bg: #f6f8fc;
  --surface: #ffffff;
  --text: #1f1f1f;
  --muted: #5f6368;
  --border: #c7cdd6;
  --primary: #0b57d0;
  --primary-text: #ffffff;
  --danger: #b3261e;
  --focus: #0b57d0;
  --radius: 10px;
  --tap: 44px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; }

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
}
main:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: -999px; top: 0;
  background: var(--primary); color: var(--primary-text);
  padding: .75rem 1rem; z-index: 10;
}
.skip-link:focus { left: 0; }

a { color: var(--primary); }

/* Header and menu */
.app-header {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .5rem 1rem;
  padding-top: max(.5rem, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.app-title { font-size: 1.125rem; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.header-right { display: flex; align-items: center; gap: .5rem; min-width: 0; }
.user-email {
  color: var(--muted); font-size: .875rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40vw;
}
.menu {
  position: absolute; right: 1rem; top: 100%; z-index: 5;
  min-width: 200px; padding: .25rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, .15);
}
.menu-item {
  display: block; width: 100%; min-height: var(--tap);
  padding: .5rem .75rem; text-align: left;
  border: 0; border-radius: 6px; background: transparent; color: var(--text);
  font: inherit; cursor: pointer;
}
.menu-item:hover { background: #eef1f6; }
a.menu-item { display: flex; align-items: center; text-decoration: none; }

/* Bars */
.tap-bar, .notice-bar {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
  padding: .5rem 1rem;
}
.tap-bar { background: #fff4cc; border-bottom: 1px solid #d9b94a; }
.notice-bar { background: #e8f0fe; border-bottom: 1px solid #aecbfa; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: var(--tap); min-width: var(--tap);
  padding: .5rem 1rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn:hover:not(:disabled) { background: #eef1f6; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover:not(:disabled) { background: #0a4cb3; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--primary); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-block { display: flex; width: 100%; }

/* Forms */
.form h2 { margin-bottom: 1rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .25rem; }
input[type="search"], input[type="text"], input[type="tel"], input[type="date"], select, textarea {
  width: 100%; min-height: var(--tap);
  padding: .5rem .75rem;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit;
}
textarea { resize: vertical; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-top: .5rem; }
.save-status { font-size: .9375rem; }
.action-row { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1rem 0; }

/* Cards and messages */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
}
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.error { color: var(--danger); }
.notice { padding: 1rem; }

/* Sign in and status screens */
.signin { text-align: center; padding-top: 12vh; }
.signin .card { max-width: 420px; margin: 0 auto; }
.signin h1 { font-size: 1.5rem; }
.signin .btn { margin-top: 1rem; width: 100%; }
.signin .error { margin-top: 1rem; }
.status-screen { text-align: center; padding-top: 12vh; }
.status-screen .btn { margin: .5rem .25rem 0; }

/* Search */
.search-row { display: flex; gap: .5rem; align-items: stretch; margin-bottom: 1rem; }
.search-row input { flex: 1; }
.section-title { font-size: 1rem; color: var(--muted); margin: 1.25rem 0 .5rem; }
.patient-list { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.patient-row {
  display: flex; justify-content: space-between; align-items: center; gap: 1rem;
  min-height: var(--tap); padding: .75rem 1rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.patient-row:hover { background: #eef1f6; }
.patient-main { display: flex; flex-direction: column; min-width: 0; }
.patient-name { font-weight: 600; overflow-wrap: anywhere; }
.patient-phone { white-space: nowrap; }
.menu-email { padding: .5rem .75rem; color: var(--muted); font-size: .875rem; overflow-wrap: anywhere; border-bottom: 1px solid var(--border); margin-bottom: .25rem; }
.empty { text-align: center; padding: 2rem 1rem; }

/* Patient view */
.back-link { display: inline-flex; align-items: center; min-height: var(--tap); }
.patient-title { font-size: 1.5rem; }
.details { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; margin: 0; }
.details dt { color: var(--muted); }
.details dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.danger-zone { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }

/* Notes */
.section-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.section-head .section-title { margin: 1.25rem 0 .5rem; }
.note-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; margin-bottom: .5rem; }
.note-status { display: flex; align-items: center; gap: .25rem; }
.note.card { padding: .75rem 1rem; }
.note-input {
  display: block; width: 100%; min-height: 5rem; max-height: 60vh;
  padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font: inherit; line-height: 1.5; resize: vertical;
  field-sizing: content; /* grows with the text where supported */
}
.day-heading { font-size: .9375rem; color: var(--muted); margin: 1rem 0 .5rem; }
.chip-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .75rem; }
.chip {
  min-height: var(--tap); max-width: 100%; padding: .25rem .75rem;
  border: 1px solid var(--border); border-radius: 999px; background: var(--bg);
  color: var(--primary); font: inherit; cursor: pointer;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Attachments: photos and PDFs shown inline on the page */
.media-list { display: grid; gap: 1rem; }
.media { margin: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.media.loading { min-height: 160px; position: relative; }
.media.loading::before { content: "Loading…"; position: absolute; top: 1rem; left: 1rem; color: var(--muted); }
.media-img { display: block; width: 100%; height: auto; max-height: 80vh; object-fit: contain; background: #e3e7ee; }
.media-pdf { display: block; width: 100%; height: 70vh; border: 0; background: #fff; }
.media figcaption { display: flex; justify-content: space-between; align-items: center; gap: .5rem; padding: .25rem .75rem; border-top: 1px solid var(--border); }
.media-name { overflow-wrap: anywhere; font-size: .9375rem; }
.file-list { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .5rem; }
.file-row {
  display: flex; justify-content: space-between; gap: 1rem; width: 100%;
  min-height: var(--tap); padding: .5rem 1rem; text-align: left;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.upload-list { list-style: none; margin: .5rem 0 0; padding: 0; display: grid; gap: .5rem; }
.upload-row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.upload-row > span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pending-img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; }

/* Phones */
@media (max-width: 520px) {
  .user-email { display: none; }          /* shown in the menu instead */
  .app-header { padding-left: max(1rem, env(safe-area-inset-left)); padding-right: max(1rem, env(safe-area-inset-right)); }
  .action-row .btn { flex: 1 1 auto; }
  .details { grid-template-columns: 1fr; gap: 0; }
  .details dt { margin-top: .5rem; font-size: .875rem; }
  .form-actions .btn { flex: 1 1 auto; }
  .media-pdf { height: 60vh; }
}

/* Tablets and larger: use the width, keep reading lines comfortable */
@media (min-width: 768px) {
  main { max-width: 860px; padding-top: 1.5rem; }
  .media-list { grid-template-columns: repeat(2, 1fr); align-items: start; }
  .media-pdf { height: 60vh; }
}
@media (min-width: 1100px) {
  main { max-width: 960px; }
}

/* Landscape phones: short screens */
@media (max-height: 480px) and (orientation: landscape) {
  .media-pdf { height: 90vh; }
  .media-img { max-height: 90vh; }
}
