:root {
  color-scheme: light;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #0f172a;
  --primary-text: #ffffff;
  --danger: #b91c1c;
  --warning-bg: #fffbeb;
  --warning-text: #92400e;
  --shadow: 0 20px 50px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.app-shell {
  min-height: 100vh;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.auth-card {
  width: min(560px, calc(100vw - 32px));
  margin: 7vh auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 28px;
}

.install-card {
  width: min(760px, calc(100vw - 32px));
}

.brand {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 24px;
}

.brand img {
  border-radius: 16px;
}

.brand h1,
.topbar h1 {
  margin: 0;
  font-size: clamp(1.5rem, 2vw, 2rem);
}

.brand p,
.topbar p,
.hint,
.message,
.sync-status {
  color: var(--muted);
}

.panel {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 650;
}

input,
textarea {
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  background: #fff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.primary,
.secondary,
.danger,
.icon-button,
.link-button {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary {
  background: var(--primary);
  color: var(--primary-text);
}

.secondary {
  background: #e2e8f0;
  color: var(--text);
}

.danger {
  background: #fee2e2;
  color: var(--danger);
}

.link-button {
  background: var(--primary);
  color: var(--primary-text);
}

.hidden {
  display: none !important;
}

.auth-actions {
  margin-top: 16px;
}

.calendar-view {
  max-width: 1180px;
  margin: 0 auto;
}

.topbar,
.sync-panel,
.offline-notice,
#calendar,
.note-panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px;
  margin-bottom: 16px;
}

.top-actions,
.sync-panel,
.note-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.mode-badge {
  margin: 6px 0 0;
}

.sync-panel,
.offline-notice {
  padding: 16px;
  margin-bottom: 16px;
}

.offline-notice {
  color: var(--warning-text);
  background: var(--warning-bg);
}

#calendar {
  padding: 16px;
  overflow: hidden;
}

.note-panel {
  position: fixed;
  right: 24px;
  top: 24px;
  width: min(440px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 20px;
  z-index: 90;
}

.note-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.note-header h2 {
  margin: 0;
}

.note-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 28px;
  line-height: 1;
  background: #f1f5f9;
}

.install-steps h2 {
  margin-top: 24px;
}

.install-steps li {
  margin: 8px 0;
}

.fc .fc-toolbar-title {
  font-size: 1.25rem;
}

@media (max-width: 720px) {
  .app-shell {
    padding: 12px;
  }

  .auth-card {
    margin-top: 18px;
    padding: 20px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button,
  .sync-panel button,
  .primary,
  .secondary,
  .danger {
    flex: 1 1 auto;
  }

  .note-panel {
    left: 12px;
    right: 12px;
    top: 12px;
    width: auto;
  }
}

.customer-name {
  font-weight: 700;
  color: var(--text) !important;
}

.care-plan-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #f8fafc;
  padding: 14px;
  margin-bottom: 16px;
}

.care-plan-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.care-plan-body {
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.care-plan-section {
  margin: 10px 0;
}

.care-plan-section strong {
  display: block;
  margin-bottom: 4px;
}

.client-note-item {
  border-top: 1px solid var(--border);
  padding-top: 10px;
  margin-top: 10px;
}

.client-note-item:first-child {
  border-top: 0;
  padding-top: 0;
  margin-top: 0;
}

.client-note-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.client-note-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.visit-actions-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #f8fafc;
  padding: 14px;
  margin: 16px 0;
}

.visit-actions-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.visit-status {
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.entry-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.48);
}

.entry-modal-card {
  width: min(720px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(15, 23, 42, 0.25);
  padding: 20px;
}

.entry-details-body {
  display: grid;
  gap: 10px;
  margin: 16px 0;
}

.entry-detail-row {
  display: grid;
  grid-template-columns: minmax(110px, 160px) 1fr;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.entry-detail-row:last-child {
  border-bottom: 0;
}

.entry-detail-label {
  color: var(--muted);
  font-weight: 700;
}

.entry-detail-value {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .entry-modal {
    padding: 12px;
    align-items: start;
  }

  .entry-modal-card {
    max-height: calc(100vh - 24px);
  }

  .entry-detail-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}

.note-sync-badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 8px;
  background: #e2e8f0;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 700;
  margin-left: 6px;
}

.note-header-actions,
.section-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-header-row {
  justify-content: space-between;
  margin-bottom: 8px;
}

.section-header-row h3 {
  margin: 0;
}

.compact-button {
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.9rem;
  flex: 0 0 auto;
}

.key-safe-row {
  align-items: center;
}

.key-safe-value-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.key-safe-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0.08em;
}

.reveal-key-button {
  min-width: 44px;
  padding: 6px 10px;
  border-radius: 999px;
}

.note-panel {
  pointer-events: auto;
}

.note-panel button,
.note-panel textarea {
  pointer-events: auto;
}

.note-panel .section-header-row button {
  position: relative;
  z-index: 2;
}

.key-safe-value-wrap {
  position: relative;
}

.key-safe-popup {
  position: absolute;
  z-index: 90;
  top: calc(100% + 8px);
  left: 0;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 64px));
  padding: 14px;
  border-radius: 16px;
  background: var(--card);
  border: 1px solid var(--border);
  box-shadow: 0 18px 48px rgba(15, 23, 42, 0.22);
}

