/* Caring Senior Service tokens, from the brand logo system directory. */
:root {
  --navy: #1B365D;
  --cloud: #F0F3F5;
  --ice: #B9D9EB;
  --text: #222223;
  --red: #E03C31;      /* small highlights and primary CTA only */
  --blue: #0057B8;     /* sub-headers on light backgrounds; never on navy */
  --muted: #5B6573;
  --line: #D5DEE6;
  --white: #FFFFFF;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 10px 30px rgba(27, 54, 93, 0.12);
  /* Brand fonts: Nunito (headers) and Merriweather (paragraphs). They are used when
     installed; to self-host, add woff2 files under public/fonts with @font-face rules. */
  --font-head: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-body: 'Merriweather', Georgia, 'Times New Roman', serif;
  --font-ui: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--cloud);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-head); color: var(--navy); margin: 0; }
h1 { font-weight: 800; line-height: 1.08; }
h2 { font-weight: 700; color: var(--blue); line-height: 1.25; }
p { font-family: var(--font-body); line-height: 1.6; margin: 0; }
a { color: var(--blue); }

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

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

/* Form controls */
.field { display: grid; gap: 6px; }
.field label, .field .label {
  font-weight: 700; font-size: 14px; color: var(--navy);
}
.field .hint { font-size: 12.5px; color: var(--muted); font-family: var(--font-ui); }
input[type="text"], input[type="email"], input[type="tel"], input[type="url"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--white);
}
input:hover { border-color: #AFC0CF; }
input:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 3px rgba(0, 87, 184, 0.18); }

.check {
  display: flex; align-items: center; gap: 10px;
  min-height: 44px; font-size: 15px; cursor: pointer;
}
.check input { width: 20px; height: 20px; accent-color: var(--navy); }

.line-row { display: flex; gap: 8px; align-items: center; }
.icon-button {
  flex: none; width: 44px; height: 44px;
  border: 1.5px solid var(--line); border-radius: var(--radius-sm);
  background: var(--white); color: var(--navy);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.icon-button:hover { border-color: var(--navy); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 10px 18px;
  border-radius: 999px; border: 1.5px solid transparent;
  font: inherit; font-weight: 800; font-size: 15px; cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--red); color: var(--cloud); }
.btn-primary:hover { background: #C7322A; }
.btn-secondary { background: var(--white); color: var(--navy); border-color: var(--navy); }
.btn-secondary:hover { background: var(--cloud); }
.btn-ghost { background: transparent; color: var(--navy); }
.btn-ghost:hover { background: rgba(27, 54, 93, 0.06); }

.upload-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.upload-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 6px 6px 10px; border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); background: var(--white); font-size: 14px;
}
.upload-chip img { height: 32px; width: auto; }
.upload-chip span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.file-drop {
  display: grid; place-items: center; gap: 4px;
  min-height: 84px; padding: 14px; text-align: center;
  border: 2px dashed #AFC0CF; border-radius: var(--radius-sm);
  background: var(--white); color: var(--navy); font-weight: 700; cursor: pointer;
}
.file-drop:hover { border-color: var(--navy); }
.file-drop small { font-weight: 400; color: var(--muted); }
/* Keep the hidden input inside its label: positioned against the page, focusing it
   during an upload scrolled the whole locked page out of place. */
.file-drop { position: relative; }
.file-drop input { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }

