/* Auto Reply Sequence Page Styles */

.autoreply-container {
    max-width: 860px;
    margin: 0 auto;
    padding: 40px 24px;
    min-height: 100vh;
    background: var(--bg-primary);
}

/* Embedded variant inside the dashboard SPA (no full-page padding/background) */
.autoreply-container.autoreply-embedded {
    max-width: none;
    padding: 0;
    min-height: auto;
    background: transparent;
}

.autoreply-header {
    margin-bottom: 32px;
}

.autoreply-header-top {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.autoreply-header h1 {
    font-size: 30px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.autoreply-back {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    text-decoration: none;
    transition: all 0.15s ease;
}

.autoreply-back:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.autoreply-header > p {
    font-size: 16px;
    color: var(--text-secondary);
    margin: 0;
}

/* Cards */
.autoreply-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 28px;
    margin-bottom: 24px;
}

.autoreply-card h2 {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0 0 12px 0;
}

.hint {
    font-size: 13px;
    color: var(--text-tertiary);
    margin: 8px 0 0 0;
}

.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

/* Session selector */
.session-row {
    display: flex;
    gap: 10px;
    align-items: center;
}

.autoreply-session-dropdown {
    width: 100%;
}

.autoreply-session-dropdown .dropdown-menu {
    z-index: 60;
    max-height: 260px;
    overflow-y: auto;
}

.dropdown-item-disabled {
    color: var(--text-tertiary);
    cursor: default;
}

.dropdown-item-disabled:hover {
    background: transparent;
    color: var(--text-tertiary);
}

/* Toggle */
.toggle-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.toggle-row h2 {
    margin-bottom: 4px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    flex-shrink: 0;
    margin-top: 4px;
}

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

.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 28px;
    transition: 0.2s;
}

.switch .slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    top: 3px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: 0.2s;
}

.switch input:checked + .slider {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.switch input:checked + .slider:before {
    transform: translateX(24px);
    background: #ffffff;
}

/* Flow editor: header with the Active switch, and grouped settings */
.flow-editor-header {
    align-items: center;
}

.flow-editor-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.active-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
}

.active-toggle-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.settings-group {
    margin-top: 22px;
    padding-top: 22px;
    border-top: 1px solid var(--border-color);
}

.settings-group-label {
    margin: 0 0 14px 0;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--text-tertiary);
}

/* Cooldown */
.cooldown-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 4px;
    font-size: 14px;
    color: var(--text-primary);
}

.cooldown-input {
    width: 80px;
    padding: 8px 10px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text-primary);
    text-align: center;
}

/* Steps */
.steps-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px 16px;
    color: var(--text-tertiary);
    font-size: 14px;
    text-align: center;
}

.steps-empty .empty-icon {
    width: 32px;
    height: 32px;
}

.step-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    background: var(--bg-secondary);
}

.step-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.step-number {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: var(--on-accent);
    font-weight: 700;
    font-size: 14px;
}

.step-controls {
    display: flex;
    gap: 6px;
}

.step-body {
    display: grid;
    gap: 14px;
}

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

.step-type {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text-primary);
}

.step-type-dropdown {
    width: 100%;
}

.step-type-dropdown .dropdown-menu {
    z-index: 60;
}

.step-text {
    width: 100%;
    min-height: 90px;
    max-height: 340px;
    padding: 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text-primary);
    resize: none;
    overflow-y: hidden;
}

.char-count {
    text-align: right;
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 4px;
}

.delay-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: var(--text-secondary);
}

.step-delay {
    width: 90px;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 14px;
    background: var(--input-bg);
    color: var(--text-primary);
    text-align: center;
}

/* Media upload */
.upload-status {
    display: block;
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-tertiary);
}

/* Square "+" tile appended to the media grid (replaces the old upload box) */
.media-add-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 96px;
    height: 96px;
    flex: 0 0 auto;
    border: 1px dashed var(--border-color);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 0;
    transition: all 0.15s ease;
}

.media-add-tile:hover:not(:disabled) {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--bg-tertiary);
}

.media-add-tile:disabled {
    opacity: 0.6;
    cursor: default;
}

.media-add-tile svg {
    width: 26px;
    height: 26px;
}

.spin {
    animation: autoreply-spin 0.9s linear infinite;
}

@keyframes autoreply-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.media-fallback {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 20px;
    color: var(--text-secondary);
    font-size: 14px;
}

.media-count {
    color: var(--text-tertiary);
    font-weight: 500;
    font-size: 12px;
}

.media-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.media-item {
    position: relative;
    display: inline-flex;
    width: 96px;
    height: 96px;
    flex: 0 0 auto;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    background: var(--bg-tertiary);
    /* Draggable tile: no text selection, and no iOS callout sheet on long-press */
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

.media-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    /* Suppress the browser's native image drag so the pointer drag owns the gesture */
    -webkit-user-drag: none;
}

/* The tile being dragged stays in the grid as the empty slot the copy drops into */
.media-item.dragging {
    border: 1px dashed var(--accent-primary);
    background: var(--bg-secondary);
    cursor: grabbing;
}

.media-item.dragging > * {
    visibility: hidden;
}

/* The copy the pointer carries: pinned to the viewport, free to leave the grid.
   Below the 1000 layer so toasts/modals still cover it. */
.media-ghost {
    position: fixed;
    z-index: 900;
    margin: 0;
    pointer-events: none;
    border-radius: 10px;
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.3);
    opacity: 0.95;
}

