/* ========================================
   RESET E VARIÁVEIS GLOBAIS
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6366f1; /* Indigo from the image vibe */
  --primary-dark: #4f46e5;
  --bg-sidebar: #ffffff;
  --bg-body: #f3f4f6;
  --text-main: #1f2937;
  --text-muted: #6b7280;
  --accent-purple: #8b5cf6;
  --accent-blue: #3b82f6;
  --accent-green: #10b981;
  --accent-red: #ef4444;
  --accent-orange: #f59e0b;
  --border-color: #e5e7eb;
  --card-shadow:
    0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  --sidebar-width: 260px;
  --sidebar-compact-width: 88px;
  --page-bottom-clearance: calc(72px + env(safe-area-inset-bottom, 0px));
}

html,
body {
  min-height: 100%;
}

body {
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
}

a {
  text-decoration: none;
  color: inherit;
}

ul {
  list-style: none;
}

/* ========================================
   LAYOUT GRID
   ======================================== */
.dashboard-container {
  display: flex;
  min-height: 100vh;
  height: auto;
}

/* ========================================
   SIDEBAR
   ======================================== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 1rem calc(4.75rem + env(safe-area-inset-bottom, 0px));
  flex-shrink: 0;
  align-self: flex-start;
  height: 100vh;
  max-height: 100vh;
  overflow-x: hidden;
  overflow-y: auto;
  position: sticky;
  top: 0;
  transition: width 0.25s ease, padding 0.25s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 2rem;
  padding: 0 0.5rem;
}

/* Quando o profissional tem logo própria, ela ocupa todo o espaço do cabeçalho */
.sidebar-clinic-logo {
  display: block;
  width: 100%;
  max-height: 64px;
  object-fit: contain;
  object-position: left center;
  border-radius: 8px;
}

.logo-icon {
  display: none !important;
}

.brand-name {
  width: min(100%, 188px);
  min-height: 54px;
  flex: 0 1 188px;
  font-size: 0;
  line-height: 0;
  color: transparent !important;
  position: relative;
  overflow: hidden;
}

.brand-name::before {
  content: "";
  display: block;
  width: 100%;
  height: 54px;
  background: url("/assets/imgs/bioplany-logopng.png") center/contain no-repeat;
}

.brand-name br,
.brand-name span {
  display: none !important;
}

.menu-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  padding-left: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
}

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

.nav-item {
  display: flex;
  align-items: center;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  color: var(--text-muted);
  font-weight: 500;
  transition: all 0.2s;
  cursor: pointer;
  white-space: nowrap;
}

.nav-item:hover {
  background-color: #f3f4f6;
  color: var(--primary);
}

.nav-item.active {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.4);
}

.nav-icon {
  margin-right: 12px;
  width: 20px;
  text-align: center;
  font-size: 1.1rem;
}

.spacer {
  flex-grow: 1;
}

.sidebar-bottom-actions {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 0;
  margin-top: auto;
  padding-top: 1rem;
  width: 100%;
}

.logout-btn {
  margin-top: auto;
  color: var(--accent-red);
}
.logout-btn:hover {
  background-color: #fef2f2;
  color: var(--accent-red);
}

body.menu-compact .sidebar,
html.menu-compact .sidebar {
  width: var(--sidebar-compact-width);
  padding-left: 0.75rem;
  padding-right: 0.75rem;
}

body.menu-compact .sidebar-header,
html.menu-compact .sidebar-header {
  justify-content: center;
  padding: 0;
}

body.menu-compact .sidebar-clinic-logo,
html.menu-compact .sidebar-clinic-logo {
  max-height: 48px;
}

body.menu-compact .sidebar-header::before,
html.menu-compact .sidebar-header::before {
  content: "";
  display: block;
  width: 76px !important;
  height: 76px !important;
  background: url("/assets/imgs/bioplany-logo-pequeno.png?v=20260325-0116") center/contain no-repeat !important;
}

