* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color: #2a2a2a;
  background: #f7f7f5;
  -webkit-font-smoothing: antialiased;
}

/* === topbar === */
.topbar {
  background: #fff;
  border-bottom: 1px solid #e5e3dc;
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 24px;
}
.brand { font-weight: 600; font-size: 15px; }
.version { font-size: 10px; color: #888780; font-weight: 400; margin-left: 4px; }
.hotel-switch { display: flex; gap: 4px; flex-wrap: wrap; }
.hotel-switch a {
  text-decoration: none;
  color: #5f5e5a;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 12px;
}
.hotel-switch a:hover { background: #f1efe8; color: #2a2a2a; }
.hotel-switch a.active { background: #2a2a2a; color: #fff; }
.hotel-switch a .muted { opacity: 0.6; font-size: 10px; }

.user-menu {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.user-info {
  color: #5f5e5a;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.user-role {
  font-size: 9px;
  padding: 1px 6px;
  border-radius: 8px;
  font-weight: 500;
  text-transform: uppercase;
}
.user-role-owner { background: #FFF8E7; color: #854F0B; }
.user-role-reception { background: #E8F0FB; color: #185FA5; }

/* === controls === */
.controls {
  padding: 12px 16px 8px;
  background: #fff;
  border-bottom: 1px solid #e5e3dc;
}
.title-row { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.title-row h1 { font-size: 16px; font-weight: 600; margin: 0; }
.title-row .meta { font-size: 11px; color: #888780; }
.nav-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }

.btn {
  text-decoration: none;
  color: #2a2a2a;
  background: #fff;
  border: 1px solid #d3d1c7;
  padding: 5px 12px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.btn:hover { background: #f1efe8; }
.btn.small { padding: 3px 8px; font-size: 11px; }
.btn.active { background: #2a2a2a; color: #fff; border-color: #2a2a2a; }
.btn.primary { background: #185FA5; color: #fff; border-color: #185FA5; }
.btn.primary:hover { background: #0C447C; }
.btn.danger { background: #fff; color: #A32D2D; border-color: #F09595; }
.btn.danger:hover { background: #FCEBEB; }

.date-range { font-weight: 500; padding: 0 8px; }
.spacer { flex: 1; }
.zoom-label { color: #888780; font-size: 11px; }

/* === calendar — flex-per-row layout === */
.calendar-wrap {
  overflow: auto;
  background: #fff;
  border-bottom: 1px solid #e5e3dc;
  /* v0.16.0 — keep horizontal scroll smooth on long grids */
  scroll-behavior: auto;
  -webkit-overflow-scrolling: touch;
  /* Anchor the visible area at a sensible max height so the scroll bar is
     reachable on tall room lists. Vertical scroll already works inside. */
  max-height: calc(100vh - 280px);
  position: relative;
}

.calendar {
  display: block;
  font-size: 11px;
  width: max-content;
  min-width: 100%;
  position: relative;
}

.cal-header,
.cal-row {
  display: flex;
  align-items: stretch;
  /* v0.16.0 — virtualize off-screen day cells. content-visibility tells
     the browser it can skip layout/paint for cells outside the viewport.
     This is critical now that each row contains 365 day-slots. */
  content-visibility: auto;
  contain-intrinsic-size: auto 32px;
}

.cal-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: #fafaf7;
  /* Header stays painted always; do not virtualize it. */
  content-visibility: visible;
}

.cell {
  border-right: 1px solid #f1efe8;
  border-bottom: 1px solid #f1efe8;
  background: #fff;
  height: 32px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-sizing: border-box;
}

/* v0.16.0 — sticky-left columns must compute their `left` cumulatively so
   they stack without overlap. The struk column sits to the right of room-num,
   contract sits to the right of struk. */
.cell.room-num {
  background: #fafaf7;
  font-weight: 500;
  position: sticky;
  left: 0;
  z-index: 3;
}
.cell.struk {
  background: #fafaf7;
  font-size: 10px;
  color: #5f5e5a;
  position: sticky;
  left: 56px;          /* width of room-num */
  z-index: 3;
  padding: 2px 4px;
}
.cell.contract {
  background: #fafaf7;
  position: sticky;
  left: 132px;         /* 56 + 76 */
  z-index: 3;
  padding: 2px 4px;
}

.cell.head {
  background: #fafaf7;
  font-weight: 500;
  border-bottom: 1px solid #d3d1c7;
}
.cell.room-num.head, .cell.struk.head, .cell.contract.head { z-index: 6; }

.cell.day-head {
  background: #fafaf7;
  font-weight: 500;
  padding: 4px 1px;
  font-size: 10px;
  flex-direction: column;
  border-bottom: 1px solid #d3d1c7;
}
.cell.day-head.weekend { background: #fcebeb; color: #a32d2d; }
.cell.day-head.today { background: #FFF8E7; color: #854F0B; outline: 2px solid #EF9F27; outline-offset: -2px; }
.cell.day-head .day-num { font-size: 12px; font-weight: 600; line-height: 1; }
.cell.day-head .day-mon { font-size: 9px; color: #888780; text-transform: lowercase; line-height: 1; margin-top: 2px; }

/* v0.16.0 — month boundary marker on day headers (1st of month gets a thicker left border) */
.cell.day-head.month-start { border-left: 2px solid #888780; }

.cell.days-area {
  position: relative;
  padding: 0;
  border-right: none;
  align-items: stretch;
  justify-content: flex-start;
}

.day-slots {
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
}
.day-slot {
  height: 100%;
  border-right: 1px solid #f1efe8;
  flex-shrink: 0;
  cursor: pointer;
  background: #fff;
}
.day-slot:hover { background: #fafaf7; }
.day-slot.weekend { background: #fcebeb40; }
.day-slot.weekend:hover { background: #fcebeb80; }
.day-slot.today { background: #FFF8E720; }

/* v0.16.0 — vertical line at today's column, spans full grid height. */
.cal-today-indicator {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #EF9F27;
  pointer-events: none;
  z-index: 4;
  box-shadow: 0 0 4px rgba(239, 159, 39, 0.5);
}

.contract-pill {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border: 1px solid;
  border-radius: 8px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.booking-bar {
  position: absolute;
  top: 3px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  overflow: hidden;
  transition: transform 0.06s, box-shadow 0.06s;
  box-shadow: 0 1px 0 rgba(0,0,0,0.1);
  z-index: 2;
}
.booking-bar:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  z-index: 10;
}
.bar-text {
  display: block;
  font-size: 10px;
  color: #fff;
  font-weight: 500;
  padding: 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 1px rgba(0,0,0,0.25);
  width: 100%;
}

/* === legend === */
.legend {
  background: #fff;
  padding: 8px 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  font-size: 11px;
  border-bottom: 1px solid #e5e3dc;
}
.legend-section { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.legend-title { font-weight: 500; color: #5f5e5a; }
.legend-item { display: inline-flex; align-items: center; gap: 4px; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.legend-source { display: inline-block; width: 10px; height: 10px; border-radius: 2px; }
.legend-source-season_contract { background: #534AB7; }
.legend-source-operator_purchased { background: #7F77DD; }
.legend-source-ad_hoc_allotment { background: #1D9E75; }
.legend-source-direct_fit { background: #888780; }
.legend-source-group { background: #D85A30; }
.legend-source-unknown { background: #5F5E5A; }

.footer { padding: 8px 16px; font-size: 11px; color: #888780; }

/* === modal === */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20, 20, 20, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-backdrop.hidden { display: none; }
.modal {
  background: #fff;
  border-radius: 8px;
  width: 720px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid #e5e3dc;
}
.modal-header h2 { margin: 0; font-size: 15px; font-weight: 600; }
.modal-close {
  background: none; border: none;
  font-size: 22px; color: #888780;
  cursor: pointer; padding: 0 4px; line-height: 1;
}
.modal-close:hover { color: #2a2a2a; }
.modal-body { padding: 16px 18px; overflow-y: auto; }

.paste-section {
  background: #FFF8E7;
  border: 1px solid #FAC775;
  border-radius: 6px;
  padding: 10px 12px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.paste-section label { font-size: 11px; font-weight: 500; color: #854F0B; }
.paste-section textarea {
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid #FAC775;
  border-radius: 4px;
  resize: vertical;
  width: 100%;
}
.paste-section button { align-self: flex-start; }
.paste-hint { font-size: 11px; color: #5F5E5A; font-style: italic; line-height: 1.4; }
.paste-hint.loading { color: #185FA5; font-style: italic; }
.paste-hint.ai-high { color: #0F6E56; font-style: normal; font-weight: 500; }
.paste-hint.ai-medium { color: #854F0B; font-style: normal; }
.paste-hint.ai-low { color: #993556; font-style: normal; }
.paste-hint.regex { color: #5F5E5A; font-style: italic; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
}
.field { display: flex; flex-direction: column; gap: 3px; }
.field.full { grid-column: span 2; }
.field label { font-size: 11px; color: #5f5e5a; font-weight: 500; }
.field input, .field select, .field textarea {
  font-family: inherit;
  font-size: 12px;
  padding: 6px 8px;
  border: 1px solid #d3d1c7;
  border-radius: 4px;
  background: #fff;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: #185FA5;
}
.field input[readonly] {
  background: #f1efe8;
  color: #5f5e5a;
}

.field-hint {
  font-size: 10px;
  color: #5f5e5a;
  margin-top: 2px;
  font-style: italic;
}

.bed-warning {
  background: #FFF8E7;
  border: 1px solid #EF9F27;
  border-left: 4px solid #EF9F27;
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 12px;
  color: #6b3a07;
  line-height: 1.45;
}
.bed-warning strong { color: #854F0B; }
.bed-warning em { color: #5f5e5a; font-style: italic; }

.suggestions-btn {
  margin-top: 8px;
  background: #fff;
  border-color: #185FA5;
  color: #185FA5;
}
.suggestions-btn:hover {
  background: #185FA5;
  color: #fff;
}
.suggestions-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.suggestions-area {
  margin-top: 8px;
  padding: 10px 12px;
  background: #f7f7f5;
  border: 1px solid #d3d1c7;
  border-radius: 4px;
  font-size: 12px;
}
.sug-loading {
  color: #185FA5;
  font-style: italic;
  text-align: center;
  padding: 4px 0;
}
.sug-error {
  color: #A32D2D;
  padding: 4px 0;
}
.sug-empty {
  color: #5F5E5A;
  text-align: center;
  padding: 8px;
  font-style: italic;
}
.sug-header {
  font-weight: 500;
  color: #2a2a2a;
  margin-bottom: 8px;
  font-size: 11px;
  border-bottom: 1px solid #e5e3dc;
  padding-bottom: 4px;
}
.sug-period {
  font-weight: 400;
  color: #888780;
  font-size: 10px;
}
.sug-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sug-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fff;
  border: 1px solid #d3d1c7;
  border-radius: 4px;
  transition: border-color 0.1s, box-shadow 0.1s;
}
.sug-card:hover {
  border-color: #185FA5;
  box-shadow: 0 0 0 2px #185FA520;
}
.sug-main {
  flex: 1;
  min-width: 0;
}
.sug-title {
  font-weight: 600;
  font-size: 12px;
  color: #2a2a2a;
}
.sug-score {
  font-weight: 400;
  color: #888780;
  font-size: 10px;
  margin-left: 6px;
}
.sug-bed-layout {
  font-size: 11px;
  color: #5f5e5a;
  margin: 2px 0;
}
.sug-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 2px;
}
.sug-tag {
  font-size: 10px;
  padding: 1px 6px;
  background: #E8F4ED;
  color: #0F6E56;
  border-radius: 8px;
}

.modal-footer {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid #e5e3dc;
  background: #fafaf7;
}
