/* ============================================================
   App Clínica v1.0 — Design System Global
   Fonte: Inter (Google Fonts)
   Paleta: Azul hospitalar #0ea5e9 + Verde #10b981
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ---------- Variáveis CSS ---------- */
:root {
  --primary: #0ea5e9;
  --primary-dark: #0284c7;
  --primary-light: #e0f2fe;
  --accent: #10b981;
  --accent-dark: #059669;
  --accent-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --dark: #0f172a;
  --dark-2: #1e293b;
  --dark-3: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
  --bg-2: #f1f5f9;
  --white: #ffffff;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 16px rgba(0, 0, 0, .06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, .07), 0 10px 30px rgba(0, 0, 0, .10);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, .14);
  --transition: .22s cubic-bezier(.4, 0, .2, 1);
  --font: 'Inter', system-ui, sans-serif;
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  font-size: 16px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--dark);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: var(--primary);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--primary-dark);
}

img {
  max-width: 100%;
  display: block;
}

ul,
ol {
  list-style: none;
}

input,
select,
textarea,
button {
  font-family: inherit;
}

/* ---------- Tipografia ---------- */
h1 {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
}

h3 {
  font-size: 1.25rem;
  font-weight: 600;
}

h4 {
  font-size: 1.1rem;
  font-weight: 600;
}

h5 {
  font-size: 1rem;
  font-weight: 600;
}

p {
  color: var(--muted);
}

.text-sm {
  font-size: .875rem;
}

.text-xs {
  font-size: .75rem;
}

.text-muted {
  color: var(--muted);
}

.text-primary {
  color: var(--primary);
}

.text-accent {
  color: var(--accent);
}

.font-bold {
  font-weight: 700;
}

.font-semibold {
  font-weight: 600;
}

/* ---------- Layout ---------- */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.container-sm {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* ---------- Navbar ---------- */
.navbar {
  background: var(--white);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 8px rgba(0, 0, 0, .06);
}

.navbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--dark);
}

.navbar-brand .brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: 1.1rem;
  font-weight: 800;
}

.navbar-menu {
  display: flex;
  align-items: center;
  gap: .25rem;
}

.navbar-menu a {
  display: flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .85rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  color: var(--muted);
  transition: background var(--transition), color var(--transition);
}

.navbar-menu a:hover,
.navbar-menu a.active {
  background: var(--primary-light);
  color: var(--primary);
}

.navbar-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.nav-user {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .4rem .8rem;
  border-radius: 50px;
  background: var(--bg-2);
  font-size: .875rem;
  font-weight: 500;
}

.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--white);
  font-size: .8rem;
  font-weight: 700;
}

/* ---------- Sidebar (painéis) ---------- */
.layout-sidebar {
  display: flex;
  min-height: calc(100vh - 64px);
}

.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--white);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
}

.sidebar-section {
  margin-bottom: 1.5rem;
}

.sidebar-label {
  padding: 0 1.25rem;
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: .4rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 1.25rem;
  font-size: .9rem;
  font-weight: 500;
  color: var(--dark-3);
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background: var(--bg);
  color: var(--primary);
}

.sidebar-link.active {
  background: var(--primary-light);
  color: var(--primary);
  border-left-color: var(--primary);
}

.sidebar-link .icon {
  font-size: 1.1rem;
  opacity: .8;
}

.main-content {
  flex: 1;
  padding: 2rem 2rem;
  overflow-x: hidden;
}

/* ---------- Page Header ---------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title h2 {
  color: var(--dark);
}

.page-title p {
  font-size: .9rem;
  margin-top: .2rem;
}

/* ---------- Cards ---------- */
.card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  color: var(--dark);
  font-size: 1rem;
}

.card-body {
  padding: 1.5rem;
}

.card-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--bg);
}

