/* Care Contract Manager — professional, centred, business-logo-first (no generic lifeline artwork) */

:root {
  --bg: #f4efe3;
  --card: #ffffff;
  --ink: #1a2b1f;
  --ink-soft: #5b6470;
  --green: #175c2f;
  --green-dark: #114722;
  --sage: #e2ecdc;
  --line: #e3d9c2;
  --line-soft: #efe8d5;
  --banner: #fbf3d7;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --ok-bg: #e9f5ec;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 1px 2px rgba(60, 50, 20, 0.05), 0 8px 24px rgba(60, 50, 20, 0.06);
  --serif: "EB Garamond", Georgia, 'Times New Roman', Times, serif;
  --sans: "Lato", system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--ink);
}

/* Anchored scrolling clears the sticky pill nav */
section, h1, h2, h3, input, select, textarea, button, iframe, table {
  scroll-margin-top: 110px;
}

a { color: var(--green); }
code { overflow-wrap: anywhere; word-break: break-all; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 20px 24px 48px; }

/* ---- Floating pill navbar ---- */
.topbar {
  position: sticky;
  top: 12px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 999px;
  box-shadow: var(--shadow);
  padding: 10px 12px 10px 14px;
  margin: 12px auto 0;
  max-width: 1180px;
}

.brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-right: auto; min-width: 0; }
.brand-logo {
  width: 48px; height: 48px; border-radius: 10px;
  object-fit: contain; flex: none; padding: 3px;
  background: #fff; border: 1px solid var(--line);
}
.brand-fallback {
  width: 48px; height: 48px; border-radius: 10px; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--green); color: #fff;
  font-family: var(--serif); font-weight: 700; font-size: 22px;
}
.brand h1 { font-family: var(--serif); font-size: 22px; margin: 0; font-weight: 700; white-space: nowrap; text-align: center; overflow: hidden; text-overflow: ellipsis; letter-spacing: 0.01em; }

