:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --ink: #1c2430;
  --muted: #5d6b7a;
  --line: #e8ebef;
  --accent: #198754;
  --accent-dark: #157347;
  --sidebar: #ffffff;
  --sidebar-ink: #334155;
  --ok-bg: #e7f6ec;
  --ok-ink: #14532d;
  --err-bg: #fdecec;
  --err-ink: #7f1d1d;
  --warn-bg: #fff6e8;
  --warn-ink: #7c4a03;
  --shadow: 0 1px 2px rgba(23, 32, 43, 0.04);
  --bs-body-font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --bs-body-color: var(--ink);
  --bs-body-bg: var(--bg);
  --bs-success: var(--accent);
  --bs-border-color: var(--line);
  --bs-border-radius: 0.65rem;
  color-scheme: light;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.skip {
  position: absolute;
  left: -999px;
  top: 0;
}

.skip:focus {
  left: 1rem;
  top: 1rem;
  z-index: 5;
  background: white;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
}

.shell {
  display: grid;
  grid-template-columns: 232px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  padding: 1.2rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  border-right: 1px solid var(--line);
}

.brand {
  color: var(--ink);
  text-decoration: none;
  padding: 0.2rem 0.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.logo {
  width: 2rem;
  height: 2rem;
  border-radius: 0.55rem;
  background: var(--accent);
  color: white;
  display: grid;
  place-items: center;
  font-size: 0.78rem;
  font-weight: 700;
}

.menu-label {
  margin: 0.2rem 0.7rem 0;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #8ea0b5;
}

.brand small {
  display: block;
  margin-top: 0.15rem;
  color: #93a3b5;
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0;
}

.nav { display: flex; flex-direction: column; gap: 0.15rem; }

.nav .nav-link {
  color: var(--sidebar-ink);
  text-decoration: none;
  padding: 0.5rem 0.7rem;
  border-radius: 0.5rem;
}

.nav .nav-link:hover:not(.active) { background: #f1f5f9; color: var(--ink); }

.nav .nav-link.active {
  background: var(--accent);
  color: white;
}

.fine {
  margin-top: auto;
  padding: 0.4rem 0.7rem 0.2rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.main { min-width: 0; }

.topbar { padding: 1.35rem 1.5rem 0; }

.topbar h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.lede {
  margin: 0.35rem 0 0;
  color: var(--muted);
  max-width: 40rem;
}

.content {
  padding: 1.1rem 1.5rem 2.5rem;
  max-width: 1120px;
}

.stack { display: grid; gap: 1rem; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 0.95rem 1rem 1rem;
  box-shadow: var(--shadow);
}

a.card { color: inherit; text-decoration: none; display: block; }

a.card:hover { border-color: #c5d0dc; }

.card-label {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.card-value {
  display: block;
  margin-top: 0.35rem;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.patients-page .layout { grid-template-columns: minmax(0, 1fr); }
.patient-list-actions { display: flex; align-items: end; gap: 0.75rem; flex-wrap: wrap; }
.sidebar-account { display: grid; gap: 0.5rem; padding: 0.5rem 0.7rem; color: var(--muted); font-size: 0.9rem; }
.sidebar-account form { margin: 0; }

.login-page { display: grid; min-height: 100vh; place-items: center; padding: 1rem; }
.login-card { width: min(100%, 25rem); padding: 1.5rem; gap: 1rem; }
.login-card h1, .login-card p { margin: 0; }

.patient-modal {
  width: min(100% - 2rem, 34rem);
  max-width: none;
  max-height: calc(100% - 2rem);
  padding: 0;
  border: 0;
  border-radius: var(--bs-border-radius);
  background: transparent;
  color: inherit;
  overflow: visible;
}

.patient-modal::backdrop { background: rgba(15, 23, 42, 0.5); }
.patient-modal .modal-content { overflow: auto; box-shadow: 0 1rem 3rem rgba(15, 23, 42, 0.2); }
.patient-modal .modal-header,
.patient-modal .modal-footer { display: flex; align-items: center; gap: 0.75rem; padding: 1rem 1.1rem; }
.patient-modal .modal-header { justify-content: space-between; border-bottom: 1px solid var(--line); }
.patient-modal .modal-footer { justify-content: flex-end; border-top: 1px solid var(--line); }
.patient-modal .modal-body { padding: 1rem 1.1rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  padding: 1rem 1.05rem 1.15rem;
  box-shadow: 0 0.125rem 0.25rem rgba(23, 32, 43, 0.055);
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-size: 1rem;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.panel-head h2 { margin: 0; }

.fields { display: grid; gap: 0.8rem; }

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.92rem;
  font-weight: 600;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.58rem 0.7rem;
  background: white;
  color: var(--ink);
  font: inherit;
  font-weight: 400;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 400;
}

button, .button {
  appearance: none;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 600;
  padding: 0.62rem 0.95rem;
  cursor: pointer;
}

button:hover, .button:hover { background: var(--accent-dark); }

button.secondary {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.secondary:hover { background: #f7f8fa; }

.form-actions { margin-top: 0.2rem; }

.inline-search { display: flex; gap: 0.45rem; align-items: end; flex-wrap: wrap; }

.inline-search label { width: auto; }

.inline-search input { width: 8rem; }

.alert {
  margin: 0;
  border-radius: 10px;
  padding: 0.7rem 0.85rem;
}

.alert.ok { background: var(--ok-bg); color: var(--ok-ink); }
.alert.err { background: var(--err-bg); color: var(--err-ink); }
.alert.warn { background: var(--warn-bg); color: var(--warn-ink); }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 700;
}

th, td {
  padding: 0.7rem 0.35rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

tr:last-child td { border-bottom: 0; }

.empty {
  color: var(--muted);
  padding: 0.4rem 0 0.2rem;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 0.12rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge.on { background: var(--ok-bg); color: var(--ok-ink); }
.badge.off { background: #eef1f4; color: #4b5563; }

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.85rem;
}

.catalog-grid ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.65rem;
}

.catalog-grid li { display: grid; gap: 0.15rem; }

.results-filter { margin-bottom: 0.9rem; }
.results-filter .inline-search input[type="month"] { width: 12rem; }
.results-cards { margin-bottom: 0.9rem; }
.results-goals, .results-types { margin-top: 0.9rem; }
.results-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  margin-top: 0.9rem;
}
.results-columns .panel { min-width: 0; }
.result-meter {
  height: 0.55rem;
  min-width: 7rem;
  overflow: hidden;
  background: #e8edf2;
  border-radius: 999px;
}
.result-meter span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: inherit;
}
.results-note { margin-top: 0.75rem; }

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

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    flex-direction: row;
    align-items: center;
    gap: 0.75rem;
    overflow-x: auto;
    padding: 0.65rem 0.75rem;
  }
  .nav { display: flex; flex-direction: row; gap: 0.15rem; }
  .nav a { white-space: nowrap; }
  .brand small, .fine, .menu-label { display: none; }
  .layout { grid-template-columns: 1fr; }
  .content, .topbar { padding-left: 1rem; padding-right: 1rem; }
}

@media (max-width: 720px) {
  .table-wrap table,
  .table-wrap thead,
  .table-wrap tbody,
  .table-wrap tr,
  .table-wrap td { display: block; width: 100%; }
  .table-wrap thead { display: none; }
  .table-wrap tr { padding: 0.35rem 0; border-bottom: 1px solid var(--line); }
  .table-wrap tr:last-child { border-bottom: 0; }
  .table-wrap td {
    border: 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.28rem 0;
  }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 700;
  }
  .inline-search, .inline-search input { width: 100%; }
  .results-filter .inline-search input[type="month"] { width: 100%; }
  .split, .board { grid-template-columns: 1fr; }
  .results-columns { grid-template-columns: 1fr; }
}

.content.wide { max-width: none; }

.subnav { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.subnav a {
  text-decoration: none;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.35rem 0.75rem;
  font-size: 0.88rem;
  font-weight: 600;
}
.subnav a[aria-current="page"] { background: #e8f7ee; border-color: #b7e4c7; color: #166534; }

.page-tools { display: flex; justify-content: flex-end; gap: 0.6rem; flex-wrap: wrap; align-items: center; }
.page-tools .inline-search input { width: 16rem; }

.chips { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.chips a {
  text-decoration: none;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.28rem 0.7rem;
  font-size: 0.85rem;
}
.chips a[aria-current="page"] { background: #eef2ff; border-color: #c7d2fe; }

.board {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(230px, 1fr);
  gap: 0.75rem;
  overflow-x: auto;
  align-items: start;
  padding-bottom: 0.4rem;
}
.board-col {
  background: #eef2f6;
  border-radius: 14px;
  padding: 0.7rem;
  min-height: 12rem;
}
.board-col h2 {
  margin: 0 0 0.7rem;
  font-size: 0.92rem;
  display: flex;
  justify-content: space-between;
}
.board-col h2 span {
  background: white;
  border-radius: 999px;
  min-width: 1.4rem;
  text-align: center;
  font-size: 0.78rem;
  padding: 0.05rem 0.4rem;
}
.kcard {
  background: white;
  border-radius: 12px;
  padding: 0.75rem;
  margin-bottom: 0.6rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.45rem;
}
.kcard-top { display: flex; gap: 0.6rem; align-items: center; }
.kcard-top a { color: inherit; text-decoration: none; font-weight: 700; }
.kcard p { margin: 0; color: var(--muted); font-size: 0.84rem; }
.kcard-actions { display: flex; justify-content: space-between; align-items: center; gap: 0.4rem; }
.avatar {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex: none;
}
.av-0 { background: #efe7ff; color: #6d28d9; }
.av-1 { background: #e7f0ff; color: #1d4ed8; }
.av-2 { background: #e7f6ec; color: #166534; }
.av-3 { background: #fff4e5; color: #c2410c; }
.av-4 { background: #fde8f3; color: #be185d; }

.badge.hoje { background: #e8f1ff; color: #1d4ed8; }
.badge.atrasado, .badge.falhou { background: #fde8e8; color: #b91c1c; }
.badge.feito, .badge.convertido { background: #e7f6ec; color: #15803d; }
.badge.futuro, .badge.pendente { background: #fff6e0; color: #b45309; }
.badge.urgente { background: #fde8e8; color: #b91c1c; }

button.danger { background: #fde8e8; color: #b91c1c; }
button.danger:hover { background: #fbd5d5; }
button.soft, .button.soft { background: #e7f6ec; color: #166534; }
button.soft:hover, .button.soft:hover { background: #d3f0de; }
.pager { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 0.8rem; }
.pager a { color: var(--accent-dark); font-weight: 600; }
button.ghost, a.ghost {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
  text-decoration: none;
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font-weight: 600;
}
.icon-btn {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.2rem 0.45rem;
  line-height: 1.2;
}
.icon-btn:hover { background: #f7f8fa; }

.split { display: grid; grid-template-columns: minmax(260px, 340px) minmax(0, 1fr); gap: 0.9rem; align-items: start; }
.kv { display: grid; grid-template-columns: 8.5rem 1fr; gap: 0.35rem 0.6rem; margin: 0; }
.kv dt { color: var(--muted); font-size: 0.84rem; }
.kv dd { margin: 0; font-weight: 600; }
.eyebrow { margin: 0 0 0.2rem; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.06em; text-transform: uppercase; }
.message {
  white-space: pre-wrap;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.9rem 1rem;
  line-height: 1.55;
}
.chip {
  display: inline-block;
  background: #e7f6ec;
  color: #166534;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
}
.action-row { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.7rem; }
.timeline li { display: grid; gap: 0.1rem; }
.daystrip { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }
.daystrip a {
  text-decoration: none;
  color: var(--ink);
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 2.6rem;
  text-align: center;
  padding: 0.3rem 0.35rem;
  font-size: 0.78rem;
}
.daystrip a strong { display: block; font-size: 0.95rem; }
.daystrip a[aria-current="page"] { background: #e8f7ee; border-color: #86efac; }
textarea {
  width: 100%;
  min-height: 4.2rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  font: inherit;
}
.stat-note { color: var(--muted); font-size: 0.8rem; display: block; margin-top: 0.25rem; }
.stat-note.warn { color: #b91c1c; }
