:root {
  --bg: #09090b;
  --panel: #18181b;
  --border: #27272a;
  --muted: #a1a1aa;
  --brand: #10b981;
  --brand-light: rgba(16, 185, 129, 0.15);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100dvh; }
body { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

[hidden] { display: none !important; }

/* Layout shell */
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100dvh; }
@media (max-width: 768px) { .shell { grid-template-columns: 1fr; } }

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 16px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100dvh;
}
@media (max-width: 768px) { .sidebar { display: none; } }

.sidebar.open { display: flex; position: fixed; inset: 0; z-index: 50; }

.main { padding: 24px 28px; max-width: 1200px; width: 100%; }
@media (max-width: 768px) { .main { padding: 16px; } }

.brand-row { display: flex; align-items: center; gap: 8px; margin-bottom: 18px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #10b981, #06b6d4); display: grid; place-items: center; font-weight: 800; }

.ws-card {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 10px; background: #1f1f23;
  cursor: pointer; transition: border .15s ease;
}
.ws-card:hover { border-color: var(--brand); }
.ws-avatar { width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; font-weight: 700; color: #000; }

.nav { margin-top: 16px; display: flex; flex-direction: column; gap: 2px; }
.nav a {
  padding: 8px 10px; border-radius: 8px; color: var(--muted); text-decoration: none;
  display: flex; align-items: center; gap: 10px; font-size: 14px;
}
.nav a:hover { background: #1f1f23; color: #f4f4f5; }
.nav a.active { background: var(--brand-light); color: #34d399; }

/* Cards / lists */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 20px; }
.card-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }

.flow-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; transition: border .15s ease, transform .15s ease;
  cursor: pointer; display: flex; flex-direction: column; gap: 10px;
}
.flow-card:hover { border-color: var(--brand); transform: translateY(-2px); }

.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; padding: 3px 8px; border-radius: 999px; }
.pill-ok { background: #052e1f; color: #34d399; }
.pill-off { background: #27272a; color: #a1a1aa; }
.pill-warn { background: #422006; color: #fbbf24; }

.btn { padding: 9px 14px; border-radius: 10px; font-weight: 500; font-size: 14px; cursor: pointer; transition: opacity .15s ease; border: 0; }
.btn:hover { opacity: 0.9; }
.btn-primary { background: var(--brand); color: #052e1f; }
.btn-ghost { background: transparent; color: #f4f4f5; border: 1px solid var(--border); }
.btn-ghost:hover { border-color: var(--brand); }
.btn-danger { background: #7f1d1d; color: #fca5a5; }

.input, .select, .textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; background: #0c0c0e;
  border: 1px solid var(--border); color: #f4f4f5; font-size: 14px;
}
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); }
.label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }

/* Canvas */
.canvas { position: relative; height: calc(100dvh - 200px); border: 1px solid var(--border); border-radius: 14px; background: radial-gradient(circle at 50% 50%, #1a1a1f 0%, #0a0a0c 100%); overflow: hidden; }

.node {
  position: absolute; min-width: 220px; max-width: 280px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; cursor: move;
  box-shadow: 0 4px 16px rgba(0,0,0,0.5);
  transition: border .15s ease;
}
.node.selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(16,185,129,0.3); }
.node-title { font-weight: 600; font-size: 13px; display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.node-summary { font-size: 12px; color: var(--muted); line-height: 1.5; word-break: break-word; }

.node-handle {
  width: 12px; height: 12px; border-radius: 50%; background: var(--brand);
  border: 2px solid var(--panel); position: absolute; cursor: crosshair;
}
.node-handle.in { left: -6px; top: 50%; transform: translateY(-50%); }
.node-handle.out { right: -6px; top: 50%; transform: translateY(-50%); }

.node[data-type="comment_trigger"] { border-top: 3px solid #f59e0b; }
.node[data-type="dm_reply_trigger"] { border-top: 3px solid #f59e0b; }
.node[data-type="send_dm"] { border-top: 3px solid #06b6d4; }
.node[data-type="comment_reply"] { border-top: 3px solid #8b5cf6; }
.node[data-type="cal_link"] { border-top: 3px solid #10b981; }
.node[data-type="condition"] { border-top: 3px solid #f43f5e; }
.node[data-type="delay"] { border-top: 3px solid #71717a; }
.node[data-type="tag_user"] { border-top: 3px solid #ec4899; }
.node[data-type="notify_admin"] { border-top: 3px solid #ef4444; }

svg.edges-layer { position: absolute; inset: 0; pointer-events: none; width: 100%; height: 100%; }
svg.edges-layer path { stroke: #52525b; stroke-width: 2; fill: none; }
svg.edges-layer path.selected { stroke: var(--brand); }

/* Drawer right */
.drawer {
  position: fixed; top: 0; right: 0; width: 380px; height: 100dvh;
  background: var(--panel); border-left: 1px solid var(--border);
  padding: 18px; overflow-y: auto;
  transform: translateX(100%); transition: transform .2s ease;
  z-index: 40;
}
.drawer.open { transform: translateX(0); }
@media (max-width: 768px) { .drawer { width: 100%; } }

/* Templates grid */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tpl-card { padding: 16px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel); cursor: pointer; transition: border .15s ease; }
.tpl-card:hover { border-color: var(--brand); }
.tpl-emoji { font-size: 28px; margin-bottom: 8px; }
.tpl-name { font-weight: 600; margin-bottom: 4px; }
.tpl-desc { font-size: 12px; color: var(--muted); line-height: 1.4; }

/* Stats */
.stat { padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); }
.stat-num { font-size: 28px; font-weight: 700; color: #f4f4f5; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* Mobile FAB */
.fab { position: fixed; bottom: 24px; right: 24px; width: 56px; height: 56px; border-radius: 50%; background: var(--brand); color: #052e1f; display: grid; place-items: center; font-size: 24px; box-shadow: 0 8px 24px rgba(16,185,129,0.4); z-index: 30; }

/* Animations */
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(12px) } to { opacity: 1; transform: translateY(0) } }
.fade-in { animation: fadeIn .2s ease; }
.slide-up { animation: slideUp .25s ease; }

/* Toasts */
.toast-stack { position: fixed; top: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; pointer-events: none; }
.toast { padding: 12px 16px; background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.4); pointer-events: auto; min-width: 240px; max-width: 360px; animation: slideUp .25s ease; font-size: 14px; }
.toast.error { border-left-color: #ef4444; }
.toast.warn { border-left-color: #f59e0b; }
.toast.success { border-left-color: var(--brand); }
.toast .title { font-weight: 600; }
.toast .body { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Validation */
.input.invalid, .textarea.invalid { border-color: #ef4444; }
.field-error { font-size: 11px; color: #fca5a5; margin-top: 4px; }
.field-help { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* Toggle switch */
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider { position: absolute; cursor: pointer; inset: 0; background: #3f3f46; border-radius: 999px; transition: .2s; }
.toggle .slider:before { content: ""; position: absolute; height: 14px; width: 14px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: .2s; }
.toggle input:checked + .slider { background: var(--brand); }
.toggle input:checked + .slider:before { transform: translateX(16px); }

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

/* Stats with bars */
.bar { height: 4px; background: #27272a; border-radius: 2px; overflow: hidden; margin-top: 8px; }
.bar-fill { height: 100%; background: var(--brand); transition: width .3s ease; }

/* Search */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.search-bar select, .search-bar input { background: var(--panel); border: 1px solid var(--border); color: white; padding: 8px 12px; border-radius: 8px; font-size: 13px; }

/* Skeleton loading */
.skel { background: linear-gradient(90deg, #1a1a1f 0%, #27272a 50%, #1a1a1f 100%); background-size: 200% 100%; animation: skelpulse 1.4s linear infinite; border-radius: 8px; }
@keyframes skelpulse { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* Badge */
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 10px; padding: 2px 6px; border-radius: 4px; background: #27272a; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Mobile bottom nav */
.bottom-nav { display: none; position: fixed; bottom: 0; left: 0; right: 0; background: var(--panel); border-top: 1px solid var(--border); justify-content: space-around; padding: 6px 0 18px; z-index: 30; }
@media (max-width: 768px) {
  .bottom-nav { display: flex; }
  .main { padding-bottom: 80px; }
}
.bottom-nav a { color: var(--muted); padding: 8px 16px; font-size: 11px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-decoration: none; }
.bottom-nav a.active { color: var(--brand); }

/* Code blocks (webhook URL helper) */
.code { background: #0c0c0e; border: 1px solid var(--border); padding: 10px; border-radius: 8px; font-family: ui-monospace, monospace; font-size: 12px; color: #e4e4e7; word-break: break-all; }

/* Overview grid */
.overview-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }

/* Icons */
.icon { width: 16px; height: 16px; flex-shrink: 0; vertical-align: -2px; }
.icon-lg { width: 20px; height: 20px; }
.icon-xl { width: 28px; height: 28px; }
.icon-wa { color: #25d366; }
.icon-ig { color: #e1306c; }
.icon-fb { color: #1877f2; }
.icon-cal { color: #10b981; }

.channel-chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; font-size: 12px; }
.channel-chip.coming { opacity: 0.5; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(4px); z-index: 90; display: grid; place-items: center; padding: 20px; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 24px; max-width: 440px; width: 100%; animation: slideUp .25s ease; box-shadow: 0 24px 64px rgba(0,0,0,0.5); }
.modal h3 { font-size: 18px; font-weight: 600; margin: 0 0 8px; color: #f4f4f5; }
.modal p { color: var(--muted); font-size: 14px; line-height: 1.5; margin: 0 0 16px; }
.modal .actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* Command palette (Cmd+K) */
.cmdk-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.7); backdrop-filter: blur(4px); z-index: 95; display: flex; align-items: flex-start; justify-content: center; padding-top: 80px; }
.cmdk { background: var(--panel); border: 1px solid var(--border); border-radius: 14px; max-width: 560px; width: calc(100% - 40px); overflow: hidden; box-shadow: 0 24px 64px rgba(0,0,0,0.6); }
.cmdk input { width: 100%; padding: 16px 20px; background: transparent; border: 0; border-bottom: 1px solid var(--border); color: white; font-size: 15px; outline: none; }
.cmdk-list { max-height: 400px; overflow-y: auto; padding: 8px; }
.cmdk-item { padding: 10px 14px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.cmdk-item:hover, .cmdk-item.selected { background: #27272a; }
.cmdk-item .kbd { margin-left: auto; font-size: 11px; color: var(--muted); }

/* Kbd */
.kbd { display: inline-flex; align-items: center; padding: 2px 6px; background: #27272a; border: 1px solid #3f3f46; border-radius: 4px; font-family: ui-monospace, monospace; font-size: 10px; color: #d4d4d8; }

/* Hero */
.hero-onboard { padding: 40px 24px; text-align: center; background: linear-gradient(135deg, rgba(16,185,129,.05), rgba(6,182,212,.05)); border: 1px solid var(--border); border-radius: 16px; margin-bottom: 20px; }
.hero-onboard h2 { font-size: 22px; font-weight: 700; color: #f4f4f5; margin: 0 0 8px; }
.hero-onboard p { color: var(--muted); font-size: 14px; margin: 0 0 16px; max-width: 480px; margin-left: auto; margin-right: auto; }

/* Search */
.search-input { width: 100%; padding: 10px 14px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; color: white; font-size: 14px; }
.search-input:focus { outline: none; border-color: var(--brand); }

/* Action button (CTA grande) */
.cta { display: inline-flex; align-items: center; gap: 8px; padding: 12px 18px; background: var(--brand); color: #052e1f; font-weight: 600; border-radius: 12px; border: 0; cursor: pointer; font-size: 14px; transition: transform .12s ease; }
.cta:hover { transform: translateY(-1px); }
.cta-secondary { background: var(--panel); color: white; border: 1px solid var(--border); }
.cta-secondary:hover { border-color: var(--brand); }

/* Topbar polish */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(9,9,11,0.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--border); padding: 14px 28px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
@media (max-width: 768px) { .topbar { padding: 12px 16px; } }

/* Channel hint cards (roadmap multi-canal) */
.channel-roadmap { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin-top: 10px; }
.channel-roadmap .ch { padding: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.channel-roadmap .ch.live { border-color: var(--brand); }
.channel-roadmap .ch .status { margin-left: auto; font-size: 10px; }

/* Toast close */
.toast .close { margin-left: 12px; cursor: pointer; opacity: 0.5; }
.toast .close:hover { opacity: 1; }

/* Online/offline indicator */
.net-status { position: fixed; bottom: 12px; left: 12px; padding: 6px 12px; border-radius: 999px; font-size: 11px; background: var(--panel); border: 1px solid var(--border); color: var(--muted); display: none; z-index: 50; }
.net-status.show { display: flex; align-items: center; gap: 6px; }
.net-status .dot { width: 6px; height: 6px; border-radius: 50%; background: #ef4444; }

/* Sidebar improvements */
.sidebar-mobile-overlay { display: none; }
@media (max-width: 768px) {
  .sidebar-mobile-overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 40; }
  .sidebar { display: none; }
  .sidebar.mobile-open { display: flex !important; position: fixed; inset: 0; z-index: 50; max-width: 280px; }
}

.menu-btn { display: none; padding: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; }
@media (max-width: 768px) { .menu-btn { display: flex; align-items: center; justify-content: center; } }

/* Improved flow card */
.flow-card .meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.flow-card .meta .icon { width: 12px; height: 12px; }

