:root {
  --brand: #4f46e5;
  --brand-dark: #4338ca;
  --brand-soft: #eef2ff;
  --bg: #f3f4f8;
  --surface: #ffffff;
  --text: #1e2130;
  --text-muted: #6b7280;
  --border: #e6e8ef;
  --sidebar-bg: #12142433;
  --sidebar-bg-solid: #14162a;
  --sidebar-text: #9ca3c4;
  --sidebar-text-active: #ffffff;
  --success: #16a34a;
  --warning: #b45309;

  /* Chart palette — validated categorical order + reserved status colors,
     see the dataviz skill. Do not reorder or reuse status hues as series. */
  --chart-1: #2a78d6; /* blue */
  --chart-2: #008300; /* green */
  --chart-3: #e87ba4; /* magenta */
  --chart-4: #eda100; /* yellow */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;
  --chart-grid: #e1e0d9;
  --chart-axis: #c3c2b7;
  --chart-muted: #898781;
  --danger: #dc2626;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  background-color: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

h1, h2, h3, h4, h5, h6 { font-weight: 700; letter-spacing: -0.01em; }

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

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

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar-bg-solid);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  padding: 20px 14px;
  z-index: 10;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 6px 10px 22px;
}
.sidebar-brand:hover { color: #fff; }

.sidebar-brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--brand), #7c6df2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-grow: 1;
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--sidebar-text);
  font-weight: 500;
  font-size: 0.92rem;
}

.sidebar-link i { font-size: 1.05rem; width: 20px; text-align: center; }

.sidebar-link:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.sidebar-link.active {
  background: var(--brand);
  color: #fff;
}

.sidebar-section-label {
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  color: #5b6088;
  margin: 16px 12px 6px;
  font-weight: 700;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px;
  margin-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-name {
  color: #fff;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

.sidebar-user-logout {
  font-size: 0.78rem;
  color: var(--sidebar-text);
}
.sidebar-user-logout:hover { color: #fff; }

.main-panel {
  margin-left: 250px;
  flex-grow: 1;
  min-width: 0;
}

.page-content {
  max-width: 1080px;
  padding: 32px 36px 64px;
  margin: 0 auto;
}

@media (max-width: 900px) {
  .sidebar { width: 72px; padding: 16px 10px; }
  .sidebar-brand-text, .sidebar-link span, .sidebar-user-info, .sidebar-section-label { display: none; }
  .sidebar-brand { justify-content: center; padding: 6px 0 22px; }
  .sidebar-link { justify-content: center; }
  .sidebar-user { justify-content: center; }
  .main-panel { margin-left: 72px; }
  .page-content { padding: 24px 16px 48px; }
}

/* ---------- Mobile: off-canvas drawer + top bar + bottom tab bar ---------- */

.nav-drawer-toggle { display: none; }
.mobile-topbar, .mobile-tabbar, .mobile-fab, .nav-drawer-backdrop { display: none; }

@media (max-width: 600px) {
  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 56px;
    padding: 0 14px;
    background: var(--sidebar-bg-solid);
    z-index: 40;
  }
  .mobile-menu-btn {
    color: #fff;
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 4px;
  }
  .mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
    flex-grow: 1;
  }
  .mobile-topbar-brand:hover { color: #fff; }
  .mobile-topbar-avatar { width: 28px; height: 28px; font-size: 0.75rem; }

  .nav-drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(11, 11, 11, 0.45);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
    z-index: 45;
  }

  /* Sidebar reverts to a full labeled off-canvas drawer, not the icon-only rail */
  .sidebar {
    width: 250px;
    padding: 20px 14px;
    position: fixed;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 50;
  }
  .sidebar-brand-text, .sidebar-link span, .sidebar-user-info, .sidebar-section-label { display: inline !important; }
  .sidebar-brand { justify-content: flex-start; padding: 6px 10px 22px; }
  .sidebar-link { justify-content: flex-start; }
  .sidebar-user { justify-content: flex-start; }

  .nav-drawer-toggle:checked ~ .app-shell .sidebar { transform: translateX(0); }
  .nav-drawer-toggle:checked ~ .app-shell .nav-drawer-backdrop { opacity: 1; pointer-events: auto; }

  .main-panel { margin-left: 0; }
  .page-content { padding: 70px 16px 84px; }

  .mobile-tabbar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    z-index: 40;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mobile-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 8px 4px 6px;
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
  }
  .mobile-tab i { font-size: 1.15rem; }
  .mobile-tab.active { color: var(--brand); }

  .mobile-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: 18px;
    bottom: 76px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--brand);
    color: #fff;
    font-size: 1.3rem;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4);
    z-index: 41;
  }
  .mobile-fab:hover { background: var(--brand-dark); color: #fff; }

  /* Compose page: keep the "Post now / Schedule" toggle from squeezing two-line labels */
  .compose-timing-toggle { display: flex; width: 100%; }
  .compose-timing-option { flex: 1; }
  .compose-timing-option span { justify-content: center; white-space: nowrap; }
}