.key-safe-popup-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.key-safe-popup-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.35rem;
  letter-spacing: 0.08em;
  overflow-wrap: anywhere;
}

.key-safe-popup-note {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.entry-modal-card,
.note-panel {
  pointer-events: auto;
}

.note-actions button {
  position: relative;
  z-index: 3;
}

.entry-modal .note-actions button,
.note-panel button {
  pointer-events: auto;
  position: relative;
  z-index: 5;
}

.note-panel.force-visible {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  z-index: 90 !important;
}

.entry-modal .note-actions button,
.note-panel button {
  pointer-events: auto;
  position: relative;
  z-index: 5;
}

/* Clearer care-plan view formatting */
.care-plan-body {
  white-space: normal;
}

.care-plan-summary,
.care-plan-message {
  margin: 0 0 14px;
  line-height: 1.45;
}

.care-plan-view-section {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #ffffff;
  margin: 14px 0;
  overflow: hidden;
}

.care-plan-view-section h3 {
  margin: 0;
  padding: 12px 14px;
  background: #e2e8f0;
  color: var(--text);
  font-size: 1.05rem;
  line-height: 1.25;
}

.care-plan-field-grid {
  display: grid;
}

.care-plan-field-row {
  display: grid;
  grid-template-columns: minmax(180px, 32%) 1fr;
  gap: 14px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.care-plan-field-row:first-child {
  border-top: 0;
}

.care-plan-field-title {
  font-weight: 800;
  color: var(--text);
  overflow-wrap: anywhere;
}

.care-plan-field-content {
  color: var(--text);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

@media (max-width: 720px) {
  .care-plan-field-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }
}

.inline-note-check-panel {
  display: grid;
  gap: 14px;
}

.inline-note-label {
  display: grid;
  gap: 8px;
}

.inline-note-label textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
}

.inline-visit-actions-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #ffffff;
  padding: 12px;
}

.inline-visit-actions-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.error-message {
  color: #b91c1c;
}

.success {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #15803d;
  color: #ffffff;
}

/* Visit popup close button: top-left inside the popup */
.entry-modal-card {
  position: relative;
}

.entry-modal .note-header {
  position: relative;
  padding-left: 52px;
}

.entry-modal .note-header #closeEntryModalButton {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 80;
  margin: 0;
  background: #0f172a;
  color: #ffffff;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.18);
}

@media (max-width: 720px) {
  .entry-modal .note-header {
    padding-left: 48px;
  }
}