/* ---------- Stat Cards ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-icon {
  width: 52px;
  height: 52px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}

.stat-icon.blue {
  background: var(--primary-light);
  color: var(--primary);
}

.stat-icon.green {
  background: var(--accent-light);
  color: var(--accent);
}

.stat-icon.orange {
  background: var(--warning-light);
  color: var(--warning);
}

.stat-icon.red {
  background: var(--danger-light);
  color: var(--danger);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--dark);
  line-height: 1;
}

.stat-label {
  font-size: .8rem;
  color: var(--muted);
  margin-top: .25rem;
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  padding: .6rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(14, 165, 233, .4);
}

.btn-accent {
  background: var(--accent);
  color: var(--white);
}

.btn-accent:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, .4);
}

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--primary);
}

.btn-outline:hover {
  background: var(--primary-light);
}

.btn-danger {
  background: var(--danger);
  color: var(--white);
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-ghost {
  background: var(--bg-2);
  color: var(--dark-3);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--border);
}

.btn-sm {
  padding: .4rem .85rem;
  font-size: .8rem;
}

.btn-lg {
  padding: .9rem 2rem;
  font-size: 1rem;
  border-radius: var(--radius);
}

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-sm);
}

/* ---------- Formulários ---------- */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  margin-bottom: .45rem;
  font-size: .875rem;
  font-weight: 600;
  color: var(--dark-2);
}

.form-label .required {
  color: var(--danger);
  margin-left: 2px;
}

.form-control {
  width: 100%;
  padding: .65rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  color: var(--dark);
  background: var(--white);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .15);
}

.form-control::placeholder {
  color: #94a3b8;
}

.form-control.is-invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, .12);
}

.form-error {
  color: var(--danger);
  font-size: .8rem;
  margin-top: .3rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row.cols-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

textarea.form-control {
  min-height: 100px;
  resize: vertical;
}

select.form-control {
  cursor: pointer;
}

/* ---------- Tabelas ---------- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.table th {
  background: var(--bg-2);
  padding: .85rem 1rem;
  text-align: left;
  font-size: .78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
}

.table td {
  padding: .9rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--dark-3);
  vertical-align: middle;
}

.table tbody tr {
  transition: background var(--transition);
}

.table tbody tr:hover {
  background: var(--bg);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table-empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  font-size: .95rem;
}

/* ---------- Badges / Status ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .25rem .7rem;
  border-radius: 50px;
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.badge-blue {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.badge-green {
  background: var(--accent-light);
  color: var(--accent-dark);
}

.badge-orange {
  background: var(--warning-light);
  color: #92400e;
}

.badge-red {
  background: var(--danger-light);
  color: #991b1b;
}

.badge-gray {
  background: var(--bg-2);
  color: var(--muted);
}

/* ---------- Alertas ---------- */
.alert {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  font-weight: 500;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  margin-bottom: 1rem;
  border-left: 4px solid;
}

.alert-success {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent-dark);
}

.alert-danger {
  background: var(--danger-light);
  border-color: var(--danger);
  color: #991b1b;
}

.alert-warning {
  background: var(--warning-light);
  border-color: var(--warning);
  color: #92400e;
}

.alert-info {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary-dark);
}

/* ---------- Fila de Espera ---------- */
.fila-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  margin-bottom: .75rem;
  box-shadow: var(--shadow);
  transition: all var(--transition);
}

.fila-card:hover {
  transform: translateX(4px);
  border-color: var(--primary);
}

.fila-pos {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: var(--white);
  font-weight: 800;
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.fila-info {
  flex: 1;
}

.fila-nome {
  font-weight: 600;
  color: var(--dark);
}

.fila-desc {
  font-size: .82rem;
  color: var(--muted);
}

.fila-espera {
  font-size: .82rem;
  font-weight: 600;
  color: var(--primary);
  text-align: right;
}

/* ---------- Página de Login ---------- */
.login-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 50%, #0ea5e9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.login-box {
  background: rgba(255, 255, 255, .97);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 440px;
  overflow: hidden;
}

.login-header {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  padding: 2.5rem;
  text-align: center;
}

.login-header .logo-mark {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  background: rgba(255, 255, 255, .2);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1rem;
  font-size: 2rem;
  color: var(--white);
}

.login-header h1 {
  color: var(--white);
  font-size: 1.5rem;
}

.login-header p {
  color: rgba(255, 255, 255, .8);
  font-size: .9rem;
  margin-top: .3rem;
}

.login-body {
  padding: 2rem;
}

.login-tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 1.75rem;
  gap: 2px;
}

