:root {
  --blue-900: #c03a20;
  --blue-700: #cd3e21;
  --blue-600: #d94325;
  --blue-500: #da4123;
  --blue-100: #f34b2a;
  --blue-50: #eff6ff;
  --white: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --text: #475569;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-soft: #e8edf4;
  --row-border: #f4f7fb;
  --surface-muted: #f8fafc;
  --danger: #dc2626;
  --success: #16a34a;
  --success-bg: #dcfce7;
  --warning: #b45309;
  --warning-bg: #fef3c7;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --sidebar-w: 240px;
  --header-h: 64px;
  --toolbar-h: 58px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  background: var(--white);
  color: var(--ink);
}

a {
  color: var(--blue-600);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

.muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.6rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn-primary {
  background: var(--blue-600);
  color: var(--white);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.24);
}
.btn-primary:hover {
  background: var(--blue-700);
  text-decoration: none;
}
.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}
.btn-link {
  background: none;
  border: none;
  color: var(--blue-600);
  cursor: pointer;
  font-size: 0.875rem;
  padding: 0;
  font-family: inherit;
}

.alert {
  padding: 0.6rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 1rem;
}
.alert-error {
  background: #fee2e2;
  color: var(--danger);
}

.avatar {
  border-radius: 50%;
  object-fit: cover;
  background: var(--blue-100);
}
.avatar-sm {
  width: 32px;
  height: 32px;
}
.avatar-lg {
  width: 46px;
  height: 46px;
}

.avatar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--blue-100);
  color: var(--blue-700);
  font-weight: 700;
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}
.badge-success {
  background: var(--success-bg);
  color: var(--success);
}
.badge-warning {
  background: var(--warning-bg);
  color: var(--warning);
}
.badge-count {
  min-width: 17px;
  height: 17px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--blue-600);
  color: var(--white);
  font-size: 0.65rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.empty-state {
  background: var(--white);
  border: 1px dashed var(--border-soft);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--text-muted);
}
.panel-loading {
  padding: 1.5rem;
  color: var(--text-muted);
  text-align: center;
}

/* ---------- Auth screen ---------- */

.auth-body {
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #cfe0fb 0%, #e8f1fe 42%, #dce9fd 100%);
}
.auth-blob {
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.34);
}
.auth-card {
  position: relative;
  background: var(--white);
  padding: 2.5rem;
  border-radius: 18px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 24px 60px rgba(30, 64, 175, 0.16);
  text-align: center;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  font-weight: 700;
  font-size: 1.2rem;
  color: var(--blue-700);
}
.brand-badge {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex-shrink: 0;
}
.auth-headline {
  margin: 1.4rem 0 0.6rem;
  font-size: 1.3rem;
  line-height: 1.4;
  font-weight: 650;
  color: var(--ink);
}
.auth-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.6;
  margin: 0 0 1.6rem;
}
.fb-login-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  background: #1877f2;
  color: var(--white);
  border-radius: var(--radius-sm);
  padding: 0.8rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
}
.fb-login-btn:hover {
  background: #1461c6;
  text-decoration: none;
}
.feature-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  text-align: left;
  margin: 1.7rem 0 1.6rem;
}
.feature-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
}
.feature-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--blue-50);
  color: var(--blue-600);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.feature-row span {
  font-size: 0.8rem;
  color: var(--ink-soft);
  line-height: 1.5;
}
.auth-footer {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ---------- App shell ---------- */

.app-shell {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.875rem;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0 0.5rem 1.4rem;
}
.sidebar-brand .brand-badge {
  width: 28px;
  height: 28px;
}
.sidebar-brand span {
  font-weight: 700;
  font-size: 0.97rem;
  color: var(--blue-700);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
}
.nav-item:hover {
  background: var(--surface-muted);
  text-decoration: none;
}
.nav-item.active {
  background: var(--blue-50);
  color: var(--blue-600);
  font-weight: 600;
}
.nav-item.active svg {
  stroke: var(--blue-600);
}
.nav-item.disabled {
  color: #cbd5e1;
  cursor: default;
}
.nav-item.disabled:hover {
  background: none;
}
.nav-item.disabled svg {
  stroke: #cbd5e1;
}

.sidebar-divider {
  height: 1px;
  background: var(--border-soft);
  margin: 0.9rem 0.5rem;
}
.sidebar-spacer {
  flex-grow: 1;
}

/* ---------- App main / header ---------- */

.app-main {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

.app-header {
  height: var(--header-h);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.6rem;
}
.app-header h1 {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.app-header-actions {
  display: flex;
  align-items: center;
  gap: 1.1rem;
}
.icon-btn-plain {
  display: inline-flex;
  color: var(--text);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}
.user-chip-name {
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.user-chip-name strong {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink);
}
.user-chip-name span {
  font-size: 0.68rem;
  color: var(--text-muted);
}
.user-chip form {
  display: contents;
}
.user-chip button.btn-link {
  font-size: 0.78rem;
}

.app-content {
  flex-grow: 1;
  padding: 1.6rem 1.75rem 2.5rem;
  overflow-y: auto;
  min-height: 0;
}

.content-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}
.content-header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}
.content-header p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text);
}

