/* =========================================================
   CRM Clínica — Stylesheet principal
   Tipografia: Fraunces (display) + Geist (body)
   Estética: editorial médica refinada, com toque de calor
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght@0,9..144,400;0,9..144,500;0,9..144,600;1,9..144,400&family=Geist:wght@300;400;500;600;700&display=swap');

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

html, body {
  height: 100%;
  font-family: 'Geist', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ── Tipografia display ────────────────────────────────────── */
.display, h1, h2, h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 500;
  letter-spacing: -0.02em;
  font-variation-settings: "opsz" 144;
}

h1 { font-size: 2.5rem; line-height: 1.1; }
h2 { font-size: 1.75rem; line-height: 1.2; }
h3 { font-size: 1.25rem; line-height: 1.3; font-weight: 600; }

a { color: var(--color-primary); text-decoration: none; transition: color .15s; }
a:hover { color: var(--color-primary-hover); }

button { font-family: inherit; cursor: pointer; border: none; background: none; }
input, textarea, select { font-family: inherit; font-size: inherit; }

::selection { background: var(--color-accent); color: white; }

/* ── Layout principal: sidebar + área de conteúdo ─────────── */
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-header {
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 4px;
}
.sidebar-logo img { width: 28px; height: 28px; object-fit: contain; }
.sidebar-logo .name {
  font-family: 'Fraunces', serif;
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--color-primary);
}
.sidebar-tagline {
  font-size: 11px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-left: 38px;
}

.sidebar-nav {
  padding: 12px 8px;
  flex: 1;
}
.nav-section-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--color-text-muted);
  padding: 16px 12px 8px;
  font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--color-text);
  font-size: 13.5px;
  font-weight: 400;
  transition: background .12s;
  cursor: pointer;
  width: 100%;
  text-align: left;
}
.nav-item:hover { background: var(--color-primary-soft); }
.nav-item.active {
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-weight: 500;
}
.nav-item .icon { width: 16px; height: 16px; opacity: 0.7; }
.nav-item.active .icon { opacity: 1; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--color-border);
}
.user-card {
  display: flex; align-items: center; gap: 10px;
  padding: 8px;
  border-radius: 6px;
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 12px;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--color-text-muted); text-transform: capitalize; }
.logout-btn {
  color: var(--color-text-muted); font-size: 11px;
  padding: 4px 8px; border-radius: 4px;
}
.logout-btn:hover { background: var(--color-danger-soft); color: var(--color-danger); }

/* ── Conteúdo principal ─────────────────────────────────────── */
.main {
  padding: 28px 40px 60px;
  overflow-x: hidden;
  max-width: 100%;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 28px;
  gap: 20px;
  flex-wrap: wrap;
}
.page-title {
  font-size: 1.75rem;
  font-weight: 500;
}
.page-title em {
  font-style: italic;
  color: var(--color-accent);
  font-weight: 400;
}
.page-subtitle {
  color: var(--color-text-muted);
  font-size: 13px;
  margin-top: 2px;
}

/* ── Botões ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn-primary {
  background: var(--color-primary); color: white;
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-secondary {
  background: var(--color-surface); color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-primary-soft); border-color: var(--color-primary); }
.btn-ghost {
  color: var(--color-text-muted);
}
.btn-ghost:hover { background: var(--color-primary-soft); color: var(--color-text); }
.btn-danger {
  background: var(--color-danger); color: white;
}
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 11px 22px; font-size: 14px; }
.btn-icon {
  width: 32px; height: 32px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 20px;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--color-border);
}
.card-title { font-size: 14px; font-weight: 600; letter-spacing: -0.005em; }

/* ── KPI Cards (dashboard) ──────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.kpi {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color .15s, transform .15s;
}
.kpi:hover {
  border-color: var(--color-primary);
  transform: translateY(-1px);
}
.kpi-icon {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--color-primary-soft);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
}
.kpi-icon svg {
  width: 18px;
  height: 18px;
}
.kpi-label {
  font-size: 11px;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  padding-right: 44px;
}
.kpi-value {
  font-family: 'Fraunces', serif;
  font-size: 1.85rem;
  font-weight: 500;
  margin-top: 8px;
  letter-spacing: -0.02em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-meta {
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 6px;
}

/* ── Chart legend & tooltip ────────────────────────────────── */
.chart-legend {
  display: flex;
  justify-content: center;
  gap: 24px;
  margin-top: 6px;
  font-size: 12px;
}
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-muted);
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}
.hover-zone { cursor: crosshair; }

