/* =========================================================
   Clínica Suhaila — Design System
   Paleta: navy + Tiffany (accent sutil)
   ========================================================= */

:root {
  --primary: #1e3a5f;
  --primary-dark: #142845;
  --primary-soft: #2d5278;
  --accent: #0ABAB5;
  --accent-hover: #089692;
  --accent-soft: #e6f7f6;
  --bg: #f4f7fa;
  --surface: #ffffff;
  --surface-alt: #fafbfd;
  --border: #e4e9f0;
  --border-strong: #cfd6e0;
  --text: #1a2433;
  --text-muted: #6b7280;
  --text-subtle: #9ca3af;
  --success: #10b981;
  --success-soft: #d1fae5;
  --warning: #f59e0b;
  --warning-soft: #fef3c7;
  --danger: #ef4444;
  --danger-soft: #fee2e2;
  --info: #3b82f6;
  --info-soft: #dbeafe;
  --shadow-sm: 0 1px 2px rgba(15, 30, 60, 0.04), 0 1px 3px rgba(15, 30, 60, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 30, 60, 0.06), 0 2px 4px rgba(15, 30, 60, 0.04);
  --shadow-lg: 0 16px 40px rgba(15, 30, 60, 0.10);
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 16px;
  --sidebar-w: 248px;
  --topbar-h: 64px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ---------- Reset / base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3, h4 { color: var(--primary); font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.5rem 0; }

/* ---------- Bootstrap overrides ---------- */
.btn { font-weight: 500; border-radius: var(--radius-sm); padding: .5rem 1rem; transition: all .15s ease; }
.btn-primary {
  background: var(--accent); border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(10,186,181,.2);
}
.btn-primary:hover, .btn-primary:focus { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-primary:active { background: var(--accent-hover) !important; border-color: var(--accent-hover) !important; }
.btn-secondary {
  background: var(--surface); color: var(--primary); border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--surface-alt); color: var(--primary); border-color: var(--border-strong); }
.btn-outline-primary { color: var(--accent); border-color: var(--accent); }
.btn-outline-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-dark { background: var(--primary); border-color: var(--primary); }
.btn-dark:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { padding: .35rem .7rem; font-size: .8125rem; }
.btn-icon { display: inline-flex; align-items: center; gap: .5rem; }

.form-control, .form-select {
  border-radius: var(--radius-sm);
  border-color: var(--border-strong);
  font-size: .9rem;
  padding: .5rem .75rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(10, 186, 181, .15);
}
.form-label { font-weight: 500; color: var(--primary); font-size: .85rem; margin-bottom: .35rem; }
.form-text { font-size: .8rem; color: var(--text-muted); }

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  background: var(--surface);
}
.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-header h3, .card-header h4 { margin: 0; }
.card-body { padding: 1.25rem; }

.table {
  margin: 0;
  font-size: .9rem;
  --bs-table-bg: transparent;
}
.table > :not(caption) > * > * { padding: .85rem 1rem; }
.table thead th {
  font-weight: 600;
  color: var(--primary);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  font-size: .72rem;
  letter-spacing: .04em;
}
.table tbody tr { border-bottom: 1px solid var(--border); }
.table tbody tr:last-child { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-alt); }