/* ---------- Connected Pages ---------- */

.page-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1.1rem;
}
.page-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  background: var(--white);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.04);
}
.page-card:hover {
  border-color: var(--blue-500);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.1);
}
.page-card-inactive {
  opacity: 0.6;
}
.page-card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}
.page-card-link:hover {
  text-decoration: none;
}
.page-card .avatar-badge {
  font-size: 0.9rem;
  margin-bottom: 0.85rem;
}
.page-card-avatar {
  margin-bottom: 0.85rem;
}
.page-card h3 {
  margin: 0 0 0.55rem;
  font-size: 0.9rem;
  font-weight: 650;
  line-height: 1.4;
}
.page-card-meta {
  margin: 0.7rem 0 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.page-card-divider {
  height: 1px;
  background: var(--row-border);
  margin: 0.95rem 0 0.75rem;
}
.page-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
}
.badge-muted {
  background: var(--surface-muted);
  color: var(--text-muted);
}

/* ---------- Toggle switch ---------- */

.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
}
.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.switch-track {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.15s ease;
}
.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  background: var(--white);
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.25);
  transition: transform 0.15s ease;
}
.switch input:checked ~ .switch-track {
  background: var(--blue-600);
}
.switch input:checked ~ .switch-track .switch-thumb {
  transform: translateX(14px);
}
.switch input:disabled ~ .switch-track {
  opacity: 0.6;
  cursor: default;
}

/* ---------- Modal / Page picker ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 50;
}
.modal-overlay.hidden {
  display: none;
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.3rem;
}
.modal-head h2 {
  margin: 0;
  font-size: 1.05rem;
}
.modal-head .icon-btn-plain {
  font-size: 1.3rem;
  line-height: 1;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text-muted);
}
.modal .muted {
  margin: 0 0 1rem;
}
.picker-list {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin-bottom: 1.1rem;
}
.picker-row {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0.4rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
}
.picker-row:hover {
  background: var(--surface-muted);
}
.picker-row input {
  flex-shrink: 0;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}
.btn-outline {
  background: var(--white);
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-outline:hover {
  background: var(--surface-muted);
}

/* ---------- Toolbar (Messages / Posts & Comments) ---------- */

.page-toolbar {
  height: var(--toolbar-h);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
}

.page-switcher {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--white);
  font-family: inherit;
  min-width: 200px;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  flex-grow: 1;
}
.search-box input {
  border: none;
  outline: none;
  font-size: 0.8rem;
  font-family: inherit;
  flex-grow: 1;
  color: var(--ink);
}
.search-box input::placeholder {
  color: var(--text-muted);
}

.toolbar-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.8rem;
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--white);
  cursor: pointer;
  white-space: nowrap;
}
.toolbar-chip.accent {
  border-color: #bfdbfe;
  background: var(--blue-50);
  color: var(--blue-600);
  font-weight: 600;
}

/* ---------- Split panel (list + detail) ---------- */

.split-body {
  flex-grow: 1;
  display: flex;
  min-height: 0;
}

.list-col {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-soft);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.list-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: none;
  border-left: 3px solid transparent;
  border-bottom: 1px solid var(--row-border);
  background: var(--white);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}
