/* ============================================================
   Citoyen branché — styles.css
   Mobile-first, responsive, modern
   ============================================================ */

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

:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #dbeafe;
  --secondary:      #6b7280;
  --secondary-light:#f3f4f6;
  --bg:             #f9fafb;
  --surface:        #ffffff;
  --border:         #e5e7eb;
  --text:           #111827;
  --text-muted:     #6b7280;
  --danger:         #dc2626;
  --danger-light:   #fee2e2;
  --success:        #16a34a;
  --success-light:  #dcfce7;
  --warning:        #d97706;
  --warning-light:  #fef3c7;
  --amber:          #f59e0b;
  --amber-light:    #fffbeb;
  --radius:         0.5rem;
  --radius-lg:      0.75rem;
  --shadow-sm:      0 1px 2px rgba(0,0,0,.06);
  --shadow:         0 2px 8px rgba(0,0,0,.09);
  --shadow-md:      0 4px 16px rgba(0,0,0,.12);
  --font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --transition:     150ms ease;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

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

a {
  color: var(--primary);
  text-decoration: none;
}

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

/* ---------- Layout ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-md);
}

.header-content {
  max-width: 42rem;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.app-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #fff;
  white-space: nowrap;
}

.header-nav {
  display: flex;
  gap: 0.5rem;
}

.nav-btn {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.35);
  color: #fff;
  border-radius: var(--radius);
  padding: 0.35rem 0.85rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.nav-btn:hover,
.nav-btn.active {
  background: rgba(255,255,255,0.3);
  border-color: rgba(255,255,255,0.6);
}

#app-main {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1rem;
}

.view {
  animation: fadeIn 200ms ease;
}

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

/* ---------- Spinner ---------- */
.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 3rem auto;
}

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

.spinner-sm {
  width: 1.1rem;
  height: 1.1rem;
  border-width: 2px;
  margin: 0;
  display: inline-block;
  vertical-align: middle;
}

/* ---------- Messages ---------- */
.msg {
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

.msg-error {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #fca5a5;
}

.msg-success {
  background: var(--success-light);
  color: var(--success);
  border: 1px solid #86efac;
}

.msg-info {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid #93c5fd;
}

.msg-warning {
  background: var(--warning-light);
  color: var(--warning);
  border: 1px solid #fcd34d;
}

/* ---------- Forms ---------- */
.form-group {
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea,
select {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 1rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

input::placeholder,
textarea::placeholder {
  color: #9ca3af;
}

textarea {
  resize: vertical;
  min-height: 5rem;
}

.char-counter {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 0.25rem;
}

.char-counter.near-limit {
  color: var(--warning);
  font-weight: 600;
}

.char-counter.at-limit {
  color: var(--danger);
  font-weight: 700;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.55rem 1.15rem;
  border-radius: var(--radius);
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid transparent;
  transition: background var(--transition), color var(--transition),
              border-color var(--transition), box-shadow var(--transition),
              opacity var(--transition);
  white-space: nowrap;
  user-select: none;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  box-shadow: 0 2px 8px rgba(37,99,235,0.35);
}

.btn-secondary {
  background: var(--surface);
  color: var(--secondary);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--secondary-light);
  border-color: #d1d5db;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: #fca5a5;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  padding: 0.4rem 0.7rem;
  font-size: 0.82rem;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--secondary-light);
  color: var(--text);
}

.btn-follow {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
  font-size: 0.82rem;
  padding: 0.3rem 0.75rem;
}

.btn-follow:hover:not(:disabled) {
  background: var(--primary-light);
}

.btn-follow.following {
  background: var(--primary-light);
  color: var(--primary-dark);
}

.btn-sm {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

.btn-report {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 0.78rem;
  padding: 0.25rem 0.5rem;
  cursor: pointer;
  font-family: var(--font);
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
}

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

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.badge-important {
  background: var(--amber-light);
  color: #92400e;
  border: 1px solid #fcd34d;
}

.badge-pinned {
  background: var(--primary-light);
  color: var(--primary-dark);
  border: 1px solid #93c5fd;
}

.badge-hidden {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #fca5a5;
}

/* ---------- Post cards ---------- */
.post-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
  margin-bottom: 0.85rem;
  border: 1px solid var(--border);
  transition: box-shadow var(--transition);
}

.post-card:hover {
  box-shadow: var(--shadow-md);
}

.post-card.pinned {
  border-left: 3px solid var(--primary);
}

.post-card.important {
  border-left: 3px solid var(--amber);
}

.post-card.pinned.important {
  border-left: 3px solid var(--amber);
}

.post-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.post-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  flex: 1;
  min-width: 0;
}

.post-username {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text);
}

.post-fsa {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--secondary-light);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-weight: 600;
}

.post-time {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.post-badges {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.post-content {
  font-size: 0.975rem;
  line-height: 1.65;
  color: var(--text);
  margin-bottom: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  padding-top: 0.6rem;
  margin-top: 0.15rem;
}

.post-action-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  margin-left: auto;
}

.comment-count-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  font-family: var(--font);
  padding: 0.3rem 0.5rem;
  border-radius: var(--radius);
  transition: color var(--transition), background var(--transition);
}

