/* DM.I.A — painel (estilo ManyChat: sidebar escura, cards brancos, badges) */

:root {
  --sidebar-bg: #1d2433;
  --sidebar-text: #aeb7c7;
  --sidebar-active: #2a3347;
  --bg: #f2f4f8;
  --card: #ffffff;
  --border: #e3e7ee;
  --text: #1f2733;
  --muted: #7a8699;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --gray-bg: #e5e7eb;
  --gray-text: #4b5563;
  --yellow-bg: #fef3c7;
  --yellow-text: #92400e;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--primary); text-decoration: none; }
code { background: var(--gray-bg); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--sidebar-bg); color: var(--sidebar-text);
  display: flex; flex-direction: column;
  padding: 20px 12px;
  position: sticky; top: 0; height: 100vh;
}
.logo { font-size: 22px; font-weight: 800; color: #fff; padding: 0 10px 22px; letter-spacing: .5px; }
.logo span { color: #60a5fa; }
.logo-dark { color: var(--text); }
.logo-dark span { color: var(--primary); }
.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  color: var(--sidebar-text); padding: 10px 12px; border-radius: 8px;
  font-weight: 500;
}
.nav-item:hover { background: var(--sidebar-active); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-icon { width: 20px; text-align: center; }
.sidebar-footer { border-top: 1px solid #2c3547; padding-top: 10px; }

.content { flex: 1; padding: 28px 36px; max-width: 1200px; }

/* Cabeçalho de página */
.page-header {
  display: flex; justify-content: space-between; align-items: flex-start;
  margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.page-header h1 { margin: 4px 0; font-size: 24px; display: flex; align-items: center; gap: 10px; }
.page-header p { margin: 4px 0 0; }
.back-link { font-size: 13px; color: var(--muted); }
.back-link:hover { color: var(--primary); }
.header-actions { display: flex; gap: 10px; }

/* Cards */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px;
}
.table-card { padding: 0; overflow: visible; }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 8px;
  padding: 9px 16px; font-size: 14px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { filter: brightness(.95); }
.btn-outline { background: #fff; border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-block { width: 100%; }

/* Inputs */
.input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; color: var(--text);
  background: #fff;
}
.input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .15); }
textarea.input { resize: vertical; }
.input-num { width: 90px; }
.field { margin-top: 12px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.field-inline { display: flex; align-items: center; gap: 8px; }
.field-inline label { margin: 0; }

/* Toolbar da lista */
.toolbar { display: flex; gap: 12px; margin-bottom: 16px; padding: 12px; }
.search-input { max-width: 340px; }
.select-input { max-width: 200px; }

/* Tabela */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: #f8fafc; }
.num { text-align: right; }
.muted { color: var(--muted); }
.row-name { font-weight: 600; color: var(--text); }
.row-name:hover { color: var(--primary); }
.empty-state { text-align: center; padding: 40px !important; color: var(--muted); }
.actions-cell { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }

/* Badges */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
}
.badge-live { background: var(--green-bg); color: var(--green); }
.badge-stopped { background: var(--gray-bg); color: var(--gray-text); }
.badge-draft { background: var(--yellow-bg); color: var(--yellow-text); }
.badge-popular { background: #ede9fe; color: #6d28d9; }

/* Menu de três pontinhos */
.menu { position: relative; }
.menu summary {
  list-style: none; cursor: pointer; padding: 4px 10px; border-radius: 6px;
  font-size: 18px; line-height: 1; color: var(--muted); user-select: none;
}
.menu summary::-webkit-details-marker { display: none; }
.menu summary:hover { background: var(--gray-bg); }
.menu[open] summary { background: var(--gray-bg); }
.menu-items {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
  min-width: 160px; padding: 6px; display: flex; flex-direction: column;
}
.menu-items button {
  background: none; border: none; text-align: left; cursor: pointer;
  padding: 8px 10px; border-radius: 6px; font-size: 13.5px; color: var(--text);
  font-family: inherit;
}
.menu-items button:hover { background: var(--bg); }
.menu-items button.danger { color: var(--danger); }

/* Renomear inline */
.rename-form { display: flex; gap: 8px; align-items: center; }
.rename-form .input { max-width: 340px; }

/* Login */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: var(--sidebar-bg);
}
.login-card {
  background: #fff; border-radius: 14px; padding: 36px;
  width: 360px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.login-sub { color: var(--muted); margin: 4px 0 20px; }
.login-card label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-error { background: #fee2e2; color: var(--danger); }

/* Galeria de modelos */
.gallery-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px;
}
.gallery-card { margin: 0; }
.gallery-btn {
  width: 100%; height: 100%; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); font-family: inherit; color: var(--text);
  display: flex; flex-direction: column; gap: 6px; position: relative;
}
.gallery-btn:hover { border-color: var(--primary); box-shadow: 0 4px 16px rgba(37, 99, 235, .15); }
.gallery-btn .badge-popular { position: absolute; top: 12px; right: 12px; }
.gallery-icon { font-size: 26px; }
.gallery-title { font-weight: 700; font-size: 15px; }
.gallery-desc { color: var(--muted); font-size: 13px; line-height: 1.4; }
.gallery-trigger { margin-top: auto; font-size: 12px; color: var(--primary); font-weight: 600; }
.scratch-card .gallery-btn { border-style: dashed; border-color: #b6c2d4; background: #fbfcfe; }

/* Wizard */
.wizard-progress { margin-bottom: 18px; }
.wizard-step-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.progress-bar { height: 6px; background: var(--gray-bg); border-radius: 999px; margin: 8px 0; overflow: hidden; }
.progress-fill { height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.wizard-step-title { font-size: 17px; font-weight: 700; margin-top: 8px; }
.wizard-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 22px; align-items: start; }
.wizard-form { padding: 20px; }
.option-card {
  display: flex; gap: 12px; align-items: flex-start;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; cursor: pointer;
}
.option-card:hover { border-color: var(--primary); }
.option-card.selected { border-color: var(--primary); background: #eff6ff; }
.option-card input[type=radio] { margin-top: 3px; }
.option-card p { margin: 4px 0 8px; font-size: 13px; }
.option-card .input { margin-top: 4px; }
.toggle-row { display: flex; align-items: center; gap: 10px; margin: 14px 0; cursor: pointer; font-weight: 500; }
.wizard-actions { display: flex; justify-content: space-between; margin-top: 20px; gap: 10px; }
.replies-box { padding: 0 14px 14px 40px; display: flex; flex-direction: column; gap: 8px; margin-top: -6px; margin-bottom: 12px; }
.replies-box .btn { align-self: flex-start; }
.replies-box.is-muted { opacity: .45; }

/* Preview de celular */
.phone-wrap { position: sticky; top: 24px; }
.phone {
  width: 280px; background: #000; border-radius: 34px; padding: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .25); margin: 0 auto;
}
.phone-notch { width: 110px; height: 20px; background: #000; border-radius: 0 0 14px 14px; margin: 0 auto; position: relative; z-index: 2; }
.phone-screen {
  background: #fff; border-radius: 26px; min-height: 460px;
  margin-top: -20px; padding: 34px 12px 16px; overflow: hidden;
}
.phone-tab-label { text-align: center; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 12px; }
.ig-comment { display: flex; gap: 8px; margin-bottom: 10px; }
.ig-reply { margin-left: 22px; }
.ig-avatar {
  width: 30px; height: 30px; border-radius: 50%; background: var(--gray-bg);
  display: flex; align-items: center; justify-content: center; font-size: 15px; flex-shrink: 0;
}
.ig-avatar.me { background: #dbeafe; }
.ig-bubble { background: #f3f4f6; border-radius: 12px; padding: 7px 10px; font-size: 12.5px; max-width: 190px; }
.ig-bubble.me { background: #eff6ff; }
.ig-user { font-weight: 700; font-size: 11px; margin-bottom: 2px; }
.ig-text { line-height: 1.35; word-wrap: break-word; }
.dm-divider {
  text-align: center; font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .6px; margin: 14px 0 10px;
  border-top: 1px dashed var(--border); padding-top: 10px;
}
.dm-bubble {
  background: #efefef; border-radius: 16px 16px 16px 4px; padding: 10px 12px;
  font-size: 12.5px; max-width: 210px;
}
.dm-btn {
  display: block; text-align: center; background: #fff; border: 1px solid #d1d5db;
  border-radius: 8px; padding: 7px; margin-top: 8px; font-weight: 700; font-size: 12px;
  color: var(--primary);
}
.dm-btn-sm { display: inline-block; padding: 4px 10px; margin: 4px 6px 0 0; font-size: 11.5px; }
.phone-hint { text-align: center; font-size: 12px; margin-top: 10px; }

/* Grade de miniaturas (Etapa 1) */
.option-body { flex: 1; min-width: 0; }
.field-label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 5px; }
.media-grid-wrap {
  max-height: 340px; overflow-y: auto; margin-top: 10px;
  border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  background: #fbfcfe;
}
.media-grid {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.media-card {
  position: relative; aspect-ratio: 1 / 1; overflow: hidden;
  border: 2px solid transparent; border-radius: 8px; padding: 0;
  background: var(--gray-bg); cursor: pointer; font-family: inherit;
  display: block; width: 100%;
}
.media-card img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  transition: transform .15s;
}
.media-card:hover { border-color: #93c5fd; }
.media-card:hover img { transform: scale(1.04); }
.media-card.selected { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .25); }
.media-noimg {
  display: flex; align-items: center; justify-content: center;
  width: 100%; height: 100%; font-size: 28px; color: var(--muted);
}
.media-badge {
  position: absolute; top: 6px; left: 6px;
  background: rgba(0, 0, 0, .65); color: #fff;
  font-size: 10px; font-weight: 700; letter-spacing: .3px;
  padding: 2px 7px; border-radius: 999px;
}
.media-check {
  position: absolute; top: 6px; right: 6px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 12px; font-weight: 800;
  display: none; align-items: center; justify-content: center;
}
.media-card.selected .media-check { display: flex; }
.media-caption {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: linear-gradient(transparent, rgba(0, 0, 0, .78));
  color: #fff; font-size: 10.5px; line-height: 1.3; text-align: left;
  padding: 14px 7px 6px; pointer-events: none;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.media-more { grid-column: 1 / -1; margin-top: 4px; }
.media-msg {
  grid-column: 1 / -1; text-align: center; color: var(--muted);
  padding: 18px 10px; font-size: 13px;
}
.media-msg a { display: block; margin-top: 6px; font-weight: 600; }
.media-msg-error { color: var(--danger); }

/* Sequência de DM */
.sequence-form { max-width: 720px; }
.seq-label {
  font-size: 12px; font-weight: 800; color: var(--muted);
  text-transform: uppercase; letter-spacing: .8px; margin: 20px 0 10px;
}
.seq-card { margin-bottom: 14px; }
.seq-head { display: flex; gap: 12px; align-items: flex-start; }
.seq-head p { margin: 3px 0 0; font-size: 12.5px; }
.seq-body { margin-top: 12px; padding-left: 56px; }
.seq-required .seq-head .badge { margin-top: 2px; }
.char-counter { text-align: right; font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.link-btn-row { display: flex; gap: 8px; margin-bottom: 8px; }
.link-btn-row input[name=link_btn_title] { max-width: 200px; }
#link-buttons { margin-top: 10px; }

/* Switch/toggle */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; cursor: pointer; background: #cbd5e1;
  border-radius: 999px; transition: .2s;
}
.slider:before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider:before { transform: translateX(20px); }

/* Visualizador */
.viewer-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 22px; align-items: start; }
.metrics-col { display: flex; flex-direction: column; gap: 12px; position: sticky; top: 24px; }
.metric-card { text-align: center; padding: 16px; }
.metric-value { font-size: 26px; font-weight: 800; }
.metric-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-top: 2px; }
.metric-sub { font-size: 12px; color: var(--green); font-weight: 700; margin-top: 4px; }
.flow-col { display: flex; flex-direction: column; align-items: stretch; max-width: 520px; }
.flow-node { padding: 16px; }
.flow-kind { font-size: 11px; font-weight: 800; color: var(--primary); letter-spacing: .6px; margin-bottom: 6px; }
.flow-link { border-color: var(--primary); }
.flow-text { white-space: pre-wrap; margin-top: 6px; font-size: 13.5px; line-height: 1.45; }
.flow-buttons { margin-top: 8px; }
.flow-connector {
  width: 2px; height: 26px; background: #c3cad6; margin: 0 auto; position: relative;
}
.flow-connector:after {
  content: "▼"; position: absolute; bottom: -7px; left: 50%; transform: translateX(-50%);
  color: #c3cad6; font-size: 10px;
}
.tag {
  display: inline-block; background: #eff6ff; color: var(--primary);
  border-radius: 6px; padding: 1px 8px; font-size: 12px; font-weight: 600; margin: 2px 3px 0 0;
}
.tag-neg { background: #fee2e2; color: var(--danger); }
.empty-node { text-align: center; padding: 26px; }
.empty-node .btn { margin-top: 8px; }

/* Configurações */
.settings-card { margin-bottom: 16px; max-width: 640px; }
.settings-card h2 { margin: 0 0 12px; font-size: 17px; }
.ig-profile { display: flex; gap: 14px; align-items: center; margin-bottom: 14px; }
.ig-pic { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; }
.ig-pic-placeholder { display: flex; align-items: center; justify-content: center; background: var(--gray-bg); font-size: 22px; }
.ig-username { font-weight: 700; font-size: 15px; }
.setup-steps { color: var(--text); line-height: 1.7; margin: 12px 0 18px; padding-left: 20px; }

/* Responsivo */
@media (max-width: 960px) {
  .wizard-layout, .viewer-layout { grid-template-columns: 1fr; }
  .phone-wrap, .metrics-col { position: static; }
  .metrics-col { flex-direction: row; flex-wrap: wrap; }
  .metric-card { flex: 1 1 40%; }
  .content { padding: 18px; }
  .sidebar { width: 64px; padding: 16px 8px; }
  .sidebar .logo { font-size: 14px; padding: 0 4px 16px; }
  .nav-item span:not(.nav-icon) { display: none; }
}
