/* views.css — View-specific styles: dashboard, posts, messaging, calendar, auth */

/* ── Password Gate ────────────────────────────────────────────────────────── */
#pw-overlay {
  position: fixed; inset: 0; z-index: 99999;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--blue-dark) 0%, var(--blue) 60%, #1a5bc4 100%);
}

#pw-overlay.hidden { display: none; }

.pw-box {
  background: #fff;
  border-radius: var(--radius-xl);
  padding: var(--space-2xl) var(--space-xl);
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: modalIn 0.35s ease;
}

.pw-logo { margin-bottom: var(--space-lg); }
.pw-logo img { height: 48px; }
.pw-box h2 { font-size: 1.3rem; margin-bottom: 4px; }
.pw-box p  { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: var(--space-xl); }
.pw-input-wrap { position: relative; margin-bottom: var(--space-md); }
.pw-input-wrap input { padding-right: 44px; }
#pw-toggle {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  display: flex; align-items: center;
}
#pw-error { color: var(--red); font-size: 0.8rem; min-height: 20px; margin-top: 8px; }

.pw-input-wrap input.shake { animation: shake 0.35s ease; border-color: var(--red) !important; }
@keyframes shake {
  0%,100%{ transform: translateX(0); }
  20%{ transform: translateX(-8px); }
  40%{ transform: translateX(8px); }
  60%{ transform: translateX(-5px); }
  80%{ transform: translateX(4px); }
}

/* ── Dashboard ────────────────────────────────────────────────────────────── */
.pages-table-row-name { font-weight: 600; }
.pages-table-row-meta { font-size: 0.8rem; color: var(--text-muted); }

/* ── Schedule Tabs ────────────────────────────────────────────────────────── */
.sched-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 5px;
  margin-bottom: var(--space-lg);
  width: fit-content;
}

.sched-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  background: transparent;
  color: var(--text-secondary);
  transition: all var(--transition);
  position: relative;
}

.sched-tab:hover { color: var(--text-primary); background: var(--surface); }
.sched-tab.active {
  background: var(--surface);
  color: var(--blue);
  box-shadow: var(--shadow-xs);
}

.sched-tab-badge {
  background: var(--red);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
  display: none;
}
.sched-tab-badge:not(:empty) { display: inline-block; }

.sched-panel { display: none; }
.sched-panel.active { display: block; }

/* ── Upcoming Post Cards ─────────────────────────────────────────────────── */
.sched-job-card {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: start;
  padding: var(--space-md) var(--space-lg);
  border-bottom: 1px solid var(--border-soft);
  transition: background var(--transition);
}
.sched-job-card:last-child { border-bottom: none; }
.sched-job-card:hover { background: var(--bg); }

.sched-job-preview {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-md);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.sched-job-main { display: flex; gap: 12px; align-items: flex-start; }
.sched-job-body { flex: 1; min-width: 0; }

.sched-job-msg {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.sched-job-time {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--blue);
  font-weight: 500;
  margin-bottom: 3px;
}
.sched-job-pages {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.sched-job-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ── Post Preview (FB style) ─────────────────────────────────────────────── */
.fb-preview-card {
  background: var(--surface);
  border: 1px solid #dddfe2;
  border-radius: 10px;
  overflow: hidden;
  max-width: 500px;
}

.fb-preview-header {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
}

.fb-preview-body {
  padding: 0 14px 12px;
  font-size: 0.9rem;
  line-height: 1.6;
  color: #1c1e21;
  white-space: pre-wrap;
}

.fb-preview-image {
  width: 100%;
  max-height: 400px;
  object-fit: cover;
}

.fb-preview-video {
  width: 100%;
  max-height: 350px;
  background: #000;
}

.fb-preview-actions {
  display: flex;
  border-top: 1px solid var(--border);
  padding: 2px;
}

.fb-preview-action-btn {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px;
  font-size: 0.8rem; font-weight: 600; color: #65676b;
  background: none; border: none; border-radius: 6px;
  cursor: pointer;
  transition: background var(--transition);
}

.fb-preview-action-btn:hover { background: var(--bg); }

/* ── Instagram Preview ────────────────────────────────────────────────────── */
.ig-preview-phone {
  width: 220px;
  border: 2px solid #e0e0e0;
  border-radius: 24px;
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow-md);
}

.ig-preview-topbar {
  background: #fff;
  padding: 10px 12px 6px;
  border-bottom: 1px solid #efefef;
  display: flex; align-items: center; gap: 6px;
}

.ig-preview-avatar-sm {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #f09433, #dc2743, #bc1888);
}

