/* ══════════════════════════════════════════════════════
   META AUTOMATION DASHBOARD – CSS
   ══════════════════════════════════════════════════════ */

:root {
  --bg-base:       #0a0a0f;
  --bg-surface:    #111118;
  --bg-card:       #16161f;
  --bg-elevated:   #1c1c28;
  --border:        rgba(255,255,255,0.07);
  --border-hover:  rgba(255,255,255,0.14);

  --text-primary:  #f0f0f8;
  --text-secondary: #8b8ba8;
  --text-muted:    #55556a;

  --ig-1: #833ab4;
  --ig-2: #fd1d1d;
  --ig-3: #fcb045;
  --ig-grad: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);

  --purple:  #a855f7;
  --blue:    #3b82f6;
  --green:   #22c55e;
  --orange:  #f97316;
  --red:     #ef4444;

  --sidebar-w: 220px;
  --radius:  12px;
  --radius-lg: 18px;
  --shadow:  0 4px 24px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  display: flex;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Scrollbar ─────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-elevated); border-radius: 3px; }

/* ══════════════════════════════════════════════ SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 38px; height: 38px;
  background: var(--ig-grad);
  border-radius: 10px;
  display: flex;
  align-items: center; justify-content: center;
}

.logo-text {
  font-size: 18px;
  font-weight: 700;
  background: var(--ig-grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(168, 85, 247, 0.15);
  color: var(--purple);
}

.nav-item.active svg {
  stroke: var(--purple);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.ig-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  transition: background 0.3s;
}
.status-dot.connected { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.disconnected { background: var(--text-muted); }

/* ════════════════════════════════════════════ MAIN */
.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ────────────────────────────────── */
.topbar {
  height: 64px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: rgba(10,10,15,0.8);
  backdrop-filter: blur(12px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-title {
  font-size: 18px;
  font-weight: 700;
}

#ig-connect-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Pages ────────────────────────────────── */
.page {
  display: none;
  padding: 28px;
  animation: fadeIn 0.3s ease;
}

.page.active { display: block; }

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

/* ══════════════════════════════════════ CONNECT HERO */
.connect-hero {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 480px;
}

.connect-hero-content {
  text-align: center;
  max-width: 460px;
}

.ig-gradient-circle {
  width: 96px; height: 96px;
  border-radius: 50%;
  background: var(--ig-grad);
  display: flex;
  align-items: center; justify-content: center;
  margin: 0 auto 24px;
  box-shadow: 0 8px 32px rgba(131,58,180,0.4);
}

.connect-hero-content h2 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 12px;
}

.connect-hero-content p {
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.6;
}

.connect-requirements {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 28px;
  text-align: left;
  background: var(--bg-card);
  padding: 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.req-item {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ══════════════════════════════════════════════ STATS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: border-color 0.2s, transform 0.2s;
}

.stat-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center; justify-content: center;
  flex-shrink: 0;
}
.stat-icon.purple { background: rgba(168,85,247,0.15); color: var(--purple); }
.stat-icon.green  { background: rgba(34,197,94,0.15);  color: var(--green); }
.stat-icon.blue   { background: rgba(59,130,246,0.15); color: var(--blue); }
.stat-icon.orange { background: rgba(249,115,22,0.15); color: var(--orange); }

.stat-value {
  display: block;
  font-size: 28px;
  font-weight: 700;
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
}

/* ════════════════════════════════════ QUICK ACTIONS */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

.quick-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
}

.quick-card:hover {
  background: var(--bg-elevated);
  border-color: var(--purple);
  color: var(--text-primary);
  transform: translateY(-2px);
}

.quick-icon { font-size: 24px; }

/* ════════════════════════════════════ WEBHOOK CARD */
.webhook-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.webhook-row {
  margin-bottom: 16px;
}

.webhook-label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.webhook-value-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.webhook-value {
  background: var(--bg-elevated);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--purple);
  flex: 1;
  font-family: 'Courier New', monospace;
}

.webhook-note {
  font-size: 12px;
  color: var(--text-muted);
}

.webhook-info {
  background: rgba(59,130,246,0.08);
  border: 1px solid rgba(59,130,246,0.2);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

.webhook-info a { color: var(--blue); }
.webhook-info code {
  background: rgba(59,130,246,0.15);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

/* ════════════════════════════════════ SECTION HEADER */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-header h3 { font-size: 16px; font-weight: 600; }

/* ════════════════════════════════════ FLOWS PAGE */
.page-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
}

.flows-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.flow-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: all 0.2s;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-12px); }
  to   { opacity: 1; transform: translateX(0); }
}

.flow-card:hover {
  border-color: var(--border-hover);
}

.flow-card.inactive {
  opacity: 0.55;
}

.flow-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: rgba(168,85,247,0.12);
  display: flex;
  align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.flow-info { flex: 1; min-width: 0; }

.flow-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.flow-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.flow-tag {
  background: var(--bg-elevated);
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  color: var(--text-secondary);
}

.flow-tag.active { background: rgba(34,197,94,0.15); color: var(--green); }

.flow-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ═══════════════════════════════ CONVERSATIONS PAGE */
.conversations-wrap {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 16px;
  height: calc(100vh - 120px);
}

.conv-list {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-y: auto;
}

.conv-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
}

.conv-item:hover { background: var(--bg-elevated); }
.conv-item.selected { background: rgba(168,85,247,0.1); border-left: 3px solid var(--purple); }

