:root {
  --primary: #b89a7a;
  --primary-dark: #927659;
  --primary-soft: #eadfd3;
  --secondary: #d7c0a6;
  --bg-light: #f5f1eb;
  --surface: #fffcf8;
  --surface-strong: #ffffff;
  --text-main: #5c5656;
  --text-muted: #818181;
  --border: #e6dbcf;
  --border-soft: #eee6dd;
  --white: #ffffff;
  --danger: #a45f5f;
  --success: #72866d;
  --shadow: 0 12px 36px rgba(92, 86, 86, 0.08);
  --shadow-lg: 0 24px 70px rgba(92, 86, 86, 0.13);
  --radius-sm: 12px;
  --radius-md: 20px;
  --radius-lg: 32px;
}

html {
  background: var(--bg-light);
  scroll-behavior: smooth;
}

body {
  background:
    radial-gradient(circle at 100% 0%, rgba(184, 154, 122, 0.14), transparent 32rem),
    radial-gradient(circle at 0% 90%, rgba(215, 192, 166, 0.14), transparent 28rem),
    var(--bg-light);
  color: var(--text-main);
  font-family: "Montserrat", sans-serif;
  line-height: 1.65;
}

body:not(.login-page)::before {
  border: 1px solid rgba(184, 154, 122, 0.14);
  border-radius: 50%;
  content: "";
  height: 28rem;
  pointer-events: none;
  position: fixed;
  right: -18rem;
  top: 8rem;
  width: 28rem;
  z-index: 0;
}

a {
  color: var(--primary-dark);
}

h1,
h2,
h3,
h4 {
  color: var(--text-main);
  font-family: "DM Serif Display", serif;
  font-weight: 400;
  letter-spacing: -0.015em;
}

h1 {
  font-size: clamp(2.15rem, 4vw, 3.4rem);
  line-height: 1.05;
}

h2 {
  font-size: clamp(1.7rem, 3vw, 2.35rem);
}

h3 {
  font-size: 1.42rem;
}

.sr-only {
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

/* Brand and navigation */
.navbar {
  backdrop-filter: blur(18px);
  background: rgba(245, 241, 235, 0.9);
  border-bottom: 1px solid rgba(184, 154, 122, 0.18);
  box-shadow: none;
  padding: 0.85rem 2rem;
}

.nav-container {
  max-width: 1320px;
}

.brand-logo {
  align-items: center;
  color: var(--text-main);
  display: inline-flex;
  font-family: "DM Serif Display", serif;
  gap: 0.75rem;
  letter-spacing: 0;
  min-width: max-content;
  text-decoration: none;
}

.brand-monogram {
  align-items: center;
  color: var(--primary);
  display: inline-flex;
  font-family: "DM Serif Display", serif;
  font-size: 1.35rem;
  font-style: italic;
  height: 42px;
  justify-content: center;
  line-height: 1;
  position: relative;
  width: 42px;
}

.brand-monogram::before,
.brand-monogram::after {
  border: 1px solid rgba(184, 154, 122, 0.55);
  border-radius: 52% 48% 60% 40%;
  content: "";
  inset: 1px;
  position: absolute;
  transform: rotate(15deg);
}

.brand-monogram::after {
  inset: 6px -1px -3px 8px;
  opacity: 0.45;
  transform: rotate(-28deg);
}

.brand-copy {
  display: grid;
  font-size: 1.1rem;
  line-height: 1.05;
}

.brand-copy small {
  color: var(--primary);
  font-family: "Montserrat", sans-serif;
  font-size: 0.58rem;
  font-style: normal;
  font-weight: 600;
  letter-spacing: 0.18em;
  margin-top: 0.3rem;
  text-transform: uppercase;
}

.nav-links {
  gap: 0.35rem;
}

.nav-links a,
.nav-menu-button {
  border-radius: 999px;
  color: var(--text-main);
  font-family: "Montserrat", sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  transition: background 0.2s ease, color 0.2s ease;
}

.nav-links a:hover,
.nav-links a.active,
.nav-menu-button:hover,
.nav-menu-button.active {
  background: rgba(184, 154, 122, 0.14);
  color: var(--primary-dark);
}

.nav-links .nav-logout {
  color: var(--danger);
}

.nav-logout-form {
  margin: 0;
}

.nav-logout-form input {
  display: none;
}

.nav-logout {
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--danger);
  cursor: pointer;
  font-family: "Montserrat", sans-serif;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.65rem 0.85rem;
  transition: background 0.2s ease;
}

