:root {
  --bg: #f7f5f0;
  --surface: #ffffff;
  --surface-soft: #fbfaf7;
  --ink: #12110f;
  --muted: #706b60;
  --line: #e5dfd2;
  --black: #0d0c0a;
  --gold: #c9a24d;
  --gold-soft: #f4ead2;
  --gold-dark: #8d6d26;
  --danger: #9f2f25;
  --danger-soft: #fff0ed;
  --success: #176b4d;
  --success-soft: #eaf6ef;
  --warning: #8a6300;
  --warning-soft: #fff6dc;
  --shadow: 0 18px 50px rgba(18, 17, 15, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(201, 162, 77, 0.16), transparent 32rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.login-body {
  align-items: center;
  background:
    linear-gradient(135deg, rgba(15, 14, 12, 0.9), rgba(15, 14, 12, 0.72)),
    radial-gradient(circle at top right, rgba(201, 162, 77, 0.28), transparent 34%),
    var(--black);
  display: grid;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: #fff;
  border: 1px solid rgba(201, 162, 77, 0.32);
  border-radius: 18px;
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.32);
  display: grid;
  gap: 22px;
  margin: auto;
  max-width: 440px;
  padding: 28px;
  width: min(100%, 440px);
}

.login-card h1 {
  font-size: 1.8rem;
  margin: 8px 0 10px;
}

.login-card p {
  color: var(--muted);
  margin: 0;
}

.login-brand {
  background: var(--black);
  border-radius: 14px;
  color: #fff;
  padding: 14px;
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-message {
  color: var(--danger);
  font-weight: 800;
  min-height: 20px;
}

button,
input,
select {
  font: inherit;
}

button {
  align-items: center;
  background: var(--black);
  border: 0;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  display: inline-flex;
  font-weight: 800;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
}

button:hover {
  background: #24211d;
}

.secondary,
.ghost,
.tab,
.today-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink);
}

.secondary:hover,
.ghost:hover,
.tab:hover,
.today-btn:hover {
  background: var(--gold-soft);
}

.ghost {
  background: transparent;
}

.danger {
  background: var(--danger);
}

.danger:hover {
  background: #7b261f;
}

.app-shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--black);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 28px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand-block {
  align-items: center;
  display: flex;
  gap: 12px;
}

