/**
 * Automation Rules Admin CSS
 *
 * @package MAI_SMART_ASSISTANT
 * @since 1.0.3
 */

/* Page Container */
#mai-automation-rules-page {
    margin: 20px 20px 0 0;
}

/* Tabs */
.nav-tab-wrapper {
    margin-bottom: 20px;
    border-bottom: 1px solid #c3c4c7;
}

.nav-tab {
    cursor: pointer;
    border: 1px solid transparent;
    background: transparent;
    padding: 8px 14px;
    font-size: 14px;
    line-height: 24px;
    text-decoration: none;
    color: #50575e;
    display: inline-block;
    margin: 0 0 -1px;
    transition: all 0.2s;
}

.nav-tab:hover {
    background: #f6f7f7;
}

.nav-tab.nav-tab-active {
    border: 1px solid #c3c4c7;
    border-bottom-color: #f0f0f1;
    background: #f0f0f1;
    color: #000;
}

/* Tab Content */
.tab-content {
    display: none;
    padding: 20px 0;
}

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

/* Header Actions */
.header-actions {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-actions h2 {
    margin: 0;
}

.header-actions .button-group {
    display: flex;
    gap: 10px;
}

/* Dashboard Widgets */
.dashboard-widgets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.dashboard-widget {
    background: #fff;
    padding: 20px;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}

.dashboard-widget h3 {
    margin: 0 0 10px;
    font-size: 14px;
    color: #646970;
    font-weight: 600;
}

.dashboard-widget .widget-value {
    font-size: 32px;
    font-weight: 600;
    color: #1d2327;
}

/* Recent Activity */
.recent-activity {
    background: #fff;
    padding: 20px;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}

.recent-activity h3 {
    margin: 0 0 15px;
    font-size: 18px;
}

/* Analytics */
.analytics-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.analytics-card {
    background: #fff;
    padding: 20px;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
    text-align: center;
}

.analytics-card h3 {
    margin: 0 0 10px;
    font-size: 14px;
    color: #646970;
    font-weight: 600;
}

.analytics-card .metric-value {
    font-size: 28px;
    font-weight: 600;
    color: #1d2327;
}

.analytics-card .metric-value.success {
    color: #00a32a;
}

.analytics-card .metric-value.error {
    color: #d63638;
}

.analytics-charts {
    background: #fff;
    padding: 20px;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}

.analytics-charts h3 {
    margin: 0 0 15px;
    font-size: 18px;
}

/* Rules List */
#rules-list,
#queue-list {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
}

.rule-actions {
    white-space: nowrap;
}

.rule-actions .button {
    margin: 2px;
    padding: 4px 8px;
    font-size: 12px;
    line-height: 1.5;
}

/* Status Badges */
.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.status-active {
    background: #d1f4dd;
    color: #00761c;
}

.status-badge.status-inactive {
    background: #f0f0f1;
    color: #646970;
}

.status-badge.status-pending {
    background: #fcf9e8;
    color: #8a6116;
}

.status-badge.status-processing {
    background: #e5f5fa;
    color: #0071a1;
}

.status-badge.status-completed,
.status-badge.status-success {
    background: #d1f4dd;
    color: #00761c;
}

.status-badge.status-failed,
.status-badge.status-error {
    background: #f8d7da;
    color: #8a1f11;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 100000;
    overflow-y: auto;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.modal-content {
    position: relative;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    z-index: 1;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #c3c4c7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 1;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
}

.modal-close {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #646970;
    padding: 0;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
}

.modal-close:hover {
    color: #000;
}

.modal-body {
    padding: 20px;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #c3c4c7;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    position: sticky;
    bottom: 0;
    background: #fff;
    z-index: 1;
}

/* Form Tabs */
.form-tabs {
    display: flex;
    border-bottom: 1px solid #c3c4c7;
    margin-bottom: 20px;
    overflow-x: auto;
}

.form-tab {
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    color: #646970;
    font-size: 14px;
    white-space: nowrap;
    transition: all 0.2s;
}

.form-tab:hover {
    color: #000;
}

.form-tab.active {
    color: #2271b1;
    border-bottom-color: #2271b1;
}

/* Form Sections */
.form-section {
    display: none;
}

.form-section.active {
    display: block;
}

.form-row {
    margin-bottom: 20px;
}

.form-row label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #1d2327;
}

.form-row label .description {
    display: block;
    font-weight: 400;
    font-size: 12px;
    color: #646970;
    margin-top: 2px;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="date"],
.form-row input[type="time"],
.form-row select,
.form-row textarea {
    width: 100%;
    max-width: 600px;
}

.form-row textarea {
    min-height: 100px;
    resize: vertical;
}

.form-row .checkbox-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-row .checkbox-group input[type="checkbox"] {
    margin: 0;
}

.form-row .checkbox-group label {
    margin: 0;
    font-weight: 400;
}

/* Two Column Layout */
.form-row-2col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.form-row-2col .form-field {
    margin-bottom: 0;
}

.form-row-2col .form-field label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
}

.form-row-2col .form-field input,
.form-row-2col .form-field select {
    width: 100%;
}

