/* ============================================================
   RESET & VARIABLES
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary:         #6366F1;
  --primary-dark:    #4F46E5;
  --primary-light:   #EEF2FF;
  --surface:         #FFFFFF;
  --surface-2:       #F8F9FA;
  --border:          #E5E7EB;
  --text:            #111827;
  --text-muted:      #6B7280;
  --available:       #16A34A;
  --available-bg:    #DCFCE7;
  --unavailable:     #DC2626;
  --unavailable-bg:  #FEE2E2;
  --radius:          14px;
  --radius-sm:       10px;
  --shadow:          0 1px 8px rgba(0,0,0,0.08);
  --shadow-md:       0 4px 20px rgba(0,0,0,0.10);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, sans-serif;
  background: var(--surface-2);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

/* ============================================================
   LOADING
   ============================================================ */
.loading-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100dvh;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   SCREEN BASE
   ============================================================ */
.screen {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 15px 24px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}

.btn:active  { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; pointer-events: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 2px solid var(--primary);
  padding: 13px 20px;
  width: auto;
  flex-shrink: 0;
}
.btn-secondary:hover { background: var(--primary-light); }

.btn-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  cursor: pointer;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}
.btn-icon:hover   { background: var(--primary); color: #fff; }
.btn-icon.success { background: var(--available); color: #fff; }

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.input {
  width: 100%;
  padding: 15px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.15s;
  -webkit-appearance: none;
}
.input:focus { border-color: var(--primary); }
.input.error { border-color: var(--unavailable); }
.input::placeholder { color: var(--text-muted); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60%  { transform: translateX(-6px); }
  40%, 80%  { transform: translateX(6px); }
}
.shake { animation: shake 0.35s ease; }

/* ============================================================
   HOME SCREEN
   ============================================================ */
.home-screen {
  display: block;
  min-height: 100dvh;
}

/* ── Hero + CTA (top section) ── */
.home-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 52px 24px 44px;
  gap: 40px;
}

.home-hero { text-align: center; }

.home-logo {
  width: 80px;
  height: 80px;
  background: var(--primary);
  color: #fff;
  font-size: 32px;
  font-weight: 900;
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 30px rgba(99,102,241,0.35);
  letter-spacing: -1px;
}

.home-hero h1 {
  font-size: 40px;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -2px;
}

.home-hero p {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 17px;
  max-width: 360px;
  line-height: 1.5;
}

.home-actions {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── SEO content (below CTA) ── */
.home-seo {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0 0 48px;
}

.seo-section {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 24px 0;
}

.seo-section h2 {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 24px;
  letter-spacing: -0.5px;
}

/* 3-step how-it-works */
.seo-steps {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.seo-step {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.step-num {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 16px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.seo-step h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 4px;
}

.seo-step p {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.55;
}

/* Feature grid */
.seo-features {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 480px) {
  .seo-features { grid-template-columns: 1fr; }
}

.seo-feature {
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.feat-icon {
  font-size: 24px;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 1px;
}

.seo-feature h3 {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 3px;
}

.seo-feature p {
  font-size: 14px;
  color: var(--text-muted);
  line-height: 1.5;
}

/* About paragraph */
.seo-about p {
  font-size: 15px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 12px;
}
.seo-about p:last-child { margin-bottom: 0; }

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-muted);
  font-size: 13px;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.join-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.join-row .input { flex: 1; }

/* ============================================================
   FORM CARD (Create + Join screens)
   ============================================================ */
.create-screen,
.join-screen {
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
}

.form-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  margin-bottom: 20px;
  -webkit-tap-highlight-color: transparent;
}
.back-btn:hover { color: var(--text); }

.form-card h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 4px;
}

.form-card .subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 16px;
}

.form-group label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.join-room-badge {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 17px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  text-align: center;
  margin-bottom: 20px;
  word-break: break-word;
}

/* ============================================================
   CALENDAR SCREEN
   ============================================================ */
.calendar-screen {
  background: var(--surface-2);
}

/* Max-width container for calendar content (below sticky header) */
.cal-body {
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
  padding-bottom: 32px;
}

/* Header */
.cal-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.cal-header-info { flex: 1; min-width: 0; }

.cal-room-name {
  font-weight: 700;
  font-size: 17px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

.cal-my-name {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: hidden;
}

/* Truncate the text portion, leave room for the pencil icon */
.editable-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

/* Pencil edit button – subtle, always visible on touch, hover-only on desktop */
.edit-icon-btn {
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.cal-room-name:hover .edit-icon-btn,
.cal-my-name:hover   .edit-icon-btn,
.edit-icon-btn:focus { opacity: 1; }
.edit-icon-btn:hover  { color: var(--primary); }

/* On touch devices: always show the pencil */
@media (hover: none) {
  .edit-icon-btn { opacity: 0.5; }
}

/* Inline edit controls (input + save + cancel) */
.inline-input {
  flex: 1;
  min-width: 0;
  font-size: inherit;
  font-weight: inherit;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--primary);
  border-radius: 6px;
  padding: 1px 6px;
  outline: none;
}

.inline-save,
.inline-cancel {
  border: none;
  background: none;
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 4px;
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.12s;
}
.inline-save   { color: var(--available); }
.inline-cancel { color: var(--unavailable); font-size: 14px; }
.inline-save:hover   { background: var(--available-bg); }
.inline-cancel:hover { background: var(--unavailable-bg); }

/* Three share/copy/qr buttons */
.share-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.share-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.share-btn:hover  { background: var(--primary); color: #fff; }
.share-btn:active { transform: scale(0.93); }
.share-btn.success { background: var(--available); color: #fff; }

/* ============================================================
   QR CODE MODAL
   ============================================================ */
.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
  animation: fadeIn 0.15s ease;
}

.qr-modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
  animation: scaleIn 0.18s ease;
  text-align: center;
}

@keyframes scaleIn {
  from { transform: scale(0.92); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

.qr-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.qr-title {
  font-weight: 700;
  font-size: 16px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  padding-right: 12px;
}

.qr-close {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.qr-close:hover { background: var(--border); color: var(--text); }

.qr-canvas-wrap {
  display: flex;
  justify-content: center;
  margin-bottom: 16px;
}

/* QRCode.js renders a table or img – make sure it fits */
.qr-canvas-wrap img,
.qr-canvas-wrap canvas {
  border-radius: 8px;
  max-width: 100%;
}

.qr-hint {
  font-size: 13px;
  color: var(--text-muted);
}

/* Mode Toggle */
.mode-toggle {
  margin: 12px 16px 0;
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
}

.mode-btn {
  flex: 1;
  padding: 10px 8px;
  border: none;
  border-radius: calc(var(--radius) - 2px);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  background: transparent;
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1.2;
}

.mode-btn.active[data-mode="available"] {
  background: var(--available);
  color: #fff;
  font-weight: 700;
}
.mode-btn.active[data-mode="unavailable"] {
  background: var(--unavailable);
  color: #fff;
  font-weight: 700;
}

/* Calendar Wrapper */
.cal-wrapper {
  margin: 12px 16px 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: pan-y;
}

.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 12px 6px;
}

.cal-nav-labels {
  display: flex;
  flex: 1;
  justify-content: center;
}

.cal-month-label {
  flex: 1;
  text-align: center;
  font-weight: 700;
  font-size: 16px;
}

/* Two-column layout for the month grids */
.cal-columns {
  display: flex;
  overflow: hidden;
}

.cal-col {
  flex: 1;
  min-width: 0;
}

.cal-col + .cal-col {
  border-left: 1px solid var(--border);
}

/* Slide animations for month transitions */
@keyframes slideFromRight {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

@keyframes slideFromLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}

.cal-columns.anim-right { animation: slideFromRight 0.22s ease-out; }
.cal-columns.anim-left  { animation: slideFromLeft  0.22s ease-out; }

.cal-nav-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  transition: all 0.15s;
  -webkit-tap-highlight-color: transparent;
  line-height: 1;
}
.cal-nav-btn:hover  { background: var(--primary-light); color: var(--primary); }
.cal-nav-btn:active { transform: scale(0.88); }
.cal-nav-btn:disabled {
  opacity: 0.25;
  cursor: default;
  pointer-events: none;
}

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  padding: 4px 8px 0;
}
.cal-weekdays span {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  padding: 4px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 3px;
  padding: 0 8px 12px;
}

/* ============================================================
   DAY CELLS
   ============================================================ */
.day {
  position: relative;
  aspect-ratio: 1;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--surface-2);
  transition: transform 0.1s ease;
  -webkit-tap-highlight-color: transparent;
}

.day.empty {
  background: transparent;
  pointer-events: none;
}

.day.past {
  opacity: 0.30;
  cursor: default;
  pointer-events: none;
}

.day:not(.empty):not(.past):hover  { transform: scale(1.08); }
.day:not(.empty):not(.past):active { transform: scale(0.92); }

/* Today indicator */
.day.today {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
}
.day.today .day-num {
  color: var(--primary);
  font-weight: 800;
}

.day-num {
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  z-index: 1;
  position: relative;
}

/* Own vote dot – top-right corner */
.day-vote {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  z-index: 2;
}
.day-vote.v-yes { background: var(--available); }
.day-vote.v-no  { background: var(--unavailable); }

/* Stats badge – bottom center */
.day-count {
  position: absolute;
  bottom: 1px;
  font-size: 8px;
  font-weight: 700;
  color: rgba(0,0,0,0.40);
  z-index: 2;
  line-height: 1;
  letter-spacing: -0.2px;
}

/* ============================================================
   PARTICIPANTS
   ============================================================ */
.participants-wrap {
  margin: 14px 16px 0;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.participants-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.p-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 5px 12px 5px 5px;
}
.p-chip.is-me {
  border-color: var(--primary);
  background: var(--primary-light);
}

.p-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.p-chip.is-me .p-avatar { background: var(--primary-dark); }

.p-name { font-size: 13px; font-weight: 500; }
.p-voted { font-size: 11px; color: var(--text-muted); }

.empty-hint {
  font-size: 13px;
  color: var(--text-muted);
}

/* ============================================================
   LEGEND
   ============================================================ */
.legend {
  margin: 14px 16px 0;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.l-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
}
.l-dot.avail   { background: var(--available); }
.l-dot.unavail { background: var(--unavailable); }

.l-heat-green {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: rgba(22,163,74,0.42);
  flex-shrink: 0;
}
.l-heat-yellow {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: rgba(234,179,8,0.55);
  flex-shrink: 0;
}
.l-heat-red {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  background: rgba(220,38,38,0.38);
  flex-shrink: 0;
}

/* On wide screens: remove side margins since .cal-body handles padding */
@media (min-width: 700px) {
  .cal-body {
    padding-left: 16px;
    padding-right: 16px;
  }
  .cal-wrapper {
    margin-left: 0;
    margin-right: 0;
  }
  .participants-wrap {
    margin-left: 0;
    margin-right: 0;
  }
  .legend {
    margin-left: 0;
    margin-right: 0;
  }
}

/* ============================================================
   ERROR SCREEN
   ============================================================ */
.error-screen {
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  gap: 16px;
}
.error-screen .error-icon { font-size: 52px; }
.error-screen h2          { font-size: 24px; font-weight: 700; }
.error-screen p           { color: var(--text-muted); max-width: 300px; }
.error-screen .btn        { max-width: 260px; }