/* Visit popup close button: fixed top-right on mobile */
@media (max-width: 720px) {
  .entry-modal .note-header {
    padding-left: 0;
    padding-right: 54px;
  }

  .entry-modal .note-header #closeEntryModalButton,
  #closeEntryModalButton {
    position: fixed !important;
    top: max(12px, env(safe-area-inset-top));
    right: max(12px, env(safe-area-inset-right));
    left: auto !important;
    z-index: 1000;
    margin: 0;
    background: #0f172a;
    color: #ffffff;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
  }
}

.live-sync-countdown {
  display: inline-flex;
  align-items: center;
  padding: 8px 10px;
  border-radius: 999px;
  background: #e2e8f0;
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
}

.care-plan-list {
  display: grid;
  gap: 10px;
}

.care-plan-accordion {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: #ffffff;
  overflow: hidden;
}

.care-plan-accordion > summary {
  cursor: pointer;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 12px;
  align-items: center;
  padding: 14px;
  background: #e2e8f0;
  list-style: none;
}

.care-plan-accordion > summary::-webkit-details-marker {
  display: none;
}

.care-plan-accordion > summary::after {
  content: "+";
  grid-column: 2;
  grid-row: 1 / span 2;
  font-size: 1.4rem;
  font-weight: 800;
}

.care-plan-accordion[open] > summary::after {
  content: "−";
}

.care-plan-summary-title {
  font-weight: 800;
}

.care-plan-summary-meta {
  color: var(--muted);
  font-size: 0.84rem;
}

.care-plan-sync-badge {
  display: inline-flex;
  width: fit-content;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.78rem;
  font-weight: 800;
}

.care-plan-sync-badge.pending {
  background: #ffedd5;
  color: #9a3412;
}

.care-plan-sync-badge.sent {
  background: #dcfce7;
  color: #166534;
}

.care-plan-accordion-body {
  padding: 12px;
}

.care-plan-section-display .care-plan-edit-button {
  margin-top: 12px;
}

.care-plan-edit-form {
  display: grid;
  gap: 12px;
}

.care-plan-edit-field {
  display: grid;
  gap: 6px;
}

.care-plan-edit-field textarea {
  width: 100%;
  min-height: 84px;
  resize: vertical;
}

@media (max-width: 720px) {
  .care-plan-accordion > summary {
    grid-template-columns: minmax(0, 1fr) 34px;
  }

  .live-sync-countdown {
    width: 100%;
    justify-content: center;
  }
}

/* Care-plan editor controls matched to the source forms */
.care-plan-edit-form {
  display: grid;
  gap: 16px;
}

.care-plan-edit-field {
  display: grid;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  background: #ffffff;
}

.care-plan-edit-field input[type="text"],
.care-plan-edit-field input[type="date"],
.care-plan-edit-field select,
.care-plan-edit-field textarea {
  width: 100%;
  box-sizing: border-box;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 11px 12px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

.care-plan-edit-field textarea {
  min-height: 112px;
  resize: vertical;
}

.care-plan-choice-group {
  border: 1px solid var(--border);
}

.care-plan-choice-group legend {
  padding: 0 4px;
}

.care-plan-choice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 0;
}

.care-plan-choice input {
  margin-top: 3px;
  flex: 0 0 auto;
}

.care-plan-current-user {
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 11px 12px;
  background: #f8fafc;
  font-weight: 700;
}

.required-mark {
  color: #b91c1c;
}

.care-plan-field-content.empty {
  color: var(--muted);
  font-style: italic;
}

.care-plan-sync-badge.blank {
  background: #fef3c7;
  color: #92400e;
}

/* Client notes: each note is a separate card */
.client-notes-list {
  display: grid;
  gap: 12px;
}

.client-note-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  background: #ffffff;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}

.client-note-card-header {
  padding: 12px 14px;
  background: #f1f5f9;
  border-bottom: 1px solid var(--border);
}

.client-note-card-header h4 {
  margin: 0 0 5px;
  font-size: 1rem;
}

