/* ═══════════════════════════════════════════════════════════════
   Canticle — main stylesheet
   ═══════════════════════════════════════════════════════════════ */

/* ── Design tokens ───────────────────────────────────────────── */
:root {
  --bg:           #f3f4f6;
  --surface:      #ffffff;
  --surface-2:    #f9fafb;
  --border:       #e5e7eb;
  --border-focus: #6366f1;
  --text:         #111827;
  --text-2:       #374151;
  --muted:        #6b7280;
  --accent:       #6366f1;
  --accent-hover: #4f46e5;
  --accent-light: rgba(99,102,241,.10);
  --danger:       #ef4444;
  --danger-light: rgba(239,68,68,.10);
  --success:      #10b981;
  --warning:      #f59e0b;

  --radius:       14px;
  --radius-sm:    8px;
  --radius-xs:    4px;
  --radius-pill:  999px;

  --shadow-xs:  0 1px 2px rgba(0,0,0,.05);
  --shadow-sm:  0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow:     0 4px 6px -1px rgba(0,0,0,.07), 0 2px 4px -2px rgba(0,0,0,.05);
  --shadow-md:  0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -4px rgba(0,0,0,.05);

  --max-w: 1120px;
  --sidebar-w: 240px;
  --aside-w: 280px;
  --transition: .15s ease;
}

/* ── Dark mode ───────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:        #0f1117;
    --surface:   #1c1f26;
    --surface-2: #242831;
    --border:    #2d3139;
    --text:      #f3f4f6;
    --text-2:    #d1d5db;
    --muted:     #6b7280;
    --accent-light: rgba(99,102,241,.15);
    --danger-light: rgba(239,68,68,.15);
    --shadow-xs: 0 1px 2px rgba(0,0,0,.25);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.30), 0 1px 2px rgba(0,0,0,.20);
    --shadow:    0 4px 6px -1px rgba(0,0,0,.30), 0 2px 4px -2px rgba(0,0,0,.20);
  }
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { text-decoration: underline; color: var(--accent-hover); }

img { max-width: 100%; display: block; }

h1, h2, h3, h4 { color: var(--text); font-weight: 700; line-height: 1.3; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }

/* ── Buttons ─────────────────────────────────────────────────── */
button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .45rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: .9rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface);
  color: var(--text-2);
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
  white-space: nowrap;
  user-select: none;
}
button:hover { background: var(--surface-2); border-color: var(--accent); color: var(--accent); }
button:active { transform: scale(.97); }

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

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--accent-light); color: var(--accent); border-color: transparent; }

.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger-light); color: var(--danger); border-color: var(--danger); }

.btn-sm { padding: .28rem .65rem; font-size: .82rem; }

/* ── ═══════════════════════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════════════════════ */
.layout {
  display: flex;
  max-width: var(--max-w);
  margin: 0 auto;
  gap: 1.25rem;
  padding: 1.25rem 1rem;
  align-items: flex-start;
}

.main { flex: 1; min-width: 0; }
.aside { width: var(--aside-w); flex-shrink: 0; position: sticky; top: 1.25rem; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  position: sticky;
  top: 1.25rem;
  height: max-content;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

.site-logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--accent);
  padding: .4rem .5rem;
  margin-bottom: 1.25rem;
  letter-spacing: -.02em;
  text-decoration: none;
}
.site-logo:hover { text-decoration: none; color: var(--accent-hover); }

.nav-link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .65rem .9rem;
  border-radius: var(--radius-pill);
  color: var(--text-2);
  font-size: 1.02rem;
  font-weight: 500;
  margin-bottom: .2rem;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.nav-link:hover { background: var(--accent-light); color: var(--accent); text-decoration: none; }
.nav-link.active { background: var(--accent-light); color: var(--accent); font-weight: 600; }

.nav-link .badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-pill);
  padding: .1rem .5rem;
  font-size: .72rem;
  font-weight: 700;
}

/* ── Card ────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 1rem;
}

/* ── Status card ─────────────────────────────────────────────── */
.status {
  padding: 1.1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.status:last-child { border-bottom: none; }
.status:hover { background: var(--surface-2); }

.boosted-by {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--muted);
  font-size: .82rem;
  margin-bottom: .6rem;
  font-weight: 500;
}

.status-header {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  margin-bottom: .55rem;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: var(--shadow-xs);
}
.avatar-sm { width: 30px; height: 30px; }

