/* ═══════════════════════════════════════════════
   EndoClinic — Design System (Light + Dark)
   ═══════════════════════════════════════════════ */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Poppins:wght@600;700;800&display=swap');

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #FFFFFF; --bg2: #F8FAFC; --bg3: #F1F5F9;
  --primary: #1E3A5F; --primary-hover: #162D4A; --primary-light: #E8EEF4;
  --accent: #3B82F6; --accent2: #60A5FA;
  --text: #1E3A5F; --text2: #64748B; --text3: #94A3B8;
  --border: #E2E8F0; --border2: #CBD5E1;
  --success: #16A34A; --success-bg: #DCFCE7;
  --error: #DC2626; --error-bg: #FEE2E2;
  --warning: #F59E0B;
  --card: #FFFFFF; --card-hover: #F8FAFC;
  --sidebar-bg: #FFFFFF;
  --radius: 12px; --radius-sm: 8px; --radius-full: 9999px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Poppins', system-ui, sans-serif;
}
.dark {
  --bg: #0F172A; --bg2: #1E293B; --bg3: #0F172A;
  --primary: #60A5FA; --primary-hover: #93C5FD; --primary-light: #1E3A5F;
  --text: #F1F5F9; --text2: #94A3B8; --text3: #64748B;
  --border: #334155; --border2: #475569;
  --success-bg: rgba(74,222,128,0.1); --error-bg: rgba(248,113,113,0.1);
  --card: #1E293B; --card-hover: #334155;
  --sidebar-bg: #0F172A; --shadow: none;
}

html { scroll-behavior: smooth; }
body { font-family: var(--font); background: var(--bg2); color: var(--text); line-height: 1.6; min-height: 100vh; }
h1, h2, h3, h4 { font-family: var(--font-heading); }
a { text-decoration: none; color: inherit; }
button { cursor: pointer; font-family: var(--font); border: none; background: none; }
input, textarea, select { font-family: var(--font); }

/* ── Utility ── */
.container { max-width: 1400px; margin: 0 auto; }
.flex { display: flex; } .flex-col { flex-direction: column; }
.items-center { align-items: center; } .justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.text-center { text-align: center; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none; }
.shrink-0 { flex-shrink: 0; }

/* ── Animations ── */
@keyframes fadeInUp { from { opacity:0; transform:translateY(24px); } to { opacity:1; transform:translateY(0); } }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes float { 0%,100% { transform:translateY(0); } 50% { transform:translateY(-12px); } }
@keyframes spin { to { transform:rotate(360deg); } }
.animate-fade-in-up { animation: fadeInUp .6s ease-out both; }
.animate-fade-in { animation: fadeIn .4s ease-out both; }
.animate-float { animation: float 6s ease-in-out infinite; }
.animate-float-d1 { animation: float 7s ease-in-out 1s infinite; }
.animate-float-d2 { animation: float 8s ease-in-out 2s infinite; }
.animate-float-d3 { animation: float 6.5s ease-in-out .5s infinite; }
.animate-float-d4 { animation: float 7.5s ease-in-out 1.5s infinite; }

/* ── Layout: Dashboard Shell ── */
.app-shell { display: flex; height: 100vh; overflow: hidden; background: var(--bg2); }
.sidebar { display: flex; flex-direction: column; width: 64px; height: 100vh; border-right: 1px solid var(--border); background: var(--sidebar-bg); transition: width .3s ease; overflow: hidden; flex-shrink: 0; }
.sidebar:hover { width: 240px; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; height: 64px; padding: 0 16px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.sidebar-brand i,
.sidebar-brand svg {
  color: var(--primary);
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  stroke: currentColor;
}
.sidebar-brand span { font-family: var(--font-heading); font-size: 18px; font-weight: 700; color: var(--text); opacity: 0; transition: opacity .2s; }
.sidebar:hover .sidebar-brand span { opacity: 1; }
.sidebar-nav { flex: 1; padding: 12px 8px; }
.sidebar-nav ul { list-style: none; display: flex; flex-direction: column; gap: 4px; }
.sidebar-footer { border-top: 1px solid var(--border); padding: 12px 8px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: all .15s;
  white-space: nowrap;
}
.nav-item i,
.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke: currentColor;
}
.nav-item span { opacity: 0; transition: opacity .2s; }
.sidebar:hover .nav-item span { opacity: 1; }
.nav-item:hover { background: var(--card-hover); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); border-left: 3px solid var(--primary); }
.nav-item.danger:hover { background: var(--error-bg); color: var(--error); }

