:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --ink: #17211f;
  --muted: #697773;
  --line: #dde4e1;
  --primary: #0b6b57;
  --primary-soft: #e7f3ef;
  --warn-soft: #fff3e4;
  --danger: #9b2c16;
  --blue: #255f85;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
}

body:not(.is-authenticated) .app-shell {
  display: none;
}

body.is-authenticated .auth-screen {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 50% -10%, rgba(21, 132, 99, 0.28), transparent 32%),
    linear-gradient(180deg, #05100d 0%, #0b1714 100%);
}

.auth-panel {
  display: grid;
  width: min(430px, 100%);
  gap: 22px;
  border: 1px solid rgba(216, 241, 233, 0.14);
  border-radius: 18px;
  padding: 28px;
  background: #f7faf9;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.35);
}

.auth-panel h1 {
  margin: 4px 0 8px;
  font-size: 30px;
  line-height: 1.05;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 248px 1fr;
  width: 100%;
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 28px;
  padding: 24px 18px;
  background: #11231f;
  color: #f7fbf9;
}

.mobile-nav-backdrop {
  display: none;
}

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

.sidebar-close,
.menu-toggle {
  display: none;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: #d7f1e9;
  color: var(--primary);
  font-weight: 900;
}

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

.brand span {
  color: #b8c9c4;
  font-size: 13px;
}

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

.nav-item {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: #dce8e4;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: #1f3a34;
  color: #ffffff;
}