/* Schedule Config */
.schedule-config {
    display: none;
    padding: 15px;
    background: #f6f7f7;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    margin-top: 10px;
}

.schedule-config.active {
    display: block;
}

/* SEO Plugin Status */
.seo-plugin-status {
    padding: 10px;
    background: #f6f7f7;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    margin-bottom: 15px;
}

.seo-plugin-status.active {
    background: #d1f4dd;
    border-color: #00a32a;
}

.seo-plugin-status.inactive {
    background: #f8d7da;
    border-color: #d63638;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: #646970;
    font-size: 14px;
}

.loading:before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #c3c4c7;
    border-top-color: #2271b1;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 10px;
    vertical-align: middle;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Test Results */
.test-results {
    padding: 20px;
}

.test-results h3 {
    margin: 0 0 15px;
    font-size: 18px;
}

.test-results h4 {
    margin: 20px 0 10px;
    font-size: 16px;
}

.test-results h5 {
    margin: 10px 0 5px;
    font-size: 14px;
}

.content-preview {
    background: #f6f7f7;
    padding: 15px;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    margin: 10px 0;
}

.content-preview div {
    margin-top: 10px;
    color: #646970;
    line-height: 1.6;
}

/* Notices */
.notice {
    background: #fff;
    border-left: 4px solid #72aee6;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
    margin: 20px 0;
    padding: 12px;
}

.notice p {
    margin: 0.5em 0;
    padding: 2px;
}

.notice-success {
    border-left-color: #00a32a;
}

.notice-error {
    border-left-color: #d63638;
}

.notice-warning {
    border-left-color: #dba617;
}

.notice-info {
    border-left-color: #72aee6;
}

.notice.is-dismissible {
    padding-right: 38px;
    position: relative;
}

/* Table Enhancements */
.wp-list-table {
    background: #fff;
}

.wp-list-table th {
    font-weight: 600;
}

.wp-list-table td {
    vertical-align: middle;
}

.wp-list-table tr:hover {
    background: #f6f7f7;
}

.wp-list-table .success {
    color: #00761c;
    font-weight: 600;
}

.wp-list-table .error {
    color: #8a1f11;
    font-weight: 600;
}

/* Responsive */
@media screen and (max-width: 782px) {
    .dashboard-widgets,
    .analytics-summary {
        grid-template-columns: 1fr;
    }

    .form-row-2col {
        grid-template-columns: 1fr;
    }

    .header-actions {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .header-actions .button-group {
        width: 100%;
        flex-direction: column;
    }

    .rule-actions {
        display: flex;
        flex-wrap: wrap;
    }

    .modal-content {
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        max-height: 100vh;
    }
}

/* Utility Classes */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-0 {
    margin-top: 0 !important;
}

.mb-0 {
    margin-bottom: 0 !important;
}

.mt-1 {
    margin-top: 10px !important;
}

.mb-1 {
    margin-bottom: 10px !important;
}

.mt-2 {
    margin-top: 20px !important;
}

.mb-2 {
    margin-bottom: 20px !important;
}

/* ========================================
   Dashboard Summary Cards (Migrated from Analytics)
   ======================================== */
.mai-smart-assistant-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.summary-card {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    transition: box-shadow 0.2s;
}

.summary-card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.summary-card .card-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: #f0f6fc;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.summary-card .card-icon .dashicons {
    font-size: 24px;
    width: 24px;
    height: 24px;
    color: #2271b1;
}

.summary-card .card-content {
    flex: 1;
}

.summary-card .card-content h3 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: #666;
    text-transform: uppercase;
}

.summary-card .card-value {
    margin: 0;
    font-size: 28px;
    font-weight: 700;
    color: #1d2327;
    line-height: 1;
}

/* ========================================
   Dashboard Tables
   ======================================== */
.mai-smart-assistant-tables {
    display: grid;
    gap: 30px;
    margin-bottom: 30px;
}

.table-container {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    padding: 20px;
}

.table-container h2 {
    margin: 0 0 15px 0;
    font-size: 16px;
    font-weight: 600;
    color: #1d2327;
}

/* Dark Mode Support for Icons */
@media (prefers-color-scheme: dark) {
    .summary-card .card-icon {
        background: rgba(34, 113, 177, 0.1);
    }
}

/* Responsive */
@media (max-width: 1200px) {
    .mai-smart-assistant-summary-cards {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }
}

@media (max-width: 782px) {
    .mai-smart-assistant-summary-cards {
        grid-template-columns: 1fr;
    }
    
    .table-container {
        overflow-x: auto;
    }
}

/* ========================================
   Enhanced Page Layout
   ======================================== */
.mai-automation-rules-wrap {
    max-width: 1200px;
    margin: 20px 20px 0 0;
}

.mai-automation-rules-wrap h1 {
    margin-bottom: 20px;
    font-size: 23px;
    font-weight: 400;
    line-height: 1.3;
}

/* ========================================
   Enhanced Tab Navigation
   ======================================== */
.mai-automation-rules-wrap .nav-tab-wrapper {
    border-bottom: 1px solid #c3c4c7;
    margin-bottom: 25px;
    padding: 0;
    display: flex;
    gap: 0;
}