.main-area { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.top-header { display: flex; align-items: center; justify-content: space-between; height: 64px; padding: 0 24px; border-bottom: 1px solid var(--border); background: var(--bg); }

/* Área principal: sem isto, conteúdo alto fica cortado (overflow hidden no shell) e não há scroll */
.main-area > #app {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Páginas SPA com wrapper extra entre #app e .main-content */
#app > .endo-pacientes,
#app > .endo-profile,
#app > .endo-paciente-detalhe {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-content { flex: 1; min-height: 0; overflow-y: auto; padding: 24px; }

/* ── Theme Toggle ── */
.theme-toggle { width: 36px; height: 36px; border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; color: var(--text2); transition: all .15s; }
.theme-toggle:hover { background: var(--bg2); color: var(--text); }

/* ── User Avatar ── */
.avatar { width: 32px; height: 32px; border-radius: var(--radius-full); background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.avatar-lg { width: 48px; height: 48px; font-size: 18px; }

/* ── Cards ── */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.card-compact { padding: 16px; }

/* ── Stat Cards ── */
.stat-card { display: flex; align-items: center; gap: 16px; }
.stat-icon { width: 48px; height: 48px; border-radius: var(--radius-sm); background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; }
.stat-icon i { width: 24px; height: 24px; }
.stat-label { font-size: 14px; color: var(--text2); }
.stat-value { font-size: 24px; font-weight: 700; color: var(--text); }

/* ── Badges ── */
.badge { display: inline-flex; padding: 2px 10px; border-radius: var(--radius-full); font-size: 12px; font-weight: 500; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-blue { background: #DBEAFE; color: #1E3A5F; }
.badge-pink { background: #FCE7F3; color: #BE185D; }
.badge-neutral { background: var(--bg2); color: var(--text2); }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-green { background: #D1FAE5; color: #065F46; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; border-radius: var(--radius); font-size: 14px; font-weight: 500; transition: all .2s; }
.btn-primary { background: #1E3A5F; color: white; }
.btn-primary:hover { background: #162D4A; }
.btn-outline { border: 1px solid var(--border); color: var(--text); background: transparent; }
.btn-outline:hover { background: var(--bg2); }
.btn-block { width: 100%; }
.btn-lg { height: 48px; font-size: 14px; font-weight: 600; }
.btn i { width: 16px; height: 16px; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: var(--radius-sm); color: var(--text3); }
.btn-icon:hover { background: var(--primary-light); color: var(--primary); }
.btn-icon.danger:hover { background: var(--error-bg); color: var(--error); }

/* Botão durante fetch — bolinha + rótulo */
.btn.btn-is-loading {
  pointer-events: none;
  opacity: 0.9;
}
.btn .btn-spinner {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btnSpinnerRotate 0.65s linear infinite;
}
.btn-primary .btn-spinner {
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
}
.btn-outline .btn-spinner,
.btn.btn-outline .btn-spinner {
  border-color: rgba(30, 58, 95, 0.2);
  border-top-color: var(--primary);
}
.btn .btn-loading-label {
  font-size: 14px;
  font-weight: 500;
}
@keyframes btnSpinnerRotate {
  to { transform: rotate(360deg); }
}

/* ── Inputs ── */
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 14px; font-weight: 500; color: var(--text); }
.form-input { width: 100%; height: 46px; padding: 0 16px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg2); font-size: 14px; color: var(--text); outline: none; transition: all .2s; }
.form-input::placeholder { color: var(--text3); }
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,0.1); }
.form-input-icon { padding-left: 48px; }
.form-textarea { height: auto; padding: 12px 16px; resize: none; }
.input-wrapper { position: relative; }
.input-icon { position: absolute; left: 16px; top: 50%; transform: translateY(-50%); color: var(--text3); pointer-events: none; }
.input-icon i { width: 18px; height: 18px; }

/* ── Tables ── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 900px; }
thead tr { background: var(--bg2); }
th { padding: 10px 12px; text-align: left; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text); white-space: nowrap; }
td { padding: 10px 12px; font-size: 14px; color: var(--text2); white-space: nowrap; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--primary-light); }
tbody tr.even { background: var(--bg2); }
.td-primary { color: var(--text); font-weight: 500; }

/* ── Section Headers ── */
.section-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 24px; border-bottom: 1px solid var(--border); }
.section-title { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 600; color: var(--text); }
.section-title i { width: 20px; height: 20px; color: var(--primary); }

/* ── Patient Row ── */
.patient-row { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); transition: background .15s; }
.patient-row:hover { background: var(--card-hover); }
.patient-row .avatar { background: var(--primary-light); color: var(--primary); }
.patient-info { flex: 1; min-width: 0; }
.patient-name { font-size: 14px; font-weight: 600; color: var(--text); }
.patient-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.patient-meta .dot { margin: 0 6px; color: var(--border2); }

/* ── Search Bar ── */
.search-bar { position: relative; }
.search-bar input { height: 40px; padding: 0 16px 0 40px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); font-size: 14px; color: var(--text); outline: none; width: 320px; transition: all .2s; }
.search-bar input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(30,58,95,0.1); }
.search-bar i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text3); width: 18px; height: 18px; }