.ig-preview-username { font-size: 0.75rem; font-weight: 700; color: #111; }

.ig-preview-image {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  background: var(--border-soft);
}

.ig-preview-video {
  width: 100%;
  aspect-ratio: 9/16;
  object-fit: cover;
  background: #000;
}

.ig-preview-actions {
  padding: 8px 10px 6px;
  display: flex; gap: 8px;
}

.ig-preview-actions svg { width: 20px; height: 20px; color: #262626; }

.ig-preview-caption {
  padding: 0 10px 10px;
  font-size: 0.72rem;
  color: #262626;
  line-height: 1.4;
}

/* ── Posts Analytics ─────────────────────────────────────────────────────── */
.post-analytics-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: var(--space-md);
}

.post-analytics-header {
  display: flex; gap: 12px; padding: 14px;
  align-items: flex-start;
}

.post-analytics-image {
  width: 64px; height: 64px; border-radius: var(--radius-md);
  object-fit: cover; background: var(--bg); flex-shrink: 0;
}

.post-analytics-meta { flex: 1; min-width: 0; }
.post-analytics-name { font-weight: 600; font-size: 0.85rem; color: var(--text-secondary); }
.post-analytics-msg  { font-size: 0.875rem; color: var(--text-primary); margin: 2px 0 6px; }

.post-analytics-stats {
  display: flex; gap: var(--space-md); padding: 10px 14px;
  background: var(--bg); border-top: 1px solid var(--border);
}

.post-stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.post-stat-val { font-size: 1rem; font-weight: 700; color: var(--text-primary); }
.post-stat-lbl { font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }

.post-comments-panel {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
  display: none;
}

.post-comments-panel.open { display: block; }

.comment-item {
  display: flex; gap: 10px; margin-bottom: 10px;
}

.comment-body {
  background: var(--bg);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 0.82rem;
  flex: 1;
}

.comment-from { font-weight: 600; font-size: 0.75rem; margin-bottom: 2px; }
.comment-text { color: var(--text-primary); }
.comment-time { font-size: 0.7rem; color: var(--text-muted); margin-top: 4px; }

.reply-input-row {
  display: flex; gap: 8px; margin-top: var(--space-sm);
}

.reply-input-row input {
  flex: 1;
}

/* ── Messaging ──────────────────────────────────────────────────────────────── */
.messaging-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  height: calc(100vh - 148px);
  min-height: 500px;
}

.conv-list {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--sidebar-bg);
}

.conv-list-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: var(--surface);
}

.conv-list-scroll {
  flex: 1;
  overflow-y: auto;
}

.conv-item {
  display: flex;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  transition: background var(--transition);
  align-items: flex-start;
}

.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--red-soft); border-left: 3px solid var(--red); }
.conv-item.conv-unread .conv-name { font-weight: 700; }

.conv-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  overflow: hidden;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name { font-weight: 600; font-size: 0.85rem; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-page-tag {
  display: flex;
  align-items: center;
  gap: 3px;
  font-size: 0.68rem;
  color: var(--blue);
  font-weight: 500;
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-snippet {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.conv-time { font-size: 0.65rem; color: var(--text-muted); white-space: nowrap; }
.msg-unread-dot {
  background: var(--red);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  min-width: 18px;
  text-align: center;
}

.thread-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.thread-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  background: var(--surface);
  min-height: 64px;
}

.thread-header-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}

.thread-header-info { flex: 1; min-width: 0; }
.thread-header-name { font-weight: 700; font-size: 0.95rem; color: var(--text-primary); }
.thread-header-sub { font-size: 0.73rem; color: var(--text-muted); }

.thread-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--bg);
}

.msg-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.msg-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 75%;
}

.msg-row-me {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-row-them {
  align-self: flex-start;
}

.msg-sender-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 0.6rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.msg-sender-name {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
  padding-left: 4px;
}

.msg-bubble {
  padding: 9px 14px;
  border-radius: 18px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-break: break-word;
}

.msg-me {
  background: var(--blue);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-them {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  padding: 0 4px;
}

.msg-time-right { text-align: right; }

.msg-attachment-img {
  max-width: 240px;
  max-height: 200px;
  border-radius: var(--radius-md);
  object-fit: cover;
  border: 1px solid var(--border);
  display: block;
  cursor: pointer;
}

.msg-attachment-file {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  color: var(--blue);
  text-decoration: none;
}

.thread-input {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  align-items: flex-end;
}

.thread-input-area {
  flex: 1;
  min-height: 40px;
  max-height: 120px;
  resize: none;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 0.875rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg);
  outline: none;
  transition: border-color var(--transition);
  line-height: 1.5;
  overflow-y: auto;
}

.thread-input-area:focus { border-color: var(--blue); }

.msg-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), transform var(--transition);
}