.badge { font-weight: 500; padding: .35em .6em; border-radius: 4px; font-size: .72rem; }
.badge-status {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .25rem .6rem; border-radius: 999px; font-weight: 500; font-size: .75rem;
}
.badge-status::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor;
}
.badge-status.s-aguardando      { background: #f3f4f6; color: #4b5563; }
.badge-status.s-triagem         { background: var(--info-soft); color: #1e40af; }
.badge-status.s-colirio_aplicado { background: #ede9fe; color: #5b21b6; }
.badge-status.s-dilatando       { background: var(--warning-soft); color: #92400e; }
.badge-status.s-dilatado        { background: var(--accent-soft); color: #047377; }
.badge-status.s-em_atendimento  { background: #cffafe; color: #155e75; }
.badge-status.s-finalizado      { background: var(--success-soft); color: #065f46; }
.badge-status.s-cancelado       { background: var(--danger-soft); color: #991b1b; }
.badge-prioridade { font-size: .7rem; padding: .15em .5em; border-radius: 4px; font-weight: 600; text-transform: uppercase; }
.badge-prioridade.p-urgencia    { background: var(--danger); color: white; }
.badge-prioridade.p-preferencial { background: var(--warning); color: white; }

/* ---------- LAYOUT: SHELL APP ---------- */
.app-shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; grid-template-rows: var(--topbar-h) 1fr; min-height: 100vh; grid-template-areas: "sidebar topbar" "sidebar main"; }
.app-sidebar { grid-area: sidebar; background: var(--primary); color: rgba(255,255,255,.85); display: flex; flex-direction: column; z-index: 1050; }
.app-topbar { grid-area: topbar; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 1.5rem; gap: 1rem; position: sticky; top: 0; z-index: 100; }
.app-main { grid-area: main; padding: 1.75rem 2rem; overflow-x: hidden; min-width: 0; }
.topbar-titles { min-width: 0; flex: 0 1 auto; }
.topbar-titles .page-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-user-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.1; }
.topbar-user-name  { font-weight: 500; font-size: .85rem; color: var(--text); white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.topbar-user-email { font-size: .72rem; color: var(--text-muted); white-space: nowrap; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.topbar-user-caret { font-size: .75rem; color: var(--text-muted); margin: 0 .35rem; }

.hamburger {
  background: var(--surface-alt); border: 1px solid var(--border);
  width: 40px; height: 40px; border-radius: 8px;
  display: grid; place-items: center; color: var(--primary); font-size: 1.25rem;
  padding: 0;
}
.hamburger:active { background: var(--border); }

.sidebar-close {
  background: rgba(255,255,255,.08); border: 0; color: rgba(255,255,255,.85);
  width: 34px; height: 34px; border-radius: 8px; margin-left: auto;
  display: grid; place-items: center; font-size: 1rem;
}
.sidebar-close:hover { background: rgba(255,255,255,.15); color: white; }

.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(15,30,60,.5);
  z-index: 1040; opacity: 0; pointer-events: none;
  transition: opacity .2s ease;
}
.sidebar-backdrop.show { opacity: 1; pointer-events: auto; }

/* Sidebar */
.brand {
  padding: 1.25rem 1.5rem;
  display: flex; align-items: center; gap: .75rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 38px; height: 38px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #14d6d0);
  display: grid; place-items: center; color: white;
  box-shadow: 0 4px 14px rgba(10,186,181,.35);
  font-size: 1.1rem;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.1; }
.brand-text strong { color: white; font-weight: 600; font-size: 1rem; letter-spacing: -.01em; }
.brand-text small { color: rgba(255,255,255,.55); font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }

.nav-section { padding: 1.25rem .75rem .5rem; font-size: .68rem; text-transform: uppercase; letter-spacing: .1em; color: rgba(255,255,255,.4); font-weight: 600; }
.nav-menu { list-style: none; padding: 0 .75rem; margin: 0; flex: 1; }
.nav-menu li a {
  display: flex; align-items: center; gap: .85rem;
  padding: .65rem .85rem;
  border-radius: 8px;
  color: rgba(255,255,255,.75);
  font-weight: 500;
  font-size: .9rem;
  margin-bottom: .15rem;
  transition: all .15s ease;
}
.nav-menu li a i { font-size: 1.05rem; opacity: .85; }
.nav-menu li a:hover {
  background: rgba(255,255,255,.06); color: white;
}
.nav-menu li.active a {
  background: linear-gradient(90deg, rgba(10,186,181,.18), transparent);
  color: white;
  position: relative;
}
.nav-menu li.active a::before {
  content: ''; position: absolute; left: -.75rem; top: 8px; bottom: 8px; width: 3px;
  background: var(--accent); border-radius: 0 3px 3px 0;
}

.sidebar-footer {
  padding: 1rem 1.25rem; border-top: 1px solid rgba(255,255,255,.08);
  font-size: .75rem; color: rgba(255,255,255,.45);
}

/* Topbar */
.page-title { font-size: 1.05rem; font-weight: 600; color: var(--primary); margin: 0; }
.page-subtitle { font-size: .78rem; color: var(--text-muted); }
.topbar-spacer { flex: 1; }
.topbar-user {
  display: flex; align-items: center; gap: .65rem;
  padding: .35rem .35rem .35rem .85rem;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
}
.topbar-user:hover { border-color: var(--border-strong); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-soft));
  color: white; display: grid; place-items: center; font-weight: 600; font-size: .8rem;
}

/* ---------- Dashboard ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  position: relative;
  overflow: hidden;
  transition: all .2s ease;
}
.kpi:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kpi-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }
.kpi-value { font-size: 1.85rem; font-weight: 600; color: var(--primary); margin-top: .35rem; letter-spacing: -.02em; }
.kpi-icon {
  position: absolute; top: 1.1rem; right: 1.1rem;
  width: 38px; height: 38px; border-radius: 8px;
  display: grid; place-items: center; font-size: 1.1rem;
}
.kpi.accent .kpi-icon { background: var(--accent-soft); color: var(--accent); }
.kpi.info .kpi-icon   { background: var(--info-soft); color: var(--info); }
.kpi.warn .kpi-icon   { background: var(--warning-soft); color: var(--warning); }
.kpi.ok .kpi-icon     { background: var(--success-soft); color: var(--success); }
.kpi-hint { font-size: .78rem; color: var(--text-subtle); margin-top: .5rem; }

/* ---------- HOME (PUBLIC) ---------- */
.home {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 80% -20%, rgba(10,186,181,.10), transparent 60%),
    radial-gradient(ellipse at -10% 90%, rgba(30,58,95,.08), transparent 60%),
    linear-gradient(180deg, #fafcfd 0%, var(--bg) 100%);
}
.home-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.25rem 2rem;
  max-width: 1240px; margin: 0 auto;
}
.home-nav .brand-text strong { color: var(--primary); }
.home-nav .brand-text small { color: var(--text-muted); }

.hero {
  max-width: 1240px; margin: 0 auto;
  padding: 2.5rem 2rem 4rem;
  display: grid; grid-template-columns: 1.1fr .9fr; gap: 3rem; align-items: center;
}
.hero h1 {
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.1; color: var(--primary);
  letter-spacing: -.02em; margin: 0 0 1.25rem;
}
.hero h1 .accent { color: var(--accent); }
.hero p.lead { font-size: 1.125rem; color: var(--text-muted); line-height: 1.6; margin-bottom: 1.75rem; max-width: 540px; }
.hero-meta { display: flex; gap: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); margin-top: 1.25rem; }
.hero-meta div { font-size: .82rem; color: var(--text-muted); }
.hero-meta strong { display: block; color: var(--primary); font-size: .92rem; margin-bottom: .15rem; }

.pill {
  display: inline-flex; align-items: center; gap: .5rem;
  background: var(--accent-soft); color: var(--accent);
  font-size: .75rem; font-weight: 600; letter-spacing: .03em;
  padding: .35rem .8rem; border-radius: 999px;
  margin-bottom: 1.25rem; text-transform: uppercase;
}
.pill::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  position: relative;
}
.login-card h2 { font-size: 1.4rem; margin: 0 0 .35rem; }
.login-card .muted { color: var(--text-muted); font-size: .9rem; margin-bottom: 1.5rem; }
.login-card .btn-primary { width: 100%; padding: .7rem 1rem; font-weight: 600; }
.login-error {
  background: var(--danger-soft); color: #991b1b;
  padding: .6rem .85rem; border-radius: var(--radius-sm); font-size: .85rem;
  margin-bottom: 1rem; display: none;
}
.login-error.show { display: block; }

/* ---------- RESPONSIVO ---------- */
/* Esconde por padrão os elementos do user no topbar pra telas estreitas */
@media (max-width: 991.98px) {
  .app-shell {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "topbar" "main";
  }
  .app-sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: 280px; max-width: 85vw;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 6px 0 24px rgba(15,30,60,.18);
  }
  .app-sidebar.open { transform: translateX(0); }
  .app-main { padding: 1rem; }
  .app-topbar { padding: 0 1rem; gap: .75rem; }
  .topbar-user-text { display: none; }
  .topbar-user-caret { display: none; }
  .topbar-user { padding: .25rem; border-radius: 50%; }
  .page-title { font-size: .95rem; }
  .page-subtitle { display: none; }

  /* Home */
  .hero { grid-template-columns: 1fr; padding: 1.5rem 1.25rem 3rem; gap: 2rem; }
  .home-nav { padding: 1rem 1.25rem; }
  .hero h1 { font-size: 2rem; }
  .hero p.lead { font-size: 1rem; }
  .hero-meta { flex-direction: column; gap: 1rem; }
  .login-card { padding: 1.5rem; }

  /* Card headers viram coluna */
  .card-header { flex-direction: column; align-items: flex-start; gap: .75rem; padding: 1rem; }
  .card-header .btn { width: 100%; justify-content: center; }
  .card-body { padding: 1rem; }

  /* KPIs num grid mais apertado */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: .65rem; margin-bottom: 1rem; }
  .kpi { padding: .85rem; }
  .kpi-value { font-size: 1.4rem; }
  .kpi-label { font-size: .68rem; }
  .kpi-icon { width: 30px; height: 30px; font-size: .9rem; top: .85rem; right: .85rem; }
  .kpi-hint { display: none; }

  /* Tabelas com scroll horizontal preservando legibilidade */
  .table > :not(caption) > * > * { padding: .6rem .65rem; font-size: .85rem; }
  .table thead th { font-size: .65rem; }

  /* Toolbar — empilhar */
  .toolbar { flex-direction: column; align-items: stretch; gap: .5rem; }
  .toolbar .search { max-width: none; }

  /* Modal — fullscreen no mobile (mantém scroll do BS modal-dialog-scrollable) */
  .modal-dialog {
    margin: 0; max-width: 100% !important;
    height: 100vh; height: 100dvh;
  }
  .modal-content {
    height: 100vh; height: 100dvh;
    max-height: 100vh; max-height: 100dvh;
    border-radius: 0;
  }
  .modal-header, .modal-footer { border-radius: 0; }
  .modal-body { padding: 1rem; }
  .section-title { margin-top: 1.25rem; }

  /* Prontuário status bar — quebrar */
  .prontuario-status-bar { flex-direction: column; align-items: stretch; gap: .75rem; }
  .prontuario-status-bar > div:last-child { display: flex; flex-wrap: wrap; gap: .35rem; }
  .prontuario-status-bar > div:last-child > * { flex: 1; min-width: 0; }

  /* Tabs de prontuário — search desce */
  #tabs-prontuario { flex-wrap: wrap; }
  #tabs-prontuario .nav-item.ms-auto { margin-left: 0 !important; width: 100%; padding: .5rem 0; }
  #tabs-prontuario .search { max-width: none !important; width: 100%; }
  #search-avulso-results { width: 100% !important; }

  /* Tabela exam: mantém compacta */
  .exam-table th, .exam-table td { padding: .25rem; }
  .exam-table th.eye-col { font-size: .75rem; }
}

