/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
  --radius: 8px;
  --radius-lg: 12px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1.5px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-full { width: 100%; justify-content: center; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: background .15s, color .15s;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── Form elements ── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary);
}
.field select { cursor: pointer; }
.field-checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field-checkbox input[type="checkbox"] { width: 16px; height: 16px; padding: 0; border: none; flex-shrink: 0; cursor: pointer; accent-color: var(--primary); }
.field-checkbox label { font-size: 14px; cursor: pointer; margin: 0; }
.error-msg { color: var(--danger); font-size: 13px; min-height: 18px; }
.field-hint { font-size: 12px; color: var(--text-muted); }

/* Advanced config collapsible */
.advanced-config {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.advanced-config summary {
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  transition: background .12s, color .12s;
}
.advanced-config summary::-webkit-details-marker { display: none; }
.advanced-config summary::before {
  content: '▸';
  font-size: 11px;
  transition: transform .15s;
  display: inline-block;
}
.advanced-config[open] summary::before { transform: rotate(90deg); }
.advanced-config summary:hover { background: var(--bg); color: var(--text); }
.advanced-config-body {
  padding: 12px 14px;
  border-top: 1.5px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── HOME PAGE ── */
.home-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px;
}

.home-container {
  width: 100%;
  max-width: 760px;
}

.home-header {
  text-align: center;
  margin-bottom: 40px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.logo-icon { width: 48px; height: 36px; transform: rotate(180deg); }
.logo-text { font-size: 28px; font-weight: 700; color: var(--text); }
.tagline { color: var(--text-muted); font-size: 16px; }

.home-cards {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 0;
}

.home-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: var(--shadow);
}
.home-card h2 { font-size: 18px; font-weight: 600; }
.card-desc { color: var(--text-muted); font-size: 14px; line-height: 1.5; }

.home-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 24px;
  padding-top: 80px;
}
.home-divider span {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  background: var(--bg);
  padding: 4px 8px;
  border-radius: 20px;
}

@media (max-width: 600px) {
  .home-cards { grid-template-columns: 1fr; }
  .home-divider { padding: 16px 0; }
  .home-divider span::before { content: ''; }
}

/* ── ROOM PAGE ── */
.room-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.room-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

#room-header {
  background: var(--surface);
  border-bottom: 1.5px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.logo-sm {
  text-decoration: none;
  flex-shrink: 0;
  display: flex;
  align-items: center;
}
.logo-sm svg { width: 29px; height: 22px; transform: rotate(180deg); }
.room-title {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 260px;
}
.room-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 2px;
}
.room-code-badge {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .08em;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 20px;
  font-family: monospace;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.participants-bar {
  width: 168px;
  flex-shrink: 0;
  border-left: 1.5px solid var(--border);
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px 0;
  gap: 2px;
}
.participant-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 12px;
  border-radius: 0;
}
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  position: relative;
}
.avatar-facilitator::before {
  content: '👑';
  position: absolute;
  top: -9px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  line-height: 1;
}
.participant-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.participant-name.is-facilitator {
  color: var(--primary);
}

.facilitator-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  position: relative;
}
.facilitator-controls.hidden { display: none; }

