:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --panel: #ffffff;
  --text: #14213d;
  --muted: #64748b;
  --line: #dbe3ef;
  --primary: #2454d6;
  --primary-dark: #173a9b;
  --success: #147d4f;
  --warning: #9a6700;
  --danger: #b42318;
  --chip: #edf2ff;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

html,
body,
#app {
  min-width: 0;
  width: 100%;
}

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

button {
  border: 0;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  padding: 10px 14px;
  touch-action: manipulation;
}

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

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

button.secondary {
  background: #e7edf7;
  color: var(--text);
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  padding: 18px 28px;
  position: sticky;
  top: 0;
  z-index: 2;
}

.brand h1 {
  font-size: 22px;
  margin: 0;
}

.brand span {
  color: var(--muted);
  display: block;
  font-size: 13px;
  margin-top: 2px;
}

.layout {
  display: grid;
  gap: 20px;
  grid-template-columns: 220px 1fr;
  padding: 20px;
}

.sidebar {
  align-self: start;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px;
  position: sticky;
  top: 86px;
}

.tab-button {
  background: transparent;
  color: var(--muted);
  display: block;
  text-align: left;
  width: 100%;
}

.tab-button.active {
  background: var(--chip);
  color: var(--primary);
}

.main {
  display: grid;
  gap: 20px;
  min-width: 0;
  width: 100%;
}

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

.login-card {
  margin: 0 auto;
  max-width: 460px;
  width: 100%;
}

.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  min-width: 0;
  padding: 20px;
  width: 100%;
}

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

.section-header h2,
.card h3 {
  margin: 0;
}

.section-header p,
.muted {
  color: var(--muted);
  margin: 4px 0 0;
}

.police-fiche-toolbar {
  align-items: flex-end;
  flex-shrink: 0;
  flex-wrap: wrap;
  gap: 12px;
}

.police-fiche-toolbar .police-fiche-date-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
}

.police-fiche-empty-hint {
  margin-top: 8px;
}

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

.stat-card,
.card {
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
}

.stat-value {
  display: block;
  font-size: 32px;
  font-weight: 800;
}

.stat-label {
  color: var(--muted);
  font-size: 13px;
}

.stat-sublabel {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 6px;
}

.grid-two {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
}

.stack-one {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

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

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 6px;
}

input,
select,
textarea {
  background: white;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  padding: 10px 12px;
  width: 100%;
}

input[type="checkbox"],
input[type="radio"] {
  accent-color: var(--primary);
  border-radius: 4px;
  padding: 0;
  width: auto;
}

.autocomplete-field {
  position: relative;
}

.guest-suggestions,
.room-suggestions,
.staff-suggestions {
  background: white;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 14px 30px rgba(15, 23, 42, 0.12);
  display: grid;
  gap: 4px;
  max-height: 190px;
  overflow-y: auto;
  padding: 6px;
  position: absolute;
  top: 74px;
  width: 100%;
  z-index: 12;
}

.guest-suggestion,
.room-suggestion,
.staff-suggestion {
  background: transparent;
  border-radius: 8px;
  color: var(--text);
  display: grid;
  font-weight: 500;
  padding: 8px 10px;
  text-align: left;
}

.guest-suggestion:hover,
.room-suggestion:hover,
.staff-suggestion:hover {
  background: var(--chip);
}

.guest-suggestion span,
.room-suggestion span,
.staff-suggestion span,
.field-help {
  color: var(--muted);
  font-size: 12px;
}

.selected-rooms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.selected-room-chip {
  align-items: center;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  display: inline-flex;
  gap: 8px;
  padding: 6px 8px 6px 10px;
}

.selected-room-chip button {
  border-radius: 999px;
  padding: 3px 8px;
}

