:root {
  --bg: #f4f1eb;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #68737d;
  --border: #ded8cf;
  --brand: #8a6a2f;
  --brand-dark: #6f5220;
  --danger: #a53636;
  --shadow: 0 12px 28px rgba(44, 36, 24, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

button, input, select, textarea { font: inherit; }

button { cursor: pointer; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px clamp(18px, 5vw, 70px);
  background: #171717;
  color: white;
}

.topbar h1 { margin: 2px 0 0; font-size: clamp(28px, 4vw, 42px); }

.eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.16em;
  font-weight: 800;
  color: var(--brand);
}

.topbar .eyebrow { color: #d8bd82; }

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.container {
  width: min(1480px, calc(100% - 32px));
  margin: 28px auto 50px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card, .panel {
  background: var(--panel);
  border: 1px solid rgba(138,106,47,.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card { padding: 18px; }

.stat-card span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.stat-card strong { font-size: clamp(20px, 2.4vw, 28px); }

.panel {
  padding: 20px;
  margin-bottom: 18px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.panel-header h2 { margin: 3px 0 0; font-size: 22px; }

.subheading { margin: 0 0 6px; font-size: 16px; }

.primary, .secondary, .icon-btn, .danger, .file-label {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font-weight: 700;
}

.primary {
  color: white;
  background: var(--brand);
}

.primary:hover { background: var(--brand-dark); }

.secondary, .file-label {
  background: white;
  color: var(--ink);
  border-color: var(--border);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.secondary:hover, .file-label:hover { border-color: #bda777; }

.topbar .secondary, .topbar .file-label {
  background: transparent;
  color: white;
  border-color: #555;
}

.icon-btn {
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 24px;
  background: white;
  border-color: var(--border);
}

.danger {
  background: #fff1f1;
  color: var(--danger);
  border-color: #f3caca;
}

.file-label { cursor: pointer; }
.file-label input { display: none; }

.calendar-controls { display: flex; gap: 8px; }

.calendar-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
}

#calendarTable {
  border-collapse: collapse;
  width: 100%;
  min-width: 1050px;
  table-layout: fixed;
}

#calendarTable col.room-col { width: 150px; }

#calendarTable th, #calendarTable td {
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}

#calendarTable th:last-child, #calendarTable td:last-child { border-right: 0; }
#calendarTable tbody tr:last-child td { border-bottom: 1px solid var(--border); }

.room-heading {
  position: sticky;
  left: 0;
  z-index: 3;
  width: 150px;
  background: #f8f6f2;
  padding: 12px;
  text-align: left;
}

.date-heading {
  padding: 10px 4px;
  text-align: center;
  background: #f8f6f2;
  font-size: 12px;
}

.date-heading.weekend { background: #f1ece1; }
.date-heading.today { background: #efe3c7; }

.room-cell {
  position: sticky;
  left: 0;
  z-index: 2;
  background: white;
  padding: 10px 12px;
  font-weight: 800;
}

.room-cell small {
  display: block;
  color: var(--muted);
  font-weight: 500;
  margin-top: 2px;
}

.calendar-cell {
  height: 58px;
  padding: 4px;
  background: white;
  vertical-align: middle;
}

.calendar-cell.weekend { background: #fbf9f4; }
.calendar-cell.today-col { background: #fdf7ea; }
.calendar-cell:not(.has-booking):hover { background: #f5efe0; cursor: pointer; }

.empty-calendar {
  padding: 30px;
  text-align: center;
  color: var(--muted);
}

.booking-chip {
  display: flex;
  align-items: center;
  height: 100%;
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  color: #2b251a;
  background: #e9dcc1;
  border-left: 4px solid var(--brand);
}

.booking-chip.st-pendente { background: #fff1ca; border-left-color: #c88c00; }
.booking-chip.st-confirmada { background: #dcebd8; border-left-color: #477a3f; }
.booking-chip.st-check-in { background: #d6e8f4; border-left-color: #2a688f; }
.booking-chip.st-check-out { background: #e9e9e9; border-left-color: #747474; }
.booking-chip.st-bloqueado {
  background: repeating-linear-gradient(45deg, #eee, #eee 6px, #e0e0e0 6px, #e0e0e0 12px);
  border-left-color: #747474;
  color: #555;
}
.booking-chip.st-no-show { background: #f8e3d0; border-left-color: #b56a1f; }
.booking-chip.st-cancelada { background: #f5dddd; border-left-color: #a53636; text-decoration: line-through; }

.occupancy-label { font-size: 12px; font-weight: 800; color: var(--muted); }

.occupancy-cell {
  text-align: center;
  font-size: 12px;
  font-weight: 800;
  padding: 8px 2px;
  background: #f8f6f2;
}

.occupancy-cell.low { color: var(--muted); }
.occupancy-cell.mid { color: #8a6a2f; background: #f5ecd9; }
.occupancy-cell.high { color: #8a2f2f; background: #f6e2da; }

.hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.hint.spaced { margin: 0 0 12px; }

/* ---------- Channel manager ---------- */

.channel-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(300px, 1fr);
  gap: 24px;
}

.channel-table-wrap { overflow-x: auto; }

.channel-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.channel-table th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  padding: 8px;
  border-bottom: 2px solid var(--border);
}

.channel-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.channel-name { font-weight: 800; }

.commission-input {
  width: 64px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 7px;
  margin-right: 3px;
}

.commission-value { color: var(--danger); }

.ical-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.ical-controls select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: white;
}

.ical-log { display: grid; gap: 6px; }

.ical-log-entry {
  font-size: 13px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #faf8f4;
}

.ical-log-entry span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}

/* ---------- Listes ---------- */

.two-columns {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(300px, .7fr);
  gap: 18px;
}

.search, .filters select, .room-form input, .form-grid input, .form-grid select, .form-grid textarea {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  background: white;
  color: var(--ink);
}

.search { min-width: 260px; }

.filters {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.reservation-list, .room-list {
  display: grid;
  gap: 10px;
}

.reservation-card {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) 1fr auto;
  gap: 14px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
}

.reservation-card:hover { border-color: #bda777; }

.reservation-card h3 {
  margin: 0 0 5px;
  font-size: 16px;
}

.ext-code {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.reservation-card p {
  margin: 2px 0;
  color: var(--muted);
  font-size: 13px;
}

.commission-line { color: var(--danger); }

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
  background: #eee;
}

.badge.st-confirmada { background: #dcebd8; }
.badge.st-pendente { background: #fff1ca; }
.badge.st-check-in { background: #d6e8f4; }
.badge.st-check-out { background: #e9e9e9; }
.badge.st-no-show { background: #f8e3d0; }
.badge.st-bloqueado { background: #e4e4e4; }
.badge.st-cancelada { background: #f5dddd; }

.card-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.wa-btn { font-size: 13px; }

.room-form {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

.room-form button { grid-column: 1 / -1; }

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

.room-item strong { display: block; }
.room-item span { color: var(--muted); font-size: 13px; }

.empty-state {
  padding: 28px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  color: var(--muted);
  text-align: center;
}

.empty-state.small { padding: 16px; font-size: 13px; }

/* ---------- Dialog ---------- */

dialog {
  width: min(760px, calc(100% - 24px));
  border: 0;
  padding: 0;
  border-radius: 18px;
  box-shadow: 0 30px 90px rgba(0,0,0,.3);
}

dialog::backdrop { background: rgba(0,0,0,.55); }

#reservationForm { padding: 22px; }

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

.dialog-header h2 { margin: 4px 0 0; }

.close-btn {
  border: 0;
  background: transparent;
  font-size: 28px;
  color: var(--muted);
}

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

.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
}

.label-hint { font-weight: 600; color: var(--brand); }

.full-width { grid-column: 1 / -1; }

.dialog-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.spacer { flex: 1; }

.form-error {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--danger);
  font-weight: 700;
}

.hidden { display: none !important; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 20px);
  background: #171717;
  color: white;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 12px 30px rgba(0,0,0,.3);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  max-width: min(520px, calc(100% - 32px));
  text-align: center;
  z-index: 50;
}

.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #7c2626; }

/* ---------- Responsive ---------- */

@media (max-width: 1150px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .channel-grid { grid-template-columns: 1fr; }
}

@media (max-width: 950px) {
  .two-columns { grid-template-columns: 1fr; }
  .reservation-card { grid-template-columns: 1fr; }
  .card-actions { justify-content: flex-start; }
}

@media (max-width: 680px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; }
  .top-actions > * { flex: 1; text-align: center; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .panel-header { align-items: flex-start; flex-direction: column; }
  .search { width: 100%; min-width: 0; }
  .filters { flex-direction: column; }
  .room-form { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .full-width { grid-column: auto; }
  .ical-controls { grid-template-columns: 1fr; }
}

/* ---------- Login ---------- */

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid rgba(138,106,47,.12);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px;
}

.login-card h1 { margin: 4px 0 6px; }

.login-subtitle { margin: 0 0 20px; color: var(--muted); font-size: 14px; }

.login-form { display: grid; gap: 14px; }

.login-form label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 800;
}

.login-form input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
}

/* ---------- Barra de usuário / sync ---------- */

.user-chip {
  font-size: 13px;
  color: #d8bd82;
  font-weight: 700;
  margin-right: 4px;
}

.ical-url-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.ical-url-row input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 12px;
  color: var(--muted);
  background: #faf8f4;
}

.ota-config {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin-bottom: 12px;
}

.ota-config input {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  font-size: 13px;
}

.ota-config select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  background: white;
}

.sync-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.sync-badge {
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 680px) {
  .ota-config { grid-template-columns: 1fr; }
  .ical-url-row { flex-direction: column; }
}

/* ---------- Mapa do dia (impressão) ---------- */

.filters input[type="date"] {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 11px;
  background: white;
}

.print-area { display: none; }

@media print {
  body * { visibility: hidden; }
  .print-area, .print-area * { visibility: visible; }
  .print-area {
    display: block;
    position: absolute;
    inset: 0;
    padding: 24px;
    background: white;
    color: #111;
    font-size: 12px;
  }
  .pm-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    border-bottom: 3px solid #111;
    padding-bottom: 10px;
    margin-bottom: 14px;
  }
  .pm-eyebrow { margin: 0; font-size: 11px; letter-spacing: .14em; font-weight: 800; }
  .pm-header h1 { margin: 4px 0 0; font-size: 22px; text-transform: capitalize; }
  .pm-meta { text-align: right; font-size: 11px; color: #444; }
  .print-area h2 { font-size: 14px; margin: 16px 0 6px; border-bottom: 1px solid #999; padding-bottom: 3px; }
  .print-area h2 span { font-weight: 600; color: #555; }
  .print-area table { width: 100%; border-collapse: collapse; }
  .print-area th {
    text-align: left; font-size: 10px; text-transform: uppercase;
    letter-spacing: .05em; color: #555; padding: 4px 6px; border-bottom: 1.5px solid #111;
  }
  .print-area td { padding: 5px 6px; border-bottom: 1px solid #ddd; vertical-align: top; }
  .pm-room { font-weight: 800; font-size: 14px; width: 52px; }
  .pm-guest { font-weight: 700; }
  .pm-guest small { font-weight: 500; color: #666; }
  .pm-due { font-weight: 800; }
  .pm-ok { color: #2c6b2c; font-weight: 700; }
  .pm-notes { color: #555; max-width: 200px; }
  .pm-empty { color: #666; font-style: italic; margin: 4px 0 0; }
  .pm-free { margin-top: 16px; border-top: 1px solid #999; padding-top: 8px; }
}