.delegate-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 170px;
  z-index: 50;
  overflow: hidden;
}
.delegate-dropdown-item {
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.delegate-dropdown-item:hover { background: var(--bg); }
.avatar-mini {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

/* Sort control */
#sort-control { position: relative; }
.sort-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  min-width: 120px;
  z-index: 50;
  overflow: hidden;
}
.sort-dropdown-item {
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
}
.sort-dropdown-item:hover { background: var(--bg); }
.sort-dropdown-item.active { color: var(--primary); font-weight: 600; }

/* ── COLUMNS ── */
.columns-container {
  flex: 1;
  display: flex;
  gap: 16px;
  padding: 20px;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: stretch;
}

.column {
  flex: 1;
  min-width: 280px;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.column-header {
  padding: 14px 16px 12px;
  border-bottom: 2px solid transparent;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.column-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.column-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.column-count {
  font-size: 12px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
  background: var(--bg);
  color: var(--text-muted);
}

.export-control {
  display: flex;
  gap: 4px;
}

.column-export-btns {
  display: flex;
  gap: 4px;
}

.column-export-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap;
}
.column-export-btn:hover { background: var(--bg); color: var(--text); border-color: #a5b4fc; }

.cards-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── CARDS ── */
.card {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  animation: cardIn .18s ease-out;
  transition: box-shadow .15s, border-color .15s;
}
.card:hover { box-shadow: var(--shadow); }
.card.is-own { border-color: #c7d2fe; background: #f5f3ff; }
.card[draggable="true"] { cursor: grab; }
.card.dragging { opacity: 0.4; }

.cards-blurred .card:not(.is-own) .card-text,
.cards-blurred .card:not(.is-own) .card-author {
  filter: blur(6px);
  user-select: none;
  transition: filter .2s;
}
.cards-blurred .card:not(.is-own):hover .card-text,
.cards-blurred .card:not(.is-own):hover .card-author {
  filter: blur(6px);
}
.cards-blurred .card:not(.is-own) .vote-btn {
  opacity: 0.4;
  pointer-events: none;
  cursor: default;
}

.cards-list.drag-over {
  background: var(--primary-light);
  border-radius: var(--radius);
  outline: 2px dashed var(--primary);
  outline-offset: -6px;
}

.card.merge-target {
  outline: 2px dashed var(--primary);
  outline-offset: -2px;
  background: var(--primary-light);
}

@keyframes cardIn {
  from { opacity: 0; transform: translateY(-6px) scale(.98); }
  to { opacity: 1; transform: none; }
}

.card-text {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  word-break: break-word;
}
.card-text.plain { white-space: pre-wrap; }
.card-text > :first-child { margin-top: 0; }
.card-text > :last-child { margin-bottom: 0; }
.card-text p { margin: 0 0 .4em; }
.card-text ul, .card-text ol { margin: 0 0 .4em; padding-left: 1.4em; }
.card-text code { font-size: 12px; background: rgba(0,0,0,.06); border-radius: 3px; padding: 1px 4px; }
.card-text pre { font-size: 12px; background: rgba(0,0,0,.06); border-radius: 4px; padding: 6px 8px; overflow-x: auto; margin: 0 0 .4em; }
.card-text pre code { background: none; padding: 0; }
.card-text strong { font-weight: 600; }
.card-text a { color: var(--primary); }
.card-author {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.vote-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all .15s;
}
.vote-btn:hover { border-color: #a5b4fc; color: var(--primary); }
.vote-btn.voted {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.vote-btn .vote-count { font-weight: 600; }

.card-actions {
  display: flex;
  gap: 4px;
}
.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .12s, color .12s;
  font-size: 13px;
}
.action-btn:hover { background: var(--bg); color: var(--text); }
.action-btn.danger:hover { background: var(--danger-light); color: var(--danger); }

/* Inline edit */
.card-edit-area {
  width: 100%;
  padding: 6px 8px;
  border: 1.5px solid var(--primary);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.55;
  resize: vertical;
  min-height: 60px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
.card-edit-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ── ADD CARD ── */
.add-card-area {
  padding: 8px 12px 12px;
  flex-shrink: 0;
}

.add-card-btn {
  width: 100%;
  padding: 10px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.add-card-btn:hover {
  background: var(--bg);
  border-style: solid;
  color: var(--text);
}

.add-card-form { display: flex; flex-direction: column; gap: 8px; }
.add-card-form textarea {
  width: 100%;
  padding: 10px;
  border: 1.5px solid var(--primary);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font);
  line-height: 1.5;
  resize: vertical;
  min-height: 80px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}
.add-card-form-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 100;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-logo { text-align: center; }
.modal-logo svg { width: 48px; height: 36px; transform: rotate(180deg); }
.modal h2 { font-size: 20px; font-weight: 700; text-align: center; }
.modal-subtitle { color: var(--text-muted); font-size: 14px; text-align: center; }

/* ── TOAST ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease-out, toastOut .3s ease-in 2.5s forwards;
  max-width: 300px;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes toastOut {
  to { opacity: 0; transform: translateY(8px); }
}

/* ── MISC ── */
.hidden { display: none !important; }

.copy-success { color: #10b981 !important; border-color: #6ee7b7 !important; }

/* Votes counter badge */
.votes-counter {
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
  white-space: nowrap;
}
.votes-counter.exhausted {
  background: var(--danger-light);
  color: var(--danger);
}

/* Disabled vote button */
.vote-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  pointer-events: none;
}
