/* ===================================================
   Painel de Input — Jornada MUDA
   Brand: cream #f5f0e8, green palette
   Fonts: Playfair Display (headings) + Lato (body)
   =================================================== */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand */
  --cream:          #f5f0e8;
  --cream-dark:     #ebe5d9;
  --green-900:      #2d3e23;
  --green-800:      #3a5130;
  --green-700:      #48643c;
  --green-600:      #567748;
  --green-500:      #658153;
  --green-400:      #7a9668;
  --green-300:      #94ad84;
  --green-200:      #b5c9a9;
  --green-100:      #d6e2cf;
  --green-50:       #eef3ea;

  /* Text */
  --text-primary:   #383431;
  --text-secondary: #6B655F;
  --text-muted:     #A39D96;
  --text-inverse:   #f5f0e8;

  /* Functional */
  --danger:         #dc3545;
  --danger-bg:      #feebeb;
  --warning:        #e6a817;
  --warning-bg:     #fff8e6;
  --success:        #28a745;
  --success-bg:     #edf7ec;
  --info:           #387bcb;
  --info-bg:        #e8f0fb;

  /* Layout */
  --sidebar-w:      240px;
  --header-h:       0px;
  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      16px;
  --shadow-card:    0 2px 8px rgba(56,52,49,0.06);
  --shadow-lg:      0 8px 24px rgba(56,52,49,0.10);

  /* Transitions */
  --ease:           cubic-bezier(0.4,0,0.2,1);
}

html { font-size: 15px; }
body {
  font-family: 'Lato', sans-serif;
  background: var(--cream);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}
h1, h2, h3, .font-display {
  font-family: 'Playfair Display', serif;
}

/* ── Sidebar ── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--green-800);
  color: var(--text-inverse);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform 0.25s var(--ease);
}
.sidebar-logo {
  padding: 24px 20px 16px;
  font-family: 'Playfair Display', serif;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-logo small {
  display: block;
  font-family: 'Lato', sans-serif;
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.6;
  margin-top: 2px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: rgba(255,255,255,0.75);
  transition: all 0.15s var(--ease);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.sidebar-item:hover {
  background: rgba(255,255,255,0.08);
  color: #fff;
}
.sidebar-item.active {
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-weight: 600;
}
.sidebar-item svg, .sidebar-item i {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.8;
}
.sidebar-item.active svg, .sidebar-item.active i {
  opacity: 1;
}
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 0.75rem;
  opacity: 0.5;
}

/* ── Main content ── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  padding: 24px 32px;
}

/* ── Health Banner ── */
.health-banner {
  position: fixed;
  top: 0; left: var(--sidebar-w); right: 0;
  background: var(--danger);
  color: #fff;
  padding: 8px 16px;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.health-banner button {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 2px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
}
.health-banner button:hover {
  background: rgba(255,255,255,0.3);
}

/* ── Page Header ── */
.page-header {
  margin-bottom: 24px;
}
.page-title {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.page-subtitle {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* ── KPI Cards ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}
.kpi-card {
  background: #fff;
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  border: 1px solid transparent;
}
.kpi-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--green-200);
  transform: translateY(-1px);
}
.kpi-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}
.kpi-value.danger { color: var(--danger); }
.kpi-value.warning { color: var(--warning); }
.kpi-value.success { color: var(--green-600); }

/* ── Sections ── */
.section-card {
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  margin-bottom: 20px;
  overflow: hidden;
}
.section-header {
  padding: 16px 20px;
  font-weight: 700;
  font-size: 1rem;
  border-bottom: 1px solid var(--cream-dark);
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-body {
  padding: 16px 20px;
}

/* ── Urgent action items ── */
.action-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--cream);
  gap: 12px;
  font-size: 0.9rem;
}
.action-item:last-child { border-bottom: none; }
.action-item .action-badge {
  flex-shrink: 0;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
}
.action-badge.checkin { background: var(--info-bg); color: var(--info); }
.action-badge.tarefa { background: var(--warning-bg); color: var(--warning); }
.action-item .action-text { flex: 1; }
.action-item .action-text strong { font-weight: 600; }
.action-item .action-delay {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--danger);
  font-weight: 600;
}
.action-item .action-link {
  flex-shrink: 0;
  color: var(--green-600);
  cursor: pointer;
  font-size: 0.8rem;
  text-decoration: none;
  font-weight: 600;
}
.action-item .action-link:hover { text-decoration: underline; }