@media (max-width: 575.98px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 1.65rem; }
  .topbar-user { display: none; }
  .app-topbar { justify-content: space-between; }
  /* Botão Sair acessível pela sidebar quando o user some do topbar */
  .sidebar-footer .btn-mobile-logout {
    display: inline-flex; align-items: center; gap: .5rem;
    background: rgba(255,255,255,.08); border: 0; color: white;
    padding: .5rem .85rem; border-radius: 8px; font-size: .85rem; margin-top: .5rem;
  }
}

/* Sempre mostrar o logout dentro da sidebar no mobile como fallback */
@media (min-width: 992px) {
  .sidebar-mobile-only { display: none !important; }
}

/* ---------- Prontuário ---------- */
.prontuario-status-bar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .85rem 1.25rem; margin-bottom: 1rem;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  box-shadow: var(--shadow-sm);
}
.prontuario-status-bar.rascunho { border-left: 4px solid var(--warning); }
.prontuario-status-bar.finalizado { border-left: 4px solid var(--success); background: var(--success-soft); }
.prontuario-status-bar .status-info { display: flex; flex-direction: column; }
.prontuario-status-bar .status-info strong { font-size: .95rem; color: var(--primary); }
.prontuario-status-bar .status-info small { color: var(--text-muted); }

.section-title {
  display: flex; align-items: center; gap: .6rem;
  color: var(--primary); font-size: .82rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em;
  margin: 1.5rem 0 .75rem;
  padding-bottom: .5rem; border-bottom: 1px solid var(--border);
}
.section-title i { color: var(--accent); }
.section-title:first-child { margin-top: 0; }

