:root {
  --bg: #f3f4f7;
  --panel: #ffffff;
  --border: #e2e5eb;
  --text: #1e2430;
  --muted: #6b7280;
  --accent: #e8590c;
  --accent-dark: #c24705;
  --accent-soft: #fdecdf;
  --brand-navy: #1f3a5f;

  --free-fill: #e9f9f1;
  --free-stroke: #22a06b;
  --free-text: #0f6b46;

  --partial-fill: #fef6e6;
  --partial-stroke: #e3a12b;
  --partial-text: #92620d;

  --full-fill: #fdecec;
  --full-stroke: #e2504f;
  --full-text: #a12e2d;

  --room-stroke: #7c6fe0;

  --wall-office-fill: #f6f4ff;
  --wall-office-stroke: #b3a6f2;
  --wall-meeting-fill: #eff5ff;
  --wall-meeting-stroke: #8db3f5;
  --wall-department-fill: #f8fafc;
  --wall-department-stroke: #a9b4c4;
  --wall-mesa-fill: #fdfdfe;
  --wall-mesa-stroke: #dde1e8;
  --wall-staff-fill: #f1f3f6;
  --wall-staff-stroke: #ccd2db;

  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1100px 480px at 12% -8%, rgba(232, 89, 12, 0.05), transparent 60%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Barra de rolagem discreta (Chromium/Edge) */
.map-wrap, .sidebar, .modal {
  scrollbar-width: thin;
  scrollbar-color: #c7cbd4 transparent;
}
.map-wrap::-webkit-scrollbar, .sidebar::-webkit-scrollbar, .modal::-webkit-scrollbar { width: 10px; height: 10px; }
.map-wrap::-webkit-scrollbar-thumb, .sidebar::-webkit-scrollbar-thumb, .modal::-webkit-scrollbar-thumb {
  background: #ccd1da; border-radius: 999px; border: 3px solid transparent; background-clip: padding-box;
}
.map-wrap::-webkit-scrollbar-track, .sidebar::-webkit-scrollbar-track, .modal::-webkit-scrollbar-track { background: transparent; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
  position: relative;
  z-index: 3;
}

.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { flex-shrink: 0; height: 32px; width: auto; }
.brand-divider { flex-shrink: 0; width: 1px; height: 28px; background: var(--border); }

.topbar h1 { margin: 0; font-size: 19px; font-weight: 800; letter-spacing: -0.02em; color: var(--brand-navy); }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12.5px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar-right label { font-size: 12.5px; font-weight: 600; color: var(--muted); margin-right: -4px; }

.date-field { position: relative; display: flex; align-items: center; }
.date-field .field-icon {
  position: absolute; left: 10px; width: 15px; height: 15px; color: var(--muted); pointer-events: none;
}
.date-field input#date-input { padding-left: 32px; }

input, select {
  font-family: inherit;
  font-size: 14px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(232, 89, 12, 0.15);
}

button { font-family: inherit; cursor: pointer; }
button svg { width: 15px; height: 15px; flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(232, 89, 12, 0.25);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background 0.12s ease, transform 0.06s ease;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  padding: 7px 13px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.btn-ghost:hover { background: #f3f4f7; border-color: #cfd4dc; }
.btn-icon-only { padding: 7px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 2;
}

.legend { display: flex; gap: 10px; flex-wrap: wrap; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
}
.dot { width: 11px; height: 11px; border-radius: 4px; display: inline-block; border: 1.5px solid; }
.dot-free { background: var(--free-fill); border-color: var(--free-stroke); }
.dot-partial { background: var(--partial-fill); border-color: var(--partial-stroke); }
.dot-full { background: var(--full-fill); border-color: var(--full-stroke); }
.dot-room { background: #fff; border-color: var(--room-stroke); border-width: 2px; }

.stats-bar { display: flex; gap: 14px; flex-wrap: wrap; }
.stat {
  display: flex;
  align-items: baseline;
  gap: 5px;
  font-size: 12.5px;
  color: var(--muted);
}
.stat strong { font-size: 15px; font-weight: 800; color: var(--text); letter-spacing: -0.01em; }
.stat.stat-free strong { color: var(--free-text); }
.stat.stat-partial strong { color: var(--partial-text); }
.stat.stat-full strong { color: var(--full-text); }

.layout {
  display: flex;
  height: calc(100vh - 112px);
}

.map-wrap {
  flex: 1;
  overflow: auto;
  padding: 24px;
  position: relative;
}

.map-loading {
  position: absolute;
  inset: 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 13.5px;
  background: #fcfcfd;
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: opacity 0.2s ease;
}
.map-loading.hidden { display: none; }
.spinner {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#floor-map {
  display: block;
  background: #fcfcfd;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

/* Paredes de salas e mesas */
.wall-rect { stroke-width: 1.75; }
.wall-divider { stroke: rgba(15, 23, 42, 0.08); stroke-width: 1; }
.wall-label {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  fill: #33415a;
}
.wall-subtitle { font-size: 10px; font-weight: 500; fill: #97a1b0; }

.wall-office .wall-rect { fill: var(--wall-office-fill); stroke: var(--wall-office-stroke); }
.wall-meeting .wall-rect { fill: var(--wall-meeting-fill); stroke: var(--wall-meeting-stroke); }
.wall-department .wall-rect { fill: var(--wall-department-fill); stroke: var(--wall-department-stroke); }
.wall-mesa .wall-rect { fill: var(--wall-mesa-fill); stroke: var(--wall-mesa-stroke); }
.wall-staff .wall-rect { fill: var(--wall-staff-fill); stroke: var(--wall-staff-stroke); stroke-dasharray: 3 3; }

/* Divisorias / bancadas / mesas de reuniao decorativas */
.deco { pointer-events: none; }
.deco-bancada-bar, .deco-bench-line { fill: #e2e6ee; stroke: #cbd2de; stroke-width: 1; pointer-events: none; }
.deco-table { fill: #efe8da; stroke: #c7ba9c; stroke-width: 1.5; pointer-events: none; }
.deco-seat { fill: #ffffff; stroke: #b7bfcb; stroke-width: 1; pointer-events: none; }
.deco-bancada-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  fill: #5b6474;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Janela (parede externa) e corredor — elementos arquitetonicos, so visuais */
.deco-window { pointer-events: none; }
.deco-window rect { fill: #e0f2fe; stroke: #7dd3fc; stroke-width: 1.5; }
.deco-window line { stroke: #7dd3fc; stroke-width: 1; }
.deco-window-label {
  font-size: 8px;
  font-weight: 600;
  fill: #0369a1;
  dominant-baseline: central;
  pointer-events: none;
}

.deco-corridor { pointer-events: none; }
.deco-corridor rect { fill: #f4f5f7; stroke: #e2e5eb; stroke-width: 1; stroke-dasharray: 3 3; }
.deco-corridor-line { stroke: #c7cbd4; stroke-width: 1.5; stroke-dasharray: 4 4; }
.deco-corridor-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.1em;
  fill: #9aa1ad;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

/* Estacoes e salas reservaveis */
.resource-rect {
  cursor: pointer;
  stroke-width: 1.5;
  transition: filter 0.12s ease, transform 0.12s ease;
  transform-box: fill-box;
  transform-origin: center;
}
.resource-rect:hover { filter: brightness(1.06) saturate(1.1); transform: scale(1.04); }
.resource-rect.selected { stroke: #1e293b !important; stroke-width: 2.5; }

.resource-desk[data-status="free"] { fill: var(--free-fill); stroke: var(--free-stroke); }
.resource-desk[data-status="partial"] { fill: var(--partial-fill); stroke: var(--partial-stroke); }
.resource-desk[data-status="full"] { fill: var(--full-fill); stroke: var(--full-stroke); }

.resource-room { stroke: var(--room-stroke); stroke-width: 2; }
.resource-room[data-status="free"] { fill: var(--free-fill); fill-opacity: 0.55; }
.resource-room[data-status="partial"] { fill: var(--partial-fill); fill-opacity: 0.7; }
.resource-room[data-status="full"] { fill: var(--full-fill); fill-opacity: 0.7; }

.resource-text {
  font-size: 9px;
  font-weight: 700;
  fill: #263043;
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: central;
}
.resource-text-number { font-size: 8px; font-weight: 700; }
.resource-text-user { font-size: 6.5px; font-weight: 600; letter-spacing: -0.1px; }
.resource-text-has-user .resource-text-number { font-size: 7.5px; }

.sidebar {
  width: 370px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 22px;
  overflow-y: auto;
}

.sidebar-empty {
  color: var(--muted);
  font-size: 14px;
  padding-top: 60px;
  text-align: center;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.sidebar-empty svg { width: 40px; height: 40px; color: #c7cdd8; }
.hidden { display: none !important; }

.sidebar-content { animation: fade-in 0.16s ease; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.sidebar h2 { margin: 10px 0 2px; font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.resource-meta {
  color: var(--muted);
  font-size: 12.5px;
  margin: 0 0 18px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar h3 {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 20px 0 10px;
}

.bookings-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bookings-list li {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  background: var(--bg);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 13px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.bookings-list li.muted { color: var(--muted); border: none; background: none; padding: 0; }
.bookings-list li.editing { align-items: stretch; flex-direction: column; gap: 8px; border-left-color: var(--accent); }
.booking-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.booking-time { font-weight: 700; }
.booking-person { color: var(--muted); font-size: 12px; }
.booking-actions { display: flex; gap: 6px; flex-shrink: 0; }
.booking-cancel, .booking-edit {
  background: #fff;
  border-radius: 6px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
  transition: background 0.12s ease;
}
.booking-cancel { border: 1px solid var(--full-stroke); color: var(--full-text); }
.booking-cancel:hover { background: var(--full-fill); }
.booking-edit { border: 1px solid var(--accent); color: var(--accent); }
.booking-edit:hover { background: var(--accent-soft); }

.edit-row { display: flex; align-items: center; gap: 6px; }
.edit-row input[type="time"] { flex: 1; min-width: 0; }
.edit-sep { color: var(--muted); font-size: 12px; }
.edit-note { width: 100%; }
.edit-actions { display: flex; gap: 6px; }
.edit-save { flex: 1; padding: 6px 10px; font-size: 12.5px; }
.edit-actions .btn-ghost { padding: 6px 10px; font-size: 12.5px; }
.edit-error { margin: 0; font-size: 12px; font-weight: 600; color: var(--full-text); min-height: 14px; }

#booking-form { display: flex; flex-direction: column; gap: 11px; }
#booking-form label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--muted); }

#booking-form label.checkbox-row {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
}
.checkbox-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.recurring-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.recurring-options label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); }

.weekday-picker { display: flex; gap: 4px; flex-wrap: wrap; }
.weekday-picker label {
  flex-direction: row;
  align-items: center;
  gap: 4px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.weekday-picker input { width: 13px; height: 13px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.weekday-picker input:checked + span { color: var(--accent); }

.modal-hint { font-size: 13px; color: var(--muted); margin: -4px 0 4px; }
.series-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 1px 7px;
  margin-left: 6px;
}
.booking-cancel-series { border: 1px solid var(--muted); color: var(--muted); background: #fff; border-radius: 6px; padding: 5px 10px; font-size: 12px; font-weight: 600; flex-shrink: 0; }
.booking-cancel-series:hover { background: var(--bg); }

.stats-cards { display: flex; gap: 12px; flex-wrap: wrap; margin: 4px 0 20px; }
.stat-card { flex: 1; min-width: 130px; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; }
.stat-card-value { font-size: 22px; font-weight: 800; color: var(--text); letter-spacing: -0.01em; line-height: 1.1; }
.stat-card-label { font-size: 11px; color: var(--muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; margin-top: 4px; }

.chart-wrap { overflow-x: auto; margin-bottom: 20px; }
#stats-chart { display: block; }
.chart-bar { fill: var(--accent); transition: fill 0.1s ease; }
.chart-bar:hover { fill: var(--accent-dark); }
.chart-axis-label { font-size: 10px; fill: var(--muted); }
.chart-baseline { stroke: var(--border); stroke-width: 1; }

#stats-top-table, #stats-person-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#stats-top-table th, #stats-person-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 6px 10px 6px 0;
  border-bottom: 1.5px solid var(--border);
}
#stats-top-table td, #stats-person-table td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--border); }
#stats-top-table tbody tr:last-child td, #stats-person-table tbody tr:last-child td { border-bottom: none; }

.stats-section-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 20px; }
.stats-section-header h3 { margin: 0; }

.admin-details {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 4px 0;
  background: var(--bg);
}
.admin-details summary { cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--muted); }
.admin-details label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-top: 8px; }
.admin-details .modal-hint { margin: 6px 0 0; }
.attendance-cancel-btn {
  background: #fff; border: 1px solid var(--full-stroke); color: var(--full-text);
  border-radius: 6px; padding: 4px 9px; font-size: 11.5px; font-weight: 600;
}
.attendance-cancel-btn:hover { background: var(--full-fill); }

.stats-empty { font-size: 13.5px; color: var(--muted); text-align: center; padding: 30px 0; }

.quick-presets { display: flex; gap: 6px; }
.preset {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 7px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
.preset:hover { background: #e9ebef; }
.preset.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.form-row { display: flex; gap: 10px; }
.form-row label { flex: 1; }

.form-message { font-size: 13px; margin: 0; min-height: 18px; font-weight: 600; }
.form-message.error { color: var(--full-text); }
.form-message.success { color: var(--free-text); }

.btn-close { align-self: flex-start; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 30, 0.5);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  animation: overlay-in 0.15s ease;
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: #fff;
  border-radius: 14px;
  padding: 26px;
  width: min(480px, 92vw);
  max-height: 80vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
  animation: modal-in 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal h2 { margin: 0 0 6px; font-weight: 800; letter-spacing: -0.01em; }
.lookup-email-label { flex: 1; }
.lookup-btn { align-self: flex-end; }
.modal-wide { width: min(760px, 94vw); }

.attendance-summary { font-size: 13.5px; color: var(--muted); margin: 4px 0 2px; }
.attendance-summary strong { color: var(--text); font-size: 15px; }
.attendance-actions { justify-content: flex-end; }

.table-wrap { overflow-x: auto; }
#attendance-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#attendance-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 6px 10px 6px 0;
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
}
#attendance-table td {
  padding: 8px 10px 8px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
#attendance-table tbody tr:last-child td { border-bottom: none; }

@media print {
  body * { visibility: hidden; }
  #attendance-modal, #attendance-modal * { visibility: visible; }
  #attendance-modal {
    position: absolute;
    inset: 0;
    background: #fff;
    display: block;
  }
  #attendance-modal .modal {
    box-shadow: none;
    max-height: none;
    overflow: visible;
    width: 100%;
    padding: 0;
    animation: none;
  }
  /* Forca cores neutras no impresso, independente de qualquer deteccao
     automatica de "entidades" (datas/nomes) que o navegador aplique. */
  #attendance-modal, #attendance-modal h2, #attendance-modal td, #attendance-modal th {
    color: #111 !important;
    background: #fff !important;
  }
  #attendance-modal .attendance-summary strong { color: #000 !important; }
  .no-print { display: none !important; }
}

/* Responsivo: tablet — mapa e barra lateral empilham em vez de lado a lado */
@media (max-width: 900px) {
  .layout { flex-direction: column; height: auto; }
  .map-wrap { flex: none; width: 100%; height: 56vh; min-height: 320px; padding: 14px; }
  .map-loading { inset: 14px; }
  .sidebar { width: 100%; border-left: none; border-top: 1px solid var(--border); }
}

/* Responsivo: celular — topo compacto, rótulos viram ícones, formulários empilham */
@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .toolbar { padding: 10px 16px; }
  .subtitle { display: none; }
  .brand-divider { display: none; }
  .brand-logo { height: 26px; }
  .topbar-right { width: 100%; flex-wrap: wrap; }
  .btn-label { display: none; }
  .btn-ghost { padding: 8px; }
  .form-row { flex-wrap: wrap; }
  .modal { padding: 20px; }
}

@media (max-width: 420px) {
  .form-row { flex-direction: column; }
  .quick-presets { flex-wrap: wrap; }
  .quick-presets .preset { min-width: 90px; }
}
