/* ==========================================
   Automation Templates Page
   ========================================== */

.automation-templates-page {
    grid-column: 2 / -1;
    grid-row: 2;
    display: flex;
    flex-direction: column;
    background: var(--page-bg-gradient);
    overflow-y: auto;
    height: calc(100vh - var(--header-height));
}

.at-wrapper {
    display: flex;
    flex-direction: column;
    padding: 32px;
    gap: 24px;
    width: 100%;
}

/* Header */
.at-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.at-header-text h1 {
    font-size: 22px;
    font-weight: 700;
    color: var(--dark-primary);
    margin: 0 0 4px;
}

.at-header-text p {
    font-size: 14px;
    color: var(--slate-500);
    margin: 0;
}

.at-search {
    position: relative;
    min-width: 260px;
    margin-left: auto;
}

.at-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--slate-400);
    font-size: 18px;
}

.at-search input {
    width: 100%;
    padding: 10px 14px 10px 38px;
    border: 1px solid var(--slate-200);
    border-radius: 10px;
    font-size: 14px;
    color: var(--dark-primary);
    background: var(--white);
    outline: none;
    transition: border-color 0.2s ease;
}

.at-search input:focus {
    border-color: var(--slate-400);
}

/* Category Tabs */
.at-categories {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.at-cat-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--slate-200);
    border-radius: 20px;
    background: var(--white);
    color: var(--slate-500);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.at-cat-tab i {
    font-size: 16px;
}

.at-cat-tab:hover {
    border-color: var(--slate-300);
    color: var(--dark-primary);
}

.at-cat-tab.active {
    background: var(--dark-primary);
    color: var(--white);
    border-color: var(--dark-primary);
}

/* Cards Grid */
.at-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.at-card {
    display: flex;
    flex-direction: column;
    padding: 20px;
    background: var(--white);
    border: 1px solid var(--slate-200);
    border-radius: 14px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    overflow: hidden;
}

.at-card-bg-icon {
    position: absolute;
    top: -10px;
    right: -10px;
    font-size: 100px;
    opacity: 0.06;
    pointer-events: none;
    line-height: 1;
    transition: opacity 0.2s ease;
}

.at-card:hover .at-card-bg-icon {
    opacity: 0.1;
}

.at-card:hover {
    border-color: var(--slate-300);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    transform: translateY(-1px);
}

.at-card-active {
    border-color: var(--whatsapp-green);
}

.at-card-locked {
    opacity: 0.7;
}

.at-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 14px;
}

.at-card-icon {
    width: 44px;
    height: 44px;
    min-width: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.at-card-body {
    flex: 1;
    margin-bottom: 16px;
}

.at-card-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--dark-primary);
    margin: 0 0 6px;
}

.at-card-desc {
    font-size: 13px;
    color: var(--slate-500);
    margin: 0;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.at-card-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 14px;
    border-top: 1px solid var(--slate-100);
}

.at-card-bottom-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.at-card-channels {
    display: flex;
    gap: 6px;
    font-size: 16px;
}

.at-card-action {
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-500);
    transition: color 0.2s ease;
}

.at-card:hover .at-card-action {
    color: var(--dark-primary);
}

.at-card-category {
    font-size: 11px;
    color: var(--slate-400);
    background: var(--slate-50);
    padding: 2px 8px;
    border-radius: 6px;
}

/* Badges */
.at-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
    white-space: nowrap;
}

.at-badge-active {
    background: var(--green-50);
    color: #22c55e;
}

.at-badge-inactive {
    background: var(--slate-100);
    color: var(--slate-500);
}

.at-badge-locked {
    background: var(--red-50);
    color: #ef4444;
    display: flex;
    align-items: center;
    gap: 3px;
}

.at-badge-package {
    background: var(--indigo-50);
    color: #818cf8;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Empty state */
.at-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    color: var(--slate-400);
    gap: 12px;
}

.at-empty i {
    font-size: 40px;
}

/* Skeleton */
.at-skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.at-skeleton-card {
    height: 180px;
    border-radius: 14px;
    overflow: hidden;
}

