:root {
  --bg: #f5efe4;
  --bg-strong: #efe3cf;
  --surface: rgba(255, 252, 247, 0.92);
  --surface-strong: #fffaf1;
  --line: #dccfb8;
  --text: #2d2418;
  --muted: #6d5f4d;
  --brand: #0e6b5c;
  --brand-dark: #09493f;
  --accent: #c96b2c;
  --danger: #a84032;
  --shadow: 0 22px 50px rgba(84, 57, 23, 0.12);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(201, 107, 44, 0.12), transparent 28%),
    radial-gradient(circle at top right, rgba(14, 107, 92, 0.18), transparent 24%),
    linear-gradient(180deg, var(--bg) 0%, #f8f4ec 48%, #f1e7d8 100%);
}

.app-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 48px; }
.login-screen { min-height: calc(100vh - 80px); display: grid; place-items: center; }

.login-card,
.session-bar {
  background: var(--surface);
  border: 1px solid rgba(220, 207, 184, 0.8);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.login-card { width: min(620px, 100%); padding: 28px; }
.auth-form { display: grid; gap: 14px; }
.auth-actions, .session-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.auth-status, .auth-hint { margin: 0; color: var(--muted); line-height: 1.5; }
.auth-hint { font-size: 0.92rem; }

.auth-switcher {
  display: flex;
  gap: 10px;
  margin: 22px 0 16px;
}

.auth-switch-button {
  border: 1px solid var(--line);
  background: #fff7ec;
  color: var(--muted);
  padding: 12px 16px;
  border-radius: 12px;
  font-weight: 700;
}

.auth-switch-button.active {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #f4fffc;
  border-color: transparent;
}

.setup-notice {
  border: 1px dashed var(--accent);
  background: rgba(201, 107, 44, 0.08);
  color: var(--text);
  border-radius: 14px;
  padding: 14px 16px;
  margin: 18px 0;
}

.session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  padding: 18px 22px;
}

.session-summary {
  display: grid;
  gap: 6px;
}

.session-meta {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.session-bar strong { display: block; font-size: 1.02rem; }

.role-badge {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(14, 107, 92, 0.12);
  color: var(--brand-dark);
  font-size: 0.82rem;
  font-weight: 700;
}

.hero {
  display: grid;
  grid-template-columns: 1.8fr 1fr;
  gap: 20px;
  align-items: stretch;
  margin-bottom: 24px;
}

.hero, .panel, .tabs { backdrop-filter: blur(10px); }
.hero, .panel {
  background: var(--surface);
  border: 1px solid rgba(220, 207, 184, 0.8);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
}

.hero { padding: 28px; }
.eyebrow { margin: 0 0 8px; text-transform: uppercase; letter-spacing: 0.14em; font-size: 0.78rem; color: var(--accent); font-weight: 700; }
h1, h2 { margin: 0; }
h1 { font-size: clamp(2.2rem, 4vw, 3.7rem); line-height: 0.98; }
.hero-text, .panel-heading p, .report-meta span, label, small { color: var(--muted); }
.hero-text { max-width: 48rem; margin: 14px 0 0; font-size: 1rem; line-height: 1.6; }

.hero-card {
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #effbf8;
  border-radius: 22px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 10px;
  min-height: 190px;
}

.hero-card span, .hero-card small { color: rgba(239, 251, 248, 0.84); }
.hero-card strong { font-size: 2rem; }

.tabs {
  display: flex;
  gap: 10px;
  padding: 8px;
  background: rgba(255, 249, 239, 0.85);
  border: 1px solid rgba(220, 207, 184, 0.85);
  border-radius: 18px;
  margin-bottom: 20px;
  position: sticky;
  top: 12px;
  z-index: 10;
}

.tab-button {
  border: none;
  background: transparent;
  color: var(--muted);
  padding: 14px 18px;
  border-radius: 12px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: 0.2s ease;
}

.tab-button.active, .tab-button:hover { background: var(--surface-strong); color: var(--brand-dark); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeUp 0.25s ease; }
.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.panel-stack { display: grid; grid-template-columns: 1fr; gap: 20px; }
.panel { padding: 24px; }
.panel-heading { margin-bottom: 18px; }
.panel-heading p { margin: 8px 0 0; line-height: 1.5; }
.form-stack, .filters-grid { display: grid; gap: 14px; }
.filters-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); align-items: end; }