/* ── Tabelas ───────────────────────────────────────────────── */
.table-wrap {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 12px 14px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-primary-soft) 40%, transparent);
}
tbody td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .1s; cursor: pointer; }
tbody tr:hover { background: var(--color-primary-soft); }

/* ── Inputs ────────────────────────────────────────────────── */
.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-soft);
}
.textarea { resize: vertical; min-height: 80px; }
.label {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 500;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field { margin-bottom: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ── Badges ────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: var(--color-primary-soft);
  color: var(--color-primary);
}
.badge-success { background: color-mix(in srgb, var(--color-success) 12%, transparent); color: var(--color-success); }
.badge-warning { background: color-mix(in srgb, var(--color-warning) 12%, transparent); color: var(--color-warning); }
.badge-danger { background: var(--color-danger-soft); color: var(--color-danger); }
.badge-muted { background: color-mix(in srgb, var(--color-text-muted) 12%, transparent); color: var(--color-text-muted); }

/* ── Kanban (funil) ────────────────────────────────────────── */
.kanban {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin: 0 -40px;
  padding-left: 40px; padding-right: 40px;
  min-height: calc(100vh - 200px);
}
.kanban-col {
  flex: 0 0 280px;
  background: color-mix(in srgb, var(--color-primary-soft) 50%, transparent);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
}
.kanban-col-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 6px 12px;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 10px;
}
.kanban-col-title {
  font-weight: 600; font-size: 13px;
  display: flex; align-items: center; gap: 8px;
}
.kanban-col-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--color-text-muted);
}
.kanban-col-count {
  font-size: 11px;
  color: var(--color-text-muted);
  font-variant-numeric: tabular-nums;
}
.kanban-col-body {
  flex: 1;
  overflow-y: auto;
  display: flex; flex-direction: column;
  gap: 8px;
  padding-right: 2px;
}
.kanban-col-body.drag-over {
  background: var(--color-primary-soft);
  border-radius: 6px;
  outline: 2px dashed var(--color-primary);
  outline-offset: -2px;
}

.lead-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 10px 12px;
  cursor: grab;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.lead-card:hover {
  border-color: var(--color-primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.04);
}
.lead-card.dragging { opacity: 0.4; cursor: grabbing; }
.lead-card-name { font-weight: 500; font-size: 13px; margin-bottom: 2px; }
.lead-card-meta {
  font-size: 11px; color: var(--color-text-muted);
  display: flex; gap: 8px; margin-top: 4px;
}
.lead-card-source {
  font-size: 10px;
  color: var(--color-accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 6px;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 30, 30, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn .15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--color-surface);
  border-radius: 10px;
  width: 100%; max-width: 600px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: slideUp .2s ease-out;
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--color-border);
  display: flex; justify-content: space-between; align-items: center;
}
.modal-title { font-size: 1.2rem; font-family: 'Fraunces', serif; font-weight: 500; }
.modal-body { padding: 22px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--color-border);
  display: flex; justify-content: flex-end; gap: 10px;
}

/* ── Filtros / barra de busca ──────────────────────────────── */
.filters {
  display: flex; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px;
  align-items: center;
}
.filters .input, .filters .select { width: auto; min-width: 180px; }
.filters .search { flex: 1; max-width: 320px; }

