: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 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text);
}
.topbar-brand:hover { text-decoration: none; }

.topbar-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1;
}

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

.topbar-link {
  font-size: 0.9rem;
  padding: 6px 4px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.topbar-link:hover { text-decoration: none; color: var(--accent); }
.topbar-link.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.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;
  box-shadow: 0 1px 2px rgba(15, 23, 32, 0.04);
  transition: box-shadow 0.15s, border-color 0.15s;
}
.visit-card:hover { box-shadow: 0 4px 14px rgba(15, 23, 32, 0.08); border-color: #c3ccd6; }

.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 input[type=time],
form.stacked select,
form.stacked textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  margin-bottom: 6px;
  font-family: inherit;
}

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

form.stacked input[type=file] {
  display: block;
  width: 100%;
  padding: 10px 0;
  margin-bottom: 6px;
  font-size: 0.9rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  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;
  transition: opacity 0.15s, transform 0.1s, box-shadow 0.15s;
}
button:hover, .btn:hover { opacity: 0.92; text-decoration: none; }
button:active, .btn:active { transform: scale(0.98); }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
button:focus-visible, .btn:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.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; }
.wrap-cell { max-width: 220px; white-space: normal; word-break: break-word; }

/* 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: 0; 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; }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 32, 0.55);
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}
.modal-box {
  background: #fff;
  border-radius: var(--radius);
  padding: 22px 20px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
}
.modal-box h3 { margin: 0 0 10px; font-size: 1.05rem; }
.modal-box p { margin: 0 0 18px; line-height: 1.4; }
.modal-actions { display: flex; gap: 10px; flex-direction: column-reverse; }
.modal-actions button { width: 100%; }

.sort-bar {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 0.9rem;
}
.sort-bar a { font-weight: 600; }

.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.search-bar input[type=search] {
  flex: 1;
  min-width: 160px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
}

.status-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.status-badge.status-not_started { background: #fdecea; color: #9a2c22; }
.status-badge.status-in_progress { background: #e8f0fe; color: var(--accent); }
.status-badge.status-submitted { background: #e6f4ea; color: #226b3a; }
.status-badge.status-neutral { background: #eceef0; color: #5b6470; }

.admin-nav {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.admin-nav a {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.admin-nav a:hover { text-decoration: none; background: #eef1f4; }
.admin-nav a.active { color: #fff; background: var(--accent); }

/* Document template field editor */
.doc-editor {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}
.doc-palette {
  position: sticky;
  top: 16px;
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
}
.doc-palette-group { display: flex; flex-direction: column; gap: 6px; }
.doc-palette-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.palette-role, .palette-field {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.palette-role + .palette-role { margin-top: 4px; }
.palette-field + .palette-field { margin-top: 4px; }
.palette-role.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.palette-field.active { background: #226b3a; border-color: #226b3a; color: #fff; }
.doc-palette-hint { font-size: 0.78rem; color: var(--muted); line-height: 1.4; }

.doc-selected-panel {
  border-top: 2px solid var(--accent);
  padding-top: 14px;
  margin-top: 4px;
}
.doc-selected-panel label { font-size: 0.78rem; font-weight: 600; color: var(--muted); }
.doc-selected-panel input[type="text"],
.doc-selected-panel input[type="number"],
.doc-selected-panel select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.85rem;
  font-family: inherit;
}
.doc-pos-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; margin-top: 4px; }
.doc-pos-grid input { padding: 5px 4px; text-align: center; }
.doc-pos-grid-labels {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  font-size: 0.65rem;
  color: var(--muted);
  text-align: center;
  margin-top: 2px;
}