/* ---------- Auth pages ---------- */

.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top left, #e9e7ff 0%, var(--bg) 45%);
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 28px;
  font-size: 1.05rem;
}
.auth-brand:hover { color: var(--text); }

.auth-title { font-size: 1.4rem; margin-bottom: 4px; }
.auth-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 24px; }
.auth-footer-link { margin-top: 20px; font-size: 0.88rem; color: var(--text-muted); }

/* ---------- Cards, forms, buttons ---------- */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  transition: box-shadow .15s ease, transform .15s ease;
}

.card:hover {
  box-shadow: 0 4px 14px rgba(16, 24, 40, 0.08), 0 2px 6px rgba(16, 24, 40, 0.06);
  transform: translateY(-1px);
}

.card-body { padding: 22px 24px; }

.form-label { font-weight: 600; font-size: 0.86rem; color: var(--text); }

.form-control, .form-select {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 9px 12px;
  font-size: 0.92rem;
}

.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
}

.btn {
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
  padding: 9px 16px;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
}
.btn-primary:hover, .btn-primary:focus {
  background: var(--brand-dark);
  border-color: var(--brand-dark);
}

.btn-outline-primary {
  color: var(--brand);
  border-color: var(--brand);
}
.btn-outline-primary:hover {
  background: var(--brand);
  border-color: var(--brand);
}

.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