.client-note-card-meta {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

.client-note-card-body {
  padding: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.client-notes-empty {
  margin: 0;
  color: var(--muted);
}

/* Entry location and Google Maps directions */
.entry-location-value {
  display: grid;
  gap: 10px;
  justify-items: start;
}

.entry-location-address {
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.entry-directions-button {
  display: inline-flex;
  width: auto;
  max-width: 100%;
  text-align: center;
  text-decoration: none;
}

@media (max-width: 720px) {
  .entry-directions-button {
    width: 100%;
  }
}

/* Entry actions shown above and below opened content */
.entry-action-bar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  flex-wrap: wrap;
}

.entry-action-bar button {
  flex: 1 1 150px;
  min-height: 44px;
}

.entry-action-bar-top {
  margin: 14px 0 8px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.entry-action-bar-bottom {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

@media (max-width: 720px) {
  .entry-action-bar {
    gap: 8px;
  }

  .entry-action-bar button {
    flex: 1 1 100%;
    width: 100%;
  }
}

/* Entry actions under Last updated and repeated at the end of opened sections */
.entry-action-bar-main {
  margin: 6px 0 16px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

.entry-action-bar-section {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.entry-action-bar-section button,
.entry-action-bar-main button {
  flex: 1 1 150px;
}

/* Compact entry action rows */
.entry-action-bar-main,
.entry-action-bar-section {
  gap: 6px;
}

.entry-action-bar-main {
  margin: 4px 0 10px;
  padding: 8px 0;
}

.entry-action-bar-section {
  margin-top: 10px;
  padding-top: 8px;
}

.entry-action-bar-main button,
.entry-action-bar-section button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 36px;
  padding: 7px 8px;
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.15;
  white-space: nowrap;
}

@media (max-width: 420px) {
  .entry-action-bar-main button,
  .entry-action-bar-section button {
    font-size: 0.75rem;
    padding-left: 5px;
    padding-right: 5px;
  }
}

/* Compact account/device action buttons */
.top-actions {
  gap: 7px;
  justify-content: flex-end;
}

.top-actions button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 8px 12px;
  border-radius: 11px;
  font-size: 0.9rem;
  line-height: 1.15;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .top-actions {
    width: 100%;
    gap: 6px;
    justify-content: flex-start;
  }

  .top-actions button,
  .top-actions .primary,
  .top-actions .secondary,
  .top-actions .danger {
    flex: 0 0 auto;
    width: auto;
    min-height: 34px;
    padding: 7px 10px;
    border-radius: 10px;
    font-size: 0.86rem;
  }
}


/* Offline tasks */
.tasks-panel {
  margin: 14px 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--card);
  padding: 14px;
}

.tasks-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.tasks-panel-header h2 {
  margin: 0 0 3px;
  font-size: 1.05rem;
}

.tasks-summary {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.tasks-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.tasks-list-entry {
  margin-top: 0;
}

.task-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--border);
  border-left: 5px solid #f59e0b;
  border-radius: 14px;
  padding: 12px;
  background: #fff7ed;
}

.task-card.completed {
  border-left-color: #16a34a;
  background: #f0fdf4;
}

.task-card h3 {
  margin: 0 0 4px;
  font-size: 0.98rem;
}

.task-meta {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.task-detail,
.task-communication {
  margin-top: 7px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.task-card-action {
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.task-completed-label {
  display: inline-flex;
  border-radius: 999px;
  padding: 6px 9px;
  background: #dcfce7;
  color: #166534;
  font-size: 0.78rem;
  font-weight: 800;
  text-align: center;
}

.task-empty {
  margin: 0;
  color: var(--muted);
}

@media (max-width: 620px) {
  .tasks-panel-header {
    align-items: flex-start;
  }

  .task-card {
    grid-template-columns: 1fr;
  }

  .task-card-action {
    justify-content: stretch;
  }

  .task-card-action button,
  .task-completed-label {
    width: 100%;
    justify-content: center;
  }
}