/* ── Birthday items ── */
.birthday-item {
  display: flex;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--cream);
  gap: 10px;
  font-size: 0.9rem;
}
.birthday-item:last-child { border-bottom: none; }
.birthday-days {
  flex-shrink: 0;
  width: 48px;
  text-align: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--green-600);
}
.birthday-days.today { color: var(--danger); }

/* ── Skeleton Loading ── */
.skeleton {
  background: linear-gradient(90deg, var(--cream) 25%, var(--cream-dark) 50%, var(--cream) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.skeleton-text { height: 14px; margin-bottom: 8px; }
.skeleton-text.w-1\/2 { width: 50%; }
.skeleton-text.w-3\/4 { width: 75%; }
.skeleton-kpi { height: 40px; width: 80px; margin-top: 6px; }

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toastIn 0.25s var(--ease);
  max-width: 380px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast.toast-success {
  background: var(--green-800);
  color: #fff;
}
.toast.toast-error {
  background: var(--danger);
  color: #fff;
}
.toast.toast-warning {
  background: #8a6914;
  color: #fff;
}
.toast.removing {
  animation: toastOut 0.2s var(--ease) forwards;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toastOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(40px); }
}

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge-ativo    { background: var(--success-bg); color: var(--success); }
.badge-pausado  { background: var(--warning-bg); color: #8a6914; }
.badge-finalizado { background: var(--cream-dark); color: var(--text-secondary); }
.badge-cancelado  { background: var(--danger-bg); color: var(--danger); }
.badge-pendente   { background: var(--info-bg); color: var(--info); }
.badge-raizes     { background: var(--green-100); color: var(--green-800); }
.badge-sementes   { background: #fef3cd; color: #8a6914; }
.badge-manutencao { background: #e0e7ff; color: #3730a3; }

/* ── Empty State ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state svg {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  opacity: 0.4;
}
.empty-state p {
  font-size: 0.9rem;
}

/* ── Error State ── */
.error-state {
  text-align: center;
  padding: 32px 24px;
  color: var(--danger);
}
.error-state p { margin-bottom: 12px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.15s var(--ease);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--green-600);
  color: #fff;
}
.btn-primary:hover:not(:disabled) {
  background: var(--green-700);
}
.btn-secondary {
  background: var(--cream-dark);
  color: var(--text-primary);
}
.btn-secondary:hover:not(:disabled) {
  background: #ddd8ce;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover:not(:disabled) {
  background: #c82333;
}
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--cream-dark);
}
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.form-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--cream-dark);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: 'Lato', sans-serif;
  background: #fff;
  color: var(--text-primary);
  transition: border-color 0.15s;
}
.form-input:focus {
  outline: none;
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(101,129,83,0.15);
}
.form-input::placeholder { color: var(--text-muted); }
.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B655F' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}
textarea.form-input { resize: vertical; min-height: 80px; }

/* ── Modal ── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(56,52,49,0.4);
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.15s var(--ease);
}
.modal-content {
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  animation: modalIn 0.2s var(--ease);
}
.modal-header {
  padding: 20px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
}
.modal-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: none; background: none;
  cursor: pointer; color: var(--text-muted);
  font-size: 1.2rem;
}
.modal-close:hover { background: var(--cream); }
.modal-body { padding: 16px 24px; }
.modal-footer {
  padding: 12px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* ── Chips / Filters ── */
.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--cream-dark);
  background: #fff;
  color: var(--text-secondary);
  transition: all 0.15s var(--ease);
}
.chip:hover { border-color: var(--green-400); }
.chip.active {
  background: var(--green-600);
  color: #fff;
  border-color: var(--green-600);
}