.skeleton {
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, var(--skeleton-base, #f0f0f0) 25%, var(--skeleton-shine, #e0e0e0) 50%, var(--skeleton-base, #f0f0f0) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================
   Modal Base
   ========================================== */

.at-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1001;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.at-modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.at-modal {
    background: var(--white);
    border-radius: 16px;
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.95) translateY(10px);
    transition: all 0.3s ease;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.at-modal-overlay.active .at-modal {
    transform: scale(1) translateY(0);
}

.at-setup-modal {
    max-width: 520px;
}

/* Modal Header */
.at-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--slate-200);
}

.at-modal-title-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.at-modal-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.at-modal-header h2 {
    font-size: 17px;
    font-weight: 600;
    color: var(--dark-primary);
    margin: 0;
}

.at-modal-category {
    font-size: 12px;
    color: var(--slate-500);
}

.at-modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--slate-100);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--slate-500);
    transition: all 0.2s ease;
}

.at-modal-close:hover {
    background: var(--slate-200);
    color: var(--dark-primary);
}

/* Detail Tabs */
.at-detail-tabs {
    display: flex;
    padding: 0 24px;
    gap: 0;
    border-bottom: 1px solid var(--slate-200);
    flex-shrink: 0;
}

.at-detail-tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 16px;
    font-size: 13px;
    font-weight: 500;
    color: var(--slate-500);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: -1px;
}

.at-detail-tab:hover {
    color: var(--dark-primary);
}

.at-detail-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.at-detail-tab i {
    font-size: 16px;
}

/* Tab content */
.at-detail-tab-content {
    display: none;
}

.at-detail-tab-content.active {
    display: block;
}

/* Package section (always visible, outside scroll) */
.at-package-section {
    padding: 0 24px 16px;
    flex-shrink: 0;
}

/* Modal Body */
.at-modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.at-modal-section {
    margin-bottom: 20px;
}

.at-modal-section:last-child {
    margin-bottom: 0;
}

.at-modal-section h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: 0 0 10px;
}

.at-modal-description {
    font-size: 14px;
    color: var(--dark-primary);
    line-height: 1.6;
}

/* Channels badges */
.at-modal-channels {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.at-channel-badge {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    background: var(--slate-50);
    color: var(--ch-color, var(--dark-primary));
    border: 1px solid var(--slate-200);
}

.at-channel-badge i {
    font-size: 16px;
}

/* Roadmap Steps */
.at-roadmap {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.at-roadmap-step {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    position: relative;
    padding-bottom: 16px;
}

.at-roadmap-number {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: var(--slate-100);
    color: var(--dark-primary);
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.at-roadmap-line {
    position: absolute;
    left: 13px;
    top: 28px;
    bottom: 0;
    width: 2px;
    background: var(--slate-200);
}

.at-roadmap-line-last {
    display: none;
}

.at-roadmap-text {
    flex: 1;
    padding-top: 3px;
}

.at-roadmap-text strong {
    display: block;
    font-size: 14px;
    color: var(--dark-primary);
    margin-bottom: 2px;
}

.at-roadmap-text span {
    font-size: 13px;
    color: var(--slate-500);
}

/* Package notice */
.at-package-notice {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--red-50);
    border: 1px solid var(--red-200);
    border-radius: 10px;
}

.at-package-notice > i {
    font-size: 22px;
    color: #ef4444;
}

.at-package-notice strong {
    display: block;
    font-size: 14px;
    color: var(--dark-primary);
    margin-bottom: 2px;
}

.at-package-notice p {
    font-size: 13px;
    color: var(--slate-500);
    margin: 0;
}

.at-btn-upgrade {
    margin-left: auto;
    white-space: nowrap;
}

/* Modal Footer */
.at-modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1px solid var(--slate-200);
}

/* Config footer split */
.at-config-footer-left {
    margin-right: auto;
}

.at-config-footer-right {
    display: flex;
    gap: 10px;
}

/* ==========================================
   Buttons
   ========================================== */

.at-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 18px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
}

.at-btn-primary {
    background: var(--dark-primary);
    color: var(--white);
}

.at-btn-primary:hover {
    opacity: 0.9;
}

.at-btn-secondary {
    background: var(--slate-100);
    color: var(--dark-primary);
}

.at-btn-secondary:hover {
    background: var(--slate-200);
}

.at-btn-danger {
    background: var(--red-50);
    color: #ef4444;
}

.at-btn-danger:hover {
    background: var(--red-100);
}

.at-btn-ghost {
    background: transparent;
    color: var(--slate-500);
    padding: 8px 12px;
}