body.menu-compact .sidebar-header .sidebar-clinic-logo,
body.menu-compact .sidebar-header .logo-icon,
body.menu-compact .sidebar-header .brand-name,
html.menu-compact .sidebar-header .sidebar-clinic-logo,
html.menu-compact .sidebar-header .logo-icon,
html.menu-compact .sidebar-header .brand-name {
  display: none !important;
}

body.menu-compact .brand-name,
body.menu-compact .menu-label,
html.menu-compact .brand-name,
html.menu-compact .menu-label {
  display: none;
}

body.menu-compact .nav-item,
body.menu-compact .logout-btn,
html.menu-compact .nav-item,
html.menu-compact .logout-btn {
  justify-content: center;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  font-size: 0;
}

body.menu-compact .nav-icon,
html.menu-compact .nav-icon {
  margin-right: 0;
  width: auto;
  min-width: 20px;
  font-size: 1.15rem;
}

body.menu-compact .logout-btn .nav-icon,
html.menu-compact .logout-btn .nav-icon {
  color: inherit;
}

.sidebar-compact-toggle {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--primary);
  padding: 0;
  box-shadow: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
  transition: transform 0.2s ease, color 0.2s ease, opacity 0.2s ease;
}

.sidebar-compact-toggle:hover {
  transform: translateY(-2px);
  color: var(--accent-purple);
}

.sidebar-compact-toggle:focus-visible {
  outline: 2px solid rgba(99, 102, 241, 0.22);
  outline-offset: 2px;
}

