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

:root {
  --bg: #0f0e17;
  --surface: #1a1928;
  --surface2: #24223a;
  --border: #312f50;
  --accent: #7c6af7;
  --accent2: #c47aff;
  --text: #efefef;
  --text-muted: #8886a8;
  --green: #4caf50;
  --yellow: #ffc107;
  --red: #f44336;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────────── */
header {
  background: linear-gradient(135deg, #1a0033 0%, #0f0e17 100%);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 16px rgba(0,0,0,0.5);
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  gap: 1rem;
}

header h1 {
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
}

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

#username-display {
  color: var(--text-muted);
  font-size: 0.85rem;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Main ─────────────────────────────────────────────────────────────────────── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

/* ── Cards ───────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.section-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; border-radius: 6px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: #6a59e0; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { opacity: 0.85; }

/* ── Inputs ──────────────────────────────────────────────────────────────────── */
input[type="text"], input[type="date"], input[type="time"], textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.8rem;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
label { display: block; font-size: 0.8rem; color: var(--text-muted); margin: 0.75rem 0 0.3rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.04em; }
.hint { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 0.75rem; }

/* ── Modals ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.75rem;
  width: 100%;
  max-width: 420px;
  position: relative;
  box-shadow: 0 8px 40px rgba(0,0,0,0.6);
  max-height: 90vh;
  overflow-y: auto;
}
.modal-wide { max-width: 600px; }

.modal h2 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.modal p { color: var(--text-muted); margin-bottom: 1rem; font-size: 0.9rem; }

.modal-close {
  position: absolute;
  top: 1rem; right: 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
}
.modal-close:hover { background: var(--surface2); color: var(--text); }

/* ── Availability Grid ───────────────────────────────────────────────────────── */
.avail-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.avail-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
  font-size: 0.82rem;
}

.avail-table th {
  padding: 0.4rem 0.5rem;
  text-align: center;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.avail-table th.name-col { text-align: left; }

.avail-table td {
  padding: 0.3rem 0.4rem;
  text-align: center;
  border-top: 1px solid var(--border);
}
.avail-table td.name-cell {
  text-align: left;
  white-space: nowrap;
  font-weight: 500;
  color: var(--text);
  padding-right: 0.75rem;
}

.slot-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-block;
  background: var(--surface2);
  border: 2px solid var(--border);
  vertical-align: middle;
}
.slot-dot.on { background: var(--accent); border-color: var(--accent); }

/* Edit grid */
.edit-cell {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-block;
  background: var(--surface2);
  border: 2px solid var(--border);
  transition: all 0.1s;
  vertical-align: middle;
}
.edit-cell.on { background: var(--accent); border-color: var(--accent); }
.edit-cell:hover { border-color: var(--accent2); }

.avail-actions { margin-top: 1rem; }

.week-nav {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Events ──────────────────────────────────────────────────────────────────── */
#events-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.event-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  cursor: pointer;
  transition: all 0.15s;
}
.event-card:hover { border-color: var(--accent); background: #1e1c35; }

.event-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.event-title { font-weight: 600; font-size: 1rem; }
.event-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.2rem; }

.rsvp-badges {
  display: flex;
  gap: 0.35rem;
  flex-shrink: 0;
  margin-top: 0.1rem;
}
.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.15rem 0.45rem;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
}
.badge-in { background: rgba(76,175,80,0.2); color: var(--green); }
.badge-maybe { background: rgba(255,193,7,0.2); color: var(--yellow); }
.badge-out { background: rgba(244,67,54,0.2); color: var(--red); }

.event-latest-comment {
  margin-top: 0.6rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  gap: 0.4rem;
  align-items: flex-start;
}
.event-latest-comment span { opacity: 0.7; }

.events-empty {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem 1rem;
  font-size: 0.9rem;
}

/* ── Event Detail Modal ──────────────────────────────────────────────────────── */
.event-detail h2 { font-size: 1.2rem; padding-right: 2rem; }
.event-detail .event-meta { margin-bottom: 1rem; }
.event-detail .desc { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.25rem; white-space: pre-wrap; }

.rsvp-section { margin-bottom: 1.25rem; }
.rsvp-section h3, .comments-section h3 { font-size: 0.85rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.75rem; }

.rsvp-buttons {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}
.rsvp-btn { transition: all 0.15s; }
.rsvp-btn.active-in { background: var(--green); color: #fff; }
.rsvp-btn.active-maybe { background: var(--yellow); color: #000; }
.rsvp-btn.active-out { background: var(--red); color: #fff; }

.rsvp-list { font-size: 0.82rem; color: var(--text-muted); }
.rsvp-list .rl-group { margin-bottom: 0.35rem; }
.rsvp-list .rl-label { font-weight: 600; color: var(--text); }

.comments-section { margin-top: 1.25rem; }
.comment-list { margin-bottom: 1rem; max-height: 200px; overflow-y: auto; }
.comment {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.88rem;
}
.comment:last-child { border-bottom: none; }
.comment .c-name { font-weight: 600; color: var(--accent2); margin-right: 0.4rem; }
.comment .c-time { font-size: 0.75rem; color: var(--text-muted); margin-left: 0.4rem; }

.comment-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.comment-input-row textarea { flex: 1; min-height: 40px; max-height: 120px; }

.delete-event-row {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  text-align: right;
}

/* ── Notify btn active ───────────────────────────────────────────────────────── */
#notify-btn.active { color: var(--accent2); }

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

.toast-container {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: center;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 0.5rem 1.25rem;
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  animation: slideUp 0.2s ease;
  pointer-events: none;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  header h1 { font-size: 1rem; }
  .modal { padding: 1.25rem; }
  .rsvp-buttons { gap: 0.35rem; }
  .rsvp-btn { padding: 0.4rem 0.75rem; font-size: 0.82rem; }
}