.conv-sender {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
}

.conv-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.conv-detail {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.conv-detail-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 14px;
}

.conv-messages {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 20px;
  flex: 1;
}

.msg-bubble {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  position: relative;
}

.msg-bubble.incoming {
  background: var(--bg-elevated);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}

.msg-bubble.outgoing {
  background: linear-gradient(135deg, rgba(131,58,180,0.4), rgba(253,29,29,0.3));
  border: 1px solid rgba(168,85,247,0.2);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

.msg-type-tag {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.msg-time {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 2px;
  text-align: right;
}

/* ═══════════════════════════════════ SETTINGS PAGE */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 20px;
}

.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.settings-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.settings-card-icon { font-size: 24px; }

.settings-card-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-secondary);
}

.info-row:last-child { border-bottom: none; }
.info-row code {
  background: var(--bg-elevated);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--purple);
}

.account-profile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--bg-elevated);
  border-radius: 12px;
  margin-bottom: 16px;
}

.account-avatar {
  width: 52px; height: 52px;
  border-radius: 50%;
  background: var(--ig-grad);
  display: flex;
  align-items: center; justify-content: center;
  font-size: 24px;
  overflow: hidden;
  flex-shrink: 0;
}

.account-avatar img { width: 100%; height: 100%; object-fit: cover; }

.account-username {
  font-weight: 700;
  font-size: 15px;
}

.account-followers {
  font-size: 12px;
  color: var(--text-secondary);
}

/* ════════════════════════════════════════════ FORMS */
.form-group {
  margin-bottom: 16px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}

input[type="text"],
input[type="password"],
select,
textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--purple);
}

select { cursor: pointer; }

small {
  display: block;
  margin-top: 5px;
  color: var(--text-muted);
  font-size: 12px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

/* ── Toggle Switch ─────────────────────────── */
.toggle-row {
  display: flex !important;
  align-items: center;
  justify-content: space-between;
  flex-direction: row !important;
  margin-bottom: 0;
  cursor: pointer;
}

.toggle {
  position: relative;
  display: inline-block;
  width: 44px; height: 24px;
  flex-shrink: 0;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: 0.3s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 2px; top: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: 0.3s;
}

.toggle input:checked + .toggle-slider { background: rgba(168,85,247,0.25); border-color: var(--purple); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); background: var(--purple); }

/* ── Buttons Builder ─────────────────────── */
#buttons-builder {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
}

.button-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.button-row input { flex: 1; }

.btn-remove-btn {
  width: 32px; height: 32px;
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: 8px;
  color: var(--red);
  cursor: pointer;
  display: flex;
  align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
  transition: background 0.2s;
}

.btn-remove-btn:hover { background: rgba(239,68,68,0.2); }

/* ════════════════════════════════════════════ BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: var(--purple);
  color: white;
}
.btn-primary:hover { background: #9333ea; transform: translateY(-1px); }

.btn-instagram {
  background: var(--ig-grad);
  color: white;
  padding: 12px 24px;
  border-radius: 12px;
  font-size: 15px;
}
.btn-instagram:hover { opacity: 0.9; transform: translateY(-1px); box-shadow: 0 8px 24px rgba(131,58,180,0.4); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--purple); color: var(--purple); }

.btn-sm { padding: 6px 12px; font-size: 13px; }

.btn-icon {
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center; justify-content: center;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 15px;
}

.btn-icon:hover { border-color: var(--border-hover); color: var(--text-primary); }
.btn-icon.danger:hover { border-color: rgba(239,68,68,0.4); color: var(--red); background: rgba(239,68,68,0.1); }

.copy-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s;
}
.copy-btn:hover { border-color: var(--purple); color: var(--purple); }

.btn-connected {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(34,197,94,0.1);
  border: 1px solid rgba(34,197,94,0.25);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--green);
  cursor: default;
}

.btn-disconnect {
  background: transparent;
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  transition: all 0.2s;
}

.btn-disconnect:hover { background: rgba(239,68,68,0.1); }

/* ════════════════════════════════════════════ MODAL */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideUp 0.3s ease;
}

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

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

.modal-header h2 { font-size: 18px; font-weight: 700; }

.modal-close {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--bg-elevated);
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center; justify-content: center;
  transition: all 0.2s;
}

.modal-close:hover { background: rgba(239,68,68,0.15); color: var(--red); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ════════════════════════════════════════════ EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-icon { font-size: 48px; margin-bottom: 16px; }

.empty-state h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.empty-state p {
  font-size: 14px;
  margin-bottom: 20px;
}

/* ══════════════════════════════════════════ AUTH ALERT */
.auth-alert {
  padding: 14px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 20px;
}

.auth-alert.success {
  background: rgba(34,197,94,0.12);
  border: 1px solid rgba(34,197,94,0.3);
  color: var(--green);
}

.auth-alert.error {
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--red);
}

/* ══════════════════════════════════════════════ TOAST */
.toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 9999;
  transform: translateY(80px);
  opacity: 0;
  transition: all 0.3s ease;
  max-width: 320px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { border-color: rgba(34,197,94,0.4); color: var(--green); }
.toast.error   { border-color: rgba(239,68,68,0.4);  color: var(--red); }

/* ════════════════════════════════════ RESPONSIVE */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; }
  .conversations-wrap { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