.sidebar-compact-toggle__icon {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.sidebar-bottom-actions .logout-btn {
  margin-top: 0;
  flex: 0 1 auto;
  align-self: center;
  padding-right: 0.24rem;
}

.sidebar-bottom-actions .sidebar-compact-toggle {
  position: static;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  align-self: center;
  margin-left: auto;
}

.sidebar-bottom-actions .sidebar-compact-toggle__icon {
  font-size: 1.65rem;
}

@media (min-width: 769px) and (max-height: 900px) {
  .sidebar {
    padding: 1.1rem 0.85rem calc(4.1rem + env(safe-area-inset-bottom, 0px));
  }

  .sidebar-header {
    gap: 10px;
    margin-bottom: 1.2rem;
    padding: 0 0.35rem;
  }

  .sidebar-clinic-logo {
    max-height: 52px;
  }

  .logo-icon {
    width: 36px;
    height: 36px;
    font-size: 18px;
  }

  .brand-name {
    font-size: 1rem;
  }

  .menu-label {
    font-size: 0.68rem;
    margin-bottom: 0.35rem;
    padding-left: 0.6rem;
  }

  .nav-menu {
    gap: 0.3rem;
  }

  .nav-item,
  .logout-btn {
    padding: 0.58rem 0.85rem;
    font-size: 0.95rem;
  }

  .nav-icon {
    margin-right: 10px;
    width: 18px;
    font-size: 1rem;
  }

  .sidebar-compact-toggle {
    right: 4px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .sidebar-compact-toggle__icon {
    font-size: 1.65rem;
  }
}

@media (min-width: 769px) and (max-height: 780px) {
  .sidebar {
    padding: 0.95rem 0.75rem calc(3.75rem + env(safe-area-inset-bottom, 0px));
  }

  .sidebar-header {
    gap: 8px;
    margin-bottom: 0.9rem;
  }

  .sidebar-clinic-logo {
    max-height: 46px;
  }

  .logo-icon {
    width: 34px;
    height: 34px;
    font-size: 17px;
  }

  .brand-name {
    font-size: 0.92rem;
  }

  .menu-label {
    font-size: 0.64rem;
    margin-bottom: 0.2rem;
  }

  .nav-menu {
    gap: 0.2rem;
  }

  .nav-item,
  .logout-btn {
    padding: 0.48rem 0.75rem;
    font-size: 0.9rem;
  }

  .nav-icon {
    margin-right: 9px;
    font-size: 0.95rem;
  }

.sidebar-compact-toggle__icon {
  font-size: 1.5rem;
}
}

/* ========================================
   MARCA BIOPLANY
   ======================================== */
.sidebar-header {
  position: relative;
  justify-content: center;
}

.logo-icon {
  display: none !important;
}

.brand-name {
  width: min(100%, 188px);
  min-height: 54px;
  flex: 0 1 188px;
  font-size: 0;
  line-height: 0;
  color: transparent !important;
  position: relative;
  overflow: hidden;
}

.brand-name::before {
  content: "";
  display: block;
  width: 100%;
  height: 54px;
  background: url("/assets/imgs/bioplany-logopng.png") center/contain no-repeat;
}

.brand-name br,
.brand-name span {
  display: none !important;
}

body.menu-compact .sidebar-header::before,
html.menu-compact .sidebar-header::before {
  content: "";
  display: block;
  width: 68px;
  height: 68px;
  background: url("/assets/imgs/bioplany-logo-pequeno.png?v=20260325-0116") center/138% auto no-repeat;
}

body.menu-compact .sidebar-header .sidebar-clinic-logo,
body.menu-compact .sidebar-header .logo-icon,
body.menu-compact .sidebar-header .brand-name,
html.menu-compact .sidebar-header .sidebar-clinic-logo,
html.menu-compact .sidebar-header .logo-icon,
html.menu-compact .sidebar-header .brand-name {
  display: none !important;
}

/* ========================================
   MAIN CONTENT
   ======================================== */
.main-content {
  flex: 1;
  min-width: 0;
  overflow: visible;
  padding: 2rem;
  padding-bottom: calc(2rem + var(--page-bottom-clearance));
  min-height: 100vh;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-main);
}

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

.user-info {
  text-align: right;
}

.user-name {
  font-weight: 600;
  font-size: 0.9rem;
  display: block;
}

.user-role {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.avatar {
  width: 40px;
  height: 40px;
  background-color: #e5e7eb;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
}

/* ========================================
   WELCOME BANNER
   ======================================== */
.welcome-banner {
  background: linear-gradient(135deg, var(--primary) 0%, #8b5cf6 100%);
  border-radius: 16px;
  padding: 2rem;
  color: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  box-shadow: 0 10px 15px -3px rgba(99, 102, 241, 0.3);
  position: relative;
  overflow: hidden;
}

.banner-content {
  z-index: 10;
  max-width: 70%;
}

.banner-title {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.banner-subtitle {
  opacity: 0.9;
  font-size: 1rem;
}

.banner-icon {
  background: rgba(255, 255, 255, 0.2);
  width: 60px;
  height: 60px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2rem;
  backdrop-filter: blur(5px);
}

/* ========================================
   STATS GRID & CARDS
   ======================================== */
.stats-grid {
  display: flex;
  gap: 1.5rem;
  flex-wrap: wrap;
  margin-bottom: 2rem;
}

.stat-card {
  flex: 1;
  min-width: 200px;
  background: white;
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: transform 0.2s;
  border: 1px solid white;
  position: relative; /* Needed for split card desktop styling */
}

/* SPLIT CARD STYLES (For Patients/Procedures) */
.stat-content-text {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.stat-content-icon {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
}

/* Shared Stat Styles */
.stat-card:hover {
  transform: translateY(-2px);
  border-color: #e5e7eb;
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 1rem;
}

.stat-title {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-right: 0.5rem; /* space from icon */
}

.stat-icon-bg {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  background-color: #f5f3ff; /* Light purple background */
  color: var(--primary); /* Primary purple color for icon */
  transition: all 0.2s ease;
}

.stat-icon-bg:hover {
  background-color: var(--primary);
  color: white;
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.stat-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ========================================
   BOTTOM SECTIONS
   ======================================== */
.bottom-section {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 2rem;
}

.card-panel {
  background: white;
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: var(--card-shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.panel-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

/* Custom list styling for tasks */
.task-list {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.task-item {
  display: flex;
  align-items: center;
  padding: 0.75rem;
  border-radius: 8px;
  background-color: #f9fafb;
  border-left: 4px solid var(--border-color);
}

.task-item.priority-high {
  border-left-color: var(--accent-red);
}
.task-item.priority-medium {
  border-left-color: var(--accent-orange);
}
.task-item.priority-normal {
  border-left-color: var(--accent-green);
}

.task-content {
  flex: 1;
}

.task-name {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-main);
}
.task-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-badge {
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-blue {
  background: #eff6ff;
  color: var(--accent-blue);
}
.badge-green {
  background: #ecfdf5;
  color: var(--accent-green);
}

/* Birthday bubbles */
.birthday-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.birthday-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bday-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #fbc2eb 0%, #a6c1ee 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  color: white;
  font-weight: bold;
}

/* Mobile Menu Button - Hidden on desktop */
.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-main);
  margin-right: 1rem;
  padding: 0.5rem;
  line-height: 1;
}

/* Overlay for sidebar */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.sidebar-overlay.show {
  display: block;
  opacity: 1;
}

body.no-scroll {
  overflow: hidden;
}

/* ========================================
   RESPONSIVO
   ======================================== */
@media (max-width: 1024px) {
  .stats-grid {
    gap: 1rem;
  }
}

@media (max-width: 768px) {
  :root {
    --page-bottom-clearance: calc(104px + env(safe-area-inset-bottom, 0px));
  }

  .sidebar-compact-toggle {
    display: none;
  }

  /* Allow scrolling on mobile body */
  body {
    height: auto;
    overflow-y: auto;
  }

  /* Show Mobile Menu Button */
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  /* Sidebar - Off-canvas functionality */
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px; /* Hide sidebar */
    width: 280px;
    height: 100vh;
    z-index: 1000;
    transition: left 0.3s ease;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    padding: 1.5rem 1rem;
    border-right: none;
    border-bottom: none;
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
  }

  .sidebar.open {
    left: 0; /* Show sidebar */
  }

  /* Restore Sidebar Elements */
  .sidebar-header,
  .menu-label,
  .logout-btn {
    display: flex !important;
  }
  .spacer {
    display: none !important;
  }
  .sidebar-header {
    margin-bottom: 2rem;
    justify-content: flex-start;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* Reset Nav Menu */
  .nav-menu {
    flex-direction: column;
    overflow-x: visible;
    padding-bottom: 0;
    gap: 0.5rem;
  }

  .sidebar-bottom-actions {
    margin-top: 1rem;
    padding: 0 0.05rem;
  }

  .sidebar-bottom-actions .logout-btn {
    margin-top: 0;
    flex: 0 1 auto;
    padding-right: 0.18rem;
  }

  .sidebar-bottom-actions .sidebar-compact-toggle {
    display: inline-flex;
    position: static;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: transparent;
    color: var(--primary);
    box-shadow: none;
    flex-shrink: 0;
    margin-left: auto;
  }

  .sidebar-bottom-actions .sidebar-compact-toggle__icon {
    font-size: 1.6rem;
  }

  .nav-item {
    flex-direction: row;
    padding: 0.75rem 1rem;
    font-size: inherit;
    text-align: left;
    white-space: normal;
    justify-content: flex-start;
    flex: none;
  }

  .nav-icon {
    margin-right: 12px;
    margin-bottom: 0;
    font-size: 1.1rem;
  }

  /* Top Bar - Mobile Layout */
  .top-bar {
    justify-content: space-between;
    flex-wrap: wrap;
  }

  .page-title {
    display: block;
    width: 100%;
    order: 3;
    margin-top: 0.5rem;
    font-size: 1.25rem;
  }

  /* Main Content */
  .main-content {
    min-width: 0;
    padding: 1rem;
    padding-bottom: calc(1rem + var(--page-bottom-clearance));
    width: 100%;
    overflow-y: visible;
  }

  .top-bar {
    position: sticky;
    top: 0;
    background: var(--bg-body);
    z-index: 10;
    padding: 0.5rem 0;
    margin-bottom: 1rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    /* Stretch edge-to-edge within padded parent */
    margin-left: -1rem;
    margin-right: -1rem;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .bottom-section {
    grid-template-columns: 1fr;
  }

  /* Responsive Tables (Card View) */
  table,
  thead,
  tbody,
  th,
  td,
  tr {
    display: block;
  }

  thead tr {
    position: absolute;
    top: -9999px;
    left: -9999px;
  }

  tr {
    margin-bottom: 0.75rem;
    border: 2px solid rgba(99, 102, 241, 0.35);
    border-radius: 12px;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    overflow: hidden;
  }

  td {
    border: none;
    border-bottom: 1px solid #eee;
    display: grid;
    grid-template-columns: minmax(96px, 38%) minmax(0, 1fr);
    column-gap: 0.65rem;
    row-gap: 0.2rem;
    align-items: start;
    padding: 0.72rem 0.85rem;
    min-height: 0;
    text-align: left;
    overflow-wrap: anywhere;
  }

  td:before {
    position: static;
    width: auto;
    padding-right: 0;
    white-space: normal;
    line-height: 1.3;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.74rem;
    content: attr(data-label);
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    grid-column: 1;
    grid-row: 1 / span 8;
  }

  td > * {
    grid-column: 2;
    min-width: 0;
    max-width: 100%;
  }

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

  td[colspan] {
    display: block !important;
    width: 100% !important;
    min-height: 0 !important;
    padding: 0.85rem !important;
    text-align: center !important;
  }

  td[colspan]::before {
    content: none !important;
    display: none !important;
  }

  td[colspan] > * {
    grid-column: auto;
  }

  /* Hide label for actions row usually if it is named 'Ações' or similar */
  td[data-label="Ações"]:before,
  td[data-label="Actions"]:before {
    display: none;
  }

  td[data-label="Ação"]:before {
    display: none;
  }

  td[data-label="Ações"]:before {
    display: none;
  }

  td[data-label="AÃ§Ãµes"],
  td[data-label="Ações"],
  td[data-label="Actions"] {
    gap: 0.75rem;
    flex-wrap: wrap;
  }

  td[data-label="Ações"],
  td[data-label="Acoes"],
  td[data-label="Ação"],
  td[data-label="Acao"] {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding-left: 1rem;
  }

  td[data-label="Ações"]::before,
  td[data-label="Acoes"]::before,
  td[data-label="Ação"]::before,
  td[data-label="Acao"]::before {
    display: none;
  }

  td[data-label="Ações"],
  td[data-label="Ação"] {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    padding-left: 1rem;
  }

  td[data-label="Ações"]::before,
  td[data-label="Ação"]::before {
    display: none;
  }

  /* Keep appointments/returns aligned with the two-column mobile card layout. */
  #appointmentsTable td,
  #returnsTable td {
    display: grid !important;
    grid-template-columns: minmax(92px, 34%) minmax(0, 1fr) !important;
    gap: 0.75rem !important;
    align-items: start !important;
    justify-content: stretch !important;
    min-height: 0 !important;
    padding: 0.95rem 1rem !important;
    text-align: left !important;
  }

  #appointmentsTable td::before,
  #returnsTable td::before {
    position: static !important;
    top: auto !important;
    left: auto !important;
    width: auto !important;
    padding-right: 0 !important;
    transform: none !important;
    white-space: normal !important;
    line-height: 1.3 !important;
  }

  #appointmentsTable td:last-child,
  #returnsTable td:last-child {
    display: flex !important;
    justify-content: flex-end !important;
    align-items: center !important;
    gap: 0.5rem !important;
    padding-left: 1rem !important;
  }

  #appointmentsTable td[colspan],
  #returnsTable td[colspan] {
    display: block !important;
    justify-content: initial !important;
    align-items: initial !important;
    width: 100% !important;
    padding: 1rem !important;
    text-align: center !important;
  }

  #appointmentsTable td[colspan]::before,
  #returnsTable td[colspan]::before {
    content: none !important;
    display: none !important;
  }

  #appointmentsTable td[data-label="Ações"]::before,
  #appointmentsTable td[data-label="AÃ§Ãµes"]::before,
  #appointmentsTable td[data-label="AÃƒÂ§ÃƒÂµes"]::before,
  #returnsTable td[data-label="Ações"]::before,
  #returnsTable td[data-label="AÃ§Ãµes"]::before,
  #returnsTable td[data-label="AÃƒÂ§ÃƒÂµes"]::before {
    display: none !important;
  }

  #appointmentsTable td > *,
  #returnsTable td > * {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: anywhere;
    word-break: break-word;
    white-space: normal;
    line-height: 1.35;
  }

  #appointmentsTable td[data-label="Paciente"] > *,
  #returnsTable td[data-label="Paciente"] > * {
    font-weight: 600;
    color: var(--text-main);
  }

  #appointmentsTable td[data-label="Procedimento"] > *,
  #appointmentsTable td[data-label="Referente a"] > *,
  #appointmentsTable td[data-label="Data / Hora"] > *,
  #appointmentsTable td[data-label="Observações"] > *,
  #appointmentsTable td[data-label="ObservaÃ§Ãµes"] > *,
  #returnsTable td[data-label="Referente a"] > *,
  #returnsTable td[data-label="Data / Hora"] > *,
  #returnsTable td[data-label="Observações"] > *,
  #returnsTable td[data-label="ObservaÃ§Ãµes"] > * {
    color: var(--text-muted);
  }

  #appointmentsTable .status-badge,
  #returnsTable .status-badge,
  #appointmentsTable .status-pill,
  #returnsTable .status-pill {
    display: inline-flex;
    align-self: start;
    max-width: 100%;
  }

  #appointmentsTable .appointments-actions,
  #returnsTable .returns-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
  }

  /* Fallback for older appointments markup where notes and actions share the same cell. */
  #appointmentsTable td[data-label="Ações"] > span,
  #appointmentsTable td[data-label="AÃ§Ãµes"] > span,
  #appointmentsTable td[data-label="AÃƒÂ§ÃƒÂµes"] > span {
    display: block;
    width: 100%;
    margin-right: 0 !important;
    color: var(--text-muted);
  }

  #appointmentsTable td[data-label="Ações"] > div,
  #appointmentsTable td[data-label="AÃ§Ãµes"] > div,
  #appointmentsTable td[data-label="AÃƒÂ§ÃƒÂµes"] > div {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
  }

  /* Compact mobile card spacing */
  td {
    column-gap: 0.65rem;
    row-gap: 0.2rem;
    padding: 0.72rem 0.85rem;
  }

  td:last-child:not([colspan]) {
    padding-left: 0.85rem;
  }

  td[colspan] {
    padding: 0.85rem !important;
  }

  #appointmentsTable td,
  #returnsTable td {
    gap: 0.65rem !important;
    padding: 0.78rem 0.85rem !important;
  }

  #appointmentsTable td:last-child,
  #returnsTable td:last-child {
    gap: 0.45rem !important;
    padding-left: 0.85rem !important;
  }

  #appointmentsTable td[colspan],
  #returnsTable td[colspan] {
    padding: 0.85rem !important;
  }

  .status-badge,
  .status-pill {
    white-space: normal;
    text-align: left;
  }

  /* Adjust Search Bar */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
  }

  .search-container {
    margin-right: 0 !important;
    max-width: 100%;
    width: 100%;
  }

  .search-box {
    max-width: 100% !important;
  }

  .btn {
    width: 100%;
  }

  /* Charts */
  .charts-container {
    grid-template-columns: 1fr !important;
  }
}