.status { min-height: 20px; font-size: 14px; font-weight: 700; color: #1E6B3A; }
.status[data-tone="warn"] { color: #A02A21; }

/* Segmented layout switch */
.segmented {
  display: inline-grid; grid-auto-flow: column; gap: 4px; padding: 4px;
  background: var(--cloud); border: 1.5px solid var(--line); border-radius: 999px;
}
.segmented label {
  display: grid; place-items: center; min-height: 40px; padding: 0 16px;
  border-radius: 999px; font-weight: 800; font-size: 14px; color: var(--navy); cursor: pointer;
}
.segmented label { position: relative; }
.segmented input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.segmented input:checked + span { color: var(--cloud); }
.segmented label:has(input:checked) { background: var(--navy); color: var(--cloud); }
.segmented label:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: 2px; }

/* The rendered signature sits on white, like an email body. */
.signature-canvas { background: var(--white); overflow: hidden; }
/* Render at the signature's natural width, then app.js zooms it down to fit. */
.signature-canvas > div { width: max-content; }

.brand-logo { height: 46px; width: auto; display: block; }

/* Studio layout */
  .topbar {
    display: flex; align-items: center; gap: 16px;
    padding: 14px 32px; background: var(--white); border-bottom: 1px solid var(--line);
  }
  .topbar .divider { width: 1px; height: 26px; background: var(--line); }
  .topbar .app-name { font-weight: 800; color: var(--navy); font-size: 15px; letter-spacing: .02em; }
  .topbar .spacer { flex: 1; }

  .layout {
    display: grid; grid-template-columns: minmax(360px, 460px) minmax(0, 1fr); gap: 32px;
    max-width: 1320px; margin: 0 auto; padding: 32px;
  }
  .intro h1 { font-size: 34px; }
  .intro p { margin-top: 8px; color: var(--muted); font-size: 15px; }

  .form { display: grid; gap: 18px; margin-top: 24px; }
  .group {
    background: var(--white); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 20px; display: grid; gap: 14px;
  }
  .group h2 { font-size: 18px; }
  .group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
  .row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .checks-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }

  .preview-col { position: relative; }
  .preview-sticky { position: sticky; top: 24px; display: grid; gap: 16px; }
  .preview-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
  .preview-head h2 { font-size: 18px; }

  .mail {
    background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow);
    border: 1px solid var(--line); overflow: hidden;
  }
  .mail-bar { display: flex; gap: 6px; padding: 12px 16px; background: var(--cloud); border-bottom: 1px solid var(--line); }
  .mail-bar i { width: 10px; height: 10px; border-radius: 50%; background: #C9D3DC; }
  .mail-meta { padding: 14px 24px; border-bottom: 1px solid var(--line); font-size: 14px; color: var(--muted); display: grid; gap: 4px; }
  .mail-meta b { color: var(--text); font-weight: 700; }
  .mail-body { padding: 24px; }
  .mail-body .greeting { font-family: Arial, sans-serif; font-size: 14px; color: var(--text); margin-bottom: 22px; line-height: 1.6; }

  .actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
  .tip {
    background: var(--ice); color: var(--navy); border-radius: var(--radius-sm);
    padding: 12px 14px; font-size: 14px; line-height: 1.5;
  }

  @media (max-width: 900px) {
    .topbar { padding: 12px 16px; }
    .topbar .app-name, .topbar .divider { display: none; }
    .layout { grid-template-columns: minmax(0, 1fr); padding: 16px; gap: 20px; }
    .intro h1 { font-size: 26px; }
    .preview-col { order: -1; }
    .preview-sticky { position: static; }
    .mail-meta { display: none; }
    .mail-body { padding: 16px; }
    .row-2 { grid-template-columns: 1fr; }
  }

/* App additions */
fieldset.group { margin: 0; min-width: 0; }
fieldset.group legend { float: left; width: 100%; padding: 0; margin-bottom: 2px; }
fieldset.group legend + * { clear: both; }
legend.group-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.hint.error { color: #A02A21; font-weight: 700; }
input[aria-invalid="true"] { border-color: #A02A21; }
.upload-chip[data-state="uploading"] { opacity: 0.6; }

/* Desktop app shell: the header and preview stay put and only the form column
   scrolls, so editing never scrolls the preview out of view. */
@media (min-width: 901px) {
  html { overflow: clip; }
  /* clip, not hidden: hidden still lets focus() scroll the page, and nothing can scroll it back. */
  body { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: clip; }
  .topbar { flex: none; }
  main.layout { flex: 1; min-height: 0; width: 100%; padding-top: 0; padding-bottom: 0; }
  .form-col, .preview-col { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 32px 0; }
  .form-col { padding-right: 12px; scrollbar-gutter: stable; }
  .preview-sticky { position: static; }
}

/* Field errors overlay the space below the input so nothing around them moves. */
.field:has(.hint.error) { position: relative; }
.field .hint.error { position: absolute; top: 100%; left: 0; margin-top: 3px; white-space: nowrap; }
.file-drop:has(input:focus-visible) { outline: 3px solid var(--blue); outline-offset: 2px; border-color: var(--navy); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
