/* Automatizaciones: flow list, visual flow editor (ManyChat style) and side drawer */

[hidden] { display: none !important; }

.auto-banner {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
    border: 1px solid;
}
.auto-banner.off { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.auto-banner.on { background: var(--success-soft); color: var(--success); border-color: var(--success); }
.auto-banner code { background: rgba(0, 0, 0, 0.06); padding: 1px 5px; border-radius: 4px; }

/* Tabs */
.auto-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}
.auto-tab {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.auto-tab:hover { color: var(--text); }
.auto-tab.active { color: var(--brand-text); border-bottom-color: var(--brand); }

.auto-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}
.auto-muted { font-size: 13px; color: var(--text-muted); margin: 0; }
.auto-empty { text-align: center; padding: 40px; color: var(--text-muted); font-size: 13px; }

/* ---------- Flow list ---------- */
.flow-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 400px), 1fr));
    gap: 16px;
}
.flow-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: left;
    font: inherit;
    color: inherit;
    text-decoration: none;
}
.flow-card *, .flow-card:hover * { text-decoration: none; }
.flow-card:hover { border-color: var(--brand); box-shadow: 0 4px 14px rgba(16, 24, 40, 0.08); }
.flow-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.flow-card-name { font-size: 15px; font-weight: 600; margin: 0; }
.flow-card-template { font-size: 12px; color: var(--text-muted); margin-top: 2px; word-break: break-all; }
.flow-card-steps { display: flex; flex-direction: column; gap: 6px; }
.flow-card { min-width: 0; }
/* button → action on one line; long names are cut with … (full text on hover) */
.flow-card-step { display: grid; grid-template-columns: fit-content(45%) auto minmax(0, 1fr); align-items: center; justify-items: start; gap: 8px; font-size: 12px; }
.flow-card-step .pill { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.flow-card-step .arrow { color: var(--text-subtle); }
.flow-card-foot { font-size: 11px; color: var(--text-subtle); border-top: 1px solid var(--border); padding-top: 10px; }

.pill {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.pill-on { background: var(--success-soft); color: var(--success); }
.pill-off { background: var(--surface-3); color: var(--text-muted); }
.pill-warn { background: var(--warning-soft); color: var(--warning); }
.pill-button { background: var(--info-soft); color: var(--info); }
.pill-action { background: #fff4d6; color: #8a5a00; }
.pill-none { background: var(--surface-2); color: var(--text-subtle); }

/* ---------- Editor bar ---------- */
.editor-bar {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.editor-back {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-decoration: none;
}
.editor-back svg { width: 16px; height: 16px; }
.editor-back:hover { color: var(--brand-text); }
.editor-name {
    font-size: 18px;
    font-weight: 600;
    border: 1px solid transparent !important;
    background: transparent !important;
    padding: 6px 8px;
    border-radius: 6px;
    min-width: 260px;
    color: var(--text);
}
.editor-name:hover, .editor-name:focus { border-color: var(--border) !important; background: var(--surface) !important; outline: none; }
.editor-bar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.editor-dirty { font-size: 12px; color: var(--warning); font-weight: 600; }
.editor-help { font-size: 12px; color: var(--text-muted); margin: 0 0 10px; }

/* Switch */
.auto-switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; }
.auto-switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.auto-switch-track {
    width: 36px;
    height: 20px;
    border-radius: 999px;
    background: var(--border-strong);
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}
.auto-switch-track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}
.auto-switch input:checked + .auto-switch-track { background: var(--brand); }
.auto-switch input:checked + .auto-switch-track::after { transform: translateX(16px); }
.auto-switch-text { color: var(--text-secondary); font-weight: 600; }

/* ---------- Canvas ---------- */
.flow-canvas {
    position: relative;
    background-color: #f7f9fb;
    background-image: radial-gradient(#d5dbe3 1px, transparent 1px);
    background-size: 18px 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px 32px;
    overflow: auto;
    min-height: 420px;
}
.flow-wires {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
    overflow: visible;
    z-index: 0;
}
.flow-wires path { fill: none; stroke-width: 2; }
.flow-row {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-start;
    gap: 90px;
    width: max-content;
}
.flow-lanes { display: flex; flex-direction: column; gap: 36px; }
.flow-lane { display: flex; align-items: flex-start; gap: 90px; }
.flow-msgs { display: flex; flex-direction: column; gap: 20px; }

.flow-canvas-general .flow-row { margin-bottom: 28px; }
.flow-canvas-general .flow-row:last-child { margin-bottom: 0; }

/* Nodes */
.node {
    position: relative;
    width: 290px;
    background: var(--surface);
    border: 1.5px solid #d9dee5;
    border-radius: 10px;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.06);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.node:hover { border-color: var(--brand); }
.node.selected { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.node.dimmed { opacity: 0.55; }
.node-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 13px;
    font-weight: 600;
    background: #e9edf2;
    border-radius: 9px 9px 0 0;
    border-bottom: 1px solid #d9dee5;
}
.node-head .tag { margin-left: auto; }
.node-head-action { background: #fff4d6; border-bottom-color: #f5d27a; }
.node-action { border-color: #f5d27a; }
.node-head-trigger { background: #e3f2fd; border-bottom-color: #b6d8f5; }
.node-body { padding: 14px; }
.node-foot { padding: 0 14px 12px; font-size: 11px; color: var(--text-muted); }
.node-start-tag {
    position: absolute;
    top: -30px;
    left: 50%;
    transform: translateX(-50%);
    background: #22c55e;
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    padding: 5px 16px;
    border-radius: 6px 6px 0 0;
    white-space: nowrap;
}
.node-template { width: 330px; }
.node-empty .node-body { color: var(--text-muted); font-size: 13px; text-align: center; padding: 22px 14px; }
.node-add { color: var(--brand-text); font-weight: 600; }

/* Action content */
.action-main { display: flex; gap: 10px; align-items: flex-start; }
.action-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: #fff4d6;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 15px;
}
.action-label { font-size: 13px; font-weight: 600; }
.action-desc { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.action-warn { font-size: 11px; color: var(--warning); margin-top: 6px; }

/* Outputs with connection ports */
.node-outs { border-top: 1px solid var(--border); }
.node-out {
    position: relative;
    padding: 9px 14px;
    font-size: 12px;
    color: var(--text-secondary);
    text-align: right;
    border-bottom: 1px solid var(--border);
}
.node-out:last-child { border-bottom: none; border-radius: 0 0 9px 9px; }
.node-out .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.port {
    position: absolute;
    right: -7px;
    top: 50%;
    width: 12px;
    height: 12px;
    margin-top: -6px;
    border-radius: 50%;
    background: #8a94a3;
    border: 2px solid #fff;
    box-shadow: 0 0 0 1px #c5ccd6;
}
.port-ok { background: #22c55e; }
.port-repeat { background: #3b82f6; }
.port-error { background: #ef4444; }
.port-in {
    position: absolute;
    left: -7px;
    top: 20px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid #8a94a3;
}

/* WhatsApp bubble */
.wa-bubble {
    background: #f0f2f5;
    border-radius: 10px;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.45;
    color: #111b21;
    word-wrap: break-word;
}
.wa-bubble.wa-empty { color: var(--text-subtle); font-style: italic; background: var(--surface-2); text-align: center; }
.wa-header { font-weight: 700; margin-bottom: 6px; }
.wa-media {
    background: #dfe3e8;
    border-radius: 6px;
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 12px;
    margin-bottom: 8px;
}
.wa-footer { color: #667781; font-size: 12px; margin-top: 6px; }
.wa-var {
    display: inline-block;
    background: #1d9bf0;
    color: #fff;
    border-radius: 4px;
    padding: 0 6px;
    font-size: 12px;
    font-weight: 600;
    line-height: 18px;
}
.wa-buttons {
    margin-top: 6px;
    border: 1px solid #e3e6ea;
    border-radius: 10px;
    background: #fff;
}
.wa-button {
    position: relative;
    padding: 10px 12px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #0a84ff;
    border-bottom: 1px solid #e3e6ea;
}
.wa-button:last-child { border-bottom: none; }
.wa-button-static { color: var(--text-muted); font-weight: 500; }
.wa-button-static small { display: block; font-size: 11px; font-weight: 400; color: var(--text-subtle); }

/* ---------- Drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.15); z-index: 900; }
.drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 100vw;
    height: 100vh;
    background: var(--surface);
    z-index: 901;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
}
.drawer.open {
    transform: translateX(0);
    visibility: visible;
    box-shadow: -8px 0 24px rgba(16, 24, 40, 0.12);
    transition: transform 0.2s ease;
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.drawer-title { font-size: 16px; font-weight: 600; margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
.drawer-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }
.drawer-foot:empty { display: none; }
.drawer-section-title { font-size: 12px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; margin: 18px 0 8px; }
.drawer-note { font-size: 12px; color: var(--text-muted); background: var(--surface-2); border-radius: 8px; padding: 10px 12px; line-height: 1.5; }

/* Action choices */
.action-choices { display: flex; flex-direction: column; gap: 8px; }
.action-choice {
    display: flex;
    gap: 10px;
    padding: 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    text-align: left;
    background: var(--surface);
    font: inherit;
    color: inherit;
}
.action-choice:hover { border-color: var(--brand-border); }
.action-choice.selected { border-color: var(--brand); background: var(--brand-softer); }
.action-choice.disabled-choice { opacity: 0.5; }

/* Forms */
.auto-field { margin-bottom: 14px; }
.auto-field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.auto-field select,
.auto-field input[type="text"],
.auto-field input[type="number"] {
    width: 100%;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
    box-sizing: border-box;
}
.auto-field input[type="number"] { width: 100px; }
.auto-field textarea {
    width: 100%;
    min-height: 140px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    line-height: 1.45;
    resize: vertical;
    box-sizing: border-box;
}
.auto-hint { font-size: 12px; color: var(--text-muted); margin-top: 6px; }
.msg-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    padding: 6px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: #f8fafc;
}
.tb-button {
    min-width: 30px;
    height: 28px;
    padding: 0 8px;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #334155;
    font-size: 14px;
    cursor: pointer;
}
.tb-button:hover { background: #fff; border-color: var(--border); }
.tb-var { color: #1d9bf0; font-size: 12px; }
.tb-var:hover { background: #e8f4fe; border-color: #bfdcf7; }
.tb-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
textarea.has-toolbar { border-top-left-radius: 0; border-top-right-radius: 0; }

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

@media (max-width: 700px) {
    .flow-canvas { padding: 32px 16px; }
    .editor-name { min-width: 0; width: 100%; }
}

/* Scheduled sends */
.auto-banner.hide-on-tab { display: none; }
.auto-field input[type="time"] {
    width: 120px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}
.sched-last { font-size: 11px; color: var(--text-muted); margin-top: 8px; }
.sched-failed { color: #dc2626; font-weight: 600; }
.sched-preview { margin-bottom: 4px; }
.drawer-foot-spacer { flex: 1; }
#schedLoad { margin-top: 8px; }
.sched-summary { font-size: 12px; color: var(--text-secondary); margin: 12px 0 8px; }
.sched-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--border); border-radius: 8px; max-height: 320px; overflow: auto; }
.sched-list li { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--border); font-size: 12px; }
.sched-list li:last-child { border-bottom: none; }
.sched-list li.skipped { color: var(--text-subtle); }
.sched-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sched-meta { color: var(--text-muted); white-space: nowrap; }
.drawer-foot .btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Ejecuciones (webhook history) ---------- */
/* Summary tiles (last 7 days), one bordered row like n8n */
.exec-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    margin-bottom: 16px;
    overflow: hidden;
}
.exec-stat { padding: 16px 20px; border-left: 1px solid var(--border); min-width: 0; display: flex; flex-direction: column; }
.exec-stat:first-child { border-left: none; }
.exec-stat-label { font-size: 14px; font-weight: 600; color: var(--text); }
.exec-stat-period { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.exec-stat-value { font-size: 26px; font-weight: 600; color: var(--text); margin-top: 10px; font-variant-numeric: tabular-nums; display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.exec-stat-value.is-empty { color: var(--text-subtle); }
/* Text values ("hace 15 min") are smaller than numbers, aligned to the bottom with them */
.exec-stat-value.is-text { font-size: 16px; margin-top: auto; padding-top: 10px; min-height: 39px; }
.exec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }
.exec-dot.recent { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.exec-dot.old { background: var(--warning); }
@media (max-width: 900px) {
    .exec-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .exec-stat:nth-child(3) { border-left: none; }
    .exec-stat:nth-child(n+3) { border-top: 1px solid var(--border); }
}
.exec-toolbar { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 8px; flex-wrap: wrap; }
.exec-toolbar select, .exec-toolbar input { height: 38px; }
/* Room for the longest option ("Sin coincidencia") and the arrow */
.exec-toolbar select { min-width: 190px; }
.exec-search { flex: 1; min-width: 200px; max-width: 360px; }
.exec-search input { width: 100%; }
.exec-help { margin: 0 0 12px; }
.exec-table-wrapper { border: 1px solid var(--border); border-radius: 10px; overflow: auto; background: var(--surface); }
.exec-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.exec-table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-muted); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.exec-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.exec-table tbody tr { cursor: pointer; }
.exec-table tbody tr:hover { background: var(--surface-2); }
.exec-table tbody tr:last-child td { border-bottom: none; }
.exec-time { white-space: nowrap; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.exec-detail { color: var(--text-muted); }
.exec-detail strong { color: var(--text); font-weight: 600; }
.exec-error { color: var(--danger); margin-top: 2px; }
.pill-error { background: var(--danger-soft); color: var(--danger); }
.pill-running { background: var(--info-soft); color: var(--info); }
.exec-pagination { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: var(--text-muted); }
.exec-pagination:empty { display: none; }
.exec-fields { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 13px; }
.exec-fields dt { color: var(--text-muted); }
.exec-fields dd { margin: 0; word-break: break-word; }
.exec-json { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 10px; font-size: 11px; line-height: 1.45; max-height: 50vh; overflow: auto; white-space: pre-wrap; word-break: break-all; }