.status-header-meta { flex: 1; min-width: 0; }
.account-name {
  font-weight: 600;
  font-size: .97rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-name a { color: inherit; }
.account-name a:hover { color: var(--accent); text-decoration: none; }
.account-acct { color: var(--muted); font-size: .83rem; margin-top: .05rem; }

.status-time {
  color: var(--muted);
  font-size: .82rem;
  white-space: nowrap;
  flex-shrink: 0;
  margin-left: auto;
  padding-left: .5rem;
}

.status-content {
  font-size: .97rem;
  line-height: 1.65;
  overflow-wrap: break-word;
  color: var(--text);
}
.status-content a { color: var(--accent); }
.status-content p { margin: 0 0 .5rem; }
.status-content p:last-child { margin: 0; }

.cw-toggle {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .3rem .7rem;
  font-size: .85rem;
  cursor: pointer;
  margin-bottom: .5rem;
  color: var(--text-2);
  font-weight: 500;
}
.cw-toggle:hover { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.cw-body { display: none; }
.cw-body.open { display: block; }

/* Media */
.status-media {
  display: grid;
  gap: .35rem;
  margin: .75rem 0 0;
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.status-media img, .status-media video {
  width: 100%;
  height: 240px;
  object-fit: cover;
  display: block;
}
.media-1 { grid-template-columns: 1fr; }
.media-2 { grid-template-columns: 1fr 1fr; }
.media-3 { grid-template-columns: 1fr 1fr; }
.media-4 { grid-template-columns: 1fr 1fr; }
.media-3 .status-media img:first-child { grid-column: span 2; }

/* Action bar */
.status-actions {
  display: flex;
  align-items: center;
  gap: .15rem;
  margin-top: .75rem;
  margin-left: -.4rem;
}
.status-actions button {
  color: var(--muted);
  border: none;
  background: none;
  font-size: .87rem;
  padding: .35rem .55rem;
  border-radius: var(--radius-sm);
  min-width: 52px;
  gap: .3rem;
}
.status-actions button:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: transparent;
  transform: none;
}
.status-actions button.active { color: var(--accent); font-weight: 600; }
.status-actions .count { font-size: .8rem; }
.status-actions a.permalink {
  margin-left: auto;
  color: var(--muted);
  font-size: .8rem;
  padding: .3rem .5rem;
  border-radius: var(--radius-xs);
  transition: color var(--transition);
}
.status-actions a.permalink:hover { color: var(--accent); text-decoration: none; }

/* ── Poll ────────────────────────────────────────────────────── */
.poll { margin: .85rem 0 0; }
.poll-option { margin: .45rem 0; }
.poll-bar {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  height: 32px;
  position: relative;
  display: flex;
  align-items: center;
  padding: 0 .65rem;
  overflow: hidden;
}
.poll-bar-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  background: var(--accent-light);
  border-right: 2px solid var(--accent);
  transition: width .4s ease;
}
.poll-bar-label { position: relative; z-index: 1; font-size: .88rem; font-weight: 500; }
.poll-votes { color: var(--muted); font-size: .82rem; margin-top: .5rem; }
.poll-vote-form label {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin: .35rem 0;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  font-size: .9rem;
}
.poll-vote-form label:hover { border-color: var(--accent); background: var(--accent-light); }

/* ── Compose modal ───────────────────────────────────────────── */
.compose-modal {
  display: none;          /* hidden by default */
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  z-index: 900;
  background: rgba(0,0,0,.55);
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.compose-modal.open { display: flex; }

.compose-modal-inner {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 680px;
  box-shadow: 0 8px 40px rgba(0,0,0,.45);
  overflow: hidden;
}

.compose-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .9rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.compose-modal-close {
  background: none !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--muted) !important;
  cursor: pointer;
  padding: .2rem .4rem !important;
  border-radius: var(--radius-sm) !important;
  display: inline-flex !important;
  width: auto !important;
}
.compose-modal-close:hover {
  background: var(--surface-2) !important;
  color: var(--text) !important;
  border-color: transparent !important;
}

.compose-modal-body { padding: 1.25rem; }

/* ── Compose area ────────────────────────────────────────────── */
.compose-area {
  padding: 1.1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.compose-area textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .75rem .9rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.55;
  resize: vertical;
  min-height: 100px;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.compose-area textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface);
}
.compose-actions {
  display: flex;
  align-items: center;
  gap: .4rem;
  margin-top: .65rem;
  flex-wrap: wrap;
}
.compose-count {
  margin-left: auto;
  font-size: .85rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 2.5rem;
  text-align: right;
}
.compose-count.warn { color: var(--danger); }
.media-preview {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .5rem;
}

/* ── Profile ─────────────────────────────────────────────────── */
.profile-header { position: relative; }
.profile-header-img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: var(--radius) var(--radius) 0 0;
  display: block;
}
.profile-avatar-wrap {
  position: absolute;
  bottom: -40px;
  left: 1.2rem;
}
.profile-avatar {
  width: 84px;
  height: 84px;
  border: 4px solid var(--surface);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
}
.profile-info { padding: 3rem 1.2rem 1.2rem; }
.profile-name { font-size: 1.4rem; font-weight: 800; letter-spacing: -.02em; }
.profile-acct { color: var(--muted); font-size: .92rem; margin-top: .1rem; }
.profile-bio { margin: .65rem 0; font-size: .95rem; color: var(--text-2); line-height: 1.55; }
.profile-stats {
  display: flex;
  gap: 1.5rem;
  margin-top: .75rem;
  font-size: .9rem;
  color: var(--muted);
}
.profile-stats strong { color: var(--text); font-weight: 700; }
.profile-actions { margin-top: 1rem; }

