:root {
  --bg: oklch(96% 0.014 75);
  --card-bg: oklch(99% 0.004 75);
  --border: oklch(90% 0.012 70);
  --text: oklch(23% 0.02 50);
  --text-muted: oklch(50% 0.02 55);
  --text-faint: oklch(62% 0.015 60);
  --accent: oklch(42% 0.075 200);
  --accent-soft: oklch(93% 0.03 200);
  --terracotta: oklch(64% 0.13 45);
  --terracotta-soft: oklch(94% 0.035 45);
  --sage: oklch(58% 0.08 150);
  --plum: oklch(52% 0.09 320);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Work Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

[x-cloak] { display: none !important; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: oklch(34% 0.075 200); }

button {
  font-family: inherit;
  cursor: pointer;
}

input, textarea {
  font-family: inherit;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  background: white;
  color: var(--text);
}
input:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.muted { color: var(--text-faint); font-size: 13.5px; }

.btn-primary {
  padding: 10px 22px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 14px;
  font-weight: 600;
}
.btn-primary:disabled { opacity: 0.6; cursor: default; }

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 40px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-word { font-family: 'Lora', Georgia, serif; font-weight: 700; font-size: 22px; color: var(--accent); letter-spacing: -0.02em; }
.brand-dot { width: 4px; height: 4px; border-radius: 50%; background: var(--text-faint); }
.brand-sub { font-size: 13px; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 16px; }

.pill-btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--bg);
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
}

.prefs-wrap { position: relative; }
.prefs-popover {
  position: absolute;
  top: 42px;
  right: 0;
  width: 236px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 28px oklch(20% 0.02 50 / 0.14);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 30;
}
.prefs-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.prefs-row { display: flex; align-items: center; justify-content: space-between; font-size: 13.5px; }
.prefs-logout { font-size: 13px; font-weight: 600; }

.toggle { width: 34px; height: 19px; border-radius: 10px; background: var(--border); border: none; position: relative; flex-shrink: 0; padding: 0; }
.toggle.on { background: var(--accent); }
.toggle-knob { position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: white; transition: left 0.15s; }
.toggle.on .toggle-knob { left: 17px; }

.user-chip { display: flex; align-items: center; gap: 10px; padding-left: 18px; border-left: 1px solid var(--border); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--plum); color: white; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600; flex-shrink: 0; }
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }

.divider { height: 1px; background: var(--border); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: 13.5px;
  z-index: 100;
  box-shadow: 0 8px 24px oklch(20% 0.02 50 / 0.2);
}