/* ── Toast ─────────────────────────────────────────────────── */
.toast-container {
  position: fixed; top: 20px; right: 20px;
  z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--color-text);
  color: var(--color-surface);
  padding: 11px 18px;
  border-radius: 6px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.15);
  animation: toastIn .2s ease-out;
  max-width: 360px;
}
.toast.success { background: var(--color-success); }
.toast.error { background: var(--color-danger); }
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Loading / vazio ───────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
}
.empty-state h3 {
  font-family: 'Fraunces', serif;
  margin-bottom: 8px;
  color: var(--color-text);
}
.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Lead detail (drawer) ──────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.detail-item .label { margin-bottom: 2px; }
.detail-item .value { font-size: 13.5px; }

.activity-item {
  padding: 10px 0;
  border-bottom: 1px solid var(--color-border);
}
.activity-item:last-child { border-bottom: none; }
.activity-meta {
  font-size: 11px; color: var(--color-text-muted);
  margin-top: 2px;
  display: flex; gap: 10px;
}
.activity-content { font-size: 13px; }

/* ── Auth pages (login / setup) ────────────────────────────── */
.auth-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.auth-side {
  background: var(--color-primary);
  color: white;
  padding: 60px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-side::before {
  content: '';
  position: absolute;
  top: -100px; right: -100px;
  width: 400px; height: 400px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--color-accent) 0%, transparent 70%);
  opacity: 0.15;
}
.auth-side h1 {
  font-family: 'Fraunces', serif;
  font-style: italic;
  font-size: 3rem;
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.02em;
  position: relative;
}
.auth-side .accent { color: var(--color-accent); font-style: italic; }
.auth-side .quote {
  font-size: 14px;
  opacity: 0.7;
  font-family: 'Fraunces', serif;
  font-style: italic;
  position: relative;
}
.auth-side .brand {
  font-size: 13px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.6;
  position: relative;
}

.auth-form-wrap {
  display: flex; align-items: center; justify-content: center;
  padding: 40px;
}
.auth-form {
  width: 100%; max-width: 380px;
}
.auth-form h2 {
  font-family: 'Fraunces', serif;
  font-size: 2rem;
  font-weight: 500;
  margin-bottom: 6px;
}
.auth-form .subtitle {
  color: var(--color-text-muted);
  margin-bottom: 28px;
  font-size: 14px;
}
.auth-form .field { margin-bottom: 16px; }
.auth-form .btn {
  width: 100%;
  justify-content: center;
  padding: 11px;
  margin-top: 6px;
}
.auth-form .error-msg {
  background: var(--color-danger-soft);
  color: var(--color-danger);
  padding: 9px 12px;
  border-radius: 5px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ── Settings tabs ─────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border);
  margin-bottom: 24px;
  gap: 4px;
}
.tab {
  padding: 9px 16px;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  color: var(--color-text-muted);
  font-weight: 500;
  margin-bottom: -1px;
  cursor: pointer;
}
.tab.active { color: var(--color-primary); border-color: var(--color-primary); }
.tab:hover:not(.active) { color: var(--color-text); }

/* ── Color picker ──────────────────────────────────────────── */
.color-picker-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--color-border);
}
.color-picker-row:last-child { border-bottom: none; }
.color-picker-row .swatch {
  width: 28px; height: 28px;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  cursor: pointer;
}
.color-picker-row .name { flex: 1; font-size: 13px; }
.color-picker-row input[type="text"] {
  width: 110px;
  padding: 5px 8px;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  font-family: 'Geist', monospace;
  font-size: 12px;
}

/* ── Utility ──────────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.text-muted { color: var(--color-text-muted); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.hidden { display: none !important; }
.text-right { text-align: right; }

/* ── Mobile responsivo (simples) ───────────────────────────── */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    width: 240px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .2s;
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 20px; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-side { padding: 30px; min-height: 200px; }
  .auth-side h1 { font-size: 2rem; }
  .field-row { grid-template-columns: 1fr; }
  .kanban { margin: 0 -20px; padding: 0 20px; }
}