/* ========================================
   TABLES & LISTS
   ======================================== */
table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--card-shadow);
  margin-bottom: 2rem;
}

th,
td {
  padding: 1rem 1.5rem;
  text-align: left;
}

th {
  background-color: #f9fafb;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-color);
}

td {
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.95rem;
}

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

tr:hover td {
  background-color: #f9fafb;
}

.responsive-cell-text {
  display: block;
  max-width: 100%;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
}

.responsive-cell-text--strong {
  color: var(--text-main);
  font-weight: 600;
}

#appointmentsTable td:last-child,
#returnsTable td:last-child {
  white-space: nowrap;
}

#appointmentsTable .appointments-actions,
#returnsTable .returns-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: nowrap;
  width: auto;
}

#appointmentsTable .appointments-actions form,
#returnsTable .returns-actions form {
  display: inline-flex;
  margin: 0;
}

#returnsTable th:last-child,
#returnsTable td:last-child {
  min-width: 148px;
  width: 148px;
}

#returnsTable td[data-label="Ações"],
#returnsTable td[data-label="AÃ§Ãµes"] {
  white-space: nowrap;
}

#returnsTable td[data-label="Ações"] > div,
#returnsTable td[data-label="AÃ§Ãµes"] > div,
#returnsTable td[data-label="Ações"] .returns-actions,
#returnsTable td[data-label="AÃ§Ãµes"] .returns-actions {
  display: inline-flex !important;
  flex-direction: row !important;
  align-items: center !important;
  justify-content: flex-end !important;
  gap: 0.5rem !important;
  flex-wrap: nowrap !important;
  width: auto !important;
}