/* ── Notifications ───────────────────────────────────────────── */
.notification {
  display: flex;
  gap: .9rem;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.notification:last-child { border-bottom: none; }
.notification:hover { background: var(--surface-2); }
.notification-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-light);
  border-radius: 50%;
}
.notification-body { min-width: 0; padding-top: .1rem; }

/* ── Auth pages ──────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 1rem;
}
.auth-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2.25rem 2rem;
  width: 100%;
  max-width: 420px;
}
.auth-box .logo {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent);
  margin-bottom: 1.5rem;
  display: block;
  letter-spacing: -.02em;
}
.auth-box h2 {
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 1.75rem;
  font-weight: 400;
}
.auth-box label {
  display: block;
  margin-bottom: 1rem;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text-2);
}
.auth-box input {
  display: block;
  width: 100%;
  padding: .65rem .85rem;
  margin-top: .3rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--surface-2);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  font-family: inherit;
}
.auth-box input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
  background: var(--surface);
}
.auth-box .btn-primary { width: 100%; margin-top: 1.5rem; padding: .7rem; font-size: 1rem; }
.auth-links { margin-top: 1.5rem; text-align: center; color: var(--muted); font-size: .9rem; }

.flash-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid rgba(239,68,68,.25);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: .9rem;
}
.flash-success {
  background: rgba(16,185,129,.10);
  color: var(--success);
  border: 1px solid rgba(16,185,129,.25);
  border-radius: var(--radius-sm);
  padding: .75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: .9rem;
}

/* ── Aside ───────────────────────────────────────────────────── */
.aside-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.1rem 1.2rem;
  margin-bottom: 1rem;
}
.aside-card h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: .65rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--border);
}

/* ── ═══════════════════════════════════════════════════════════
   ADMIN PANEL
   ═══════════════════════════════════════════════════════════ */
.admin-layout { display: flex; min-height: 100vh; }

.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #18181b;
  padding: 1.25rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .1rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.admin-sidebar .admin-logo {
  font-size: 1.1rem;
  font-weight: 800;
  color: #fff;
  padding: .3rem .5rem .8rem;
  margin-bottom: .5rem;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: block;
  letter-spacing: -.01em;
}
.admin-sidebar a {
  color: #a1a1aa;
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .5rem .65rem;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.admin-sidebar a:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.admin-sidebar a.active { background: var(--accent); color: #fff; }
.admin-sidebar hr { border: none; border-top: 1px solid rgba(255,255,255,.1); margin: .65rem 0; }
.admin-sidebar .back-link { color: #71717a; font-size: .85rem; margin-top: auto; }

.admin-main {
  flex: 1;
  padding: 2rem 2.25rem;
  max-width: 1000px;
  min-width: 0;
}
.admin-main h1 { margin-bottom: 1.5rem; font-size: 1.6rem; }
.admin-main h2 { margin: 1.75rem 0 .75rem; font-size: 1.1rem; color: var(--text-2); }

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.25rem 1rem;
  transition: box-shadow var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); }
.stat-card .num {
  font-size: 2.1rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
  letter-spacing: -.03em;
}
.stat-card .lbl { color: var(--muted); font-size: .83rem; margin-top: .4rem; font-weight: 500; }

/* Admin table */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.admin-table thead { background: var(--surface-2); }
.admin-table th {
  text-align: left;
  padding: .7rem 1rem;
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
  vertical-align: middle;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--surface-2); }
.admin-table .actions { display: flex; gap: .4rem; }

/* Admin forms */
.admin-form {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.admin-form label { display: block; font-size: .88rem; font-weight: 600; color: var(--text-2); margin-bottom: .3rem; }
.admin-form input, .admin-form select, .admin-form textarea {
  display: block;
  width: 100%;
  padding: .55rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .95rem;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  margin-bottom: 1rem;
  transition: border-color var(--transition);
}
.admin-form input:focus, .admin-form select:focus { outline: none; border-color: var(--border-focus); }

.inline-form { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.inline-form input { margin-bottom: 0; flex: 1; min-width: 140px; }

/* Badges */
.badge-pill {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: var(--radius-pill);
  font-size: .75rem;
  font-weight: 700;
}
.badge-success { background: rgba(16,185,129,.12); color: var(--success); }
.badge-warning { background: rgba(245,158,11,.12); color: var(--warning); }
.badge-danger  { background: var(--danger-light); color: var(--danger); }
.badge-muted   { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 960px) {
  :root { --aside-w: 240px; }
}
@media (max-width: 780px) {
  .aside { display: none; }
  :root { --sidebar-w: 68px; }
  .site-logo span { display: none; }
  .nav-link span { display: none; }
  .nav-link { justify-content: center; padding: .65rem; }
  .nav-link .badge { display: none; }
}
@media (max-width: 520px) {
  .layout { flex-direction: column; padding: .5rem; }
  .sidebar { width: 100%; position: static; }
  .site-logo span { display: inline; }
  .nav-link { display: inline-flex; }
  .nav-link span { display: inline; }
  .sidebar nav { display: flex; flex-wrap: wrap; gap: .25rem; }
  .admin-sidebar { display: none; }
  .admin-main { padding: 1rem; }
}