.exam-table { width: 100%; }
.exam-table th { text-align: left; font-size: .78rem; color: var(--text-muted); font-weight: 500; padding: .5rem .75rem; background: var(--surface-alt); }
.exam-table td { padding: .35rem; }
.exam-table th.eye-col { text-align: center; color: var(--accent); font-weight: 600; }

/* ---------- Misc ---------- */
.empty {
  text-align: center; padding: 3rem 1rem; color: var(--text-muted);
}
.empty i { font-size: 2.5rem; color: var(--text-subtle); display: block; margin-bottom: 1rem; }

.toolbar {
  display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem;
  flex-wrap: wrap;
}
.toolbar .search { flex: 1; max-width: 380px; position: relative; }
.toolbar .search i { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--text-subtle); }
.toolbar .search input { padding-left: 2.4rem; }

.spinner-overlay {
  position: fixed; inset: 0; background: rgba(244,247,250,.75); z-index: 9999;
  display: none; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.spinner-overlay.show { display: flex; }
.spinner-overlay .loader {
  width: 38px; height: 38px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg, #eef1f5 25%, #f7f9fc 50%, #eef1f5 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 4px; height: 1em; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Modal — scroll manual via flex + backgrounds explícitos */
.modal-dialog {
  display: flex; align-items: center;
  min-height: calc(100% - 1rem * 2);
}
.modal-content {
  border-radius: var(--radius); border: 0;
  background-color: var(--surface);
  max-height: calc(100vh - 2rem);
  display: flex; flex-direction: column;
  width: 100%;
}
.modal-header { background-color: var(--surface);     border-bottom: 1px solid var(--border); padding: 1rem 1.5rem; flex-shrink: 0; border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.modal-footer { background-color: var(--surface-alt); border-top: 1px solid var(--border);    padding: 1rem 1.5rem; flex-shrink: 0; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.modal-title  { color: var(--primary); font-weight: 600; }
.modal-body   {
  background-color: var(--surface);
  padding: 1.5rem;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

/* DataTables overrides */
.dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_length { font-size: .85rem; padding: .25rem 0; }
.dataTables_wrapper .dataTables_filter input { border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: .35rem .65rem; margin-left: .5rem; }
.page-link { color: var(--primary); }
.page-item.active .page-link { background: var(--accent); border-color: var(--accent); }