/* ── Patient Cards Grid ── */
.patients-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.patient-card {
  background: #fff;
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-card);
  cursor: pointer;
  transition: all 0.2s var(--ease);
  border: 1px solid transparent;
}
.patient-card:hover {
  box-shadow: var(--shadow-lg);
  border-color: var(--green-200);
}
.patient-name {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 4px;
}
.patient-meta {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.patient-stats {
  display: flex;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.patient-stat { display: flex; align-items: center; gap: 4px; }
.patient-stat.alert { color: var(--danger); font-weight: 600; }

/* ── Ficha (tabs) ── */
.ficha-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.ficha-back {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  border: 1px solid var(--cream-dark);
  background: #fff;
  cursor: pointer;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.ficha-back:hover { background: var(--cream-dark); }
.ficha-name { font-size: 1.3rem; font-weight: 700; }
.ficha-phone {
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
}
.ficha-phone:hover { color: var(--green-600); }

.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--cream-dark);
  margin-bottom: 20px;
  overflow-x: auto;
}
.tab {
  padding: 10px 18px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.15s var(--ease);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}
.tab:hover { color: var(--text-primary); }
.tab.active {
  color: var(--green-700);
  border-bottom-color: var(--green-600);
}

/* ── Action Bar (ficha) ── */
.action-bar {
  position: sticky;
  bottom: 0;
  background: #fff;
  border-top: 1px solid var(--cream-dark);
  padding: 12px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
  z-index: 10;
}

/* ── Tooltip ── */
.tooltip-wrapper { position: relative; }
.tooltip-content {
  display: none;
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: #fff;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  white-space: nowrap;
  z-index: 20;
  pointer-events: none;
}
.tooltip-wrapper:hover .tooltip-content { display: block; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-content {
    margin-left: 0;
    padding: 16px;
  }
  .health-banner { left: 0; }
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .patients-grid {
    grid-template-columns: 1fr;
  }
  .mobile-menu-btn {
    display: flex !important;
  }
}

.mobile-menu-btn {
  display: none;
  position: fixed;
  top: 12px; left: 12px;
  z-index: 45;
  width: 40px; height: 40px;
  align-items: center; justify-content: center;
  background: var(--green-800);
  color: #fff;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-card);
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 39;
}
@media (max-width: 768px) {
  .sidebar-overlay.open { display: block; }
}

/* ── View transitions ── */
.view-enter {
  animation: viewFadeIn 0.2s var(--ease);
}
@keyframes viewFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--cream-dark); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #ccc; }

/* ── Spinner ── */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.spinner-dark {
  border-color: rgba(56,52,49,0.15);
  border-top-color: var(--green-600);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tabulator Overrides ── */
.tabulator {
  border: 1px solid var(--cream-dark) !important;
  font-family: 'Lato', sans-serif !important;
  font-size: 0.85rem !important;
}
.tabulator .tabulator-header {
  background: var(--cream) !important;
  border-bottom: 2px solid var(--cream-dark) !important;
}
.tabulator .tabulator-header .tabulator-col {
  background: transparent !important;
  border-right: 1px solid var(--cream-dark) !important;
}
.tabulator .tabulator-header .tabulator-col .tabulator-col-title {
  font-weight: 700 !important;
  color: var(--text-secondary) !important;
  font-size: 0.78rem !important;
  text-transform: uppercase !important;
  letter-spacing: 0.03em !important;
}
.tabulator .tabulator-row {
  border-bottom: 1px solid var(--cream) !important;
  cursor: pointer !important;
}
.tabulator .tabulator-row:hover {
  background: var(--green-50) !important;
}
.tabulator .tabulator-row.tabulator-selected {
  background: var(--green-100) !important;
}
.tabulator .tabulator-row .tabulator-cell {
  border-right: 1px solid var(--cream) !important;
  padding: 8px 12px !important;
}
.tabulator .tabulator-placeholder {
  color: var(--text-muted) !important;
}

/* ── Focus visible ── */
.btn:focus-visible,
.chip:focus-visible,
.tab:focus-visible,
.form-input:focus-visible,
.sidebar-item:focus-visible {
  outline: 2px solid var(--green-500);
  outline-offset: 2px;
}

/* ── Hover states polish ── */
.sidebar-item { position: relative; }
.kpi-card { position: relative; }

/* ── Count-up animation helper ── */
.kpi-value {
  transition: color 0.3s var(--ease);
}

/* ── Mobile warning (ficha) ── */
@media (max-width: 640px) {
  .ficha-desktop-warning {
    display: block !important;
    padding: 16px;
    background: var(--warning-bg);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: #8a6914;
    text-align: center;
    margin-bottom: 16px;
  }
}
.ficha-desktop-warning { display: none; }

/* ── Utility ── */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