.msg-send-btn:hover { background: var(--blue-dark); transform: scale(1.05); }
.msg-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

@media (max-width: 768px) {
  .messaging-layout { grid-template-columns: 1fr; height: auto; }
  .conv-list { max-height: 300px; }
}

/* ── Calendar ─────────────────────────────────────────────────────────────── */
.calendar-controls {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-md);
  gap: var(--space-md);
}

.calendar-nav { display: flex; align-items: center; gap: var(--space-sm); }
.calendar-month-label { font-size: 1.1rem; font-weight: 700; min-width: 160px; text-align: center; }

.calendar-wrap { overflow-x: auto; }

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  min-width: 700px;
}

.cal-day-header {
  background: var(--bg);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
  padding: 10px 0;
}

.cal-cell {
  background: var(--surface);
  min-height: 100px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  cursor: default;
  transition: background var(--transition);
}

.cal-cell:hover { background: var(--bg); }
.cal-cell.today { background: var(--blue-soft); }
.cal-cell.other-month { background: var(--bg); }

.cal-date {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.cal-cell.today .cal-date {
  background: var(--red);
  color: #fff;
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}

.cal-event {
  font-size: 0.68rem;
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.cal-event.fb  { background: #eff4ff; color: #1d4ed8; border-left: 2px solid #1d4ed8; }
.cal-event.ig  { background: #fdf2f8; color: #9d174d; border-left: 2px solid #9d174d; }
.cal-event.sched { background: var(--red-soft); color: var(--red); border-left: 2px solid var(--red); }

/* ── Page filter chips ────────────────────────────────────────────────────── */
.page-chips {
  display: flex; flex-wrap: wrap; gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

.page-chip {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.page-chip:hover { border-color: var(--red); color: var(--red); }
.page-chip.active { background: var(--red); color: #fff; border-color: var(--red); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .messaging-layout { grid-template-columns: 280px 1fr; }
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .app-layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    left: -260px;
    top: 0; bottom: 0;
    width: 260px;
    z-index: 9000;
    transition: left 0.25s ease;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open { left: 0; }

  #menu-toggle { display: flex !important; }

  .main-content { grid-column: 1; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }

  .messaging-layout {
    grid-template-columns: 1fr;
    height: auto;
    min-height: auto;
  }

  .conv-list {
    height: 320px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .thread-panel {
    height: 520px;
  }

  .two-col { grid-template-columns: 1fr !important; }

  .table-wrap { overflow-x: auto; }

  .page-body { padding: var(--space-md) !important; }

  .fb-preview-card { max-width: 100%; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-card { padding: var(--space-md); }
  .pw-box { padding: var(--space-xl) var(--space-md); }
  .topbar { padding: 10px var(--space-md); }
}

/* ── Templates ────────────────────────────────────────────────────────────── */
.tpl-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: var(--space-lg);
}

.tpl-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: box-shadow var(--transition), transform var(--transition);
}
.tpl-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

.tpl-card-media {
  width: 100%;
  height: 180px;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}
.tpl-card-media-empty {
  display: flex;
  align-items: center;
  justify-content: center;
}
.tpl-card-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
  transition: transform 0.3s ease;
}
.tpl-card:hover .tpl-card-img { transform: scale(1.04); }

.tpl-card-body {
  padding: var(--space-md) var(--space-lg);
  flex: 1;
}
.tpl-card-name {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text-primary);
  margin-bottom: 6px;
}
.tpl-card-msg {
  font-size: 0.825rem;
  color: var(--text-secondary);
  line-height: 1.5;
  min-height: 36px;
}

.tpl-card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm) var(--space-md);
  border-top: 1px solid var(--border-soft);
  background: var(--bg);
}
.tpl-card-actions .btn { font-size: 0.8rem; }

/* ── Template picker dropdown ─────────────────────────────────────────────── */
.tpl-picker {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: var(--space-sm);
}
.tpl-picker.hidden { display: none; }

.tpl-picker-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background var(--transition);
}
.tpl-picker-item:last-child { border-bottom: none; }
.tpl-picker-item:hover { background: var(--bg); }

.tpl-picker-thumb {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.tpl-picker-thumb-empty {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.tpl-picker-info { flex: 1; min-width: 0; }
.tpl-picker-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tpl-picker-msg {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tpl-picker-empty {
  padding: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
}

@media (max-width: 768px) {
  .tpl-grid { grid-template-columns: 1fr; }
}