.at-btn-ghost:hover {
    background: var(--slate-100);
    color: var(--dark-primary);
}

.at-btn.loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.at-btn.loading::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    animation: atSpin 0.8s linear infinite;
}

.at-btn-primary.loading::after {
    border-color: var(--white);
    border-top-color: transparent;
}

@keyframes atSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==========================================
   Setup Wizard
   ========================================== */

.at-setup-step-label {
    font-size: 12px;
    color: var(--slate-400);
}

/* Progress steps */
.at-setup-progress {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-bottom: 24px;
}

.at-progress-step {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.at-progress-step::after {
    content: '';
    width: 24px;
    height: 2px;
    background: var(--slate-200);
    flex-shrink: 0;
}

.at-progress-step:last-child::after {
    display: none;
}

.at-progress-current {
    flex-shrink: 1;
    min-width: 0;
}

.at-progress-dot {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    background: var(--slate-100);
    color: var(--slate-500);
    transition: all 0.2s ease;
}

.at-progress-current .at-progress-dot {
    background: var(--dark-primary);
    color: var(--white);
}

.at-progress-done .at-progress-dot {
    background: var(--whatsapp-green);
    color: #fff;
}

.at-progress-done::after {
    background: var(--whatsapp-green);
}

.at-progress-step span {
    font-size: 12px;
    color: var(--slate-400);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.at-progress-current span {
    color: var(--dark-primary);
    font-weight: 600;
}

/* Step Content */
.at-step-header {
    margin-bottom: 16px;
}

.at-step-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--dark-primary);
    margin: 0 0 4px;
}

.at-step-header p {
    font-size: 13px;
    color: var(--slate-500);
    margin: 0;
}

.at-step-body {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.at-step-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 30px;
    text-align: center;
    color: var(--slate-400);
}

.at-step-empty i {
    font-size: 32px;
}

.at-step-error {
    color: #ef4444;
    padding: 20px;
    text-align: center;
}

.at-setup-loading {
    display: flex;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--slate-200);
    border-top-color: var(--dark-primary);
    border-radius: 50%;
    animation: atSpin 0.8s linear infinite;
}

/* Radio Card Selection */
.at-radio-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid var(--slate-200);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.at-radio-card:hover {
    border-color: var(--slate-300);
}

.at-radio-card.selected {
    border-color: var(--whatsapp-green);
    background: var(--green-50);
}

.at-radio-card input {
    display: none;
}

.at-radio-card-icon {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 8px;
    background: var(--slate-50);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    color: var(--slate-500);
}

.at-radio-card.selected .at-radio-card-icon {
    background: var(--green-100);
}

.at-radio-card-text {
    flex: 1;
    min-width: 0;
}

.at-radio-card-text strong {
    display: block;
    font-size: 14px;
    color: var(--dark-primary);
}

.at-radio-card-text span {
    font-size: 12px;
    color: var(--slate-500);
}

.at-radio-check {
    font-size: 20px;
    color: var(--slate-300);
    transition: all 0.2s ease;
}

.at-radio-card.selected .at-radio-check {
    color: var(--whatsapp-green);
}

/* Form Controls */
.at-form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--slate-200);
    border-radius: 8px;
    font-size: 14px;
    color: var(--dark-primary);
    background: var(--white);
    outline: none;
    transition: border-color 0.2s ease;
}

.at-form-control:focus {
    border-color: var(--slate-400);
}

.at-field-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--dark-primary);
    margin-bottom: 6px;
}

/* ==========================================
   Config Modal
   ========================================== */

.at-config-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 0;
    border-bottom: 1px solid var(--slate-100);
}

.at-config-row:last-child {
    border-bottom: none;
}

.at-config-toggle-row {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
}

.at-config-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--slate-500);
}

.at-config-status {
    font-size: 12px;
    font-weight: 600;
}

.at-status-active {
    color: #22c55e;
}

.at-status-inactive {
    color: var(--slate-400);
}

.at-config-logs-row {
    border-bottom: none;
    padding-top: 8px;
}

/* Toggle Switch */
.at-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
    cursor: pointer;
}

.at-toggle input {
    display: none;
}

.at-toggle-slider {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--slate-300);
    border-radius: 24px;
    transition: all 0.3s ease;
}