.nav-logout:hover {
  background: rgba(164, 95, 95, 0.1);
}

.nav-submenu {
  background: var(--surface);
  border-color: var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 0.55rem;
}

.nav-submenu a {
  border-radius: 11px;
  padding: 0.7rem 0.8rem;
}

.user-chip {
  align-items: center;
  color: var(--text-muted);
  display: flex;
  font-size: 0.72rem;
  gap: 0.55rem;
  max-width: 190px;
}

.user-chip strong {
  color: var(--text-main);
}

.user-avatar {
  align-items: center;
  background: var(--primary);
  border: 3px solid rgba(255, 255, 255, 0.65);
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(146, 118, 89, 0.18);
  color: white;
  display: inline-flex;
  flex: 0 0 auto;
  font-family: "DM Serif Display", serif;
  font-size: 1rem;
  height: 36px;
  justify-content: center;
  width: 36px;
}

.mobile-nav-toggle {
  background: transparent;
  border: 0;
  cursor: pointer;
  display: none;
  padding: 0.6rem;
}

.mobile-nav-toggle > span:not(.sr-only) {
  background: var(--text-main);
  display: block;
  height: 2px;
  margin: 4px 0;
  width: 22px;
}

/* Main surfaces */
.container {
  margin: 0 auto;
  max-width: 1280px;
  padding: 2.75rem 1.5rem 4rem;
  position: relative;
  z-index: 1;
}

.card {
  background: rgba(255, 252, 248, 0.93);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  margin-bottom: 1.5rem;
  padding: clamp(1.25rem, 2.5vw, 2rem);
}

.dashboard-header {
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.75rem;
  padding-bottom: 1.5rem;
}

.dashboard-header h1 {
  margin: 0;
}

.dashboard-header p,
.page-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  letter-spacing: 0.04em;
}

.page-header {
  align-items: flex-end;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: 2rem;
}

.page-header h1 {
  margin: 0.45rem 0 0;
}

.page-header p {
  color: var(--text-muted);
  margin: 0.35rem 0 0;
}