.content {
  display: grid;
  align-content: start;
  gap: 22px;
  min-width: 0;
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.topbar > div {
  min-width: 0;
}

.menu-toggle {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  place-items: center;
  gap: 4px;
}

.menu-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  border-radius: 999px;
  background: var(--ink);
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 30px;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

h3 {
  margin-bottom: 0;
  font-size: 15px;
}

.month-control {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 250px;
  justify-content: flex-end;
}

.sync-status {
  grid-column: 1 / -1;
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: flex-end;
  min-width: 0;
}

.user-menu span {
  max-width: 190px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.company-theme-1 {
  --company-accent: #0b6b57;
  --company-soft: #eef8f4;
  --company-chip: #dff2eb;
  --company-ink: #074e40;
}

.company-theme-2 {
  --company-accent: #255f85;
  --company-soft: #eef6fb;
  --company-chip: #dcecf6;
  --company-ink: #1d4c6b;
}

.company-theme-3 {
  --company-accent: #8f5d13;
  --company-soft: #fff8ea;
  --company-chip: #f7ead0;
  --company-ink: #70480d;
}

.company-theme-4 {
  --company-accent: #7a4ea3;
  --company-soft: #f5f0fb;
  --company-chip: #eadff5;
  --company-ink: #5c397e;
}

.company-theme-5 {
  --company-accent: #9b3d54;
  --company-soft: #fff1f4;
  --company-chip: #f5dfe5;
  --company-ink: #7d2f42;
}

.company-theme-6 {
  --company-accent: #4f6f28;
  --company-soft: #f3f8ec;
  --company-chip: #e4efd5;
  --company-ink: #3c541f;
}

.mobile-card-kicker {
  display: none;
}

.icon-btn,
.text-btn,
.primary-btn,
.danger-btn,
.status-btn {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-btn {
  width: 38px;
  font-size: 22px;
  line-height: 1;
}

.text-btn {
  padding: 0 12px;
  color: var(--primary);
  font-weight: 750;
}

.primary-btn {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

.danger-btn {
  border-color: #efcec5;
  background: #fff8f6;
  color: var(--danger);
}

.status-btn {
  padding: 0 12px;
  color: var(--primary);
  font-weight: 750;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

#companies-view.active {
  display: grid;
  gap: 18px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  max-width: 1120px;
}

.metric,
.panel,
.form-panel,
.report-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.metric {
  position: relative;
  overflow: hidden;
  min-height: 138px;
  padding: 18px;
  box-shadow: 0 14px 38px rgba(23, 33, 31, 0.05);
}

.metric span,
.metric small,
.muted-line,
.mini-section span {
  color: var(--muted);
}

.metric strong {
  display: block;
  margin: 18px 0 8px;
  font-size: 29px;
  line-height: 1;
}

.metric::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  content: "";
}

.metric-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.metric-top span {
  color: var(--ink);
  font-weight: 850;
}

.metric-title {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.metric-icon {
  display: inline-grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: inset 0 0 0 1px rgba(23, 33, 31, 0.08);
  font-size: 17px;
}

.metric-top small {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 0 9px;
  background: #f2f5f4;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.metric-produced::before {
  background: var(--primary);
}

.metric-receivable::before {
  background: var(--blue);
}

.metric-schedule::before {
  background: #7a5c12;
}

.metric-pending::before {
  background: var(--danger);
}

.metric-produced {
  background: linear-gradient(135deg, #ffffff 0%, #eef8f4 100%);
}

.metric-receivable {
  background: linear-gradient(135deg, #ffffff 0%, #eef6fb 100%);
}

.metric-schedule {
  background: linear-gradient(135deg, #ffffff 0%, #fff8ea 100%);
}

.metric-pending {
  background: linear-gradient(135deg, #ffffff 0%, #fff1f4 100%);
}

.metric-progress {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  margin: 12px 0 8px;
  background: #e8ecea;
}

.metric-progress div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 180ms ease;
}

.clickable-metric {
  cursor: pointer;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.clickable-metric:hover,
.clickable-metric:focus-visible {
  border-color: #b9c9c3;
  box-shadow: 0 18px 48px rgba(23, 33, 31, 0.1);
  outline: none;
  transform: translateY(-2px);
}

.split-layout,
.workbench {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(330px, 0.75fr);
  gap: 16px;
  margin-top: 16px;
}

.panel,
.form-panel {
  padding: 16px;
}

.panel-heading,
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.action-row,
.table-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
}

.panel-heading.compact {
  margin-bottom: 10px;
}

.form-panel {
  display: grid;
  align-content: start;
  gap: 13px;
}

label {
  display: grid;
  gap: 7px;
  color: #2c3936;
  font-size: 14px;
  font-weight: 750;
}

.field-label {
  display: block;
  margin-bottom: 8px;
  color: #2c3936;
  font-size: 14px;
  font-weight: 750;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 9px;
}

.checkbox-line input,
.weekday-grid input {
  width: 16px;
  min-height: 16px;
}

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

.weekday-grid label {
  display: flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  font-size: 13px;
}

.form-feedback {
  min-height: 20px;
  margin: 0;
  color: var(--primary);
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  color: var(--ink);
}

input:not([type="email"]):not([type="password"]):not([type="file"]),
textarea {
  text-transform: uppercase;
}

input,
select {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  min-height: 104px;
  padding: 11px;
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.subsection {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

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

.activity-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 132px auto;
  gap: 8px;
  align-items: center;
}

.activity-row > *,
.patient-row > * {
  min-width: 0;
}

.activity-row select,
.patient-row select {
  width: 100%;
}

.entry-line-total {
  display: grid;
  min-height: 42px;
  align-content: center;
  gap: 2px;
  border: 1px solid rgba(16, 126, 96, 0.2);
  border-radius: 8px;
  padding: 6px 10px;
  background: #f2fbf7;
}

.entry-line-total span {
  color: var(--muted);
  font-size: 10px;
  font-weight: 850;
  text-transform: uppercase;
}

.entry-line-total strong {
  color: var(--primary);
  font-size: 13px;
}

.entry-total-panel {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid rgba(16, 126, 96, 0.22);
  border-left: 5px solid var(--primary);
  border-radius: 8px;
  padding: 13px 14px;
  background: linear-gradient(90deg, #effaf6 0%, #ffffff 75%);
}

.entry-total-panel span {
  display: block;
  color: var(--ink);
  font-size: 13px;
  font-weight: 850;
}

.entry-total-panel small {
  color: var(--muted);
}

.entry-total-panel strong {
  color: var(--primary);
  font-size: 24px;
  white-space: nowrap;
}

.patient-row {
  display: grid;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.entry-patient-search-wrap {
  gap: 8px;
}

.entry-patient-results {
  max-height: 190px;
}

.entry-patient-results:empty {
  display: none;
}

.compact-option {
  min-height: 46px;
  padding: 8px 10px;
}

.entry-patient-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.entry-patient-actions button {
  min-height: 38px;
}

.branch-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(160px, 0.8fr);
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #ffffff;
}

.branch-row .company-branch-address {
  grid-column: 1 / -2;
}

.cep-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.single-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.list {
  display: grid;
  gap: 9px;
}

.selection-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow-y: auto;
}

.selection-option {
  display: grid;
  gap: 3px;
  width: 100%;
  min-height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
}

.selection-option:hover,
.selection-option.selected {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.selection-option small {
  color: var(--muted);
}

.list-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 62px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--company-accent, var(--primary));
  border-radius: 8px;
  padding: 12px;
  background: linear-gradient(90deg, var(--company-soft, #fbfcfc) 0%, #ffffff 70%);
}

.list-item strong,
.list-item small,
.list-item span {
  display: block;
}

.list-item small {
  margin-top: 3px;
  color: var(--muted);
}

.amount {
  color: var(--primary);
  font-weight: 900;
  text-align: right;
}

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

table {
  width: 100%;
  min-width: 800px;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 11px 10px;
  text-align: left;
  vertical-align: middle;
  min-width: 0;
  overflow-wrap: anywhere;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.mini-section {
  display: grid;
  gap: 5px;
}

.mini-section p {
  margin: 0;
  color: #34413e;
}

.details-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(260px, 0.85fr);
  gap: 16px;
}

.detail-item {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfc;
}

.detail-item small,
.detail-item span {
  color: var(--muted);
}

.attachment-item {
  grid-template-columns: 72px minmax(0, 1fr);
  align-items: center;
}

.attachment-preview,
.attachment-file {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border-radius: 8px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 850;
  object-fit: cover;
}

.attachment-link {
  display: inline-grid;
  width: fit-content;
  min-height: 32px;
  margin-top: 8px;
  place-items: center;
  padding: 0 12px;
  text-decoration: none;
}

.inline-detail {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

.calendar-panel {
  overflow: hidden;
}

.calendar-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.calendar-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--line);
}

.legend-dot.busy {
  background: var(--primary);
}

.legend-dot.pointed {
  background: #2f7dbc;
}

.legend-dot.free {
  background: #cfd8d5;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--line);
  gap: 1px;
}

.calendar-weekday {
  min-height: 34px;
  display: grid;
  place-items: center;
  background: #f6f8f7;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.calendar-day {
  display: grid;
  min-height: 148px;
  align-content: start;
  gap: 8px;
  padding: 9px;
  background: #ffffff;
  min-width: 0;
}

.calendar-day.is-empty {
  background: #f7f9f8;
}

.calendar-day.is-free {
  background: linear-gradient(180deg, #ffffff 0%, #f8faf9 100%);
}

.calendar-day.has-schedule {
  background: linear-gradient(180deg, #f5fbf8 0%, #ffffff 74%);
}

.calendar-day.is-today {
  box-shadow: inset 0 0 0 2px var(--primary);
}

.calendar-day-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.calendar-day-head strong {
  color: var(--ink);
  font-size: 17px;
}

.calendar-day-head span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  white-space: nowrap;
}

.calendar-events {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.calendar-event {
  display: grid;
  gap: 1px;
  width: 100%;
  border: 1px solid rgba(14, 113, 88, 0.18);
  border-left: 4px solid var(--company-accent, var(--primary));
  border-radius: 7px;
  padding: 7px 8px;
  background: var(--company-soft, #f4fbf8);
  color: var(--ink);
  text-align: left;
}

.calendar-event:hover {
  border-color: var(--company-accent, var(--primary));
}

.calendar-event.is-pointed {
  background: #f2f8fd;
}

.calendar-event strong,
.calendar-event span,
.calendar-event small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-event strong {
  color: var(--primary);
  font-size: 11px;
  text-transform: uppercase;
}

.calendar-event span {
  font-size: 12px;
  font-weight: 850;
}

.calendar-event small,
.calendar-more {
  color: var(--muted);
  font-size: 11px;
}

.calendar-add {
  width: 100%;
  min-height: 34px;
  border: 1px dashed #bdcbc7;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
  font-weight: 850;
}

.calendar-add:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-soft);
}

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

.report-card {
  display: grid;
  min-height: 132px;
  align-content: space-between;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(180deg, #ffffff 0%, #f8faf9 100%);
  box-shadow: 0 14px 38px rgba(23, 33, 31, 0.04);
}

.report-card span,
.report-card small {
  color: var(--muted);
}

.report-card strong {
  display: block;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.25;
}

.report-panel {
  margin-top: 16px;
}

.bi-builder {
  margin-top: 16px;
}

.bi-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(160px, 1fr));
  gap: 12px;
}

.bi-toolbar label {
  min-width: 0;
}

.bi-toolbar label > span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.report-charts {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 16px;
  margin-top: 16px;
}

.chart-list {
  display: grid;
  gap: 14px;
}

.chart-row {
  display: grid;
  gap: 7px;
}

.chart-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chart-label strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-label span,
.chart-row small {
  color: var(--muted);
}

.chart-track {
  height: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1ef;
}

.chart-track div {
  height: 100%;
  min-width: 4px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #2d8f79);
}

.compact-chart-row .chart-track div {
  background: linear-gradient(90deg, var(--blue), #4f88ad);
}

.ranking-list {
  display: grid;
  gap: 12px;
}

.ranking-row {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid #e7ecea;
  border-radius: 8px;
  padding: 11px;
  background: #fbfcfc;
}

.ranking-position {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 8px;
  background: #e7f3ef;
  color: var(--primary);
  font-size: 13px;
  font-weight: 900;
}

.ranking-main {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.ranking-main small {
  color: var(--muted);
}

.ranking-bar {
  height: 13px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf1ef;
}

.ranking-bar div {
  height: 100%;
  min-width: 4px;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #255f85);
}

.distribution-layout {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  gap: 18px;
  align-items: center;
}

.donut-chart {
  position: relative;
  display: grid;
  width: min(100%, 220px);
  aspect-ratio: 1;
  place-items: center;
  border-radius: 50%;
}

.donut-chart::after {
  position: absolute;
  inset: 13px;
  border: 1px solid rgba(255, 255, 255, 0.8);
  border-radius: inherit;
  content: "";
}

.donut-center {
  position: relative;
  z-index: 1;
  display: grid;
  width: 58%;
  aspect-ratio: 1;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #ffffff;
  text-align: center;
  box-shadow: 0 16px 38px rgba(23, 33, 31, 0.08);
}

.donut-center span,
.donut-legend small {
  color: var(--muted);
}

.donut-center strong {
  max-width: 92px;
  overflow-wrap: anywhere;
  font-size: 15px;
}

.donut-legend {
  display: grid;
  gap: 9px;
}

.legend-item {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr);
  gap: 4px 8px;
  align-items: center;
  min-width: 0;
}

.legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.legend-item strong,
.legend-item small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-item small {
  grid-column: 2;
  font-size: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(280px, 420px);
  gap: 12px;
  margin-bottom: 14px;
}

.tag {
  display: inline-flex;
  width: fit-content;
  min-height: 26px;
  align-items: center;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--company-chip, var(--warn-soft));
  color: var(--company-ink, #9a4b08);
  font-size: 12px;
  font-weight: 800;
}

.tag.success,
.paid {
  background: var(--primary-soft);
  color: var(--primary);
}

.empty {
  border: 1px dashed #bbc8c3;
  border-radius: 8px;
  padding: 20px;
  color: var(--muted);
  text-align: center;
}

.hidden-field {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal.active {
  display: flex;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 18, 16, 0.46);
  backdrop-filter: blur(3px);
}

.modal-panel {
  position: relative;
  z-index: 1;
  display: grid;
  width: min(620px, 100%);
  max-width: calc(100vw - 40px);
  max-height: min(92vh, 860px);
  gap: 14px;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 20px 20px;
  background: var(--surface);
  box-shadow: 0 24px 70px rgba(10, 18, 16, 0.22);
  animation: modal-in 140ms ease;
}

#entry-form {
  width: min(760px, calc(100vw - 40px));
  gap: 12px;
}

.wide-modal {
  width: min(880px, 100%);
}

.modal-heading {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  margin: 0 -20px 2px;
  padding: 18px 20px 14px;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-actions .primary-btn,
.modal-actions .text-btn {
  min-width: 140px;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.99);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 16px;
  }

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

  .nav-item {
    text-align: center;
  }

  .metrics-grid,
  .report-grid,
  .report-charts,
  .distribution-layout,
  .split-layout,
  .workbench,
  .details-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  body {
    background:
      radial-gradient(circle at 50% -10%, rgba(25, 103, 82, 0.34), transparent 34%),
      linear-gradient(180deg, #05100d 0%, #081411 42%, #06100e 100%);
  }

  body.menu-open {
    overflow: hidden;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  body.menu-open .mobile-nav-backdrop {
    display: block;
  }

  .app-shell {
    display: block;
  }

  .mobile-nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 19;
    background: rgba(10, 18, 16, 0.46);
    backdrop-filter: blur(2px);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 20;
    width: min(84vw, 312px);
    height: 100dvh;
    gap: 22px;
    padding: 18px;
    box-shadow: 20px 0 50px rgba(10, 18, 16, 0.28);
    transform: translateX(-105%);
    transition: transform 180ms ease;
  }

  .sidebar-close {
    display: inline-grid;
    margin-left: auto;
    place-items: center;
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
  }

  .menu-toggle {
    display: grid;
    flex: 0 0 auto;
  }

  .content {
    gap: 16px;
    min-height: 100dvh;
    padding: 18px 16px 28px;
    background:
      radial-gradient(circle at 50% -8%, rgba(25, 103, 82, 0.32), transparent 34%),
      linear-gradient(180deg, #05100d 0%, #081411 42%, #06100e 100%);
  }

  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
    gap: 12px 14px;
  }

  .topbar h1 {
    margin-top: 1px;
    color: #f7fffc;
    font-size: 23px;
    line-height: 1.08;
  }

  .topbar .month-control {
    grid-column: 1 / -1;
    min-height: 50px;
    border: 1px solid rgba(216, 241, 233, 0.18);
    border-radius: 16px;
    padding: 6px 7px;
    background: rgba(13, 29, 25, 0.9);
    color: #f7fffc;
    box-shadow: 0 18px 38px rgba(0, 0, 0, 0.24);
    backdrop-filter: blur(10px);
  }

  .eyebrow {
    margin-bottom: 4px;
    color: #89ddc6;
  }

  .menu-toggle {
    width: 44px;
    height: 44px;
    border-color: rgba(216, 241, 233, 0.2);
    background: rgba(13, 29, 25, 0.9);
    box-shadow: 0 12px 26px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(10px);
  }

  .menu-toggle span {
    background: #f7fffc;
  }

  .topbar .icon-btn {
    border-color: rgba(216, 241, 233, 0.16);
    background: rgba(19, 39, 33, 0.95);
    color: #f7fffc;
  }

  .topbar .month-control strong {
    color: #ffffff;
  }

  .user-menu {
    grid-column: 1 / -1;
    justify-content: space-between;
    padding: 10px 12px;
    border: 1px solid rgba(216, 241, 233, 0.14);
    border-radius: 14px;
    background: rgba(13, 29, 25, 0.72);
  }

  .user-menu span {
    color: #cde4dc;
  }

  .sync-status {
    margin: -4px 0 0;
    color: #9fc8bc;
  }

  .nav,
  .form-grid,
  .bi-toolbar,
  .activity-row,
  .patient-row,
  .single-row,
  .branch-row,
  .cep-row,
  .action-row,
  .table-actions {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .nav {
    display: grid;
    gap: 10px;
  }

  .nav-item {
    min-height: 48px;
    padding: 0 14px;
    text-align: left;
  }

  .metrics-grid,
  .report-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .calendar-panel {
    padding-right: 10px;
    padding-left: 10px;
  }

  .calendar-grid {
    border-radius: 10px;
  }

  .calendar-weekday {
    min-height: 30px;
    font-size: 10px;
  }

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

  .calendar-day-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 1px;
  }

  .calendar-day-head strong {
    font-size: 14px;
  }

  .calendar-day-head span {
    font-size: 9px;
  }

  .calendar-event {
    border-left-width: 3px;
    padding: 5px;
  }

  .calendar-event span,
  .calendar-event small {
    display: none;
  }

  .calendar-event strong {
    font-size: 9px;
  }

  .calendar-add {
    min-height: 28px;
    padding: 0 2px;
    font-size: 9px;
  }

  .metric,
  .report-card {
    border-color: rgba(255, 255, 255, 0.14);
    min-height: 154px;
    padding: 18px;
    box-shadow: 0 22px 52px rgba(0, 0, 0, 0.24);
  }

  .metric strong {
    margin: 16px 0 8px;
    overflow-wrap: anywhere;
    font-size: 30px;
    line-height: 1.08;
  }

  .metric-top {
    align-items: center;
    flex-direction: row;
    gap: 10px;
  }

  .metric-title {
    align-items: center;
    font-size: 15px;
  }

  .metric-icon {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  .metric-top small {
    margin-left: auto;
  }

  .report-card {
    background: #ffffff;
    min-height: 126px;
  }

  .report-card strong {
    font-size: 20px;
  }

  .panel,
  .form-panel {
    border-color: rgba(255, 255, 255, 0.14);
    border-radius: 18px;
    padding: 16px;
    box-shadow: 0 24px 58px rgba(0, 0, 0, 0.26);
  }

  .panel {
    background: #fbfdfc;
  }

  .panel-subtitle {
    color: #52635f;
  }

  .panel-heading,
  .card-head {
    align-items: stretch;
    flex-direction: column;
  }

  .action-row,
  .table-actions {
    display: grid;
    width: 100%;
  }

  .modal-actions {
    display: grid;
  }

  .modal-actions .primary-btn,
  .modal-actions .text-btn {
    width: 100%;
  }

  .action-row .primary-btn,
  .table-actions button,
  .status-btn {
    width: 100%;
  }

  .primary-btn {
    min-height: 46px;
    border-radius: 12px;
    background: linear-gradient(180deg, #118365 0%, #0b6b57 100%);
    box-shadow: 0 12px 22px rgba(11, 107, 87, 0.22);
  }

  input,
  select,
  textarea {
    min-height: 48px;
    border-radius: 12px;
    background: #ffffff;
  }

  .toolbar {
    grid-template-columns: 1fr;
  }

  .month-control {
    min-width: 0;
    width: 100%;
    justify-content: space-between;
  }

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

  .list-item {
    border-color: rgba(255, 255, 255, 0.22);
    grid-template-columns: 1fr;
    box-shadow: 0 14px 34px rgba(0, 0, 0, 0.13);
  }

  .list-item > div:last-child {
    display: grid;
    gap: 8px;
  }

  .amount {
    text-align: left;
  }

  .table-wrap {
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 12px;
  }

  tr {
    position: relative;
    overflow: hidden;
    border: 1px solid color-mix(in srgb, var(--company-accent, var(--line)) 22%, var(--line));
    border-radius: 16px;
    padding: 0 14px 12px;
    background: #ffffff;
    box-shadow: 0 16px 38px rgba(0, 0, 0, 0.15);
  }

  tr::before {
    display: block;
    height: 5px;
    margin: 0 -14px 10px;
    background: linear-gradient(90deg, var(--company-accent, var(--primary)), color-mix(in srgb, var(--company-accent, var(--primary)) 18%, #ffffff));
    content: "";
  }

  td {
    display: grid;
    grid-template-columns: 94px minmax(0, 1fr);
    gap: 12px;
    border-bottom: 1px solid rgba(23, 33, 31, 0.06);
    padding: 10px 0;
    color: #10211d;
    font-size: 13px;
  }

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

  td::before {
    color: #5d6c68;
    font-size: 10px;
    font-weight: 850;
    text-transform: uppercase;
  }

  td strong {
    color: var(--ink);
  }

  .mobile-card-kicker {
    display: none;
  }

  .mobile-hidden-cell {
    display: none;
  }

  .mobile-primary-cell {
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
    border-bottom-color: rgba(23, 33, 31, 0.08);
    padding: 4px 0 12px;
  }

  .mobile-primary-cell::before {
    display: none;
  }

  .mobile-primary-cell .mobile-card-kicker {
    display: block;
    color: var(--company-ink, var(--primary));
    font-size: 11px;
    font-weight: 850;
    text-transform: uppercase;
  }

  .mobile-primary-cell strong {
    font-size: 16px;
    line-height: 1.2;
  }

  tr .tag {
    background: var(--company-chip, var(--warn-soft));
    color: var(--company-ink, #9a4b08);
  }

  tr .tag.success {
    background: #dff5e9;
    color: #087248;
  }

  #schedule-table td:nth-child(1)::before {
    content: "Data";
  }

  #schedule-table td:nth-child(2)::before {
    content: "Empresa";
  }

  #schedule-table td:nth-child(3)::before {
    content: "Filial";
  }

  #schedule-table td:nth-child(4)::before {
    content: "Periodo";
  }

  #schedule-table td:nth-child(5)::before {
    content: "Status";
  }

  #schedule-table td:nth-child(6)::before {
    content: "Total";
  }

  #schedule-table td:nth-child(7)::before {
    content: "Acoes";
  }

  #companies-table td:nth-child(1)::before {
    content: "Cod. empresa";
  }

  #companies-table td:nth-child(2)::before {
    content: "Empresa";
  }

  #companies-table td:nth-child(3)::before {
    content: "Cod. filial";
  }

  #companies-table td:nth-child(4)::before {
    content: "Filial";
  }

  #companies-table td:nth-child(5)::before {
    content: "Atividades";
  }

  #companies-table td:nth-child(6)::before {
    content: "Pagamento";
  }

  #companies-table td:nth-child(7)::before {
    content: "Acoes";
  }

  #patients-table td:nth-child(1)::before {
    content: "Paciente";
  }

  #patients-table td:nth-child(2)::before {
    content: "Idade";
  }

  #patients-table td:nth-child(3)::before {
    content: "Telefone";
  }

  #patients-table td:nth-child(4)::before {
    content: "E-mail";
  }

  #patients-table td:nth-child(5)::before {
    content: "Ultimo";
  }

  #patients-table td:nth-child(6)::before {
    content: "Anexos";
  }

  #patients-table td:nth-child(7)::before {
    content: "Acoes";
  }

  #reports-table td:nth-child(1)::before {
    content: "Empresa";
  }

  #reports-table td:nth-child(2)::before {
    content: "Filial";
  }

  #reports-table td:nth-child(3)::before {
    content: "Agendas";
  }

  #reports-table td:nth-child(4)::before {
    content: "Apontadas";
  }

  #reports-table td:nth-child(5)::before {
    content: "Total";
  }

  #reports-table td:nth-child(6)::before {
    content: "Media";
  }

  .distribution-layout {
    justify-items: center;
  }

  .donut-legend {
    width: 100%;
  }

  .modal {
    align-items: stretch;
    justify-content: stretch;
    padding: 0;
  }

  .modal-panel,
  .wide-modal {
    width: 100%;
    max-height: 100dvh;
    min-height: 100dvh;
    border-radius: 0;
    padding: 0 14px 18px;
  }

  .modal-heading {
    margin-right: -14px;
    margin-left: -14px;
    padding: 16px 14px 12px;
  }

  .branch-row .company-branch-address {
    grid-column: auto;
  }

  h1 {
    overflow-wrap: anywhere;
    font-size: 24px;
  }
}