.permissions-grid {
  align-items: stretch;
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.permission-chip {
  align-items: start;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 12px;
  column-gap: 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  grid-template-rows: auto auto;
  min-height: 76px;
  padding: 10px 12px;
  row-gap: 6px;
}

.permission-chip input[type="checkbox"] {
  align-self: start;
  flex-shrink: 0;
  grid-column: 1;
  grid-row: 1;
  height: 18px;
  justify-self: start;
  margin: 3px 0 0;
  max-height: 18px;
  max-width: 18px;
  width: 18px;
}

.permission-chip__title {
  font-size: 13px;
  font-weight: 600;
  grid-column: 2;
  grid-row: 1;
  line-height: 1.35;
  min-width: 0;
}

.permission-chip__slug {
  color: var(--muted);
  display: block;
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 11px;
  grid-column: 1 / -1;
  grid-row: 2;
  line-height: 1.35;
  margin: 0;
  padding-inline-start: 28px;
  word-break: break-word;
}

.guest-suggestion[hidden],
.room-suggestion[hidden],
.staff-suggestion[hidden] {
  display: none;
}

.guest-suggestions[hidden],
.room-suggestions[hidden],
.staff-suggestions[hidden] {
  display: none;
}

textarea {
  min-height: 84px;
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 10px;
  grid-column: 1 / -1;
}

.history-filters {
  display: grid;
  gap: 12px;
  grid-template-columns: minmax(220px, 1.5fr) repeat(3, minmax(150px, 1fr));
  margin-bottom: 16px;
}

.history-filters.guest-search-only {
  grid-template-columns: minmax(0, 1fr);
  max-width: 560px;
}

.guest-filter-count {
  margin: -4px 0 10px;
}

.table-wrap {
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
}

.table-pagination {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  margin-top: 12px;
}

.table-pagination button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

table {
  border-collapse: collapse;
  min-width: 100%;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.compact-label {
  min-width: 150px;
}

.daily-sheet-wrap {
  border: 1px solid var(--line);
  border-radius: 14px;
}

.daily-sheet-table th,
.daily-sheet-table td {
  text-align: center;
}

.daily-sheet-table th:first-child,
.daily-sheet-table td:first-child {
  text-align: left;
}

.daily-planning-note-input {
  min-width: 160px;
  width: 100%;
}

.daily-sheet-status {
  border-radius: 8px;
  font-weight: 800;
}

.daily-sheet-status.status-av {
  background: #dcfce7;
  color: #166534;
}

.daily-sheet-status.status-na {
  background: #fee2e2;
  color: #991b1b;
}

.daily-sheet-status.status-nc {
  background: #fef3c7;
  color: #92400e;
}

.pill {
  background: var(--chip);
  border-radius: 999px;
  color: var(--primary);
  display: inline-flex;
  font-size: 12px;
  font-weight: 800;
  padding: 4px 9px;
  text-transform: capitalize;
}

.pill.success {
  background: #e7f7ef;
  color: var(--success);
}

.pill.warning {
  background: #fff4d6;
  color: var(--warning);
}

.pill.danger {
  background: #fee4e2;
  color: var(--danger);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.dashboard-controls {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.dashboard-controls label {
  display: grid;
  font-size: 12px;
  gap: 4px;
}

.dashboard-controls input,
.dashboard-controls select {
  min-width: 130px;
}

.finance-tables {
  margin-top: 16px;
}

.calendar {
  display: grid;
  gap: 8px;
}

.calendar-controls {
  align-items: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.calendar-controls label {
  display: grid;
  font-size: 12px;
  gap: 4px;
}

.calendar-controls input {
  min-width: 150px;
}

.calendar-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 120px repeat(7, minmax(110px, 1fr));
}

.calendar-cell {
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 108px;
  padding: 10px;
}

.calendar-cell.clickable {
  cursor: pointer;
  transition:
    border-color 0.15s ease,
    box-shadow 0.15s ease,
    transform 0.15s ease;
}

.calendar-cell.clickable:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(36, 84, 214, 0.12);
  transform: translateY(-1px);
}

.calendar-cell.selected {
  background: #edf2ff;
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.calendar-cell.header {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  min-height: auto;
  text-transform: uppercase;
}

.room-calendar-header {
  align-content: start;
  display: grid;
  gap: 8px;
}

.calendar-housekeeping {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.housekeeping-badge {
  background: #fff4d6;
  border-radius: 999px;
  color: var(--warning);
  display: inline-flex;
  font-size: 11px;
  font-weight: 800;
  justify-content: center;
  max-width: 86px;
  overflow: hidden;
  padding: 4px 9px;
  text-transform: capitalize;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-housekeeping-actions {
  display: inline-flex;
  gap: 5px;
}

.mini-action {
  background: white;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
  padding: 6px 9px;
}

.mini-action:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.mini-action.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.mini-action.primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.housekeeping-cell-hint {
  color: var(--warning);
  font-weight: 800;
  padding-right: 6px;
}

.booking {
  background: var(--primary);
  border-radius: 8px;
  color: white;
  display: block;
  font-size: 12px;
  font-weight: 800;
  padding: 6px;
  text-align: left;
  width: 100%;
}

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

.details-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.detail-item {
  background: #fbfdff;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: grid;
  gap: 4px;
  padding: 12px;
}

.detail-item.full {
  grid-column: 1 / -1;
}

.detail-item span {
  color: var(--muted);
  font-size: 12px;
}

.detail-item strong {
  font-size: 14px;
  font-weight: 800;
}

.price-estimate {
  background: #edf2ff;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  justify-content: space-between;
  padding: 12px;
}

.price-estimate span {
  color: var(--muted);
}

.price-estimate strong {
  color: var(--primary);
}

.price-estimate div {
  display: grid;
  gap: 2px;
  text-align: right;
}

.price-estimate small {
  color: var(--muted);
}

.auto-room-hint {
  background: #f8fafc;
  border: 1px dashed var(--line);
  border-radius: 12px;
  color: var(--muted);
  padding: 12px;
}

.billing-panel {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 16px;
  margin-top: 16px;
  padding-top: 16px;
}

.billing-panel h3 {
  margin: 0;
}

.billing-stats .stat-value {
  font-size: 20px;
}

.compact-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.compact-grid > * {
  min-width: 0;
}

.cell-hint {
  color: var(--muted);
  display: inline-block;
  font-size: 12px;
  padding-top: 10px;
}

.cell-hint.strong {
  color: var(--primary);
  font-weight: 800;
}

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

.alert {
  background: #fee4e2;
  border: 1px solid #fecdca;
  border-radius: 12px;
  color: var(--danger);
  margin-bottom: 12px;
  padding: 12px;
}

.modal-backdrop {
  align-items: center;
  background: rgba(15, 23, 42, 0.48);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: fixed;
  z-index: 50;
}

.modal {
  background: var(--panel);
  border-radius: 20px;
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.28);
  isolation: isolate;
  max-height: calc(100vh - 40px);
  max-width: 760px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 20px;
  transform: translateZ(0);
  width: min(760px, 100%);
}

.modal.modal--guest {
  max-width: min(640px, 100%);
}

.guest-empty-hint {
  margin-top: 12px;
  text-align: center;
}

.guests-page .section-header .guests-page-actions {
  flex-shrink: 0;
}

.modal form[data-form] .form-actions {
  position: relative;
  z-index: 2;
}

form[data-form] button[type="submit"] {
  position: relative;
  touch-action: manipulation;
  z-index: 1;
}

@media (max-width: 980px) {
  .history-filters.guest-search-only {
    grid-template-columns: minmax(0, 1fr);
    max-width: none;
    width: 100%;
  }

  .layout,
  .grid-two {
    grid-template-columns: 1fr;
  }

  .layout {
    gap: 14px;
    padding: 14px;
  }

  .sidebar {
    position: static;
  }

  .main {
    min-width: 0;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  body {
    font-size: 14px;
    overflow-x: hidden;
  }

  button {
    padding: 10px 12px;
  }

  .app-shell {
    min-width: 0;
    width: 100%;
  }

  .topbar {
    display: grid;
    gap: 12px;
    grid-template-columns: 1fr;
    padding: 14px;
    position: static;
    width: 100%;
  }

  .topbar,
  .section-header {
    align-items: stretch;
    flex-direction: column;
  }

  .brand h1 {
    font-size: 18px;
  }

  .topbar .form-actions,
  .section-header .form-actions {
    display: grid;
    flex-wrap: wrap;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .topbar .form-actions button,
  .section-header .form-actions button,
  .form-actions button {
    flex: 1 1 auto;
  }

  form[data-form] .form-actions button[type="submit"] {
    min-height: 48px;
  }

  .layout {
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(0, 1fr);
    padding: 10px;
    width: 100%;
  }

  .sidebar {
    border-radius: 16px;
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-width: 100%;
    overflow: visible;
    padding: 8px;
    position: static;
    width: 100%;
  }

  .tab-button {
    min-width: 0;
    overflow-wrap: anywhere;
    text-align: center;
    white-space: normal;
    width: 100%;
  }

  .main {
    min-width: 0;
    width: 100%;
  }

  .section {
    border-radius: 16px;
    padding: 14px;
  }

  .stats-grid,
  .form-grid,
  .history-filters,
  .details-grid {
    grid-template-columns: 1fr;
  }

  .stat-value {
    font-size: 26px;
  }

  .form-actions,
  .row-actions,
  .dashboard-controls,
  .calendar-controls {
    align-items: stretch;
    flex-direction: column;
  }

  .history-filters.guest-search-only {
    grid-template-columns: minmax(0, 1fr);
    max-width: none;
    width: 100%;
  }

  .history-filters.guest-search-only label,
  .history-filters.guest-search-only input[type="search"] {
    min-width: 0;
  }

  .history-filters.guest-search-only input[type="search"] {
    min-height: 44px;
  }

  .dashboard-controls input,
  .dashboard-controls select,
  .calendar-controls input {
    min-width: 0;
  }

  .table-wrap {
    margin-inline: 0;
    max-width: 100%;
    min-width: 0;
    overflow-x: auto;
    padding-inline: 0;
    width: 100%;
  }

  .calendar {
    margin-inline: -14px;
    overflow-x: auto;
    padding-inline: 14px;
  }

  .table-wrap > table {
    width: max-content;
  }

  th,
  td {
    padding: 10px 8px;
  }

  .calendar-grid {
    grid-template-columns: 96px repeat(7, minmax(96px, 1fr));
    min-width: 780px;
  }

  .calendar-cell {
    min-height: 96px;
    padding: 8px;
  }

  .housekeeping-badge {
    max-width: 72px;
  }

  .price-estimate {
    align-items: flex-start;
    display: grid;
    gap: 8px;
  }

  .price-estimate div {
    text-align: left;
  }

  .permissions-grid {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    align-items: stretch;
    padding: 10px;
  }

  .modal {
    border-radius: 16px;
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    max-width: none;
    padding: 14px;
    padding-bottom: max(14px, calc(14px + env(safe-area-inset-bottom, 0px)));
    width: 100%;
  }

  .modal .form-actions {
    background: var(--panel);
    border-top: 1px solid var(--line);
    box-shadow: none;
    flex-direction: column;
    gap: 12px;
    isolation: isolate;
    justify-content: stretch;
    margin-left: 0;
    margin-right: 0;
    margin-top: 16px;
    padding: 16px 0 max(8px, env(safe-area-inset-bottom, 0px));
    position: static;
    transform: none;
    z-index: auto;
  }

  .modal .form-actions button {
    flex: 1 1 auto;
    min-height: 48px;
    position: relative;
    width: 100%;
    z-index: 1;
  }
}

@media (max-width: 420px) {
  .layout {
    padding: 8px;
  }

  .topbar .form-actions,
  .section-header .form-actions {
    grid-template-columns: 1fr;
  }

  .section {
    padding: 12px;
  }

  .sidebar {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    gap: 10px;
  }

  .stat-card,
  .card {
    padding: 12px;
  }

  .selected-room-chip {
    font-size: 12px;
  }

  .permission-chip__title {
    font-size: 12px;
  }

  .permission-chip__slug {
    font-size: 10px;
  }
}