:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6eb;
  --text: #1c2230;
  --muted: #6b7385;
  --primary: #e8452c;
  --primary-hover: #d13a22;
  --primary-soft: #fde9e5;
  --tg: #2aabee;
  --ok: #18a058;
  --ok-soft: #e3f5ec;
  --warn: #c98a00;
  --warn-soft: #fbf1d9;
  --err: #d03050;
  --err-soft: #fbe5ea;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  --bubble: #effdde;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --surface: #1a1e27; --surface-2: #232834; --border: #2c3240;
    --text: #e6e9ef; --muted: #8f97a8; --primary-soft: #3a1f1a; --ok-soft: #173326;
    --warn-soft: #3a2f12; --err-soft: #3b1b24; --bubble: #2b5278; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12151c; --surface: #1a1e27; --surface-2: #232834; --border: #2c3240;
  --text: #e6e9ef; --muted: #8f97a8; --primary-soft: #3a1f1a; --ok-soft: #173326;
  --warn-soft: #3a2f12; --err-soft: #3b1b24; --bubble: #2b5278; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 15px; }
.brand .logo { width: 32px; height: 32px; border-radius: 8px; background: linear-gradient(135deg, var(--primary), #ff8a3d); display: grid; place-items: center; color: #fff; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav .ico { width: 20px; text-align: center; }
.sidebar .spacer { flex: 1; }
.sidebar-foot { display: flex; gap: 6px; padding: 0 4px; }

.main { padding: 28px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }

.topbar { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 30; left: 0; top: 0; width: 250px; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .topbar { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
  .main { padding: 20px 16px 60px; }
}

/* ---------- Componentes ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 20px; border-bottom: 1px solid var(--border); gap: 10px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3-1 { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-3-1 { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .grid-4, .grid-2 { grid-template-columns: 1fr; } }

.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .sub { font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-tg { background: var(--tg); border-color: var(--tg); color: #fff; }
.btn-tg:hover { filter: brightness(.95); background: var(--tg); }
.btn-danger { color: var(--err); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-block { width: 100%; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-err { background: var(--err-soft); color: var(--err); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

label.field { display: flex; flex-direction: column; gap: 5px; font-weight: 500; font-size: 13px; }
label.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 500; }
.check input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.stack { display: flex; flex-direction: column; gap: 16px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--surface-2); flex: none; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.num { font-variant-numeric: tabular-nums; }

.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- Gráfico ---------- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 10px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars .fill { width: 100%; max-width: 34px; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; position: relative; }
.bars .fill:hover::after { content: attr(data-v); position: absolute; top: -22px; left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 600; color: var(--text); }
.bars .lbl { font-size: 11px; color: var(--muted); }
.hbar { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; margin-bottom: 10px; }
.hbar .track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.hbar .track span { display: block; height: 100%; background: var(--primary); }

/* ---------- Produtos ---------- */
.products { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; }
.product { display: flex; flex-direction: column; overflow: hidden; }
.product .img { position: relative; aspect-ratio: 1; background: var(--surface-2); }
.product .img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product .img .badge { position: absolute; top: 8px; left: 8px; }
.product .img .posted { position: absolute; top: 8px; right: 8px; }
.product .body { padding: 12px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.product .title { font-size: 13px; }
.product .price { font-size: 18px; font-weight: 700; color: var(--primary); }
.product .old { text-decoration: line-through; color: var(--muted); font-size: 12px; margin-left: 6px; font-weight: 400; }
.product .meta { font-size: 12px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.product .actions { display: flex; gap: 6px; margin-top: auto; padding-top: 6px; }
.product .actions .btn { flex: 1; }

.search-bar { display: grid; grid-template-columns: minmax(0, 2fr) repeat(3, minmax(0, 1fr)) auto; gap: 10px; align-items: end; }
@media (max-width: 1000px) { .search-bar { grid-template-columns: 1fr 1fr; } }

/* ---------- Telegram preview ---------- */
.tg-chat { background: linear-gradient(135deg, #8ab087, #c4d39a); border-radius: var(--radius); padding: 18px; }
:root[data-theme="dark"] .tg-chat { background: #0e1621; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tg-chat { background: #0e1621; } }
.tg-bubble { background: var(--bubble); color: var(--text); border-radius: 12px; max-width: 360px; overflow: hidden; box-shadow: 0 1px 1px rgba(0,0,0,.15); }
.tg-bubble img { width: 100%; display: block; max-height: 360px; object-fit: cover; }
.tg-bubble .cap { padding: 8px 12px 10px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.tg-bubble .cap a { color: #168acd; }
.tg-btn { max-width: 360px; margin-top: 4px; background: rgba(0,0,0,.25); color: #fff; text-align: center; padding: 8px; border-radius: 8px; font-weight: 500; font-size: 14px; }

/* ---------- Log ---------- */
.log {
  background: #0f131a; color: #d6dbe4; font: 12.5px/1.6 ui-monospace, Consolas, monospace;
  padding: 14px 16px; border-radius: 8px; min-height: 220px; max-height: 480px; overflow: auto; white-space: pre-wrap; margin: 0;
}
.log .l-ok { color: #63e6a0; }
.log .l-err { color: #ff7b8f; }
.log .l-dim { color: #7c8597; }

/* ---------- Modal / Toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 14, 20, .5); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { width: min(720px, 100%); max-height: calc(100vh - 32px); overflow: auto; }
.modal .card-head { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--border); }

#toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; animation: pop .18s ease-out; }
.toast.err { background: var(--err); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); padding: 28px; }
.login .brand { padding: 0 0 18px; justify-content: center; font-size: 17px; }

.spinner { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.switch { position: relative; width: 36px; height: 20px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 20px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 14px; height: 14px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(16px); }
code.inline { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; }
.copy-box { display: flex; gap: 8px; }
.copy-box input { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px 16px; }

/* ---------- Plano de ação ---------- */
.progress { height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--ok); border-radius: 4px; transition: width .3s; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { font: inherit; font-weight: 500; padding: 7px 14px; border-radius: 99px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; }
.tab.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.task { border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: 0; }
.task-row { display: flex; align-items: center; gap: 10px; padding: 10px 14px 10px 20px; }
.task-check { width: 18px; height: 18px; flex: none; accent-color: var(--ok); cursor: pointer; }
.task-title { flex: 1; text-align: left; background: none; border: 0; padding: 0; font: inherit; font-weight: 500; color: var(--text); cursor: pointer; }
.task.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-body { padding: 0 20px 16px 48px; }
.guide { color: var(--text); font-size: 13.5px; }
.guide p { margin: 0 0 8px; }
.guide ul, .guide ol { margin: 0 0 8px; padding-left: 20px; }
.guide li { margin-bottom: 4px; }
.guide code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; }
@media (max-width: 640px) { .task-row { flex-wrap: wrap; padding-left: 14px; } .task-body { padding-left: 14px; } }

/* ---------- Canais ---------- */
.channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
@media (max-width: 640px) { .channels { grid-template-columns: 1fr; } }
.channel { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.channel-head { display: flex; gap: 12px; align-items: center; }
.channel-logo { width: 52px; height: 52px; border-radius: 50%; flex: none; object-fit: cover; }
.channel-actions { margin-top: auto; padding-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); }
.wizard-step { display: flex; gap: 14px; }
.wizard-step .num { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; }
.detected-chat { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; flex-wrap: nowrap; }

/* ---------- Ideias (kanban) ---------- */
.kanban { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; align-items: start; }
@media (max-width: 1200px) { .kanban { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 640px) { .kanban { grid-template-columns: 1fr; } }
.kanban-col { background: var(--surface-2); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.kanban-head { display: flex; justify-content: space-between; align-items: center; padding: 2px 4px; }
.idea { padding: 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.idea-body { white-space: pre-wrap; color: var(--text); max-height: 160px; overflow: auto; }

/* Cards clicáveis (atalhos do painel) */
a.card { color: inherit; text-decoration: none; display: block; }
a.card:hover { border-color: var(--primary, #e8452c); }