.list-item:hover {
  background: var(--surface-muted);
}
.list-item.active {
  background: var(--blue-50);
  border-left-color: var(--blue-600);
}
.list-item-body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-grow: 1;
  gap: 2px;
}
.list-item-body strong {
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item-body span {
  font-size: 0.72rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.detail-col {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.detail-empty {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.thread-header {
  height: var(--header-h);
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
}
.thread-header-name {
  font-size: 0.9rem;
  font-weight: 650;
}
.thread-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 2px;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.message-thread {
  flex-grow: 1;
  overflow-y: auto;
  padding: 1.1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.bubble-row {
  display: flex;
}
.bubble-row.outgoing {
  justify-content: flex-end;
}
.bubble {
  max-width: 62%;
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  background: var(--surface-muted);
  font-size: 0.85rem;
  line-height: 1.5;
  word-wrap: break-word;
}
.bubble-row.outgoing .bubble {
  background: var(--blue-600);
  color: var(--white);
}
.bubble-row.outgoing .bubble.bubble-failed {
  background: var(--danger);
}
.bubble-status {
  display: block;
  font-size: 0.68rem;
  opacity: 0.85;
  margin-top: 0.25rem;
}

.bubble-attachment {
  display: block;
  margin-bottom: 0.4rem;
}
.bubble-attachment img {
  max-width: 100%;
  max-height: 220px;
  border-radius: 10px;
  display: block;
  object-fit: cover;
}
.bubble-attachment-fallback {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  text-decoration: underline;
}

.load-more-btn {
  align-self: center;
  margin-bottom: 0.5rem;
  font-size: 0.78rem;
}

.reply-form {
  flex-shrink: 0;
  padding: 0.9rem 1.5rem 1.25rem;
}
.reply-compose-row {
  display: flex;
  gap: 0.6rem;
}
.reply-form input {
  flex: 1;
  padding: 0.65rem 0.9rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  font-family: inherit;
}
.reply-attachment-preview {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}
.reply-attachment-preview.hidden {
  display: none;
}
.reply-attachment-preview img {
  width: 54px;
  height: 54px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.reply-attachment-remove {
  border: none;
  background: none;
  color: var(--danger);
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
}

/* ---------- Posts list + comment detail ---------- */

.post-item {
  align-items: flex-start;
  gap: 0.75rem;
}
.post-thumb {
  width: 42px;
  height: 42px;
  border-radius: 9px;
  background: linear-gradient(135deg, #94a3b8, #475569);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.post-thumb-img {
  width: 42px;
  height: 42px;
  border-radius: 9px;
  object-fit: cover;
  flex-shrink: 0;
  background: var(--surface-muted);
}
.post-item-meta {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}
.post-item-meta span {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

.comment-panel-head {
  flex-shrink: 0;
  padding: 1.1rem 1.5rem 0.9rem;
  border-bottom: 1px solid var(--border-soft);
}
.comment-panel-head h2 {
  margin: 0 0 0.3rem;
  font-size: 0.95rem;
  font-weight: 650;
  line-height: 1.45;
}
.comment-panel-head .post-item-meta {
  margin-top: 0.4rem;
}
.comment-panel-head-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.comment-panel-head-top .btn {
  flex-shrink: 0;
  white-space: nowrap;
}
.comment-panel-head #load-new-comments-btn {
  margin-top: 0.5rem;
}

.comment-list {
  flex-grow: 1;
  overflow-y: auto;
  padding: 0.25rem 1.5rem;
}
.comment-item {
  border-bottom: 1px solid var(--row-border);
  padding: 1rem 0.15rem;
}
.comment-item.comment-hidden {
  opacity: 0.5;
}
.comment-item.comment-item-page {
  background: var(--blue-50);
  border-left: 3px solid var(--blue-500);
  padding-left: 0.85rem;
}
.comment-replies {
  margin-left: 1.75rem;
  padding-left: 0.9rem;
  border-left: 2px solid var(--border-soft);
}
.comment-replies .comment-item {
  padding-top: 0.75rem;
  padding-bottom: 0.75rem;
}
.comment-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
}
.comment-author {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.comment-item p {
  margin: 0.2rem 0 0.55rem;
  font-size: 0.85rem;
  line-height: 1.5;
}
.comment-actions {
  display: flex;
  gap: 1.1rem;
}
.comment-reply-form {
  display: flex;
  gap: 0.55rem;
  margin-top: 0.65rem;
}
.comment-reply-form.hidden {
  display: none;
}
.comment-reply-form input {
  flex: 1;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.8rem;
  font-family: inherit;
}

/* ---------- Legal pages / error ---------- */

.legal-page {
  max-width: 720px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 4rem;
  line-height: 1.65;
}
.legal-page h1 {
  color: var(--blue-700);
}
.legal-page h2 {
  color: var(--blue-600);
  font-size: 1.05rem;
  margin-top: 1.6rem;
}

@media (max-width: 860px) {
  .sidebar {
    display: none;
  }
  .list-col {
    width: 260px;
  }
}