.mai-automation-rules-wrap .nav-tab {
    border: 1px solid transparent;
    border-bottom: none;
    background: transparent;
    padding: 10px 15px;
    font-size: 14px;
    font-weight: 500;
    line-height: 24px;
    text-decoration: none;
    color: #50575e;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 -1px;
    transition: all 0.2s ease;
    border-radius: 4px 4px 0 0;
}

.mai-automation-rules-wrap .nav-tab .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
}

.mai-automation-rules-wrap .nav-tab:hover {
    background: #f6f7f7;
    color: #1d2327;
}

.mai-automation-rules-wrap .nav-tab.nav-tab-active {
    border: 1px solid #c3c4c7;
    border-bottom-color: #f0f0f1;
    background: #f0f0f1;
    color: #1d2327;
    font-weight: 600;
}

/* ========================================
   Enhanced Form Container (New Rule Page)
   ======================================== */
.mai-rule-form-container {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.04);
    padding: 0;
    margin-bottom: 30px;
}

.mai-rule-form-header {
    padding: 20px 25px;
    border-bottom: 1px solid #e6e6e6;
    background: #f9f9f9;
    border-radius: 4px 4px 0 0;
}

.mai-rule-form-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1d2327;
}

.mai-rule-form-body {
    padding: 25px;
}

/* ========================================
   Enhanced Form Tab Navigation
   ======================================== */
.form-tabs {
    display: flex;
    border-bottom: 2px solid #e2e4e7;
    margin-bottom: 25px;
    padding: 0;
    background: transparent;
    gap: 0;
}

.form-tab {
    padding: 12px 20px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    color: #646970;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.form-tab .dashicons {
    font-size: 18px;
    width: 18px;
    height: 18px;
}

.form-tab:hover {
    color: #1d2327;
    background: rgba(0,0,0,0.02);
}

.form-tab.active {
    color: #2271b1;
    border-bottom-color: #2271b1;
    font-weight: 600;
}

/* ========================================
   Enhanced Form Fields
   ======================================== */
.form-field {
    margin-bottom: 24px;
    position: relative;
}

.form-field:last-child {
    margin-bottom: 0;
}

.form-field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: #1d2327;
    font-size: 14px;
    line-height: 1.4;
}

.form-field label .required {
    color: #d63638;
    font-weight: 700;
    margin-left: 2px;
}

.form-field .description {
    margin-top: 6px;
    font-size: 12px;
    color: #646970;
    line-height: 1.5;
}

.form-field input[type='text'],
.form-field input[type='number'],
.form-field input[type='email'],
.form-field input[type='url'],
.form-field input[type='date'],
.form-field input[type='time'],
.form-field select,
.form-field textarea {
    width: 100%;
    max-width: 100%;
    padding: 10px 12px;
    border: 1px solid #8c8f94;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    background: #fff;
}

.form-field .widefat {
    max-width: 600px;
}

.form-field input:focus,
.form-field select:focus,
.form-field textarea:focus {
    border-color: #2271b1;
    box-shadow: 0 0 0 1px #2271b1;
    outline: none;
}

.form-field textarea {
    min-height: 120px;
    resize: vertical;
}

.form-field select[multiple] {
    min-height: 120px;
}

/* ========================================
   Enhanced Action Buttons
   ======================================== */
.rule-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.rule-actions .button {
    padding: 6px 12px;
    font-size: 12px;
    line-height: 1.4;
    border-radius: 3px;
    min-height: auto;
    height: auto;
}

/* ========================================
   Enhanced Status Badges
   ======================================== */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

/* ========================================
   Page Header with Actions
   ======================================== */
.mai-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid #c3c4c7;
}

.mai-page-header h1 {
    margin: 0;
}

.mai-page-header .page-actions {
    display: flex;
    gap: 10px;
}

/* ========================================
   Empty State
   ======================================== */
.mai-empty-state {
    text-align: center;
    padding: 60px 40px;
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
}

.mai-empty-state .dashicons {
    font-size: 48px;
    width: 48px;
    height: 48px;
    color: #c3c4c7;
    margin-bottom: 20px;
}

.mai-empty-state h3 {
    font-size: 18px;
    color: #1d2327;
    margin: 0 0 10px;
}

.mai-empty-state p {
    color: #646970;
    font-size: 14px;
    margin: 0 0 20px;
}

/* ========================================
   Form Footer Actions
   ======================================== */
.mai-form-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    background: #f9f9f9;
    border-top: 1px solid #e6e6e6;
    border-radius: 0 0 4px 4px;
    gap: 15px;
}

.mai-form-footer .primary-actions {
    display: flex;
    gap: 10px;
}

/* ========================================
   Responsive Adjustments
   ======================================== */
@media (max-width: 960px) {
    .mai-automation-rules-wrap {
        margin: 10px 10px 0 0;
    }
    
    .mai-rule-form-body {
        padding: 20px;
    }
}

@media (max-width: 782px) {
    .mai-page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .mai-form-footer {
        flex-direction: column;
        align-items: stretch;
    }
}