#returnsTable td[data-label="Ações"] form,
#returnsTable td[data-label="AÃ§Ãµes"] form {
  display: inline-flex !important;
  margin: 0;
}

.image-modal-shell {
  background: white;
  width: 95%;
  max-width: 1200px;
  height: 90vh;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.image-modal-toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid #ddd;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: #f9fafb;
}

.image-modal-toolbar-primary,
.image-modal-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.image-modal-toolbar-actions .btn {
  width: auto;
}

.image-modal-heading {
  margin: 0;
  font-size: 1.1rem;
  color: #333;
}

.image-modal-toolbar h3 {
  margin: 0;
  font-size: 1.1rem;
  color: #333;
}

.image-modal-divider {
  width: 1px;
  height: 24px;
  background: #ccc;
  flex-shrink: 0;
}

.image-modal-select {
  padding: 6px;
  border-radius: 4px;
  border: 1px solid #ccc;
  font-size: 0.9rem;
}

.image-modal-colors {
  display: flex;
  gap: 5px;
  margin-right: 15px;
  background: #eee;
  padding: 4px;
  border-radius: 20px;
}

.image-modal-line-actions {
  display: flex;
  gap: 5px;
  margin-right: 15px;
}

.image-modal-stage {
  flex: 1;
  display: flex;
  background: #333;
  overflow: hidden;
  position: relative;
}