/* ---------- Layout ---------- */
.body-grid { max-width: 1200px; margin: 0 auto; padding: 32px 40px 60px; }
.feed-layout { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.main-col { display: flex; flex-direction: column; gap: 20px; }
.sidebar-col { display: flex; flex-direction: column; gap: 20px; position: sticky; top: 90px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 1px 2px oklch(20% 0.02 50 / 0.04);
}

.widget-title { font-family: 'Lora', Georgia, serif; font-weight: 600; font-size: 15.5px; }
.widget-subtitle { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* ---------- Composer ---------- */
.composer-tabs { display: flex; gap: 6px; }
.composer-tabs button {
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
}
.composer-tabs button.active { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.composer-textarea { width: 100%; min-height: 70px; resize: vertical; }
.composer-link, .composer-poll { display: flex; flex-direction: column; gap: 10px; }
.composer-link input, .composer-poll > input { width: 100%; }

.poll-option-input { display: flex; gap: 8px; align-items: center; }
.poll-option-input input { flex-grow: 1; }
.poll-option-input button { background: none; border: none; color: var(--text-faint); font-size: 14px; }

.link-btn { background: none; border: none; color: var(--accent); font-size: 13px; font-weight: 600; padding: 4px 0; text-align: left; }

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

/* ---------- Link preview card ---------- */
.link-preview-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  color: var(--text);
}
.link-preview-card img { width: 100%; height: 150px; object-fit: cover; display: block; background: linear-gradient(135deg, var(--accent-soft), oklch(93% 0.03 150)); }
.link-preview-body { padding: 12px 16px; display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
.link-preview-site { font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: 0.05em; }
.link-preview-title { font-size: 14px; font-weight: 600; color: var(--text); }
.link-preview-desc { font-size: 12.5px; color: var(--text-muted); line-height: 1.4; }

/* ---------- Posts ---------- */
.post-header { display: flex; gap: 12px; align-items: center; }
.post-author { font-size: 14px; font-weight: 600; }
.post-date { font-size: 12px; color: var(--text-faint); }
.post-body { font-size: 14.5px; line-height: 1.55; white-space: pre-line; }

.post-actions { display: flex; align-items: center; gap: 18px; padding-top: 10px; border-top: 1px solid var(--border); }
.action-btn { display: flex; align-items: center; gap: 6px; color: var(--text-muted); font-size: 13px; background: none; border: none; padding: 0; }
.action-btn.active { color: var(--terracotta); }

.comments { display: flex; flex-direction: column; gap: 10px; }
.comment { display: flex; gap: 10px; }
.comment-body { background: var(--bg); border-radius: 10px; padding: 8px 12px; font-size: 13px; line-height: 1.4; }

.comment-form { display: flex; gap: 8px; }
.comment-form input { flex-grow: 1; }
.comment-form button { padding: 8px 16px; border-radius: 8px; border: none; background: var(--bg); color: var(--text-muted); font-size: 13px; font-weight: 500; }

/* ---------- Polls ---------- */
.poll { display: flex; flex-direction: column; gap: 8px; }
.poll-question { font-size: 14.5px; font-weight: 600; }
.poll-bar {
  position: relative;
  height: 36px;
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
  border: none;
  width: 100%;
  text-align: left;
  padding: 0;
}
.poll-bar-fill { position: absolute; inset: 0; background: var(--terracotta-soft); }
.poll-bar-label { position: relative; display: flex; align-items: center; justify-content: space-between; height: 100%; padding: 0 14px; font-size: 13px; font-weight: 500; color: var(--text); }
.poll-footer { display: flex; align-items: center; justify-content: space-between; padding-top: 4px; }

.mini-poll { display: flex; flex-direction: column; gap: 8px; }
.mini-poll > span:first-child { font-size: 13px; font-weight: 500; }
.mini-poll-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--border); }
.mini-poll-bar span { background: var(--terracotta); height: 100%; }

/* ---------- Calendar ---------- */
.calendar-nav { display: flex; align-items: center; justify-content: space-between; }
.calendar-nav button { background: none; border: none; color: var(--text-faint); font-size: 16px; padding: 4px 8px; }
.calendar-nav span { font-size: 13px; font-weight: 500; text-transform: capitalize; }

.calendar-weekdays, .calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.calendar-weekdays span { font-size: 11px; color: var(--text-faint); }
.calendar-grid { row-gap: 4px; }
.calendar-grid span { font-size: 12.5px; padding: 6px 0; border-radius: 50%; position: relative; }
.calendar-grid span.out-month { color: oklch(78% 0.012 60); }
.calendar-grid span.today { font-weight: 700; color: white; background: var(--accent); }
.calendar-grid span.has-event::after {
  content: '';
  position: absolute;
  bottom: 1px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--terracotta);
}
.calendar-grid span.today.has-event::after { background: white; }

.upcoming-list { display: flex; flex-direction: column; gap: 12px; }
.upcoming-item { display: flex; gap: 10px; align-items: center; }
.date-chip { width: 38px; height: 38px; border-radius: 8px; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; flex-shrink: 0; }
.date-chip span:first-child { font-size: 9px; color: var(--text-faint); text-transform: uppercase; line-height: 1.1; }
.date-chip span:last-child { font-size: 14px; font-weight: 700; line-height: 1.1; }
.upcoming-title { font-size: 13px; font-weight: 600; }
.upcoming-date { font-size: 12px; color: var(--text-muted); text-transform: capitalize; }

.add-event-btn {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px; border-radius: 8px; border: 1px dashed var(--border);
  background: none; color: var(--accent); font-size: 13px; font-weight: 600;
}
.add-event-form { display: flex; flex-direction: column; gap: 8px; }

/* ---------- Admin ---------- */
.admin-panel { display: flex; flex-direction: column; gap: 20px; }
.admin-create-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.admin-create-form input { flex: 1 1 180px; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.admin-table th { text-align: left; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.admin-table td { padding: 10px; border-bottom: 1px solid var(--border); }
.admin-row-actions { display: flex; gap: 8px; }
.admin-row-actions button { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); font-size: 12.5px; color: var(--text-muted); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; margin-right: 6px; }
.badge-active { background: oklch(93% 0.03 150); color: var(--sage); }
.badge-inactive { background: var(--border); color: var(--text-muted); }
.badge-admin { background: var(--accent-soft); color: var(--accent); }

/* ---------- Auth pages ---------- */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 1px 2px oklch(20% 0.02 50 / 0.04);
}
.auth-brand { font-family: 'Lora', Georgia, serif; font-weight: 700; font-size: 26px; color: var(--accent); text-align: center; }
.auth-sub { text-align: center; color: var(--text-muted); font-size: 13px; margin: 0 0 16px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-muted); }
.auth-error { color: var(--terracotta); font-size: 13px; margin: 0; }
.auth-success { color: var(--sage); font-size: 13px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .app-header { padding: 14px 20px; }
  .body-grid { padding: 20px 16px 40px; }
  .feed-layout { grid-template-columns: 1fr; }
  .sidebar-col { position: static; }
  .brand-sub { display: none; }
}