@media (max-width: 520px) {
  .calendar-panel {
    border-color: rgba(255, 255, 255, 0.08);
    padding: 12px 10px;
    background: #202124;
    color: #e8eaed;
  }

  .calendar-panel .panel-heading {
    gap: 12px;
  }

  .calendar-panel h2 {
    color: #ffffff;
  }

  .calendar-panel .panel-subtitle,
  #calendar-summary {
    color: #bdc1c6;
  }

  .calendar-legend {
    gap: 8px;
    margin-bottom: 10px;
    color: #bdc1c6;
    font-size: 11px;
  }

  .calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 1px;
    border: 1px solid #3c4043;
    border-radius: 0;
    background: #3c4043;
    overflow: hidden;
  }

  .calendar-weekday {
    display: grid;
    min-height: 28px;
    background: #202124;
    color: #bdc1c6;
    font-size: 9px;
  }

  .calendar-day {
    min-height: 72px;
    gap: 3px;
    border: 0;
    border-radius: 0;
    padding: 4px 3px;
    background: #202124;
  }

  .calendar-day.is-empty {
    display: grid;
    background: #1b1c1f;
  }

  .calendar-day.is-free,
  .calendar-day.has-schedule {
    background: #202124;
  }

  .calendar-day.is-today {
    box-shadow: inset 0 0 0 1px #8ab4f8;
  }

  .calendar-day-head {
    align-items: flex-start;
    flex-direction: row;
    justify-content: space-between;
    gap: 2px;
  }

  .calendar-day-head strong {
    display: inline-grid;
    width: 20px;
    height: 20px;
    place-items: center;
    border-radius: 999px;
    background: transparent;
    color: #e8eaed;
    font-size: 11px;
    line-height: 1;
  }

  .calendar-day.is-today .calendar-day-head strong {
    background: #8ab4f8;
    color: #202124;
  }

  .calendar-day-head span {
    color: #9aa0a6;
    font-size: 8px;
    line-height: 1.1;
  }

  .calendar-events {
    gap: 2px;
  }

  .calendar-event {
    display: block;
    min-height: 14px;
    border: 0;
    border-left: 0;
    border-radius: 2px;
    padding: 1px 3px;
    background: #16a085;
    color: #031f18;
    line-height: 1.1;
  }

  .calendar-event strong {
    display: block;
    min-width: 0;
    color: #031f18;
    font-size: 8px;
    font-weight: 900;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .calendar-event span,
  .calendar-event small {
    display: none;
  }

  .calendar-event.is-pointed {
    background: #24a4d8;
    color: #05202c;
  }

  .calendar-event.is-pointed strong {
    color: #05202c;
  }

  .calendar-more {
    color: #bdc1c6;
    font-size: 8px;
    line-height: 1;
  }

  .calendar-add {
    justify-self: start;
    width: 18px;
    min-height: 18px;
    border: 0;
    border-radius: 999px;
    padding: 0;
    background: transparent;
    color: #8ab4f8;
    font-size: 0;
  }

  .calendar-add::after {
    content: "+";
    font-size: 13px;
    font-weight: 900;
  }
}

@media (max-width: 380px) {
  .metrics-grid,
  .report-grid {
    grid-template-columns: 1fr;
  }

  td {
    grid-template-columns: 92px minmax(0, 1fr);
  }
}