.image-modal-pane {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-modal-pane--main {
  border-right: 1px solid #555;
}

.image-modal-pane--compare {
  display: none;
  background: #222;
  border-left: 1px solid #555;
}

.image-modal-compare-label {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.image-modal-pane--compare > div:first-child {
  position: absolute;
  top: 10px;
  left: 10px;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
}

@media (max-width: 768px) {
  .image-modal-shell {
    width: 100% !important;
    max-width: none !important;
    height: 100dvh !important;
    border-radius: 0 !important;
  }

  .image-modal-toolbar {
    flex-direction: column !important;
    align-items: stretch !important;
    padding: 0.9rem 1rem !important;
  }

  .image-modal-toolbar-primary,
  .image-modal-toolbar-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
  }

  .image-modal-toolbar-primary {
    justify-content: flex-start;
  }

  .image-modal-heading {
    width: 100%;
    font-size: 1rem;
  }

  .image-modal-toolbar h3 {
    width: 100%;
    font-size: 1rem;
  }

  .image-modal-divider {
    display: none;
  }

  .image-modal-select {
    width: 100%;
    min-height: 42px;
  }

  .image-modal-colors,
  .image-modal-line-actions {
    margin-right: 0;
  }

  .image-modal-stage {
    flex-direction: column;
  }

  .image-modal-pane--main {
    min-height: 44vh;
    border-right: none;
    border-bottom: 1px solid #555;
  }

  .image-modal-pane--compare {
    min-height: 28vh;
    border-left: none;
    border-top: 1px solid #555;
  }

  .image-modal-compare-label {
    left: 50%;
    transform: translateX(-50%);
  }

  .image-modal-pane--compare > div:first-child {
    left: 50% !important;
    transform: translateX(-50%);
  }
}

/* ========================================
   FORMS & INPUTS
   ======================================== */
.form-group {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-main);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="tel"],
select,
textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.95rem;
  transition: all 0.2s;
  font-family: inherit;
  background-color: white;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* Remove Autofill Blue Background */