.login-tabs .tab {
  padding: .5rem .25rem;
  border-radius: 6px;
  font-size: .72rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: all var(--transition);
  color: var(--muted);
  border: none;
  background: transparent;
}

.login-tabs .tab.active {
  background: var(--white);
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .1);
}

/* ---------- Responsividade ---------- */
@media (max-width: 900px) {
  .sidebar {
    display: none;
  }

  .form-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 600px) {
  h1 {
    font-size: 1.5rem;
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .navbar-menu {
    display: none;
  }

  .main-content {
    padding: 1rem;
    padding-bottom: 5rem;
    /* Espaço para a mobile-nav */
  }
}

/* ---------- Mobile Bottom Nav ---------- */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--white);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
  z-index: 1000;
  padding: 0.5rem 0.25rem env(safe-area-inset-bottom);
}

@media (max-width: 900px) {
  .mobile-nav {
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--muted);
  gap: 0.2rem;
  flex: 1;
  min-width: 0;
}

.mobile-nav-item .icon {
  font-size: 1.25rem;
  line-height: 1;
}

.mobile-nav-item .label {
  font-size: 0.65rem;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  width: 100%;
}

.mobile-nav-item.active {
  color: var(--primary);
}

/* ---------- Utilitários ---------- */
.flex {
  display: flex;
}

.flex-center {
  display: flex;
  align-items: center;
  justify-content: center;
}

.gap-1 {
  gap: .5rem;
}

.gap-2 {
  gap: 1rem;
}

.gap-3 {
  gap: 1.5rem;
}

.mt-1 {
  margin-top: .5rem;
}

.mt-2 {
  margin-top: 1rem;
}

.mb-1 {
  margin-bottom: .5rem;
}

.mb-2 {
  margin-bottom: 1rem;
}

.mb-3 {
  margin-bottom: 1.5rem;
}

.mb-4 {
  margin-bottom: 2rem;
}

.p-0 {
  padding: 0 !important;
}

.d-none {
  display: none;
}

.w-100 {
  width: 100%;
}

.text-center {
  text-align: center;
}

.text-right {
  text-align: right;
}

/* ---------- Animações ---------- */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse-ring {
  0% {
    box-shadow: 0 0 0 0 rgba(14, 165, 233, .4);
  }

  70% {
    box-shadow: 0 0 0 10px rgba(14, 165, 233, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(14, 165, 233, 0);
  }
}

.animate-fade {
  animation: fadeInUp .4s ease both;
}

.animate-pulse {
  animation: pulse-ring 2s infinite;
}

/* ---------- Loading Spinner ---------- */
.spinner {
  width: 22px;
  height: 22px;
  border: 3px solid rgba(255, 255, 255, .3);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Impressão (PDF) ---------- */
@media print {

  .navbar,
  .sidebar,
  .btn,
  .navbar-actions,
  .card-header button,
  #form-anexo,
  hr,
  .flex.gap-1,
  .btn-primary,
  .btn-accent {
    display: none !important;
  }

  .layout-sidebar {
    display: block;
  }

  .main-content {
    padding: 0;
    margin: 0;
    width: 100%;
  }

  body {
    background: white;
  }

  .card {
    border: none;
    box-shadow: none;
    margin-bottom: 2rem;
  }

  .card-header {
    border-bottom: 2px solid var(--dark);
    padding: 0.5rem 0;
  }

  .card-header h3 {
    font-size: 1.5rem;
  }

  .table th {
    background: #eee !important;
    color: black !important;
  }

  .page-header {
    margin-bottom: 2rem;
    border-bottom: 1px solid #eee;
    padding-bottom: 1rem;
  }

  .grid {
    display: block;
  }

  .col-span-2 {
    width: 100%;
  }

  canvas {
    max-width: 100% !important;
    height: auto !important;
  }
}

/* ---------- Toast ---------- */
#toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.toast {
  background: var(--dark-2);
  color: var(--white);
  padding: .9rem 1.25rem;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  min-width: 260px;
  display: flex;
  align-items: center;
  gap: .75rem;
  animation: fadeInUp .3s ease;
}

.toast.toast-success {
  border-left: 4px solid var(--accent);
}

.toast.toast-error {
  border-left: 4px solid var(--danger);
}

.toast.toast-info {
  border-left: 4px solid var(--primary);
}