.brand-mark {
  align-items: center;
  background: linear-gradient(135deg, #f3d889, var(--gold));
  border-radius: 12px;
  color: var(--black);
  display: grid;
  font-weight: 900;
  height: 46px;
  place-items: center;
  width: 46px;
}

.brand-block strong,
.brand-block span {
  display: block;
}

.brand-block span {
  color: #c8c0b0;
  font-size: 0.8rem;
  margin-top: 2px;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav a {
  border-radius: 8px;
  color: #ded6c7;
  font-weight: 750;
  padding: 12px;
  text-decoration: none;
}

.side-nav a.active,
.side-nav a:hover {
  background: rgba(201, 162, 77, 0.18);
  color: #fff;
}

.sync-card {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  margin-top: auto;
  padding: 14px;
}

.sync-card span,
.eyebrow {
  color: var(--gold-dark);
  display: block;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.sync-card span {
  color: var(--gold);
}

.sync-card strong {
  display: block;
  margin-top: 5px;
}

.sync-card p {
  color: #c8c0b0;
  font-size: 0.86rem;
  line-height: 1.45;
  margin: 8px 0 0;
}

.workspace {
  min-width: 0;
}

.topbar {
  align-items: center;
  background: rgba(247, 245, 240, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 22px clamp(18px, 4vw, 42px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar h1,
.hero-panel h2,
.panel h2,
.patient-details h3 {
  margin: 0;
}

.topbar h1 {
  font-size: clamp(1.35rem, 2vw, 2rem);
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

main {
  display: grid;
  gap: 20px;
  padding: 22px clamp(18px, 4vw, 42px) 42px;
}

.app-page[hidden] {
  display: none !important;
}

.hero-panel,
.panel,
.kpi-card,
.finance-cards article {
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.hero-panel {
  align-items: stretch;
  background:
    linear-gradient(135deg, rgba(13, 12, 10, 0.96), rgba(39, 34, 27, 0.94)),
    var(--black);
  color: #fff;
  display: grid;
  gap: 22px;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 380px);
  padding: clamp(22px, 4vw, 40px);
}

.hero-panel .gold {
  color: var(--gold);
}

.hero-panel h2 {
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  line-height: 1.02;
  margin-top: 8px;
  max-width: 760px;
}

.hero-panel p {
  color: #ded6c7;
  line-height: 1.6;
  margin: 12px 0 0;
  max-width: 640px;
}

.security-panel {
  display: grid;
  gap: 18px;
}

.security-seal {
  background: var(--black);
  border-radius: 999px;
  color: var(--gold);
  font-size: 0.78rem;
  padding: 9px 13px;
  white-space: nowrap;
}

.security-hero {
  background:
    linear-gradient(135deg, rgba(13, 12, 10, 0.94), rgba(54, 43, 25, 0.9)),
    var(--black);
  border-radius: 14px;
  color: #fff;
  padding: clamp(20px, 4vw, 34px);
}

.security-hero h3 {
  font-size: clamp(1.45rem, 3vw, 2.3rem);
  line-height: 1.08;
  margin: 8px 0 0;
  max-width: 760px;
}

.security-hero p {
  color: #e3d9c5;
  line-height: 1.6;
  max-width: 680px;
}

.security-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.security-card {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-width: 0;
  padding: 16px;
}

.security-card span {
  color: var(--muted);
  display: block;
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.security-card strong {
  display: block;
  font-size: 1.05rem;
  margin-top: 8px;
}

.security-card p {
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 0;
}

.security-card.ok {
  border-color: rgba(40, 122, 78, 0.24);
}

.security-card.attention {
  border-color: rgba(197, 154, 72, 0.38);
}

.security-checklist {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px;
}

.security-checklist h3 {
  margin: 0 0 10px;
}

.security-checklist ul {
  color: var(--muted);
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 20px;
}

.alert-stack {
  display: grid;
  gap: 10px;
}

.alert-stack article {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 12px;
  padding: 14px;
}

.alert-stack span,
.kpi-card span,
.finance-cards span,
.detail-grid span {
  color: var(--muted);
  display: block;
  font-size: 0.82rem;
  font-weight: 750;
}

.alert-stack span {
  color: #d8d0bf;
}

.alert-stack strong {
  color: var(--gold);
  display: block;
  font-size: 2rem;
  margin-top: 6px;
}

.kpi-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.kpi-card {
  min-height: 132px;
  padding: 18px;
}

.revenue-kpi-card {
  grid-column: 1 / -1;
}

.kpi-card strong {
  display: block;
  font-size: clamp(1.8rem, 3vw, 2.5rem);
  line-height: 1.05;
  margin-top: 14px;
  overflow-wrap: anywhere;
}

.kpi-values {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-top: 14px;
}

.kpi-values > div {
    min-width: 0;
}

.kpi-values small {
    color: var(--muted);
    display: block;
    font-size: 0.72rem;
    font-weight: 800;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.kpi-values strong {
    font-size: clamp(1.1rem, 1.7vw, 1.45rem);
    margin-top: 0;
    white-space: nowrap;
}

.success-text { color: var(--success); }
.warning-text { color: var(--warning); }
.danger-text { color: var(--danger); }

.content-grid {
  align-items: start;
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}

.finance-grid {
  display: grid;
  gap: 20px;
  grid-template-columns: 1fr;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-header {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 18px;
}

.panel-header-actions {
    display: flex;
    gap: 16px;
}

.panel-header.compact {
  margin-bottom: 12px;
}

.switch {
  align-items: center;
  color: var(--muted);
  display: flex;
  gap: 8px;
  font-size: 0.9rem;
  white-space: nowrap;
}

.switch input {
  height: 16px;
  width: 16px;
}

.table-tools {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(0, 1fr) minmax(180px, 240px);
  margin-bottom: 12px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 0.84rem;
  font-weight: 700;
  gap: 6px;
}

input,
select {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  min-height: 42px;
  padding: 0 12px;
  width: 100%;
}

input:focus,
select:focus {
  border-color: var(--gold);
  outline: 3px solid rgba(201, 162, 77, 0.18);
}

.patient-lookup {
  min-width: 260px;
  position: relative;
}

.patient-lookup input[type="text"],
.patient-lookup input[data-patient-search] {
  padding-left: 38px;
}

.lookup-icon {
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 900;
  left: 12px;
  line-height: 1;
  pointer-events: none;
  position: absolute;
  top: 13px;
  z-index: 2;
}

.lookup-results {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 16px 36px rgba(15, 14, 12, 0.14);
  display: grid;
  left: 0;
  max-height: 260px;
  overflow-y: auto;
  padding: 6px;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 18;
}

.lookup-results[hidden] {
  display: none;
}

.lookup-results button {
  background: transparent;
  border-radius: 8px;
  color: var(--ink);
  display: block;
  min-height: 0;
  padding: 9px 10px;
  text-align: left;
  width: 100%;
}

.lookup-results button:hover {
  background: var(--gold-soft);
}

.lookup-results strong,
.lookup-results span {
  display: block;
}

.lookup-results span {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 2px;
}

.lookup-results .lookup-empty {
  color: var(--muted);
  cursor: default;
  font-weight: 800;
}

.patient-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0 16px;
}

.tab {
  min-height: 34px;
  padding: 0 12px;
}

.tab.active {
  background: var(--black);
  color: #fff;
}

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

.pagination {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 12px;
  padding-top: 12px;
}

.pagination span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.pagination div {
  display: flex;
  gap: 8px;
}

.pagination button {
  min-height: 34px;
  padding: 0 12px;
}

.pagination button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.package-panel {
  margin-bottom: 20px;
}

.package-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

.package-card {
  align-items: start;
  background: linear-gradient(180deg, #fff, var(--surface-soft));
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--black);
  cursor: pointer;
  display: grid;
  font: inherit;
  gap: 8px;
  grid-template-rows: auto 1fr auto;
  min-height: 132px;
  padding: 14px;
  text-align: center;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
  width: 100%;
}

.package-card:hover,
.package-card.active {
  border-color: rgba(201, 162, 77, 0.72);
  box-shadow: 0 12px 24px rgba(15, 14, 12, 0.08);
  transform: translateY(-1px);
}

.package-card.active {
  background: #fff7e3;
}

.package-card.total-card {
  background: linear-gradient(180deg, var(--black), #2b261d);
  color: #fff;
}

.package-card.total-card span,
.package-card.total-card small {
  color: #e8dcc6;
}

.package-card.total-card strong {
  color: var(--gold);
}

.package-card span,
.package-card small {
  color: var(--muted);
  display: block;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
}

.package-card strong {
  align-self: center;
  display: block;
  font-size: 2.15rem;
  line-height: 1;
  margin: 0;
  text-align: center;
}

.patients-table {
  border-collapse: collapse;
  min-width: 760px;
  width: 100%;
}

.patients-table th {
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  text-align: left;
  text-transform: uppercase;
}

.patients-table td {
  border-top: 1px solid var(--line);
  padding: 14px 12px;
  vertical-align: middle;
}

.patients-table tr.selected-row td {
  background: #fffaf0;
}

.patients-table td strong,
.patients-table td span {
  display: block;
}

.patients-table td span {
  color: var(--muted);
  font-size: 0.86rem;
  margin-top: 3px;
}

.patients-panel .patients-table {
  min-width: 0;
  table-layout: fixed;
}

.patients-panel .patients-table th,
.patients-panel .patients-table td {
  overflow-wrap: anywhere;
}

.patients-panel .patients-table th:nth-child(1),
.patients-panel .patients-table td:nth-child(1) {
  width: 31%;
}

.patients-panel .patients-table th:nth-child(2),
.patients-panel .patients-table td:nth-child(2) {
  width: 20%;
}

.patients-panel .patients-table th:nth-child(3),
.patients-panel .patients-table td:nth-child(3) {
  width: 16%;
}

.patients-panel .patients-table th:nth-child(4),
.patients-panel .patients-table td:nth-child(4) {
  width: 19%;
}

.patients-panel .patients-table th:nth-child(5),
.patients-panel .patients-table td:nth-child(5) {
  width: 14%;
}

.table-actions {
  text-align: right;
}

.table-actions button {
  min-width: 74px;
  padding-inline: 10px;
  white-space: nowrap;
}

.patients-panel .table-actions {
  padding-left: 8px;
  padding-right: 8px;
}

.patients-panel .table-actions button {
  width: 100%;
}

.empty-cell,
.empty {
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.status-badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 0.74rem;
  font-weight: 900;
  padding: 7px 10px;
  width: max-content;
}

.status-badge.active,
.status-badge.renewed {
  background: var(--success-soft);
  color: var(--success);
}

.status-badge.ending,
.status-badge.reschedule {
  background: var(--warning-soft);
  color: var(--warning);
}

.status-badge.debt {
    background: var(--danger-soft);
    color: var(--danger);
}

.status-badge.finished {
  background: #ece7dd;
  color: #5d5548;
}

.patient-details {
  display: grid;
  gap: 14px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.patient-identity {
  align-items: center;
  display: grid;
  gap: 12px;
  grid-template-columns: auto minmax(0, 1fr) auto;
  min-width: 0;
}

.avatar {
  align-items: center;
  background: var(--black);
  border-radius: 14px;
  color: var(--gold);
  display: grid;
  font-weight: 900;
  height: 54px;
  place-items: center;
  width: 54px;
}

.patient-identity strong,
.patient-identity span {
  display: block;
  min-width: 0;
  overflow-wrap: anywhere;
}

.patient-identity span {
  color: var(--muted);
  margin-top: 4px;
}

.detail-warning {
  background: var(--warning-soft);
  border: 1px solid #ecd180;
  border-radius: 10px;
  color: var(--warning);
  font-weight: 800;
  padding: 12px;
}

.detail-warning.debt {
    background: var(--danger-soft);
    border-color: #f8c2bb;
    color: var(--danger);
}

.detail-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  min-width: 0;
}

.detail-grid article {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  min-width: 0;
  padding: 12px;
}

.detail-grid strong {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
}

.detail-actions,
.form-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.renewal-form {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 14px;
}

.renewal-form[hidden] {
  display: none;
}

.renewal-form h3,
.renewal-form .wide {
  grid-column: 1 / -1;
}

.package-history {
  display: grid;
  gap: 10px;
}

.package-history-card {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  padding: 12px;
}

.package-history-card strong,
.package-history-card span {
  display: block;
}

.package-history-card span {
  color: var(--muted);
  font-size: 0.84rem;
  margin-top: 4px;
}

.patient-details h3 {
  font-size: 1rem;
}

.consultations-list {
  display: grid;
  gap: 8px;
}

.consultation-row {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  gap: 10px;
  justify-content: space-between;
  min-width: 0;
  padding: 12px;
}

.consultation-row span {
  color: var(--muted);
  display: block;
  font-size: 0.86rem;
  margin-top: 3px;
}

.finance-cards {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.finance-cards article {
  box-shadow: none;
  padding: 16px;
}

.finance-cards strong {
  display: block;
  font-size: 1.5rem;
  margin-top: 8px;
}

.finance-chart-head {
  align-items: center;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-top: 18px;
  padding-top: 18px;
}

.finance-chart-head h3 {
  font-size: 1rem;
  margin-top: 4px;
}

.year-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.revenue-chart {
  align-items: end;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(12, minmax(64px, 1fr));
  height: 280px;
  margin-top: 18px;
  overflow-x: auto;
  padding-top: 40px;
}

.chart-bar {
  align-items: center;
  background: transparent;
  border: 1px solid transparent;
  color: inherit;
  cursor: pointer;
  display: grid;
  gap: 8px;
  grid-template-rows: 1fr auto auto; /* A primeira linha agora eh a area da barra e dos labels */
  height: 100%;
  min-width: 64px;
  padding: 0 2px;
}

.chart-bar:hover,
.chart-bar.active {
  background: transparent;
  border-color: var(--gold);
}

.chart-bar:disabled {
  cursor: default;
  opacity: 0.45;
}

.chart-bar:disabled:hover {
  border-color: transparent;
}

.bar-column {
  position: relative;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.bar-labels {
    display: flex;
    flex-direction: column;
    left: 0;
    position: absolute;
    right: 0;
    text-align: center;
}

.bar-labels small {
    display: block;
    font-size: 0.68rem;
    font-weight: 900;
    white-space: nowrap;
}

.pending-label { color: var(--muted); margin-bottom: 2px; }
.paid-label { color: var(--black); }

.bar-stack {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    height: 100%;
    width: 100%;
}

.bar-stack span {
    display: block;
    width: 100%;
}

.bar-stack .pago {
    background: linear-gradient(180deg, #e6c66d, var(--gold-dark));
}

.bar-stack .pendente {
    background: #e5dfd2;
}

.chart-bar strong {
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.chart-bar em {
  color: var(--muted);
  font-size: 0.68rem;
  font-style: normal;
  font-weight: 800;
  text-align: center;
  white-space: nowrap;
}

.finance-month-details {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  margin-top: 18px;
  padding: 16px;
}

.finance-month-details .panel-header {
  margin-bottom: 12px;
}

.finance-month-details p {
  color: var(--muted);
  margin: 4px 0 0;
}

.finance-month-table .money-input,
.finance-month-table .date-input {
  min-width: 96px;
  width: 112px;
}

.finance-month-table .date-input {
  width: 138px;
}

.chart-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 16px;
}

.legend-item {
    align-items: center;
    color: var(--muted);
    display: flex;
    font-size: 0.8rem;
    font-weight: 700;
    gap: 6px;
}

.legend-item i {
    border-radius: 3px;
    height: 12px;
    width: 12px;
}

.legend-item i.pago { background: var(--gold); }
.legend-item i.pending, .legend-item i.pendente { background: var(--line); }
.legend-item i.done { background: var(--success); }
.legend-item i.reschedule { background: var(--warning); }
.legend-item i.first { background: #6f42c1; }
.legend-item i.remaining-two { background: #1f78b4; }
.legend-item i.remaining-one { background: var(--danger); }

.calendar-sync-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    display: grid;
    gap: 18px;
    margin-bottom: 20px;
    padding: 20px;
}

.sync-panel-head {
    align-items: start;
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.sync-panel-head h3 {
    font-size: 1.15rem;
    margin: 4px 0 0;
}

.sync-panel-head strong {
    background: var(--black);
    border-radius: 999px;
    color: var(--gold);
    font-size: 0.78rem;
    padding: 8px 12px;
    white-space: nowrap;
}

.calendar-sync-form {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.calendar-sync-form .wide {
    grid-column: 1 / -1;
}

.calendar-import-summary {
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--ink);
    padding: 16px;
}

.calendar-import-summary.empty {
    color: var(--muted);
}

.sync-result-head {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 14px;
}

.sync-result-head span,
.sync-result-grid span,
.sync-result-list span {
    color: var(--muted);
    display: block;
    font-size: 0.78rem;
    font-weight: 800;
}

.sync-result-head strong,
.sync-result-grid strong {
    display: block;
    font-size: 1.15rem;
    margin-top: 4px;
}

.sync-result-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.sync-result-grid article {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 12px;
}

.sync-result-list {
    border-top: 1px solid var(--line);
    display: grid;
    gap: 10px;
    list-style: none;
    margin: 14px 0 0;
    padding: 14px 0 0;
}

.sync-result-list li {
    align-items: center;
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.google-api-box {
    align-items: center;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 16px;
}

.google-api-box strong {
    display: block;
    margin-top: 4px;
}

.google-api-box p {
    color: var(--muted);
    margin: 6px 0 0;
}

.google-sync-controls {
    display: grid;
    gap: 10px;
    min-width: min(420px, 100%);
}

.google-sync-controls label {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
}

.google-sync-row,
.google-sync-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.google-sync-row input {
    min-width: 0;
}

.google-sync-actions button,
.google-sync-row button {
    white-space: nowrap;
}

.calendar-wrapper {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 16px;
    display: grid;
    gap: 16px;
    grid-template-columns: 170px minmax(0, 1fr);
    margin-bottom: 20px;
    overflow: hidden;
    padding: 16px;
}

.calendar-sidebar {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.calendar-view-toggle {
    display: grid;
    gap: 6px;
    grid-template-columns: 1fr 1fr;
}

.calendar-search {
    color: var(--muted);
    display: grid;
    font-size: 0.78rem;
    font-weight: 900;
    gap: 6px;
}

.today-btn {
    width: 100%;
}

.calendar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: center;
}

.calendar-nav button {
    background: var(--surface-soft);
    color: var(--ink);
    font-size: 1.5rem;
    height: 36px;
    padding: 0;
}

.calendar-nav strong {
    font-size: 0.95rem;
    text-transform: capitalize;
}

.calendar-legend {
    display: grid;
    gap: 12px;
    margin-top: auto;
}

.calendar-main {
    min-width: 0;
    overflow: hidden;
}

.calendar-schedule {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
}

.schedule-header {
    background: var(--surface-soft);
    border-bottom: 1px solid var(--line);
    display: grid;
    grid-template-columns: 64px repeat(7, minmax(0, 1fr));
}

.schedule-corner,
.schedule-day-head {
    border-right: 1px solid var(--line);
    min-width: 0;
    padding: 8px 6px;
}

.schedule-corner {
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 900;
}

.schedule-day-head {
    background: transparent;
    border-radius: 0;
    color: var(--ink);
    display: grid;
    gap: 2px;
    min-height: 48px;
    text-align: center;
}

.schedule-day-head.today {
    background: var(--gold-soft);
}

.schedule-day-head span {
    color: var(--muted);
    font-size: 0.68rem;
    font-weight: 900;
    text-transform: uppercase;
}

.schedule-day-head strong {
    font-size: 1rem;
}

.schedule-body {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
}

.schedule-hours {
    display: grid;
    grid-template-rows: repeat(34, 40px);
}

.schedule-hours span {
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.64rem;
    font-weight: 800;
    padding: 3px 6px 0 0;
    text-align: right;
}

.schedule-days {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    min-width: 0;
}

.schedule-day-column {
    border-left: 1px solid var(--line);
    display: grid;
    grid-template-rows: repeat(34, 40px);
    min-width: 0;
    position: relative;
}

.schedule-day-column.today {
    background: rgba(244, 234, 210, 0.28);
}

.schedule-hour-line {
    background: linear-gradient(to bottom, rgba(18, 17, 15, 0.025), rgba(18, 17, 15, 0));
    border-bottom: 1px solid rgba(18, 17, 15, 0.12);
    min-width: 0;
}

.schedule-hour-line:hover,
.schedule-hour-line.drop-target,
.schedule-day-column.drop-target,
.month-day.drop-target {
    background-color: rgba(197, 154, 72, 0.14);
}

.calendar-chip {
    align-items: stretch;
    border-radius: 7px;
    display: grid;
    gap: 1px;
    justify-content: stretch;
    line-height: 1.1;
    min-height: 0;
    min-width: 0;
    padding: 4px 5px;
    text-align: left;
    width: 100%;
}

.calendar-chip[draggable="true"] {
    cursor: grab;
}

.calendar-chip.dragging {
    cursor: grabbing;
    opacity: 0.55;
}

.calendar-chip span {
    display: block;
    font-size: 0.64rem;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.calendar-chip strong {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    display: inline-flex;
    font-size: 0.56rem;
    font-weight: 900;
    justify-self: start;
    padding: 1px 5px;
    text-transform: uppercase;
}

.calendar-chip.realizada { background: var(--success); }
.calendar-chip.nao_realizada { background: var(--black); }
.calendar-chip.reagendar { background: var(--warning); color: var(--black); }
.calendar-chip.first-visit { background: #6f42c1; color: #fff; }
.calendar-chip.remaining-two { background: #1f78b4; color: #fff; }
.calendar-chip.remaining-one { background: var(--danger); color: #fff; }
.calendar-chip.needs-reschedule { background: var(--warning); color: var(--black); }

.schedule-event {
    border: 2px solid #fff;
    box-shadow: 0 8px 16px rgba(18, 17, 15, 0.12);
    left: 4px;
    overflow: hidden;
    position: absolute;
    right: 4px;
    z-index: 2;
}

.schedule-event small {
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.54rem;
    font-weight: 800;
}

.schedule-event.reagendar small {
    color: rgba(13, 12, 10, 0.72);
}

.month-calendar {
    display: grid;
    min-width: 0;
}

.month-weekdays,
.month-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
}

.month-weekdays span {
    background: var(--surface-soft);
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 900;
    padding: 8px;
    text-align: center;
    text-transform: uppercase;
}

.month-day {
    border-bottom: 1px solid var(--line);
    border-right: 1px solid var(--line);
    min-height: 138px;
    min-width: 0;
    padding: 6px;
}

.month-day.outside {
    background: #fdfdfc;
    opacity: 0.45;
}

.month-day.today {
    background: rgba(244, 234, 210, 0.36);
}

.month-day .day-number {
    align-items: center;
    border-radius: 50%;
    display: grid;
    font-size: 0.82rem;
    font-weight: 900;
    height: 24px;
    margin-bottom: 6px;
    place-items: center;
    width: 24px;
}

.month-day.today .day-number {
    background: var(--black);
    color: #fff;
}

.month-events {
    display: grid;
    gap: 4px;
    max-height: 104px;
    overflow-y: auto;
}

.month-event {
    padding: 4px 5px;
}

.month-event small {
    color: rgba(255, 255, 255, 0.78);
    font-size: 0.56rem;
    font-weight: 800;
}

.month-event.reagendar small,
.month-event.needs-reschedule small {
    color: rgba(13, 12, 10, 0.72);
}

.more-count {
    color: var(--muted);
    font-size: 0.65rem;
    font-weight: 900;
}

.form-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-form {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.form-actions {
  grid-column: 1 / -1;
}

.report-tools {
  align-items: flex-end;
  display: flex;
  gap: 12px;
  margin-bottom: 22px;
}

.report-tools label {
  flex: 1;
}

.report-tools button {
  min-height: 42px;
}

.toast {
  background: var(--black);
  border-radius: 10px;
  bottom: 32px;
  color: #fff;
  font-size: 0.88rem;
  font-weight: 800;
  left: 50%;
  opacity: 0;
  padding: 12px 16px;
  pointer-events: none;
  position: fixed;
  transform: translateX(-50%) translateY(12px);
  transition: 180ms ease;
  z-index: 30;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    position: static;
  }

  .side-nav {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .revenue-kpi-card {
    grid-column: span 2;
  }

  .calendar-wrapper {
      grid-template-columns: 1fr;
  }

  .calendar-sidebar {
      display: grid;
      grid-template-columns: 120px minmax(0, 1fr);
  }

  .calendar-legend {
      grid-column: 1 / -1;
      grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  main {
    padding-inline: 18px;
  }

  .topbar,
  .hero-panel,
  .table-tools,
  .kpi-grid,
  .content-grid,
  .finance-grid,
  .finance-cards,
  .package-grid,
  .security-grid,
  .calendar-sync-form,
  .sync-result-head,
  .sync-result-grid,
  .form-grid,
  .compact-form,
  .renewal-form,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions,
  .detail-actions,
  .form-actions,
  .google-api-box,
  .google-sync-row,
  .google-sync-actions,
  .pagination {
    display: grid;
  }

  .side-nav {
    grid-template-columns: 1fr 1fr;
  }

  .topbar {
    align-items: stretch;
    display: grid;
    gap: 12px;
  }

  .topbar h1 {
    font-size: 1.35rem;
    line-height: 1.15;
  }

  .topbar-actions {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .topbar-actions button {
    font-size: 0.9rem;
    min-width: 0;
    padding-inline: 10px;
  }

  .panel-header {
    align-items: flex-start;
    display: grid;
  }

  .panel-header-actions {
    display: grid;
    gap: 8px;
    grid-template-columns: 1fr;
  }

  .panel-header > strong {
    justify-self: start;
    width: auto;
  }

  .sync-panel-head {
    display: grid;
  }

  .sync-panel-head strong {
    justify-self: start;
  }

  .report-tools {
    display: grid;
    grid-template-columns: 1fr;
  }

  .report-tools button {
    width: 100%;
  }

  .revenue-kpi-card {
    grid-column: auto;
  }

  .kpi-values {
    grid-template-columns: 1fr;
  }

  .kpi-values strong {
    white-space: normal;
  }

  .patient-identity {
    grid-template-columns: auto 1fr;
  }

  .calendar-wrapper {
    padding: 10px;
  }

  .calendar-weekdays span {
    font-size: 0.62rem;
  }

  .calendar-day {
    min-height: 84px;
    padding: 5px;
  }

  .day-number {
    font-size: 0.78rem;
    height: 22px;
    width: 22px;
  }

  .calendar-chip {
    padding: 4px;
  }

  .calendar-chip span {
    font-size: 0.6rem;
  }

  .patients-table {
    min-width: 680px;
  }
}