.alert {
  border-radius: var(--radius-sm);
  border: none;
  font-size: 0.9rem;
}
.alert-success { background: #ecfdf3; color: #166534; }
.alert-danger { background: #fef2f2; color: #991b1b; }

/* ---------- Page heading ---------- */

.page-content > h1:first-child,
.page-content > .d-flex:first-child > h1 {
  font-size: 1.5rem;
  margin-bottom: 20px;
}

/* ---------- Charts ---------- */

.chart-card-title {
  font-size: 0.95rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.chart-card-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 14px;
}

.chart-canvas-wrap {
  position: relative;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--text);
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.chart-legend-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 220px;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ---------- Compose ---------- */

.ai-panel {
  background: var(--brand-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.compose-accounts {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.compose-account-option {
  cursor: pointer;
}

.compose-account-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.compose-account-card {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color .15s, background .15s, box-shadow .15s;
}

.compose-account-name {
  font-size: 0.88rem;
  font-weight: 500;
}

.compose-account-check {
  display: none;
  color: var(--brand);
  font-size: 0.9rem;
}

.compose-account-input:checked + .compose-account-card {
  border-color: var(--brand);
  background: var(--brand-soft);
}
.compose-account-input:checked + .compose-account-card .compose-account-check {
  display: inline-block;
}
.compose-account-input:focus-visible + .compose-account-card {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.account-picker-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  overflow: hidden;
}

.account-picker-group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.account-picker-count {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-right: auto;
}

.account-picker-chevron {
  transition: transform .15s;
  color: var(--text-muted);
}

.account-picker-group-header[aria-expanded="true"] .account-picker-chevron {
  transform: rotate(180deg);
}

.account-picker-group-body {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}

.compose-timing-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.compose-timing-option {
  cursor: pointer;
}

.compose-timing-option input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.compose-timing-option span {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}
.compose-timing-option:last-child span { border-right: none; }

.compose-timing-option input:checked + span {
  background: var(--brand);
  color: #fff;
}
.compose-timing-option input:focus-visible + span {
  outline: 2px solid var(--brand);
  outline-offset: -2px;
}

/* ---------- Topbar / notifications ---------- */

.main-topbar {
  display: flex;
  justify-content: flex-end;
  padding: 16px 36px 0;
  max-width: 1080px;
  margin: 0 auto;
}

.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  font-size: 0.6rem;
  padding: 2px 5px;
}

.notif-dropdown {
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  padding: 0;
}

.notif-item {
  white-space: normal;
  border-bottom: 1px solid var(--border);
}

.notif-unread {
  background: var(--brand-soft);
}

@media (max-width: 900px) {
  .main-topbar { padding: 16px 16px 0; }
}

/* ---------- Content calendar ---------- */

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
}

.calendar-dow {
  padding: 10px;
  text-align: center;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: #fafafc;
  border-bottom: 1px solid var(--border);
}

.calendar-cell {
  min-height: 100px;
  padding: 6px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

.calendar-cell-empty { background: #fafafc; }

.calendar-cell-today { background: var(--brand-soft); }

.calendar-daynum {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.calendar-post {
  display: block;
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.calendar-post:hover { border-color: var(--brand); color: var(--text); }

@media (max-width: 700px) {
  .calendar-dow:nth-child(n) { font-size: 0.6rem; padding: 6px 2px; }
  .calendar-cell { min-height: 60px; font-size: 0.7rem; }
  .calendar-post { font-size: 0.62rem; }
}

.calendar-grid-week { grid-template-columns: repeat(7, 1fr); }

.calendar-drop-hover { background: var(--brand-soft); outline: 2px dashed var(--brand); outline-offset: -2px; }

.calendar-approval-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}

.calendar-day-timeline {
  max-height: 65vh;
  overflow-y: auto;
}

.calendar-hour-row {
  display: flex;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.calendar-hour-row-now {
  background: var(--brand-soft);
}

.calendar-hour-label {
  flex: 0 0 72px;
  padding: 6px 10px;
  text-align: right;
  font-size: 0.72rem;
  color: var(--text-muted);
  border-right: 1px solid var(--border);
}

.calendar-hour-slot {
  flex: 1;
  padding: 6px 10px;
}

.calendar-day-post {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  margin-bottom: 4px;
}
.calendar-day-post:hover { border-color: var(--brand); color: var(--text); }

.calendar-day-post-time {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.calendar-day-post-content {
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 700px) {
  .calendar-hour-label { flex-basis: 54px; font-size: 0.65rem; padding: 6px 4px; }
  .calendar-day-post-content { font-size: 0.75rem; }
}

/* ---------- Stat tiles ---------- */

.stat-tile {
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-tile-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  background: var(--brand-soft);
  color: var(--brand);
  flex-shrink: 0;
}

.stat-tile .h4 { margin: 0; font-size: 1.5rem; }

/* ---------- Tables ---------- */

.table {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 0;
}

.table thead th {
  background: #fafafc;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
}

.table td {
  padding: 14px 16px;
  vertical-align: middle;
  border-color: var(--border);
}

.table tbody tr:hover { background: #fafafc; }

/* ---------- Badges ---------- */

.platform-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  margin-right: 6px;
}

.platform-facebook { background-color: #1877f2; }
.platform-instagram { background: linear-gradient(135deg, #f58529, #dd2a7b, #8134af); }
.platform-twitter { background-color: #14151a; }
.platform-linkedin { background-color: #0a66c2; }
.platform-reddit { background-color: #ff4500; }
.platform-tiktok { background-color: #000000; }
.platform-youtube { background-color: #ff0000; }
.platform-pinterest { background-color: #e60023; }
.platform-threads { background-color: #000000; }
.platform-bluesky { background-color: #0085ff; }
.platform-googlebusiness { background-color: #4285f4; }
.platform-telegram { background-color: #26a5e4; }
.platform-discord { background-color: #5865f2; }
.platform-whatsapp { background-color: #25d366; }

.platform-preview-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: 100%;
  display: flex;
  flex-direction: column;
}

.platform-preview-header {
  padding: 8px 12px;
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
}

.platform-preview-body {
  padding: 10px 12px;
  flex: 1;
}

.platform-preview-image {
  width: 100%;
  max-height: 160px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 8px;
}

.platform-preview-text {
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.platform-preview-footer {
  padding: 6px 12px;
  font-size: 0.75rem;
  border-top: 1px solid var(--border);
}

.status-posted, .status-completed {
  color: var(--success);
  font-weight: 600;
  font-size: 0.82rem;
}
.status-pending, .status-scheduled, .status-processing {
  color: var(--warning);
  font-weight: 600;
  font-size: 0.82rem;
}
.status-failed {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.82rem;
}

/* ---------- Nav tabs (admin) ---------- */

.nav-tabs {
  border-bottom: 1px solid var(--border);
  gap: 4px;
}
.nav-tabs .nav-link {
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  padding: 8px 16px;
}
.nav-tabs .nav-link.active {
  color: var(--brand);
  background: var(--brand-soft);
}

/* ---------- Engagement Hub (comments / messages) ---------- */

.message-thread {
  max-height: 480px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message-bubble-row { max-width: 100%; }

.message-bubble {
  display: inline-block;
  max-width: 75%;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  text-align: left;
}

.message-bubble-in {
  background: var(--brand-soft);
}

.message-bubble-out {
  background: var(--brand);
  color: #fff;
  margin-left: auto;
}

.badge-check {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}
.badge-check input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.badge-check input:not(:checked) + .badge {
  opacity: 0.35;
}

/* ---------- Organization switcher ---------- */

.org-switcher { padding: 0 10px 14px; }

.org-switcher-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  color: var(--sidebar-text-active);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: left;
}
.org-switcher-btn:hover { background: rgba(255,255,255,0.1); }

.org-switcher-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-switcher-logo {
  width: 20px;
  height: 20px;
  border-radius: 4px;
  object-fit: cover;
}

.org-switcher .dropdown-item {
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
