:root {
  --bg: #f4f5fb;
  --surface: #ffffff;
  --border: #e3e4ee;
  --text: #1f2233;
  --muted: #6b6f86;
  --accent: #5b5bd6;
  --accent-strong: #4444c4;
  --accent-soft: #ecebfb;
  --good: #21a366;
  --good-soft: #d8f1e4;
  --warn: #c2410c;
  --shadow: 0 1px 2px rgba(20, 22, 48, 0.06), 0 8px 24px rgba(20, 22, 48, 0.06);
  --radius: 14px;
  --genius-gradient: linear-gradient(120deg, #5b5bd6, #9333ea 45%, #ec4899);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  /* Column layout so the footer is pushed to the bottom on short pages. */
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

main {
  flex: 1;
}

a {
  color: var(--accent);
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 0.4em;
}

p {
  margin: 0 0 1em;
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-header .inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin-top: 40px;
  font-size: 13px;
  color: var(--muted);
}

.site-footer .inner {
  max-width: 1040px;
  margin: 0 auto;
  padding: 18px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-links {
  display: flex;
  gap: 18px;
}

.footer-links a {
  color: var(--muted);
  text-decoration: none;
}

.footer-links a:hover {
  color: var(--text);
}

.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.01em;
}

.genius {
  background: var(--genius-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  color: transparent;
  font-weight: 700;
}

/* The wordmark: "Roomie" in solid ink, "Genius" in gradient. In the header
   and hero (.brandmark) "Genius" becomes a filled gradient pill instead. */
.roomie {
  color: var(--text);
  font-weight: 700;
}

.brandmark .genius {
  margin-left: 5px;
  padding: 1px 10px;
  border-radius: 9px;
  background: var(--genius-gradient);
  -webkit-background-clip: border-box;
  background-clip: border-box;
  -webkit-text-fill-color: #fff;
  color: #fff;
}

.header-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 14px;
  color: var(--muted);
}

/* --- account menu --- */
.user-menu {
  position: relative;
  display: flex;
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.user-avatar:hover {
  filter: brightness(0.96);
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  box-shadow: 0 8px 28px rgba(20, 22, 48, 0.14);
  padding: 6px;
  z-index: 50;
}

.user-menu-id {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}

.user-menu-id strong {
  font-size: 14px;
  color: var(--text);
}

.user-menu-id .muted {
  font-size: 13px;
}

.user-menu form {
  margin: 0;
}

.user-menu-item {
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 7px;
  padding: 8px 10px;
  cursor: pointer;
}

.user-menu-item:hover {
  background: var(--bg);
}

.page {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 24px 80px;
}

.page-narrow {
  max-width: 620px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}

.card + .card {
  margin-top: 20px;
}

.danger-zone {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

/* Accent-tinted intro card on the demo dashboard. */
.demo-notice {
  background: var(--accent-soft);
  border-color: transparent;
  box-shadow: none;
  color: var(--accent-strong);
  padding: 16px 20px;
  line-height: 1.5;
}

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

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

.dashboard-head {
  margin-bottom: 22px;
}

.dashboard-meta {
  margin-top: 8px;
}

.event-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.event-title h1 {
  margin: 0;
}

.event-title-edit {
  border: none;
  background: transparent;
  padding: 4px;
  cursor: pointer;
  color: var(--muted);
  line-height: 0;
}

.event-title-edit:hover {
  color: var(--accent);
}

.event-title-edit svg {
  display: block;
  width: 18px;
  height: 18px;
}

.event-title-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.title-edit-input {
  flex: 1;
  min-width: 0;
}

.muted {
  color: var(--muted);
}

.label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}

input[type="text"],
input[type="number"],
textarea,
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 11px;
}

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

input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.field {
  margin-bottom: 16px;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  font-size: 14px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 16px;
  text-decoration: none;
  transition: background 120ms ease, border-color 120ms ease;
}

.btn:hover {
  background: var(--bg);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-genius {
  background: var(--genius-gradient);
  border-color: transparent;
  color: #fff;
  /* Hold a steady width so the label can swap to "Working…" without a jump. */
  min-width: 132px;
  white-space: nowrap;
}

.btn-genius:hover {
  background: var(--genius-gradient);
  filter: brightness(1.08);
}

/* Pulsing ring to draw the eye to the primary call to action. */
@keyframes btn-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(147, 51, 234, 0.5);
  }
  70% {
    box-shadow: 0 0 0 12px rgba(147, 51, 234, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(147, 51, 234, 0);
  }
}

.btn-pulse {
  animation: btn-pulse 2s infinite;
}

.btn-pulse:disabled {
  animation: none;
}

@media (prefers-reduced-motion: reduce) {
  .btn-pulse {
    animation: none;
  }
}

.btn-lg {
  padding: 12px 22px;
  font-size: 16px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
}

/* Borderless, quiet button — reads as a text link next to a real button. */
.btn-ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
}

.btn-ghost:hover {
  background: transparent;
  color: var(--text);
}

.btn-danger {
  color: var(--warn);
}

.btn-danger:hover {
  background: #fdeceb;
  border-color: var(--warn);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* The delete form wraps a button; flex strips the inline line-box slack
   that otherwise misaligns it next to the Edit link. */
.row-actions form {
  display: flex;
  margin: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.pill-good {
  background: var(--good-soft);
  color: var(--good);
}

.pill-draft {
  background: #f0f0f4;
  color: var(--muted);
}

.notice {
  border-radius: 9px;
  padding: 10px 13px;
  font-size: 14px;
}

.notice-error {
  background: #fdeceb;
  color: #b42318;
}

.notice-info {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.notice-good {
  background: var(--good-soft);
  color: var(--good);
}

.hero {
  text-align: center;
  padding: 28px 0 8px;
}

.hero h1 {
  font-size: 38px;
  letter-spacing: -0.02em;
}

.hero p.lead {
  font-size: 17px;
  color: var(--muted);
  max-width: 540px;
  margin: 0 auto 24px;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.feature h3 {
  font-size: 15px;
}

.feature p {
  font-size: 14px;
  color: var(--muted);
  margin: 0;
}

.copy-link {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.share-link {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
  word-break: break-all;
}

.copy-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

.copy-btn:hover {
  background: var(--bg);
  color: var(--accent);
}

.copy-btn svg {
  display: block;
  width: 16px;
  height: 16px;
}

/* --- toggle switch --- */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 14px;
}

.switch {
  flex-shrink: 0;
  width: 40px;
  height: 23px;
  padding: 2px;
  border: none;
  border-radius: 999px;
  background: var(--border);
  cursor: pointer;
  display: inline-flex;
  transition: background 140ms ease;
}

.switch-knob {
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 22, 48, 0.3);
  transition: transform 140ms ease;
}

.switch-on {
  background: var(--good);
}

.switch-on .switch-knob {
  transform: translateX(17px);
}

/* Checkbox styled as a switch — submits as a normal form field. */
.toggle-row {
  cursor: pointer;
}

.switch-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  margin: 0;
}

.switch-input:checked + .switch {
  background: var(--good);
}

.switch-input:checked + .switch .switch-knob {
  transform: translateX(17px);
}

.switch-input:focus-visible + .switch {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.event-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 20px;
}

.event-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: border-color 120ms ease, background 120ms ease;
}

.event-row:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.event-row-name {
  font-weight: 600;
  font-size: 16px;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 3px 8px;
}

.tag-done {
  background: var(--good-soft);
  border-color: transparent;
  color: var(--good);
}

.roster-group + .roster-group {
  margin-top: 14px;
}

.roster-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.roster-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px 3px 2px 8px;
}

.roster-pill.done {
  background: var(--good-soft);
  border-color: transparent;
  color: var(--good);
}

.roster-pill.removing {
  opacity: 0.4;
  pointer-events: none;
}

.roster-pill-x {
  border: none;
  background: transparent;
  cursor: pointer;
  color: inherit;
  opacity: 0.55;
  font-size: 15px;
  line-height: 1;
  padding: 1px 5px;
  border-radius: 5px;
}

.roster-pill-x:hover {
  opacity: 1;
  background: rgba(20, 22, 48, 0.1);
}

.token-input {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 16px;
}

.token-input .btn {
  align-self: flex-start;
}

.field .token-input {
  margin-top: 0;
}

.token-field {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 8px;
  cursor: text;
  min-height: 38px;
}

.token-field:focus-within {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.token-pills {
  display: contents;
}

.token-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-radius: 7px;
  padding: 2px 3px 2px 8px;
}

.token-pill.active {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.token-pill-x {
  border: none;
  background: transparent;
  cursor: pointer;
  color: inherit;
  opacity: 0.6;
  font-size: 15px;
  line-height: 1;
  padding: 1px 5px;
  border-radius: 5px;
}

.token-pill-x:hover {
  opacity: 1;
  background: rgba(20, 22, 48, 0.1);
}

.token-text {
  flex: 1;
  min-width: 120px;
  border: none !important;
  outline: none !important;
  background: transparent;
  padding: 3px 2px !important;
}

.token-input.pending {
  opacity: 0.7;
}

/* --- Optimizer --- */

.opt-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.sim-count {
  margin-left: auto;
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}

.unassigned-bucket {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border: 1px dashed var(--border);
  border-radius: 11px;
  background: var(--surface);
}

.unassigned-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.drag-pill {
  cursor: grab;
  position: relative;
}

.drag-pill:active {
  cursor: grabbing;
}

.pill-pop {
  display: none;
  position: absolute;
  z-index: 20;
  left: 0;
  top: calc(100% + 6px);
  min-width: 150px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
  pointer-events: none;
}

.drag-pill:hover .pill-pop {
  display: block;
}

/* Suppress the hover card while a drag is in progress. */
.stack.dragging .pill-pop {
  display: none;
}

.pop-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

.pill-chip {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 14px;
  font-weight: 600;
}

.drag-over {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  background: var(--accent-soft);
}

.room {
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 12px;
  background: var(--surface);
}

.add-room {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 140px;
  border: 2px dashed var(--border);
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.add-room:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.add-room svg {
  width: 30px;
  height: 30px;
}

.room-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.room-head h4 {
  margin: 0;
  font-size: 14px;
}

.slot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 8px;
  margin-top: 6px;
  font-size: 14px;
}

.slot.empty {
  color: var(--muted);
  font-style: italic;
  justify-content: center;
}

.slot.locked {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.slot-name {
  font-weight: 600;
  flex: 1;
  min-width: 0;
}

/* The name text ellipsizes here so .slot-name itself has no overflow
   clipping — that would hide the .pill-pop hover card. */
.pill-name {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.slot-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  padding: 3px 6px;
}

.icon-btn:hover {
  background: var(--bg);
}

.icon-btn svg {
  display: block;
  width: 14px;
  height: 14px;
}

.pref-grid {
  display: flex;
  gap: 3px;
  position: relative;
  cursor: help;
}

/* In a room, the hover card is triggered by the pref squares, and opens
   leftward so it stays inside the room card. */
.pref-grid:hover .pill-pop {
  display: block;
}

.pref-grid .pill-pop {
  left: auto;
  right: 0;
}

.pref-cell {
  width: 9px;
  height: 16px;
  border-radius: 2px;
  border: 1px solid var(--border);
}

.pref-cell.hit {
  background: var(--good);
  border-color: var(--good);
}

.pref-cell.miss {
  background: #e7e7ee;
}

.pref-cell.none {
  background: transparent;
}

.table-scroll {
  overflow-x: auto;
}

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

.people-table tr.superseded td {
  opacity: 0.55;
}

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

.people-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

@media (max-width: 640px) {
  .feature-grid {
    grid-template-columns: 1fr;
  }
  .hero h1 {
    font-size: 30px;
  }
}

/* --- CSV import dialog --- */
.import-submissions {
  display: inline-flex;
}

.import-dialog {
  margin: auto;
  max-width: 460px;
  width: calc(100vw - 40px);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

.import-dialog::backdrop {
  background: rgba(20, 22, 48, 0.45);
}

.import-dialog h3 {
  font-size: 17px;
}

.import-dialog input[type="file"] {
  width: 100%;
  font: inherit;
  font-size: 14px;
}