.topbar nav { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.tab {
  border: 0; background: transparent; cursor: pointer;
  font: inherit; font-size: 15px; color: #4d5c4f;
  padding: 10px 18px; border-radius: 999px; min-height: 44px;
}
.tab:hover { background: #f1ecdd; }
.tab[aria-selected="true"] { background: var(--sage); color: var(--green-dark); font-weight: 700; }

.btn-export {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 10px 20px; min-height: 44px;
  font: inherit; font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn-export:hover { background: #faf7ee; }

/* ---- Toolbar row: search + primary action ---- */
.toolbar { display: flex; gap: 12px; align-items: center; margin: 20px 0 16px; }
.search { position: relative; flex: none; }
.search input {
  width: 340px; max-width: 60vw;
  border: 1px solid var(--line); border-radius: 999px;
  padding: 12px 18px 12px 42px; font: inherit; background: #fff; color: var(--ink);
}
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; opacity: 0.55; }
.toolbar .spacer { flex: 1; }

/* ---- Buttons ---- */
.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 10px 22px;
  border-radius: 999px; border: 1px solid transparent;
  font: inherit; font-size: 15px; font-weight: 700; cursor: pointer;
  text-decoration: none;
  transition: filter 150ms ease, background 150ms ease;
}
.btn-primary { background: var(--green); color: #fff; box-shadow: 0 2px 8px rgba(23, 92, 47, 0.3); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: #faf7ee; }
button:disabled { opacity: 0.6; cursor: not-allowed; }

/* ---- Cards, banners, empty states ---- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 20px;
}
.card h2 { font-family: var(--serif); font-size: 27px; line-height: 1.25; margin: 0 0 16px; text-align: center; text-wrap: balance; }
.card h3 { font-family: var(--serif); font-size: 20px; line-height: 1.3; margin: 24px 0 8px; text-align: center; text-wrap: balance; }

.banner {
  background: var(--banner);
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  margin-bottom: 20px;
  color: #5c4d1a;
}
.banner a { color: var(--green); font-weight: 700; }

.empty {
  border: 1.5px dashed #d8cdb2;
  border-radius: var(--radius-sm);
  padding: 48px 20px;
  text-align: center;
}
.empty h3 { font-family: var(--serif); font-size: 22px; margin: 0 0 8px; }
.empty p { color: var(--ink-soft); margin: 0; }

/* ---- Forms ---- */
label { display: block; font-size: 14px; color: var(--ink-soft); margin: 14px 0 6px; font-weight: 500; }

input, select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
}
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: #a8a29e; }

input:focus-visible, select:focus-visible, textarea:focus-visible,
button:focus-visible, a:focus-visible, .tab:focus-visible {
  outline: 3px solid var(--green);
  outline-offset: 2px;
}

.field-error { color: var(--danger); font-size: 14px; margin-top: 4px; min-height: 20px; }
.form-error {
  color: var(--danger); background: var(--danger-bg);
  border: 1px solid var(--danger); padding: 10px 14px;
  border-radius: var(--radius-sm); margin-top: 12px; overflow-wrap: anywhere;
}
.form-ok {
  color: var(--green-dark); background: var(--ok-bg);
  border: 1px solid var(--green); padding: 10px 14px;
  border-radius: var(--radius-sm); margin-top: 12px;
}
.hint { color: var(--ink-soft); font-size: 14px; }

/* ---- Login-only auth card (shared office login) ---- */
.auth-card { max-width: 520px; margin: 48px auto; }
.auth-card h2 { font-family: var(--serif); font-size: 28px; margin: 0 0 8px; }
.auth-card .hint { margin: 0 0 8px; }
#view-auth input { background: #eef3ff; border-radius: 14px; }
.btn-block { width: 100%; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 20px; }

/* ---- Tables & status ---- */
table { width: 100%; border-collapse: collapse; margin-top: 12px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { color: var(--ink-soft); font-weight: 500; font-size: 14px; }

.status { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.status-draft { background: #eee9d8; color: #6b5f2a; }
.status-sent { background: #e4e0f7; color: #4c1d95; }
.status-viewed { background: #dceefb; color: #0c4a6e; }
.status-signed { background: #d9f0df; color: #14532d; }

.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions .btn { min-height: 40px; padding: 8px 16px; font-size: 14px; }
.visit-row .row-actions { flex-wrap: nowrap; align-items: center; }
.visit-row .v-mins { flex: 1; min-width: 0; }
.visit-row .v-del { flex: none; }

iframe.preview { display: block; width: 100%; max-width: 100%; min-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; }

canvas#sigpad {
  display: block; width: 100%; max-width: 600px; height: auto; aspect-ratio: 3 / 1;
  border: 1.5px dashed #c9bfa4; border-radius: var(--radius-sm);
  background: #fff; touch-action: none;
}

.logo-preview { max-height: 80px; border-radius: 8px; border: 1px solid var(--line); margin-top: 8px; }
.checkline { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.checkline input { width: auto; min-height: 24px; width: 24px; accent-color: var(--green); }

@media (max-width: 860px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .wrap { padding: 12px 12px 40px; }
  .topbar { border-radius: 22px; flex-wrap: wrap; }
  .search input { width: 100%; }
  .search { flex: 1; }
}

@media (max-width: 640px) {
  .topbar { width: calc(100% - 24px); padding: 10px; justify-content: center; }
  .brand { width: 100%; margin-right: 0; }
  .brand h1 { white-space: normal; font-size: 19px; }
  .topbar nav { width: 100%; justify-content: center; }
  .tab { padding-inline: 10px; font-size: 14px; }
  .btn-export { flex: 1 1 auto; padding-inline: 12px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .toolbar .spacer { display: none; }
  .toolbar .btn { width: 100%; }
  .card { padding: 20px 16px; }
  .row-actions .btn { flex: 1 1 140px; }

  .contracts-table, .clients-table { display: block; }
  .contracts-table thead, .clients-table thead { display: none; }
  .contracts-table tbody, .clients-table tbody,
  .contracts-table tr, .clients-table tr { display: block; }
  .contracts-table tr, .clients-table tr {
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-bottom: 12px;
    box-shadow: 0 2px 8px rgba(60, 50, 20, 0.04);
  }
  .contracts-table td, .clients-table td {
    display: grid;
    grid-template-columns: 86px minmax(0, 1fr);
    gap: 8px;
    border-bottom: 1px solid var(--line-soft);
    padding: 9px 0;
    overflow-wrap: anywhere;
  }
  .contracts-table td:last-child, .clients-table td:last-child { border-bottom: 0; }
  .contracts-table td::before, .clients-table td::before {
    content: attr(data-label);
    color: var(--ink-soft);
    font-size: 13px;
    font-weight: 700;
  }
  .contracts-table td[data-label="Actions"] .row-actions { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
  html { scroll-behavior: auto; }
}
