:root {
  color-scheme: light;
  --ink: #20352e;
  --pine: #253c33;
  --pine-dark: #1b3028;
  --muted: #53635b;
  --cream: #f6f4ed;
  --paper: #fffefb;
  --line: #dcded3;
  --soft: #eaf0e7;
  --gold: #b98848;
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 100%;
  color: var(--ink);
  background: var(--cream);
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
h1, h2, h3, p, dl, dd { margin: 0; }
h1, h2, h3 { overflow-wrap: anywhere; }
h1, h2 { font-family: Georgia, "Times New Roman", serif; font-weight: 400; }
h1 { font-size: clamp(2.15rem, 4vw, 3.65rem); letter-spacing: -.045em; line-height: 1.03; }
h2 { font-size: clamp(1.45rem, 2.5vw, 2rem); letter-spacing: -.025em; }
h3 { font-size: 1.125rem; line-height: 1.3; }
a { color: var(--pine); text-underline-offset: .18em; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
:focus-visible { outline: 3px solid #a35d19; outline-offset: 3px; }
[hidden] { display: none !important; }

.brand { display: inline-flex; align-items: center; gap: .75rem; text-align: left; }
.brand strong, .brand small { display: block; }
.brand strong { font: 400 1.42rem/1.08 Georgia, serif; white-space: nowrap; }
.brand small { margin-top: .22rem; font-size: .88rem; font-weight: 500; }
.mark { position: relative; flex: 0 0 2.75rem; width: 2.75rem; height: 3.12rem; border: 1px solid currentColor; border-radius: 1.45rem 1.45rem .35rem .35rem; color: var(--gold); }
.mark span::before, .mark span::after { position: absolute; left: 50%; content: ""; background: currentColor; border-radius: 1rem; transform: translateX(-50%); }
.mark span::before { top: .72rem; width: 2px; height: 1.58rem; }
.mark span::after { top: 1.19rem; width: 1.1rem; height: 2px; }

.login-layout { display: grid; grid-template-columns: 53% 47%; min-height: 100svh; }
.login-panel { display: grid; place-items: center; padding: 4rem clamp(1.6rem, 5vw, 6rem); }
.login-inner { width: min(100%, 28rem); }
.login-inner > .brand { margin-bottom: clamp(2.75rem, 8vh, 6rem); }
.login-intro { margin-bottom: 2rem; }
.login-intro h1 { font-size: clamp(2.45rem, 4.4vw, 4.35rem); }
.login-intro p { margin-top: .9rem; color: var(--muted); line-height: 1.55; }
.login-form { display: grid; gap: 1rem; }
.login-form .button { margin-top: .55rem; }
.login-photo { background: #694d36 url("/assets/chapel.webp") center 46% / cover; min-height: 100%; }

.layout { display: grid; grid-template-columns: minmax(13.5rem, 16rem) minmax(0, 1fr); min-height: 100svh; }
.sidebar { position: sticky; top: 0; min-width: 0; display: flex; flex-direction: column; gap: 2.85rem; padding: 2rem 1.15rem 1.4rem; height: 100svh; background: var(--pine-dark); color: #fffdf4; }
.sidebar a { color: inherit; text-decoration: none; }
.sidebar .brand-link { align-self: flex-start; margin-inline: .3rem; }
.sidebar .brand { gap: .55rem; }
.sidebar .brand strong { font-size: 1.19rem; white-space: normal; }
.sidebar .mark { width: 2.4rem; flex-basis: 2.4rem; }
.sidebar .brand small, .sidebar small { color: #cbd8cc; }
.sidebar .mark { color: #d7b075; }
.sidebar nav { display: grid; gap: .3rem; }
.sidebar nav a { display: block; padding: .7rem .85rem; border: 1px solid transparent; border-radius: .45rem; }
.sidebar nav a[aria-current="page"] { background: #365449; border-color: #517164; font-weight: 650; }
.sidebar nav a:hover, .sidebar .account a:hover { background: #365449; }
.sidebar :focus-visible { outline-color: #f0ca84; }
.account { margin-top: auto; display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; border-top: 1px solid #476058; padding-top: 1.15rem; }
.account-name { flex: 1 0 100%; margin-bottom: .2rem; overflow-wrap: anywhere; }
.account-name > * { display: block; }
.account a, .account .button { padding: .5rem .35rem; color: #f9f6e9; min-height: 2.35rem; font-size: .875rem; }
.account .button:hover { background: #365449; }

.workspace { width: min(100%, 92rem); padding: clamp(1.5rem, 3.5vw, 4rem); }
.page-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.65rem; }
.page-heading p { margin-top: .65rem; color: var(--muted); line-height: 1.45; }
.page-heading p:first-letter { text-transform: uppercase; }
.page-heading .button { flex-shrink: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(9rem, 100%), 1fr)); gap: .8rem; margin-bottom: 1.2rem; }
.stat { display: grid; align-content: start; gap: .42rem; border: 1px solid var(--line); border-top: 2px solid #b38a56; border-radius: .55rem; background: var(--paper); padding: .9rem 1rem; }
.stat span { color: var(--muted); font-size: .9rem; line-height: 1.4; }
.stat strong { font: 400 2.3rem/.95 Georgia, serif; letter-spacing: -.045em; }
a.stat { text-decoration: none; }
a.stat:hover { background: var(--soft); }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 23rem), 1fr)); gap: .85rem; align-items: start; }
.admin-grid .sheet-heading { flex-wrap: wrap; }
.admin-list { list-style: none; margin: 0; padding: 0; }
.admin-list > li { padding: .8rem 0; overflow-wrap: anywhere; }
.admin-list > li + li { border-top: 1px solid var(--line); }
.admin-list > li:first-child { padding-top: .2rem; }
.sheet { min-width: 0; border: 1px solid var(--line); border-radius: .65rem; background: var(--paper); padding: clamp(.9rem, 2vw, 1.55rem); }
.sheet-heading { display: flex; justify-content: space-between; align-items: center; gap: .7rem; margin-bottom: .85rem; }
.sheet-heading > span { color: var(--muted); font-size: .9rem; white-space: nowrap; }
.tabs { display: flex; flex-wrap: wrap; gap: .38rem; padding-bottom: .85rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .55rem .75rem; text-decoration: none; border-radius: .32rem; color: var(--muted); font-size: .925rem; }
.tabs a:hover { background: var(--cream); }
.tabs a[aria-current="page"] { background: var(--soft); color: var(--pine-dark); font-weight: 700; }
.filters { display: flex; flex-wrap: wrap; align-items: end; gap: .65rem; padding-block: 1rem 1.15rem; }
.filters .field { flex: 1 1 8rem; max-width: 15rem; }
.filters .field:has(input[type="search"]) { flex-basis: 13rem; }
.filters:first-child { padding-top: 0; }
.field { min-width: 0; display: grid; gap: .36rem; font-size: .925rem; font-weight: 600; }
.field input, .field select, .field textarea { border: 1px solid #b7c0b4; border-radius: .38rem; width: 100%; min-width: 0; min-height: 2.7rem; padding: .5rem .7rem; background: #fff; color: var(--ink); font-size: 1rem; font-weight: 400; }
.field [data-format] { padding-inline: .55rem; font-variant-numeric: tabular-nums; }
.field [data-format]::placeholder { font-size: .875rem; }
.date-entry { position: relative; display: flex; gap: .25rem; }
.date-entry .native-date-picker { position: absolute; inset-inline-end: 0; inset-block-end: 0; width: 1px; min-height: 0; height: 1px; padding: 0; border: 0; opacity: 0; pointer-events: none; }
.calendar-picker { display: grid; flex: 0 0 2.4rem; place-items: center; border: 1px solid #b7c0b4; border-radius: .38rem; background: #fff; color: var(--pine); }
.calendar-picker:hover { background: var(--soft); }
.calendar-icon { width: .95rem; height: .85rem; border: 1.5px solid currentColor; border-radius: .13rem; box-shadow: inset 0 .2rem currentColor; }
.field select { appearance: none; padding-right: 1.75rem; background-image: linear-gradient(45deg, transparent 52%, var(--muted) 52%), linear-gradient(135deg, var(--muted) 52%, transparent 52%); background-repeat: no-repeat; background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; background-size: 5px 5px; }
.field textarea { resize: vertical; }
.button { display: inline-flex; justify-content: center; align-items: center; text-align: center; min-height: 2.7rem; padding: .5rem .82rem; border: 1px solid transparent; border-radius: .4rem; line-height: 1.3; text-decoration: none; font-size: .94rem; font-weight: 650; }
.primary { background: var(--pine); color: white; }
.primary:hover { background: #38594c; }
.secondary { background: #fffefb; border-color: #b7c0b4; color: var(--pine); }
.secondary:hover, .quiet:hover { background: var(--soft); }
.quiet { background: transparent; color: var(--pine); }
.danger { background: #832e27; color: white; }
.danger:hover { background: #69231e; }
.notice { padding: .72rem .9rem; margin-bottom: 1rem; border: 1px solid; border-radius: .4rem; line-height: 1.45; overflow-wrap: anywhere; }
.notice.error { background: #fcf1ed; color: #782821; border-color: #d7a49a; }
.notice.success { background: var(--soft); color: #264332; border-color: #aebfad; }
.records, .card-grid { display: grid; gap: .75rem; }
.card-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 17.5rem), 1fr)); }
.card { min-width: 0; border: 1px solid var(--line); border-radius: .5rem; padding: 1rem; overflow-wrap: anywhere; }
.visit { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: .85rem; }
.calendar { display: grid; place-items: center; gap: .16rem; min-width: 5.1rem; padding: .45rem .3rem; border-radius: .42rem; background: var(--cream); text-align: center; font-variant-numeric: tabular-nums; }
.calendar strong { font: 400 1.45rem/.95 Georgia, serif; }
.calendar span { font-size: .82rem; }
.visit-heading { display: flex; align-items: center; gap: .55rem; flex-wrap: wrap; }
.person .visit-heading { margin-bottom: .22rem; }
.person h2 { font-size: 1.35rem; }
.subtle, .record-note { margin-top: .22rem; line-height: 1.45; }
.subtle { color: var(--muted); font-size: .92rem; }
.record-note { white-space: pre-wrap; }
.subtle + .record-note { margin-top: .55rem; }
.badge { padding: .16rem .52rem; border-radius: 10rem; background: var(--cream); color: #544321; font-size: .8rem; font-weight: 700; }
.badge.em_atendimento { background: #f7e8c7; color: #614918; }
.badge.finalizado { background: #e3efe5; color: #234a34; }
.badge.cancelado { background: #f7e6e1; color: #722d25; }
.row-actions, .contact-links { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; }
.contact-links { gap: .85rem; margin-top: .5rem; font-size: .9rem; }
.person .row-actions { margin-top: .7rem; }
.details { display: grid; gap: .5rem; margin-top: .68rem; }
.details dt { color: var(--muted); font-size: .85rem; }
.details dd { font-size: .96rem; }
.health-details { margin-top: .75rem; }
.health-details summary { cursor: pointer; width: fit-content; color: var(--pine); font-weight: 650; }
.visit-photo { display: block; max-width: 100%; max-height: 58vh; margin-top: 1rem; border-radius: .4rem; }
.visit-photo-form { margin-top: 1rem; }
.visit-photo-form > .field { margin-top: .85rem; }
.photo-removal { margin-top: 1rem; border-top: 1px solid var(--line); padding-top: .8rem; }
.photo-removal summary { cursor: pointer; width: fit-content; color: #782821; font-weight: 650; }
.photo-removal form { margin-top: .75rem; }
.photo-inputs { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(14rem, 100%), 1fr)); gap: .8rem; margin-top: .75rem; }
.photo-inputs input { padding: .48rem; }
.empty { border: 1px dashed #bfc5b9; border-radius: .5rem; padding: clamp(1.4rem, 4vw, 2.45rem) 1rem; text-align: center; line-height: 1.5; }
.empty p { color: var(--muted); margin-top: .25rem; }
.edit-form { max-width: 52rem; }
.edit-form .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .95rem; }
.span { grid-column: 1 / -1; }
.record-person { font: 400 1.65rem/1.1 Georgia, serif; overflow-wrap: anywhere; }
.check { display: flex; grid-column: 1 / -1; align-items: center; gap: .65rem; min-height: 2.55rem; }
.check input { appearance: auto; width: 1.2rem; height: 1.2rem; accent-color: var(--pine); }
.form-actions, .report-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .4rem; margin-top: 1rem; }
.report-actions { margin: 0 0 .7rem; }
.print-title { padding-bottom: .75rem; }
.print-title p { margin-top: .35rem; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .58rem .65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { background: var(--soft); }
td { white-space: pre-wrap; overflow-wrap: anywhere; }
.birthday { background: #fff2d8; }
.today-tag { color: #6b4a15; white-space: nowrap; }
.table-actions a { display: block; white-space: normal; }

@media (max-width: 1150px) {
  .visit .row-actions { grid-column: 2; }
}
@media (max-width: 850px) {
  .layout { display: block; }
  .sidebar { position: static; height: auto; gap: .85rem; padding: .9rem 1.25rem .65rem; }
  .sidebar .brand-link { margin-inline: 0; }
  .sidebar .brand strong { font-size: 1.35rem; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: .23rem; }
  .sidebar nav a { padding: .5rem .62rem; font-size: .925rem; }
  .account { margin: 0; padding-top: .3rem; gap: .3rem; }
  .account-name { flex: 1 1 8rem; margin: 0; padding: .25rem 0; }
  .account-name strong { font-size: .875rem; }
  .account-name small { font-size: .8rem; }
  .account .button { font-size: .85rem; padding-inline: .25rem; }
  .workspace { padding: 1.35rem 1rem 2rem; }
}
@media (max-width: 620px) {
  .login-layout { display: flex; flex-direction: column; }
  .login-panel { padding: 2rem 1.4rem 2.25rem; }
  .login-photo { min-height: 13rem; flex: 1; background-position: center 39%; }
  .login-inner > .brand { margin-bottom: 2.4rem; }
  .page-heading { display: grid; align-items: start; margin-bottom: 1.18rem; }
  .page-heading .button { justify-self: start; }
  .edit-form .form-grid { grid-template-columns: minmax(0, 1fr); }
  .visit { padding: .72rem; gap: .6rem; }
  .visit .row-actions { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .45rem; }
  .stat { padding: .64rem .55rem; }
  .stat strong { font-size: 1.85rem; }
  .stat span { font-size: .81rem; overflow-wrap: anywhere; }
  .report-sheet .stats { display: flex; flex-wrap: wrap; }
  .report-sheet .stat { flex: 1 1 7rem; }
  .filters .field { max-width: none; }
  .tabs a { padding: .42rem .5rem; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr { display: block; }
  .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; }
  .table-wrap tr { margin-bottom: .7rem; border: 1px solid var(--line); border-radius: .4rem; }
  .table-wrap td { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); gap: .5rem; padding: .4rem .55rem; }
  .table-wrap td::before { content: attr(data-label); font-weight: 650; }
  .table-wrap td:last-child { border-bottom: 0; }
}
@media print {
  :root { background: white; }
  .sidebar, .page-heading, .tabs, .filters, .report-actions, .table-actions, .today-tag { display: none !important; }
  .layout, .workspace { display: block; width: 100%; padding: 0; }
  .report-sheet { border: 0; padding: 0; }
  .report-sheet table { display: table; font-size: 9pt; }
  .report-sheet thead { display: table-header-group; position: static; width: auto; height: auto; }
  .report-sheet tbody { display: table-row-group; }
  .report-sheet tr { display: table-row; break-inside: avoid; }
  .report-sheet th, .report-sheet td { display: table-cell; padding: .3rem; }
  .report-sheet td::before { display: none; }
}