/* Keep the "carrying" cursor for the whole gesture, wherever the pointer is */
body.media-dragging,
body.media-dragging * {
    cursor: grabbing !important;
}

.media-item:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* Which image carries the step's caption (media index 0) */
.media-primary-badge {
    position: absolute;
    left: 4px;
    bottom: 4px;
    max-width: calc(100% - 8px);
    padding: 1px 5px;
    border-radius: 5px;
    background: rgba(0, 0, 0, 0.62);
    color: #ffffff;
    font-size: 10px;
    line-height: 1.5;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
}

/* File (non-image) preview fills the tile */
.media-item .media-fallback {
    width: 100%;
    height: 100%;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    padding: 0;
    font-size: 12px;
}

.media-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 26px;
    height: 26px;
    background: rgba(0, 0, 0, 0.55);
    color: #ffffff;
    border: none;
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-danger {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--accent-primary);
    color: var(--on-accent);
    /* 1px border to match .btn-danger's border box so heights align (box-sizing: border-box is global) */
    border: 1px solid var(--accent-primary);
}

.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--card-bg);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-danger {
    background: transparent;
    color: #ef4444;
    border: 1px solid #ef4444;
}

.btn-danger:hover {
    background: #ef4444;
    color: #ffffff;
}

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

.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-icon:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.step-remove:hover {
    color: #ef4444;
    border-color: #ef4444;
}

.autoreply-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

/* Logs table */
.logs-table-wrapper {
    overflow-x: auto;
}

.logs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.logs-table th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text-secondary);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.logs-table td {
    padding: 10px 12px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
}

.logs-table .loading-row td {
    color: var(--text-tertiary);
    text-align: center;
    padding: 24px 12px;
}

.log-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    text-transform: capitalize;
}

.status-sent {
    background: rgba(34, 197, 94, 0.12);
    color: #16a34a;
}

.status-failed {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
}

.status-skipped {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 48px 24px;
}

.empty-state .empty-icon {
    width: 40px;
    height: 40px;
    color: var(--text-tertiary);
    margin-bottom: 8px;
}

.empty-state h3 {
    color: var(--text-primary);
    margin: 0 0 8px 0;
}

.empty-state p {
    color: var(--text-secondary);
    margin: 0 0 20px 0;
    font-size: 14px;
}

/* Responsive */
/* Flows loading skeleton (reuses .skel-line + shimmer from css/statistics.css) */
.flows-skeleton {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.flow-skeleton-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
}

.flow-skeleton-card .skel-line {
    height: 14px;
    border-radius: 6px;
    background: var(--skeleton-bg, #E5E7EB);
    animation: shimmer 1.5s ease-in-out infinite;
    margin-bottom: 10px;
}

.flow-skeleton-card .skel-line:last-child {
    margin-bottom: 0;
}

.flow-skeleton-card .skel-line:nth-child(1) {
    width: 38%;
    height: 16px;
}

.flow-skeleton-card .skel-line:nth-child(2) {
    width: 62%;
}

.flow-skeleton-card .skel-line:nth-child(3) {
    width: 30%;
    height: 12px;
}

/* Flows list */
.flow-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--bg-secondary);
    padding: 14px 16px;
    margin-bottom: 12px;
}

.flow-card-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.flow-card-text {
    min-width: 0;
}

.flow-card-name {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.flow-card-meta {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 6px;
}

.flow-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    max-width: 100%;
    overflow-wrap: anywhere;
}

.flow-badge-any {
    background: rgba(var(--accent-rgb, 34, 197, 94), 0.12);
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
}

.flow-badge-keyword {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

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

.switch-sm {
    width: 42px;
    height: 24px;
}

.switch-sm .slider:before {
    height: 16px;
    width: 16px;
}

.switch-sm input:checked + .slider:before {
    transform: translateX(18px);
}

/* Flow editor fields */
.flow-name-input,
.keyword-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--input-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    background: var(--input-bg);
    color: var(--text-primary);
}

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

.keyword-input-row .keyword-input {
    flex: 1;
}

.keyword-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.keyword-chips:empty {
    margin-top: 0;
}

.keyword-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 14px;
    font-size: 13px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.keyword-chip-remove {
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0;
}

.keyword-chip-remove:hover {
    color: #ef4444;
}

.flow-trigger-dropdown,
.flow-match-dropdown {
    width: 100%;
}

/* Responsive */
@media (max-width: 480px) {
    /* Smaller tiles so three fit per row on a phone */
    .media-item,
    .media-add-tile {
        width: 84px;
        height: 84px;
    }

    .media-add-tile svg {
        width: 22px;
        height: 22px;
    }
}

@media (max-width: 640px) {
    .flow-card-main {
        flex-direction: column;
        align-items: stretch;
    }

    .flow-card-actions {
        justify-content: flex-end;
    }
}

@media (max-width: 640px) {
    .autoreply-container {
        padding: 24px 16px;
    }

    .autoreply-header h1 {
        font-size: 24px;
    }

    .autoreply-card {
        padding: 20px;
        border-radius: 12px;
    }

    .toggle-row {
        flex-direction: column;
    }

    .toggle-row .switch {
        margin-top: 0;
    }

    .cooldown-row {
        flex-wrap: wrap;
    }

    .autoreply-actions {
        flex-direction: column;
    }

    .autoreply-actions .btn-primary,
    .autoreply-actions .btn-danger {
        justify-content: center;
    }
}
