:root {
  /* Geometry — JS reads/sets the px values too; keep names in sync with app.js */
  --label-w: 196px;
  --night-w: 92px;
  --lane-h: 46px;
  --row-pad: 8px;
  --gap: 6px;

  --ink: #1f2430;
  --ink-soft: #5b6472;
  --line: #e4e7ee;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --primary: #2f6f5b;
  --primary-ink: #ffffff;
  --danger: #c0413b;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 6px 20px rgba(20, 30, 50, .08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: "Fraunces", Georgia, serif; font-weight: 600; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 22px;
  background: linear-gradient(120deg, #2f6f5b 0%, #3b5c7a 100%);
  color: #fff;
  box-shadow: var(--shadow);
}
.topbar-title { display: flex; align-items: center; gap: 14px; }
.mark {
  font-size: 26px;
  background: rgba(255,255,255,.16);
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 12px;
}
.topbar h1 { margin: 0; font-size: 22px; letter-spacing: .2px; }
.topbar h1 .muted { opacity: .8; font-weight: 500; }
.subtitle { margin: 2px 0 0; font-size: 13px; opacity: .9; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* Sync status pill */
.sync {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25);
  padding: 6px 11px; border-radius: 999px; color: #fff; white-space: nowrap;
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: #cfd8e3; flex: none; }
.sync.ok .sync-dot { background: #7ee0a8; }
.sync.busy .sync-dot { background: #ffd479; animation: pulse 1s ease-in-out infinite; }
.sync.err .sync-dot { background: #ff8a80; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@media (max-width: 560px) { .sync .sync-text { display: none; } }

/* Full-board loading / error message */
.board-msg { padding: 40px 24px; text-align: center; color: var(--ink-soft); font-size: 14px; }
.board-msg a { color: var(--primary); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  transition: transform .04s ease, background .15s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: #28604f; }
.btn-ghost { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.25); }
.btn-ghost:hover { background: rgba(255,255,255,.24); }
.btn-ghost.danger:hover { background: var(--danger); border-color: var(--danger); }

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 304px 1fr;
  gap: 18px;
  padding: 18px;
  align-items: start;
}
@media (max-width: 880px) {
  .layout { grid-template-columns: 1fr; }
}

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; gap: 16px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px;
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel h2.mt { margin-top: 16px; }
.hint { margin: 0 0 12px; font-size: 12px; color: var(--ink-soft); line-height: 1.4; }

.add-person { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 14px; }
.add-person input, .add-person select, .field input, .field select {
  font: inherit; font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  background: #fff;
  color: var(--ink);
}
.add-person input { grid-column: 1 / 2; }
.add-person select { grid-column: 1 / 2; }
.add-person .btn { grid-column: 2 / 3; grid-row: 1 / 3; }
.add-person input:focus, .add-person select:focus { outline: 2px solid var(--primary); outline-offset: 0; }

/* ---------- People pool ---------- */
.people-pool { display: flex; flex-wrap: wrap; gap: 8px; }
.person-card {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px 6px 8px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 600;
  cursor: grab;
  user-select: none;
  touch-action: none;
  box-shadow: 0 1px 1px rgba(20,30,50,.05);
}
.person-card:active { cursor: grabbing; }
.person-card.placed { opacity: .55; }
.person-card .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.person-card .ptype { font-size: 10px; color: var(--ink-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.person-card .px { margin-left: 2px; color: var(--ink-soft); font-weight: 700; cursor: pointer; padding: 0 2px; }
.person-card .px:hover { color: var(--danger); }
.pool-empty { font-size: 12px; color: var(--ink-soft); font-style: italic; }

/* ---------- Legend ---------- */
.legend { display: flex; flex-direction: column; gap: 7px; }
.legend-item { display: flex; align-items: center; gap: 9px; font-size: 13px; }
.legend-item .sw { width: 16px; height: 16px; border-radius: 5px; flex: none; border: 1px solid rgba(0,0,0,.08); }
.legend-item .cnt { margin-left: auto; font-size: 11px; color: var(--ink-soft); }
.legend-item .badge { font-size: 10px; }

/* ---------- Board ---------- */
.board-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: calc(100vh - 116px);
}
.board { min-width: max-content; position: relative; }

.board-header { display: flex; position: sticky; top: 0; z-index: 6; }
.week-band-row, .day-row { display: flex; }

.corner {
  flex: 0 0 var(--label-w);
  position: sticky; left: 0; z-index: 7;
  background: #fbfcfe;
  border-right: 2px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; padding: 0 14px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-soft);
}
.weeks { display: flex; flex-direction: column; background: #fbfcfe; }
.week-band {
  display: flex; align-items: center; justify-content: center;
  height: 26px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
}
.day-cells { display: flex; }
.day-head {
  flex: 0 0 var(--night-w);
  height: 46px;
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 12px; gap: 1px;
  background: #fbfcfe;
}
.day-head.weekend { background: #f1f5fb; }
.day-head .dow { font-size: 10px; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .04em; }
.day-head .dnum { font-weight: 700; }
.day-head.week-edge, .week-band.week-edge { border-right: 2px solid #cdd4e0; }

/* Unit rows */
.unit-row { display: flex; border-bottom: 1px solid var(--line); }
.unit-row:last-child { border-bottom: none; }
.unit-label {
  flex: 0 0 var(--label-w);
  position: sticky; left: 0; z-index: 5;
  background: #fff;
  border-right: 2px solid var(--line);
  padding: 10px 12px 10px 14px;
  display: flex; flex-direction: column; gap: 3px;
  border-left: 5px solid var(--owner, #ccc);
}
.unit-label .uname { font-weight: 700; font-size: 14px; }
.unit-label .uowner { font-size: 11px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; }
.unit-label .ubeds { font-size: 11px; color: var(--ink-soft); }

.unit-track { position: relative; flex: none; }
.night-cells { position: absolute; inset: 0; display: flex; z-index: 1; }
.night-cell {
  flex: 0 0 var(--night-w);
  border-right: 1px solid var(--line);
}
.night-cell.weekend { background: #f7f9fd; }
.night-cell.week-edge { border-right: 2px solid #cdd4e0; }
.night-cell.drop-target { background: rgba(47,111,91,.14); box-shadow: inset 0 0 0 2px rgba(47,111,91,.4); }

/* Stay bars */
.stays-layer { position: relative; z-index: 2; }
/* While dragging, let the hit-test fall through bars to the night cells below */
body.dragging .stays-layer { pointer-events: none; }
body.dragging { cursor: grabbing; }
.stay {
  position: absolute;
  height: calc(var(--lane-h) - var(--gap));
  border-radius: 9px;
  background: var(--c, #6b7a8d);
  color: #fff;
  display: flex; align-items: center;
  padding: 0 9px;
  font-size: 12.5px; font-weight: 600;
  cursor: grab;
  user-select: none;
  touch-action: none;
  box-shadow: 0 1px 3px rgba(20,30,50,.28);
  overflow: hidden;
  white-space: nowrap;
}
.stay:active { cursor: grabbing; }
.stay .stay-name { overflow: hidden; text-overflow: ellipsis; }
.stay .stay-type { margin-left: 6px; font-size: 9px; opacity: .85; text-transform: uppercase; letter-spacing: .04em; background: rgba(255,255,255,.22); padding: 1px 5px; border-radius: 5px; }
.stay-handle {
  position: absolute; top: 0; bottom: 0; width: 11px;
  cursor: ew-resize; touch-action: none;
}
.stay-handle.left { left: 0; }
.stay-handle.right { right: 0; }
.stay-handle::after {
  content: ""; position: absolute; top: 50%; transform: translateY(-50%);
  height: 16px; width: 3px; border-radius: 3px; background: rgba(255,255,255,.6);
}
.stay-handle.left::after { left: 3px; }
.stay-handle.right::after { right: 3px; }

/* Drag ghost */
.drag-ghost {
  position: fixed; z-index: 999; pointer-events: none;
  padding: 6px 12px; border-radius: 999px; color: #fff; font-size: 13px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(20,30,50,.3); transform: translate(-50%, -140%);
  background: #6b7a8d;
}

/* ---------- Popover ---------- */
.popover-backdrop {
  position: fixed; inset: 0; background: rgba(20,30,50,.4);
  display: grid; place-items: center; z-index: 50; padding: 16px;
}
/* The [hidden] attribute must win over the display rule above, or the overlay
   stays up and blocks every click on the page. */
.popover-backdrop[hidden] { display: none; }
.popover {
  background: #fff; border-radius: 16px; width: min(360px, 100%);
  box-shadow: 0 20px 60px rgba(20,30,50,.3); overflow: hidden;
}
.popover-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700;
}
.icon-btn { border: none; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-soft); }
.icon-btn:hover { color: var(--ink); }
.popover-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.field select, .field input { width: 100%; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper .val { flex: 1; text-align: center; font-size: 13px; font-weight: 600; }
.stepper button {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; font-size: 16px; cursor: pointer; font-weight: 700;
}
.stepper button:hover { background: #f3f5f9; }
.pop-actions { display: flex; justify-content: space-between; gap: 8px; }
.nights-summary { font-size: 12px; color: var(--ink-soft); }

/* ---------- Week sections & year control (fixed-week layout) ---------- */
/* The board stacks one section per timeshare week (24, 25). */
.week-section:not(:last-child) { border-bottom: 8px solid var(--bg); }

/* Sticky headers from later sections replace earlier ones as you scroll. */
.week-section:nth-child(2) .board-header { z-index: 4; }

/* Corner shows the week number above the "Condo · Owner" caption. */
.corner {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 2px;
  text-transform: none;
}
.corner-week {
  font-family: "Fraunces", Georgia, serif;
  font-size: 14px; font-weight: 600; letter-spacing: 0;
  color: var(--ink); text-transform: none;
}
.corner-sub { font-size: 10px; text-transform: uppercase; letter-spacing: .05em; }

/* "small" / other per-unit notes next to the unit name. */
.unit-label .unote {
  font-weight: 500; font-size: 10px; color: var(--ink-soft);
  font-style: italic; text-transform: lowercase;
}

/* Year switcher in the top bar (flips odd/even-year ownership). */
.year-control {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.25);
  border-radius: 999px; padding: 4px 8px; color: #fff;
  font-size: 13px; font-weight: 700;
}
.year-control #year-val { min-width: 40px; text-align: center; }
.yr-btn {
  background: rgba(255,255,255,.18); border: none; color: #fff;
  width: 22px; height: 22px; border-radius: 50%; cursor: pointer;
  font-size: 10px; line-height: 1; display: grid; place-items: center;
}
.yr-btn:hover { background: rgba(255,255,255,.32); }

/* ---------- Password gate ---------- */
.auth-gate {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 20px;
  background: linear-gradient(120deg, #2f6f5b 0%, #3b5c7a 100%);
}
.auth-gate[hidden] { display: none; }
.auth-card {
  background: #fff; border-radius: 18px; box-shadow: 0 20px 60px rgba(20,30,50,.35);
  width: min(360px, 100%); padding: 28px 26px; text-align: center;
  display: flex; flex-direction: column; gap: 10px;
}
.auth-mark {
  font-size: 30px; width: 58px; height: 58px; margin: 0 auto 4px;
  display: grid; place-items: center; border-radius: 14px; background: #eef3f1;
}
.auth-card h2 { margin: 0; font-size: 20px; }
.auth-sub { margin: 0 0 6px; font-size: 13px; color: var(--ink-soft); line-height: 1.4; }
.auth-card input {
  font: inherit; font-size: 15px; text-align: center;
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; background: #fff;
}
.auth-card input:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.auth-card .btn { padding: 11px; font-size: 14px; }
.auth-error { margin: 0; font-size: 12px; font-weight: 600; color: var(--danger); }
.auth-error[hidden] { display: none; }
