:root {
  --border: #d8dee5;
  --text: #1f2933;
  --muted: #6b7785;
  --accent: #1565c0;
  --danger: #c62828;
  --bg-subtle: #eaf6fb;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: #fff;
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 10;
}

.topbar-brand { font-weight: 700; font-size: 1.05rem; }

.topbar-actions { display: flex; align-items: center; gap: 12px; }

.topbar-link { font-size: 0.9rem; }

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #e3e8ee;
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
}

.page { max-width: 720px; margin: 0 auto; padding: 16px; }

.flash {
  background: var(--bg-subtle);
  border: 1px solid #bfe3f0;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.section-label {
  text-transform: uppercase;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.visit-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}

.visit-card-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
}

.visit-card-patient { font-weight: 600; }

.visit-card-action { font-size: 0.9rem; font-weight: 600; }
.visit-card-action.status-submitted { color: var(--muted); }
.visit-card-action.status-not_started,
.visit-card-action.status-in_progress { color: var(--danger); }

.visit-card-date { color: var(--muted); font-size: 0.85rem; margin-bottom: 8px; }

.visit-card-rows {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  font-size: 0.9rem;
}

.visit-card-row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
}

.visit-card-row .label { color: var(--muted); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

form.stacked label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 4px;
}

form.stacked input[type=text],
form.stacked input[type=email],
form.stacked input[type=password],
form.stacked input[type=number],
form.stacked input[type=date],
form.stacked select,
form.stacked textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 14px;
  font-family: inherit;
}

form.stacked textarea { min-height: 80px; resize: vertical; }

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
  padding: 8px 4px;
  min-height: 44px;
  cursor: pointer;
}
.checkbox-row input {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  accent-color: var(--accent);
}
.checkbox-row label { margin: 0; cursor: pointer; }

button, .btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 13px 18px;
  min-height: 44px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
button:hover, .btn:hover { opacity: 0.92; text-decoration: none; }

.btn-secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-danger { background: var(--danger); }

.btn-small { min-height: 36px; padding: 8px 12px; font-size: 0.85rem; }

.form-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}

.form-section h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.section-card { padding: 0; overflow: hidden; }
.section-card summary {
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 600;
  font-size: 1rem;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
}
.section-card summary::-webkit-details-marker { display: none; }
.section-card summary::after {
  content: "";
  width: 10px;
  height: 10px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s;
  flex-shrink: 0;
  margin-left: 12px;
}
.section-card[open] summary::after { transform: rotate(45deg); }
.section-card-body { padding: 0 16px 16px; }

.section-toggle-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.sticky-action-bar {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--border);
  padding: 12px 0;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  margin-top: 8px;
  display: flex;
  gap: 10px;
  z-index: 5;
}
.sticky-action-bar button { flex: 1; }

.locked-banner {
  background: #fff4e5;
  border: 1px solid #ffd699;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

table.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  margin-bottom: 20px;
}
table.admin-table th, table.admin-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
table.admin-table th { color: var(--muted); font-weight: 600; }

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 4px;
}
.table-scroll table.admin-table { margin-bottom: 0; }

/* Below ~640px, responsive-table rows become stacked cards instead of a
   horizontally-scrolling table -- much easier to read one-handed on a phone.
   Requires each <td> to carry a data-label attribute. */
@media (max-width: 640px) {
  table.responsive-table thead { display: none; }
  table.responsive-table, table.responsive-table tbody,
  table.responsive-table tr, table.responsive-table td { display: block; width: 100%; }
  table.responsive-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 12px;
  }
  table.responsive-table td {
    border: none;
    padding: 6px 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    text-align: right;
  }
  table.responsive-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    font-size: 0.78rem;
    text-align: left;
    flex-shrink: 0;
  }
  table.responsive-table td:empty,
  table.responsive-table td[data-label]:not([data-label=""]):has(> *:only-child:empty) { display: none; }

  /* Action cells (no label -- buttons/forms) stack full-width instead of
     sitting in the label/value flex row. */
  table.responsive-table td[data-label=""] {
    display: block;
    text-align: left;
  }
  table.responsive-table td[data-label=""]::before { content: none; }
  table.responsive-table td[data-label=""] form { margin-bottom: 6px; }
  table.responsive-table td[data-label=""] form:last-child { margin-bottom: 0; }
  table.responsive-table td[data-label=""] > form > button,
  table.responsive-table td[data-label=""] > details > summary { width: 100%; }
}

.help-text { color: var(--muted); font-size: 0.8rem; margin-top: -10px; margin-bottom: 14px; }

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

.login-wrap {
  max-width: 360px;
  margin: 60px auto;
  padding: 0 16px;
}
.login-wrap h1 { font-size: 1.2rem; margin-bottom: 20px; }

.error-text { color: var(--danger); font-size: 0.9rem; margin-bottom: 12px; }