.comment-count-btn:hover {
  color: var(--primary);
  background: var(--primary-light);
}

.comment-icon {
  font-size: 1rem;
}

/* ---------- Pinned section ---------- */
.section-title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.pinned-section {
  margin-bottom: 1.5rem;
}

/* ---------- Register / onboarding ---------- */
.register-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 2rem 1.5rem;
  max-width: 28rem;
  margin: 2rem auto;
  border: 1px solid var(--border);
}

.register-card h2 {
  font-size: 1.4rem;
  font-weight: 800;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.register-card p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
}

.register-logo {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

/* ---------- Post detail / comments ---------- */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 600;
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0.4rem 0;
  margin-bottom: 1rem;
  font-family: var(--font);
}

.back-btn:hover {
  text-decoration: underline;
}

.comments-section {
  margin-top: 1.25rem;
}

.comments-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.85rem;
  color: var(--text);
}

.comment-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 0.75rem 1rem;
  margin-bottom: 0.6rem;
}

.comment-header {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
  flex-wrap: wrap;
}

.comment-username {
  font-weight: 700;
  font-size: 0.85rem;
}

.comment-fsa {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--secondary-light);
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
}

.comment-time {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-left: auto;
}

.comment-content {
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.4rem;
}

.comment-form-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1rem;
  margin-top: 1rem;
}

.comment-form-card h3 {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.no-comments {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 1.5rem 0;
}

/* ---------- New post form ---------- */
.new-post-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.new-post-card h2 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text);
}

/* ---------- Profile view ---------- */
.profile-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.profile-card h2 {
  font-size: 1.15rem;
  font-weight: 800;
  margin-bottom: 0.25rem;
}

.profile-username-display {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 0.5rem;
}

.profile-fsa {
  display: inline-block;
  font-size: 0.875rem;
  color: var(--text-muted);
  background: var(--secondary-light);
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-weight: 600;
  margin-bottom: 1rem;
}

.profile-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
}

.profile-section h3 {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.next-change-notice {
  font-size: 0.82rem;
  color: var(--warning);
  background: var(--warning-light);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  border: 1px solid #fcd34d;
}

/* ---------- Load more ---------- */
.load-more-wrap {
  text-align: center;
  padding: 1rem 0 0.5rem;
}

.end-of-feed {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 1.5rem 0;
}

/* ---------- Notification banner ---------- */
.notif-banner {
  background: var(--primary-light);
  border: 1px solid #93c5fd;
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.notif-banner p {
  font-size: 0.875rem;
  color: var(--primary-dark);
  flex: 1;
}

.notif-dismiss {
  background: transparent;
  border: none;
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.1rem 0.3rem;
}

/* ---------- Empty states ---------- */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}

.empty-state p {
  font-size: 0.95rem;
  max-width: 20rem;
  margin: 0 auto;
}

/* ---------- Admin panel ---------- */
.admin-wrap {
  max-width: 56rem;
  margin: 0 auto;
  padding: 1.5rem 1rem;
  font-family: var(--font);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}

.admin-section {
  margin-bottom: 2rem;
}

.admin-section h2 {
  font-size: 1.1rem;
  font-weight: 800;
  margin-bottom: 1rem;
  color: var(--text);
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.admin-table th {
  background: var(--secondary-light);
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.admin-table td {
  padding: 0.65rem 0.75rem;
  border-top: 1px solid var(--border);
  vertical-align: top;
}

.admin-table tr:hover td {
  background: var(--bg);
}

.admin-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.admin-content-cell {
  max-width: 18rem;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
  color: var(--text);
}

/* ---------- Divider ---------- */
.divider {
  height: 1px;
  background: var(--border);
  margin: 1.25rem 0;
}

/* ---------- Utility ---------- */
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.d-flex { display: flex; }
.gap-1 { gap: 0.5rem; }
.align-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.hidden { display: none !important; }

/* ---------- Responsive ---------- */
@media (min-width: 640px) {
  .header-content {
    padding: 0.85rem 1.5rem;
  }

  #app-main {
    padding: 1.5rem;
  }

  .register-card {
    padding: 2.5rem 2rem;
  }

  .profile-card {
    padding: 2rem;
  }
}

@media (min-width: 768px) {
  .app-title {
    font-size: 1.25rem;
  }

  .post-card {
    padding: 1.25rem 1.4rem;
  }
}

/* PWA Install Banner */
#pwa-install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: #1e40af;
  color: #fff;
  padding: 0.875rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  z-index: 1000;
  box-shadow: 0 -2px 12px rgba(0,0,0,0.2);
  font-size: 0.9rem;
}

#pwa-install-banner span {
  flex: 1;
  font-weight: 500;
}

.pwa-banner-actions {
  display: flex;
  gap: 0.5rem;
  flex-shrink: 0;
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.82rem;
}

/* New post toggle button */
.new-post-toggle {
  display: block;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  font-size: 1rem;
  font-weight: 600;
  color: #2563eb;
  cursor: pointer;
  padding: 0.1rem 0;
  margin: 0;
  user-select: none;
}

.new-post-toggle:hover {
  color: #1d4ed8;
}