/* ── Modal ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; animation: fadeIn .2s ease; }
.modal-overlay.hidden { display: none !important; }
.modal { background: var(--card); border-radius: var(--radius); width: 90%; max-width: 520px; max-height: 90vh; overflow-y: auto; animation: fadeInUp .3s ease; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 18px; font-weight: 600; color: var(--text); }
.modal-body { padding: 24px; }

/* Modal: novo paciente (layout — disponível em dashboard e pacientes) */
#add-patient-modal .modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text2);
}
#add-patient-modal .modal-close:hover { background: var(--bg2); color: var(--text); }
#add-patient-modal .modal-close-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}
#add-patient-modal select.form-input {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 40px;
}
#add-patient-modal .form-label-hint {
  font-weight: 400;
  color: var(--text3);
}
/* Novo paciente: sem scroll no viewport típico */
#add-patient-modal .modal {
  max-height: none;
  overflow: visible;
}
#add-patient-modal .modal-header {
  padding: 14px 18px;
}
#add-patient-modal .modal-body {
  padding: 16px 20px 18px;
}
#add-patient-modal #add-patient-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
#add-patient-modal #add-patient-form .form-textarea {
  min-height: 0;
}
@media (max-height: 640px) {
  #add-patient-modal .modal {
    max-height: min(92vh, 900px);
    overflow-y: auto;
  }
}

/* Modal: confirmação excluir paciente */
#delete-patient-modal {
  z-index: 110;
}
#delete-patient-modal .modal-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  color: var(--text2);
}
#delete-patient-modal .modal-close:hover { background: var(--bg2); color: var(--text); }
#delete-patient-modal .modal-close-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}
.modal--confirm-delete {
  max-width: 440px;
}
.modal-delete-lead {
  font-size: 15px;
  color: var(--text);
  line-height: 1.5;
  margin: 0 0 12px;
}
.modal-delete-lead strong {
  color: var(--text);
  font-weight: 600;
}
.modal-delete-hint {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.5;
  margin: 0;
}
.modal-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}
.modal-footer--end {
  justify-content: flex-end;
}
.btn-danger-solid {
  background: #dc2626;
  color: #fff;
  border: 1px solid #dc2626;
}
.btn-danger-solid:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

/* ── Auth Pages ── */
.auth-layout { display: flex; min-height: 100vh; }
.auth-left { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; background: white; }
.auth-right { width: 40%; display: flex; flex-direction: column; align-items: center; justify-content: center; background: linear-gradient(to bottom, #1E3A5F, #0F172A); position: relative; overflow: hidden; }
.auth-right-content { position: relative; z-index: 10; max-width: 380px; padding: 0 40px; text-align: center; }
.auth-right h2 { font-family: var(--font-heading); font-size: 30px; font-weight: 700; color: white; line-height: 1.3; }
.auth-right p { margin-top: 16px; font-size: 18px; color: rgba(255,255,255,0.8); line-height: 1.7; }
.feature-pill { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border: 1px solid rgba(255,255,255,0.15); background: rgba(255,255,255,0.1); border-radius: 16px; backdrop-filter: blur(4px); }
.feature-pill i { width: 20px; height: 20px; color: rgba(255,255,255,0.9); flex-shrink: 0; }
.feature-pill span { font-size: 14px; font-weight: 500; color: rgba(255,255,255,0.9); }
.floating-icon { position: absolute; color: rgba(255,255,255,0.08); }
.dot-pattern { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ── Grid ── */
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
.grid-detail { display: grid; grid-template-columns: 45% 1fr; gap: 24px; }
.space-y-4 > * + * { margin-top: 16px; }
.space-y-5 > * + * { margin-top: 20px; }
.space-y-6 > * + * { margin-top: 24px; }
.space-y-8 > * + * { margin-top: 32px; }

/* ── Responsive ── */
@media (max-width: 1024px) {
  .auth-right { display: none; }
  .auth-left { width: 100%; }
  .grid-detail { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 768px) {
  .grid-3 { grid-template-columns: 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .search-bar input { width: 100%; }
}