input:-webkit-autofill,
input:-webkit-autofill:hover, 
input:-webkit-autofill:focus, 
input:-webkit-autofill:active{
    -webkit-box-shadow: 0 0 0 30px white inset !important;
    -webkit-text-fill-color: var(--text-main) !important;
    transition: background-color 5000s ease-in-out 0s;
}

/* ========================================
   BUTTONS
   ======================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  font-size: 0.9rem;
  text-decoration: none;
  gap: 0.5rem;
}

.btn-primary {
  background-color: var(--primary);
  color: white;
  box-shadow: 0 4px 6px -1px rgba(99, 102, 241, 0.4);
}

.btn-primary:hover {
  background-color: var(--primary-dark);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: white;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-secondary:hover {
  background-color: #f9fafb;
  border-color: #d1d5db;
}

.btn-danger {
  background-color: var(--accent-red);
  color: white;
}

.btn-danger:hover {
  background-color: #dc2626;
}

/* ========================================
   UTILITIES & CONTAINERS
   ======================================== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
}

.search-container {
  margin-bottom: 1.5rem;
}

.container-card {
  background: white;
  padding: 2rem;
  border-radius: 16px;
  box-shadow: var(--card-shadow);
}

/* Action Buttons (Standardized Grey) */
.action-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: #6b7280; /* Standardized grey color */
  padding: 4px;
  border-radius: 4px;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}
