:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.45;
  color-scheme: light;
  color: #1c2b39;
  background: #eef2f5;
  --blue: #175a64;
  --blue-dark: #10444d;
  --muted: #536575;
  --line: #d5dee6;
  --panel: #fff;
}
* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
button, input, textarea, select { font: inherit; }
button {
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid var(--blue);
  border-radius: 7px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 650;
  line-height: 1.25;
  cursor: pointer;
}
button:hover { background: var(--blue-dark); border-color: var(--blue-dark); }
button:disabled { opacity: .55; cursor: wait; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible { outline: 2px solid #a55b00; outline-offset: 2px; }
button.secondary { background: #fff; color: var(--blue); }
button.secondary:hover { background: #edf4f9; }
button.danger { background: #fff; color: #a12832; border-color: #b64b53; }
button.danger:hover { background: #fff1f2; }
input, textarea, select {
  display: block;
  width: 100%;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid #8094a6;
  border-radius: 7px;
  background: #fff;
  color: #1c2b39;
  font-size: 15px;
}
input, select { min-height: 38px; }
textarea { resize: vertical; }
::placeholder { color: #627587; opacity: 1; }
label { display: block; margin: 12px 0 4px; font-size: 14px; font-weight: 650; }
form > button { margin-top: 14px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }
h1 { font-size: 22px; letter-spacing: -.02em; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
h4 { font-size: 14px; }
p { margin: 6px 0 12px; }
.muted { color: var(--muted); }
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  height: 52px;
  padding: 0 max(18px, calc((100vw - 1404px) / 2));
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; white-space: nowrap; }
.brand strong { font-size: 16px; letter-spacing: -.02em; }
.brand-mark { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(140deg, #183b50, #176b6f); color: #fff; font: 24px Georgia, serif; }
.brand-name { display: grid; gap: 1px; }
.brand-name strong { font-size: 18px; line-height: 1; }
.brand-name > span { color: var(--muted); font-size: 8px; font-weight: 650; letter-spacing: .16em; }
.eyebrow { margin: 0 0 6px; color: var(--blue); font-size: 10px; font-weight: 750; letter-spacing: .14em; }
.list-intro { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.pane-caption { margin-left: 7px; color: var(--muted); font-size: 9px; font-weight: 600; letter-spacing: .1em; }
.simulation { padding: 3px 7px; border-radius: 5px; background: #eef3f7; color: #41586c; font-size: 11px; font-weight: 700; letter-spacing: .02em; }
.site-header button { min-height: 34px; padding: 5px 10px; }
main {
  display: flex;
  flex-direction: column;
  width: min(100%, 1440px);
  height: calc(100vh - 52px);
  height: calc(100dvh - 52px);
  min-height: 0;
  margin: 0 auto;
  padding: 12px 18px 14px;
  overflow-y: auto;
}
.card { min-width: 0; padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); box-shadow: 0 1px 3px #1c3d5710; }
.narrow { width: min(100%, 460px); margin: min(10vh, 72px) auto; }
.narrow h1 { margin: 0 0 12px; }
#new-screen h1 { margin-top: 14px; }
.narrow form { margin-top: 14px; }
.notice { flex: none; padding: 9px 12px; margin: 0 0 10px; border: 1px solid #9bbbd2; border-radius: 7px; background: #eaf3f9; color: #173c59; font-size: 14px; }
.notice.error { border-color: #ce8f94; background: #fff0f0; color: #872029; }
.status { margin: 6px 0; color: #36566e; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.status:empty { display: none; }
.status.error { color: #9a2530; font-weight: 650; }
.heading-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-width: 0; }

#list-screen { width: min(100%, 920px); margin: 10px auto 0; }
#list-screen > .heading-row { margin: 12px 0 20px; }
#list-screen h1 { font-size: 30px; }
.list-card { padding: 0; overflow: hidden; }
.search-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
#search { flex: 1; }
#list-count { flex: none; margin: 0; font-size: 13px; white-space: nowrap; }
#list-status { margin: 10px 14px; }
.patient-list { display: grid; }
.patient-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  min-height: 54px;
  padding: 9px 14px;
  border: 0;
  border-bottom: 1px solid #e5ebf0;
  border-radius: 0;
  background: #fff;
  color: #1c2b39;
  text-align: left;
}
.patient-item:last-child { border-bottom: 0; }
.patient-item:hover { border-color: #e5ebf0; background: #f0f6fb; }
.patient-item strong { font-size: 15px; font-weight: 650; }
.patient-item strong::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 12px; border: 2px solid #47818a; border-radius: 50%; }
.patient-item span { color: var(--muted); font-size: 13px; font-weight: 400; text-align: right; }

#patient-screen:not([hidden]) { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.patient-heading { flex: none; min-height: 46px; margin-bottom: 5px; }
.patient-heading > div { display: grid; flex: 1; grid-template-columns: auto minmax(0, 1fr); align-items: center; column-gap: 12px; min-width: 0; }
#volver { grid-row: 1 / 3; }
#patient-name, #patient-meta { grid-column: 2; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
#patient-name { font-size: 20px; }
#patient-meta { margin: 0; font-size: 13px; }
.privacy { flex: none; margin: 0 0 9px; color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.privacy summary { width: fit-content; cursor: pointer; }
.privacy p { max-width: 90ch; margin: 5px 0 0 16px; }
.patient-layout { display: grid; flex: 1; grid-template-columns: minmax(0, 47fr) minmax(0, 53fr); gap: 12px; min-height: 0; }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 12px; overflow: hidden; }
#chat-panel > h2 { flex: none; margin-bottom: 8px; }
#chat-status { flex: none; margin: 0 0 7px; }
.messages { flex: 1; min-height: 0; padding: 12px; overflow-y: auto; border: 0; border-radius: 7px; background: #f5f7f9; }
.message { margin: 0 0 10px; padding: 11px 12px; border: 1px solid #e0e7ed; border-radius: 9px; background: #fff; }
.message:last-child { margin-bottom: 0; }
.message.user { margin-left: 8%; border-color: #c4dddf; background: #edf6f5; }
.message .pending { color: var(--muted); font-size: 14px; }
.message strong { color: #344e62; font-size: 13px; }
.message p { margin: 5px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 16px; line-height: 1.5; }
.message small { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; }
.activity { margin-top: 9px; padding-top: 7px; border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.activity summary { width: fit-content; color: var(--blue); font-weight: 650; cursor: pointer; }
.activity-list { display: grid; gap: 5px; margin: 8px 0 0; padding: 0; list-style: none; }
.activity-row { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #f8fafc; line-height: 1.35; overflow-wrap: anywhere; }
#chat-form { display: grid; flex: none; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "draft send" "status status"; align-items: end; column-gap: 8px; padding-top: 9px; }
#chat-draft { grid-area: draft; height: 72px; min-height: 68px; max-height: 136px; font-size: 16px; line-height: 1.45; }
#send-chat { grid-area: send; min-width: 74px; margin: 0; }
#draft-status { grid-area: status; margin: 6px 0 0; }

.sheet-toolbar { flex: none; padding-bottom: 9px; }
.sheet-toolbar h2 { margin: 0; }
.sheet-toolbar h2 { font-family: Georgia, "Times New Roman", serif; font-size: 21px; font-weight: 500; color: #243e50; }
.sheet-hint { margin: 4px 0 9px; color: var(--muted); font-size: 13px; }
.sheet-content { display: flex; flex: 1; flex-direction: column; gap: 8px; min-height: 0; overflow-y: auto; }
.sheet-text { flex: 1 0 190px; min-height: 190px; padding: 20px 24px; resize: none; font-size: 16px; line-height: 1.65; background: #fffefa; border-color: #e0ddd4; border-radius: 4px; box-shadow: 0 2px 6px #243e5008; }
.sheet-footer { flex: none; padding-top: 5px; }
.sheet-footer .status { margin: 3px 0; }
#retry-sync { margin-top: 4px; }
.conflict { flex: none; padding: 10px; border: 1px solid #c77d43; border-radius: 7px; background: #fff8ed; }
.conflict h3, .conflict h4 { margin-bottom: 5px; }
.conflict p { margin: 0 0 10px; font-size: 14px; }
.conflict pre, .version-text { max-height: 180px; margin: 7px 0; padding: 9px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: #fff; white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; font-size: 14px; }
#resolve-conflict { max-width: 100%; white-space: normal; }
.versions { flex: none; padding-top: 8px; border-top: 1px solid var(--line); font-size: 14px; }
.versions summary { width: fit-content; color: var(--blue); font-weight: 650; cursor: pointer; }
.versions-body { padding: 8px 0 2px; }
.versions-list { display: grid; gap: 8px; margin-top: 8px; }
.version { padding: 9px; border: 1px solid var(--line); border-radius: 7px; }
.version strong { font-size: 13px; }
.version button { margin-top: 4px; }
.mobile-tabs { display: none; }

@media (max-width: 800px) {
  main { padding: 8px 10px 10px; }
  button { min-height: 44px; font-size: 15px; }
  input, textarea, select { font-size: 16px; }
  .site-header { padding: 0 10px; }
  .site-header button { min-height: 44px; }
  #list-screen { margin-top: 6px; }
  .patient-item { display: block; min-height: 58px; }
  .patient-item span { display: block; margin-top: 2px; text-align: left; }
  .patient-heading > div { column-gap: 8px; }
  #patient-name { font-size: 17px; }
  #patient-meta { overflow: visible; white-space: normal; }
  .privacy { margin-bottom: 7px; }
  .mobile-tabs { display: grid; flex: none; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; margin-bottom: 7px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: #edf2f6; }
  .mobile-tabs button { border: 0; background: transparent; color: var(--blue); }
  .mobile-tabs button:hover { border: 0; background: #e0ebf3; }
  .mobile-tabs button[aria-selected="true"] { background: #fff; color: #173e5e; box-shadow: 0 1px 3px #1c3d5720; }
  .patient-layout { display: flex; flex-direction: column; }
  .pane { display: none; flex: 1; padding: 10px; }
  .pane.active { display: flex; }
  #chat-draft { height: 68px; min-height: 64px; }
}
@media (max-width: 480px) {
  .brand { gap: 6px; }
  .brand strong { font-size: 15px; }
  .simulation { font-size: 10px; }
  .search-row { flex-wrap: wrap; gap: 6px; }
  #search { flex-basis: 100%; }
  #list-count { margin-left: auto; }
  #list-screen > .heading-row { flex-wrap: wrap; }
  #abrir-alta { margin-left: auto; }
  .sheet-hint { font-size: 12px; }
  .brand-mark { width: 28px; height: 28px; font-size: 22px; }
  .brand-name strong { font-size: 17px; }
  .sheet-text { padding: 14px; }
  .pane-caption { display: none; }
}