.page-eyebrow {
  color: var(--primary);
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.back-link {
  align-items: center;
  color: var(--text-muted);
  display: inline-flex;
  font-size: 0.8rem;
  font-weight: 600;
  gap: 0.35rem;
  text-decoration: none;
}

.back-link:hover {
  color: var(--primary-dark);
}

/* Buttons and controls */
.btn {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 999px;
  display: inline-flex;
  font-family: "Montserrat", sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  justify-content: center;
  letter-spacing: 0.01em;
  min-height: 42px;
  padding: 0.72rem 1.25rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  background: var(--primary);
  box-shadow: 0 8px 18px rgba(146, 118, 89, 0.18);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  box-shadow: 0 10px 22px rgba(146, 118, 89, 0.24);
  transform: translateY(-1px);
}

.btn-secondary,
.btn:not(.btn-primary):not(.icon-btn) {
  background: transparent !important;
  border-color: var(--border) !important;
  color: var(--text-main) !important;
}

.btn-secondary:hover,
.btn:not(.btn-primary):not(.icon-btn):hover {
  background: var(--primary-soft) !important;
}

.icon-btn {
  border: 1px solid var(--border);
  border-radius: 50%;
  height: 42px;
  min-height: 42px;
  width: 42px;
}

.icon-btn-consultas,
.icon-btn-editar,
.icon-btn-encaminhamento,
.icon-btn-relatorio {
  background: #f4ede6;
  color: var(--primary-dark);
}

.icon-btn:hover {
  background: var(--primary-soft);
}

input,
select,
textarea {
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-family: "Montserrat", sans-serif;
  font-size: 0.9rem;
  min-height: 46px;
  padding: 0.78rem 0.95rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

textarea {
  min-height: 120px;
}

input::placeholder,
textarea::placeholder {
  color: #aaa19b;
}

input:focus,
select:focus,
textarea:focus {
  background: white;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(184, 154, 122, 0.13);
  outline: none;
}

label {
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 600 !important;
}

input[type="checkbox"] {
  accent-color: var(--primary);
}

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

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

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.password-card {
  max-width: 680px;
}

.password-field + .password-field {
  margin-top: 1.25rem;
}

.password-field label {
  display: block;
  margin-bottom: 0.45rem;
}

.password-field input {
  width: 100%;
}

.field-help {
  color: var(--text-muted);
  display: block;
  font-size: 0.72rem;
  margin-top: 0.45rem;
}

.search-form {
  align-items: start;
  display: grid;
  gap: 0.75rem;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  margin-bottom: 1.5rem;
}

/* Metrics and charts */
.metric-grid {
  gap: 1rem;
}

.metric-card {
  background:
    linear-gradient(145deg, rgba(255, 252, 248, 0.98), rgba(244, 237, 230, 0.85));
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: none;
  min-height: 145px;
  overflow: hidden;
  padding: 1.45rem;
  position: relative;
}

.metric-card::after {
  border: 1px solid rgba(184, 154, 122, 0.25);
  border-radius: 50%;
  content: "";
  height: 90px;
  position: absolute;
  right: -35px;
  top: -35px;
  width: 90px;
}

.metric-card strong {
  color: var(--primary-dark);
  font-family: "DM Serif Display", serif;
  font-size: 2.85rem;
  font-weight: 400;
  margin-top: 1.1rem;
}

.metric-label {
  color: var(--text-muted);
  font-size: 0.68rem;
  letter-spacing: 0.13em;
}

.dashboard-grid {
  gap: 1.25rem;
}

.chart-heading {
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 1.25rem;
  padding-bottom: 0.9rem;
}

.chart-heading h3 {
  font-weight: 400;
}

.chart-heading span {
  color: var(--primary);
  font-size: 0.72rem;
}

.agenda-event {
  background: #f8f2ec;
  border: 1px solid #eadfd3;
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
}

.agenda-event-color-2 {
  background: #f4eee8;
  border-color: #e4d4c5;
  border-left-color: var(--secondary);
}

.bar-track {
  background: #ebe2da;
  height: 8px;
}

.city-fill,
.day-bar-fill {
  background: linear-gradient(90deg, var(--primary), var(--secondary));
}

.day-bar-fill {
  background: linear-gradient(180deg, var(--secondary), var(--primary));
}

.empty-chart,
.empty-state {
  background: rgba(244, 237, 230, 0.62);
  border: 1px dashed #d8c8ba;
  border-radius: var(--radius-md);
  color: var(--text-muted);
}

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  border-collapse: separate;
  border-spacing: 0;
}

th {
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.65rem;
  letter-spacing: 0.1em;
  padding: 0.85rem 1rem;
}

td {
  background: transparent;
  border-bottom: 1px solid var(--border-soft);
  padding: 1rem;
}

td:first-child,
td:last-child {
  border-radius: 0;
}

tbody tr:hover td {
  background: rgba(234, 223, 211, 0.38);
}

/* Messages */
.msg {
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
}

.msg-error {
  background: #f8ece9;
  border-color: #e5c8c2;
  color: #8a5450;
}

/* Patient record */
.patient-header {
  border-bottom: 1px solid var(--border);
  padding-bottom: 1.5rem;
}

.record-card-title {
  border-bottom-color: var(--border) !important;
}

.patient-facts {
  gap: 0 !important;
}

.patient-facts > div {
  border-bottom: 1px solid var(--border-soft);
  padding: 0.7rem 0;
}

.patient-facts > div:last-child {
  border-bottom: 0;
}

.next-consultation {
  background: linear-gradient(135deg, #f3e9df, #faf5ef) !important;
  border-color: var(--border) !important;
  border-radius: var(--radius-md) !important;
}

.timeline::before {
  background: #dfd1c4 !important;
}

.timeline-item::before {
  background: var(--primary) !important;
  border-color: var(--surface) !important;
  box-shadow: 0 0 0 2px #d8c6b5 !important;
}

.timeline-entry {
  background: rgba(255, 252, 248, 0.85) !important;
  border-color: var(--border) !important;
  border-left-color: var(--primary) !important;
  border-radius: var(--radius-sm) !important;
}

.timeline-badge {
  background: var(--primary-soft) !important;
  color: var(--primary-dark) !important;
}

/* Login */
body.login-page {
  background:
    radial-gradient(circle at 85% 20%, rgba(184, 154, 122, 0.34), transparent 28rem),
    linear-gradient(135deg, #f5f1eb, #ede1d5);
  padding: 2rem;
}

.login-container {
  background: rgba(255, 252, 248, 0.93);
  border: 1px solid rgba(184, 154, 122, 0.18);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  max-width: 1120px;
  min-height: 680px;
}

.login-sidebar {
  background:
    radial-gradient(circle at 80% 20%, rgba(255, 255, 255, 0.8), transparent 17rem),
    linear-gradient(155deg, #ead9c8 0%, #f4ebe2 58%, #d8bfa6 100%);
}

.login-sidebar::before {
  border: 2px solid rgba(255, 255, 255, 0.62);
  border-radius: 50% 0 0 50%;
  content: "";
  height: 520px;
  position: absolute;
  right: -240px;
  top: 70px;
  transform: rotate(-8deg);
  width: 520px;
}

.login-sidebar img {
  filter: saturate(0.55) sepia(0.08);
  max-height: 84%;
  mix-blend-mode: multiply;
  opacity: 0.92;
}

.login-content {
  background: rgba(255, 252, 248, 0.9);
  padding: clamp(2.5rem, 6vw, 5rem);
}

.login-content h1 {
  font-size: clamp(2.6rem, 5vw, 4rem) !important;
}

.login-content form {
  margin-top: 0.5rem;
}

/* Responsive */
@media (max-width: 1080px) {
  .navbar {
    padding-inline: 1rem;
  }

  .user-chip {
    display: none;
  }
}

@media (max-width: 820px) {
  .nav-container {
    position: relative;
  }

  .mobile-nav-toggle {
    display: block;
  }

  .nav-links {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: none;
    left: 0;
    padding: 0.75rem;
    position: absolute;
    right: 0;
    top: calc(100% + 0.8rem);
  }

  .nav-links.is-open {
    display: grid;
  }

  .nav-links a,
  .nav-menu-button,
  .nav-logout {
    justify-content: flex-start;
    text-align: left;
    width: 100%;
  }

  .nav-dropdown:hover .nav-submenu,
  .nav-dropdown:focus-within .nav-submenu {
    display: block;
    position: static;
  }

  .nav-submenu {
    box-shadow: none;
    margin-top: 0.35rem;
  }

  .container {
    padding: 2rem 1rem 3rem;
  }

  .metric-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .form-grid,
  .form-grid--three {
    grid-template-columns: 1fr;
  }

  .search-form {
    grid-template-columns: 1fr;
  }

  .search-form .btn {
    width: 100%;
  }

  .patient-record-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (max-width: 640px) {
  body.login-page {
    padding: 0;
  }

  .login-container {
    border: 0;
    border-radius: 0;
    min-height: 100vh;
  }

  .login-sidebar {
    display: none;
  }

  .login-content {
    min-height: 100vh;
    padding: 2rem 1.25rem;
  }

  .brand-copy {
    font-size: 0.98rem;
  }

  .dashboard-header,
  .page-header,
  .patient-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .card {
    border-radius: 16px;
  }

  .action-buttons {
    justify-content: flex-start;
  }
}