.action-btn:hover {
  color: #4f46e5; /* Primary color on hover */
  background-color: #f3f4f6;
}

.action-link-grey {
  color: #6b7280;
  text-decoration: none;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  border-radius: 6px;
  transition: all 0.2s;
}
.action-link-grey:hover {
  color: #4f46e5;
  background-color: #f3f4f6;
}

/* Circular Action Buttons Pattern */
.action-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid #d1d5db;
  background-color: white;
  color: #6b7280;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.action-icon-btn svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

.action-icon-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.08);
}

/* Variants */
.action-icon-btn.complete {
  color: #10b981;
  border-color: #10b981;
}
.action-icon-btn.complete:hover {
  background-color: #ecfdf5;
  color: #059669;
}

.action-icon-btn.edit {
  color: #3b82f6;
  border-color: #3b82f6;
}
.action-icon-btn.edit:hover {
  background-color: #eff6ff;
  color: #2563eb;
}

.action-icon-btn.delete {
  color: #ef4444;
  border-color: #ef4444;
}
.action-icon-btn.delete:hover {
  background-color: #fef2f2;
  color: #dc2626;
}

/* ========================================
   PRINT STYLES
   ======================================== */
@media print {
  .sidebar, .mobile-menu-btn, .sidebar-compact-toggle, .user-profile, .btn, .no-print {
    display: none !important;
  }
  .dashboard-container {
    display: block;
    height: auto;
  }
  .main-content {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow: visible;
  }
  body {
    background: white;
    height: auto;
    overflow: visible;
  }
  .report-card, .chart-container {
    break-inside: avoid;
    box-shadow: none;
    border: 1px solid #eee;
  }
}


@media (max-width: 480px) {
  .table {
    background: none !important;
    box-shadow: none !important;
  }
}