.doc-pages {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.page-canvas {
  position: relative;
  display: inline-block;
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.page-canvas img { display: block; max-width: 100%; height: auto; cursor: crosshair; }

.field-box {
  position: absolute;
  border: 2px solid;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 1px 4px;
  overflow: hidden;
  cursor: move;
}
.field-box.selected {
  outline: 2px dashed #000;
  outline-offset: 2px;
  overflow: visible;
  z-index: 5;
}
.field-box.selected .field-box-label { overflow: visible; text-overflow: clip; }
.field-box-label {
  font-size: 0.62rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.field-box-delete {
  flex: 0 0 auto;
  border: none;
  background: rgba(0, 0, 0, 0.15);
  color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  line-height: 14px;
  font-size: 0.72rem;
  cursor: pointer;
  padding: 0;
}
.field-box-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 9px;
  height: 9px;
  cursor: nwse-resize;
  background: rgba(0, 0, 0, 0.25);
  border-top-left-radius: 3px;
}
.field-role-admin { border-color: var(--accent); background: rgba(21, 101, 192, 0.14); color: #0d3f75; }
.field-role-recipient { border-color: #226b3a; background: rgba(34, 107, 58, 0.14); color: #164826; }

.field-box-value {
  font-size: 0.7rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.field-box-empty { font-style: italic; opacity: 0.7; font-weight: 500; }
.field-box-input {
  width: 100%;
  height: 100%;
  border: none;
  background: transparent;
  font-size: 0.72rem;
  font-weight: 600;
  color: inherit;
  padding: 0 2px;
}
.field-box-input:focus { outline: 2px solid currentColor; background: rgba(255, 255, 255, 0.6); }

@media (max-width: 720px) {
  .doc-editor { flex-direction: column; }
  .doc-palette { position: static; flex: 1 1 auto; width: 100%; }
}

/* Message threads */
.message-thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
  max-height: 60vh;
  overflow-y: auto;
  padding: 4px;
}
.message-bubble {
  align-self: flex-start;
  max-width: 75%;
  background: #eef1f4;
  border-radius: 12px;
  padding: 8px 12px;
}
.message-bubble.mine {
  align-self: flex-end;
  background: var(--bg-subtle);
}
.message-meta { font-size: 0.7rem; color: var(--muted); margin-bottom: 3px; }
.message-body { font-size: 0.9rem; white-space: pre-wrap; word-break: break-word; }
.message-delete {
  border: none;
  background: none;
  color: var(--danger);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* Scheduling calendar -- Google-Calendar-style day/week time grid +
   month overview, sharing one visual language (clean 1px borders,
   generous cell size, a red-accent "today" marker). */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.calendar-nav-left { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.calendar-today-btn { text-decoration: none; }
.calendar-nav-arrows { display: flex; gap: 2px; }
.calendar-arrow {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text);
}
.calendar-arrow:hover { background: #eef1f4; text-decoration: none; }
.calendar-label { font-size: 1.2rem; font-weight: 700; }
.calendar-view-select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 32px 8px 14px;
  font-size: 0.88rem;
  font-weight: 600;
  background: #fff;
  cursor: pointer;
}
.calendar-print-heading { display: none; }

@media print {
  .topbar, .admin-nav, .top-actions, .calendar-nav, .flash,
  .calendar-modal-backdrop, .visit-popover-panel, .no-print {
    display: none !important;
  }
  .calendar-print-heading {
    display: block;
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 14px;
  }
  .calendar-frame { border-color: #999; }
  table.calendar-month, .calendar-timegrid-wrap { break-inside: avoid; }
  table.calendar-month tr { break-inside: avoid; }
  .calendar-visit-block, .cal-chip, .visit-card {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    break-inside: avoid;
  }
}

.calendar-frame {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
}

/* Month view */
table.calendar-month { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.calendar-month th {
  text-align: center;
  padding: 10px 4px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
table.calendar-month td {
  vertical-align: top;
  border: 1px solid var(--border);
  padding: 6px;
  height: 130px;
  width: 14.28%;
  overflow: hidden;
}
table.calendar-month td.muted { background: #fbfbfc; }
table.calendar-month td.muted .calendar-day-number { color: var(--muted); }
.calendar-day-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  font-size: 0.85rem;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text);
}
.calendar-day-number:hover { background: #eef1f4; text-decoration: none; }
.calendar-day-number.today { background: var(--danger); color: #fff; }
.calendar-day-number.today:hover { background: #a81f1f; }
.calendar-day-chips { display: flex; flex-direction: column; gap: 2px; }
.cal-chip {
  display: block;
  width: 100%;
  font-family: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  background: rgba(21, 101, 192, 0.12);
  color: #0d3f75;
  border: none;
  border-left: 3px solid var(--accent);
  border-radius: 3px;
  padding: 2px 5px;
  margin-bottom: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: left;
  cursor: pointer;
}
button.cal-chip:hover { filter: brightness(0.95); }
.cal-chip.unassigned { background: rgba(198, 40, 40, 0.08); color: #8a1f1f; border-left-color: var(--danger); }
a.cal-more { display: block; }
.cal-more { font-size: 0.64rem; color: var(--muted); padding-left: 5px; }

/* Day/week time grid */
.calendar-timegrid-wrap { display: flex; flex-direction: column; }
.calendar-hour-gutter { flex: 0 0 56px; }
.calendar-timegrid-header {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: #fafbfc;
}
.calendar-col-header {
  flex: 1;
  text-align: center;
  padding: 10px 4px;
  border-left: 1px solid var(--border);
  color: var(--text);
}
.calendar-col-header:hover { background: #f1f3f5; text-decoration: none; }
.calendar-col-weekday { display: block; font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.calendar-col-daynum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 700;
  margin-top: 2px;
}
.calendar-col-daynum.today { background: var(--danger); color: #fff; }
.calendar-untimed-row { display: flex; border-bottom: 1px solid var(--border); min-height: 28px; }
.calendar-untimed-label { font-size: 0.65rem; color: var(--muted); padding: 4px 6px 0 0; text-align: right; }
.calendar-untimed-col { flex: 1; display: flex; flex-wrap: wrap; gap: 3px; padding: 4px 6px; border-left: 1px solid var(--border); }
.calendar-timegrid-body { position: relative; display: flex; }
.calendar-hour-labels { position: relative; }
.calendar-hour-label {
  position: absolute;
  right: 8px;
  transform: translateY(-50%);
  font-size: 0.68rem;
  color: var(--muted);
  white-space: nowrap;
}
.calendar-timegrid-col {
  position: relative;
  flex: 1;
  border-left: 1px solid var(--border);
}
.calendar-hour-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); }
.calendar-timegrid-col.today { background: rgba(198, 40, 40, 0.025); }
.calendar-now-line { position: absolute; left: 0; right: 0; border-top: 2px solid var(--danger); z-index: 3; pointer-events: none; }
.calendar-now-dot {
  position: absolute;
  left: -5px;
  top: -5px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--danger);
}
.calendar-visit-block {
  position: absolute;
  background: rgba(21, 101, 192, 0.14);
  border: none;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 3px 6px;
  overflow: hidden;
  font-size: 0.7rem;
  font-family: inherit;
  line-height: 1.25;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  cursor: pointer;
  text-align: left;
}
.calendar-visit-block:hover { box-shadow: 0 2px 6px rgba(0,0,0,0.18); z-index: 4; }
.calendar-visit-block.unassigned { background: rgba(198, 40, 40, 0.08); border-left-color: var(--danger); }
.calendar-visit-time { font-weight: 700; }
.calendar-visit-who { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.calendar-visit-notes { color: var(--muted); font-size: 0.65rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Visit detail popover (opened from month/week chips) */
.calendar-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 60;
}
.calendar-modal-backdrop.open { display: block; }
.visit-popover-panel {
  display: none;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 61;
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  max-width: 380px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.visit-popover-panel.open { display: block; }
.visit-popover-panel .visit-card { border: none; padding: 0; box-shadow: none; }
.visit-popover-close {
  float: right;
  border: none;
  background: none;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
}
.visit-popover-close:hover { color: var(--text); }

@media (max-width: 640px) {
  table.calendar-month td { height: 72px; padding: 3px; }
  .calendar-day-chips { display: none; }
  .cal-chip { font-size: 0.6rem; }
  .calendar-label { font-size: 1rem; }
  .calendar-hour-gutter { flex-basis: 42px; }
  .calendar-hour-label { font-size: 0.6rem; right: 4px; }
  .calendar-col-header { padding: 6px 2px; }
}