.at-toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    bottom: 3px;
    background: #fff;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.at-toggle input:checked + .at-toggle-slider {
    background: var(--whatsapp-green);
}

.at-toggle input:checked + .at-toggle-slider::before {
    transform: translateX(20px);
}

/* ==========================================
   Logs View
   ========================================== */

.at-logs-list {
    display: flex;
    flex-direction: column;
}

.at-logs-header {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-500);
    text-transform: uppercase;
    border-bottom: 1px solid var(--slate-200);
}

.at-logs-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 12px;
    padding: 10px 12px;
    font-size: 13px;
    color: var(--dark-primary);
    border-bottom: 1px solid var(--slate-100);
}

.at-logs-row:last-child {
    border-bottom: none;
}

.at-log-status {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 6px;
}

.at-log-success {
    background: var(--green-50);
    color: #22c55e;
}

.at-log-failed {
    background: var(--red-50);
    color: #ef4444;
}

.at-log-pending {
    background: var(--slate-100);
    color: var(--slate-500);
}

/* ==========================================
   Responsive
   ========================================== */

@media (max-width: 768px) {
    .at-wrapper {
        padding: 16px;
    }

    .at-header {
        flex-direction: column;
    }

    .at-search {
        min-width: 100%;
    }

    .at-cards {
        grid-template-columns: 1fr;
    }

    .at-skeleton-grid {
        grid-template-columns: 1fr;
    }

    .at-modal {
        max-width: calc(100vw - 32px);
        max-height: calc(100vh - 32px);
    }

    .at-setup-progress {
        gap: 2px;
    }

    .at-progress-step::after {
        width: 12px;
    }

    .at-progress-step::after {
        width: 12px;
    }
}

/* ==========================================
   Dark Mode
   ========================================== */

[data-theme="dark"] .at-detail-tabs {
    border-bottom-color: var(--form-border);
}

[data-theme="dark"] .at-detail-tab {
    color: var(--text-secondary);
}

[data-theme="dark"] .at-detail-tab:hover {
    color: var(--text-primary);
}

[data-theme="dark"] .at-detail-tab.active {
    color: var(--primary);
}

[data-theme="dark"] .at-package-notice {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
}

[data-theme="dark"] .at-header-text h1,
[data-theme="dark"] .at-card-title,
[data-theme="dark"] .at-modal-header h2,
[data-theme="dark"] .at-modal-description,
[data-theme="dark"] .at-roadmap-text strong,
[data-theme="dark"] .at-package-notice strong,
[data-theme="dark"] .at-step-header h3,
[data-theme="dark"] .at-radio-card-text strong,
[data-theme="dark"] .at-field-label,
[data-theme="dark"] .at-logs-row,
[data-theme="dark"] .at-roadmap-number {
    color: var(--text-primary);
}

[data-theme="dark"] .at-search input,
[data-theme="dark"] .at-form-control {
    color: var(--text-primary);
    background: var(--form-bg);
    border-color: var(--form-border);
}

[data-theme="dark"] .at-cat-tab:hover,
[data-theme="dark"] .at-modal-close:hover {
    color: var(--text-primary);
}

[data-theme="dark"] .at-cat-tab.active {
    background: var(--text-primary);
    color: var(--white);
    border-color: var(--text-primary);
}

[data-theme="dark"] .at-card:hover {
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .at-card-bg-icon {
    opacity: 0.08;
}

[data-theme="dark"] .at-card:hover .at-card-bg-icon {
    opacity: 0.14;
}

[data-theme="dark"] .at-card:hover .at-card-action {
    color: var(--text-primary);
}

[data-theme="dark"] .at-channel-badge {
    color: var(--text-primary);
}

[data-theme="dark"] .at-btn-primary {
    background: var(--text-primary);
    color: var(--white);
}

[data-theme="dark"] .at-btn-secondary {
    color: var(--text-primary);
}

[data-theme="dark"] .at-btn-ghost:hover {
    color: var(--text-primary);
}

[data-theme="dark"] .at-progress-current .at-progress-dot {
    background: var(--text-primary);
}

[data-theme="dark"] .at-progress-current span {
    color: var(--text-primary);
}

[data-theme="dark"] .spinner {
    border-top-color: var(--text-primary);
}

[data-theme="dark"] .at-config-toggle-row strong {
    color: var(--text-primary);
}