label { display: grid; gap: 8px; font-size: 0.95rem; font-weight: 600; }
input, select, button { font: inherit; }
input, select {
  width: 100%;
  padding: 13px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fffdfa;
  color: var(--text);
}

input:focus, select:focus { outline: 2px solid rgba(14, 107, 92, 0.18); border-color: var(--brand); }
button { cursor: pointer; }

.primary-button, .secondary-button {
  padding: 13px 18px;
  border-radius: 12px;
  border: none;
  font-weight: 700;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.primary-button:hover, .secondary-button:hover { transform: translateY(-1px); }
.primary-button { background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%); color: #f4fffc; }
.secondary-button { background: #ece1cf; color: var(--text); }

.filter-actions {
  display: flex;
  gap: 10px;
  align-items: stretch;
  flex-wrap: nowrap;
  justify-content: flex-start;
  grid-column: 1 / -1;
}

.filter-actions button { flex: 0 0 auto; }
.table-wrapper { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 14px 10px; border-bottom: 1px solid rgba(220, 207, 184, 0.75); text-align: left; }
.data-table th { color: var(--brand-dark); font-size: 0.92rem; }

.settings-content {
  display: grid;
  gap: 20px;
}

.settings-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.settings-stat-card,
.settings-section {
  border: 1px solid rgba(220, 207, 184, 0.85);
  background: rgba(255, 250, 241, 0.72);
  border-radius: 18px;
}

.settings-stat-card {
  padding: 18px 20px;
  display: grid;
  gap: 8px;
}

.settings-stat-card span,
.settings-stat-card small {
  color: var(--muted);
}

.settings-stat-card strong {
  font-size: 2rem;
  color: var(--brand-dark);
}

.settings-section {
  padding: 18px;
}

.settings-section-header {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.settings-section h3 {
  margin: 0 0 6px;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.role-cell {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.role-select {
  min-width: 180px;
}

.empty-state {
  border: 1px dashed var(--line);
  background: rgba(239, 227, 207, 0.42);
  color: var(--muted);
  border-radius: 14px;
  padding: 18px;
  text-align: center;
}

.hidden { display: none; }
.inline-danger { border: none; background: transparent; color: var(--danger); font-weight: 700; padding: 0; }
.report-meta { margin: 20px 0 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.print-only-header { display: none; }
.print-only-header h3 { margin: 0 0 6px; }
.print-only-header p { margin: 0 0 4px; color: var(--muted); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(45, 36, 24, 0.42);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 30;
}

.modal-overlay.hidden {
  display: none !important;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.modal-overlay[hidden] {
  display: none !important;
}

.modal-card {
  width: min(520px, 100%);
  background: var(--surface-strong);
  border: 1px solid rgba(220, 207, 184, 0.9);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 24px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.modal-close { border: none; background: transparent; color: var(--muted); font-weight: 700; padding: 4px 6px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  padding: 14px 18px;
  background: rgba(45, 36, 24, 0.92);
  color: #fff9ef;
  border-radius: 12px;
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: 0.2s ease;
}

.toast.show { opacity: 1; transform: translateY(0); }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 900px) {
  .hero, .panel-grid, .filters-grid, .settings-summary-grid { grid-template-columns: 1fr; }
  .session-bar { flex-direction: column; align-items: flex-start; }
  .session-actions { width: 100%; }
  .tabs { position: static; overflow-x: auto; }
  .tab-button { white-space: nowrap; }
  .filter-actions {
    flex-wrap: wrap;
  }
}

@media print {
  @page { size: A4 portrait; margin: 12mm; }
  body { background: #ffffff; }
  .app-shell { width: 100%; margin: 0; padding: 0; }
  .hero, .tabs, .session-bar, .modal-overlay, #residentes, #consultas, .filters-grid, .report-meta, .empty-state, .toast { display: none !important; }
  #relatorios { display: block !important; }
  .panel { box-shadow: none; border: none; background: #ffffff; padding: 0; }
  .panel-heading { display: none; }
  .print-only-header { display: block; margin-bottom: 12px; }
  .report-wrapper { overflow: visible; }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 8px 6px; color: #000000; }
}
