/**
 * Kiplot Forms - Styles
 *
 * Base styles for frontend forms and admin interface.
 *
 * @package Kiplot_Forms
 */

/* ==========================================================================
   Frontend Form Styles
   ========================================================================== */

/* Form container */
[data-kiplot-form] {
    position: relative;
}

[data-kiplot-form].kiplot-form-initialized {
    /* Form is ready */
}

/* Loading state */
[data-kiplot-form].kiplot-loading {
    pointer-events: none;
    opacity: 0.7;
}

[data-kiplot-form].kiplot-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 24px;
    height: 24px;
    margin: -12px 0 0 -12px;
    border: 3px solid #e0e0e0;
    border-top-color: #333;
    border-radius: 50%;
    animation: kiplot-spin 0.8s linear infinite;
}

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

/* Form messages */
.kiplot-form-message {
    padding: 12px 16px;
    margin-bottom: 20px;
    border-radius: 4px;
    font-size: 14px;
    line-height: 1.5;
}

.kiplot-form-message--success {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.kiplot-form-message--error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

/* Field error state */
.kiplot-error {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 1px #dc3545 !important;
}

.kiplot-error:focus {
    border-color: #dc3545 !important;
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.25) !important;
}

.kiplot-error-message {
    display: block;
    color: #dc3545;
    font-size: 12px;
    margin-top: 4px;
    line-height: 1.4;
}

/* Submit button loading state */
[data-kiplot-form].kiplot-loading [type="submit"] {
    cursor: wait;
}

/* ==========================================================================
   Auto-rendered Form Styles (from shortcode)
   ========================================================================== */

/* CSS Custom Properties for easy theming */
:root {
    --kiplot-font-family: 'Century Gothic', 'Segoe UI', Tahoma, sans-serif;
    --kiplot-primary-color: #3d3cb4 !important;
    --kiplot-primary-hover: #3d3cb4 !important;
    --kiplot-text-color: #444;
    --kiplot-label-color: #333;
    --kiplot-border-color: #ddd;
    --kiplot-border-radius: 7px !important;
    --kiplot-input-padding: 12px 14px;
    --kiplot-field-spacing: 18px;
    --kiplot-focus-shadow: 0 0 0 1px rgba(61, 60, 180, 0.1);
}

/* Form container */
.kiplot-form {
    font-family: var(--kiplot-font-family);
}

/* Form fields wrapper */
.kiplot-form-fields {
    margin-bottom: 10px;
}

/* Field container */
.kiplot-field {
    margin-bottom: var(--kiplot-field-spacing);
}

.kiplot-field label {
    display: block;
    font-family: var(--kiplot-font-family);
    font-size: 14px;
    font-weight: 600;
    color: var(--kiplot-label-color);
    margin-bottom: 8px;
}

.kiplot-field .kiplot-required {
    color: var(--kiplot-primary-color);
    margin-left: 2px;
}

/* Form inputs - polished styling */
.kiplot-field input[type="text"],
.kiplot-field input[type="email"],
.kiplot-field input[type="tel"],
.kiplot-field input[type="number"],
.kiplot-field input[type="date"],
.kiplot-field input[type="url"],
.kiplot-field select,
.kiplot-field textarea {
    width: 100%;
    padding: var(--kiplot-input-padding);
    border: 1px solid var(--kiplot-border-color);
    border-radius: var(--kiplot-border-radius);
    font-family: var(--kiplot-font-family);
    font-size: 15px;
    line-height: 1.5;
    color: var(--kiplot-text-color);
    background-color: #fff;
    box-sizing: border-box;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* Placeholder styling */
.kiplot-field input::placeholder,
.kiplot-field textarea::placeholder {
    color: #999;
    opacity: 1;
}

/* Focus state */
.kiplot-field input:focus,
.kiplot-field select:focus,
.kiplot-field textarea:focus {
    outline: none;
    border-color: var(--kiplot-primary-color);
    box-shadow: var(--kiplot-focus-shadow);
}

/* Select dropdown arrow */
.kiplot-field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23444' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

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

/* Side by side fields */
.kiplot-field-row {
    display: flex;
    gap: 20px;
    margin-bottom: var(--kiplot-field-spacing);
}

.kiplot-field-row .kiplot-field {
    flex: 1;
    margin-bottom: 0;
}

/* Radio and checkbox groups */
.kiplot-radio-group,
.kiplot-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 4px;
}

.kiplot-radio-label,
.kiplot-checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: var(--kiplot-font-family);
    font-size: 14px;
    color: var(--kiplot-text-color);
    cursor: pointer;
    line-height: 1.4;
}

.kiplot-radio-label input,
.kiplot-checkbox-label input {
    margin: 0;
    width: 18px;
    height: 18px;
    accent-color: var(--kiplot-primary-color);
}

/* Submit button - polished styling */
.kiplot-submit-btn {
    display: block;
    width: 100%;
    padding: 14px 24px !important;
    margin-top: 10px !important; 
    background-color: var(--kiplot-primary-color) !important;
    color: #fff;
    border: none;
    border-radius: var(--kiplot-border-radius) !important;
    font-family: var(--kiplot-font-family);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease !important;
    text-transform: none;
    letter-spacing: 0.3px;
}

.kiplot-submit-btn:hover {
    background-color: var(--kiplot-primary-hover) !important;
    transform: translateY(-1px) !important;
}

.kiplot-submit-btn:active {
    transform: translateY(1px) !important;
}

.kiplot-submit-btn:disabled {
    opacity: 0.7;
    cursor: wait;
    transform: none;
}

/* Form messages - polished */
[data-kiplot-form] .kiplot-form-message {
    font-family: var(--kiplot-font-family);
    padding: 14px 18px;
    margin-bottom: 20px;
    border-radius: var(--kiplot-border-radius);
    font-size: 15px;
    line-height: 1.5;
}

/* Error styling refinements */
[data-kiplot-form] .kiplot-error-message {
    font-family: var(--kiplot-font-family);
    font-size: 13px;
    margin-top: 6px;
}

/* Responsive: stack fields on mobile */
@media screen and (max-width: 600px) {
    .kiplot-field-row {
        flex-direction: column;
        gap: 0;
    }

    .kiplot-field-row .kiplot-field {
        margin-bottom: var(--kiplot-field-spacing);
    }

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

    .kiplot-submit-btn {
        padding: 16px 24px;
    }
}

/* ==========================================================================
   Admin Styles
   ========================================================================== */

.kiplot-forms-admin {
    /* Admin container */
}

.kiplot-forms-admin .nav-tab-wrapper {
    margin-bottom: 20px;
}

.kiplot-forms-tab-content {
    background: #fff;
    padding: 20px;
    border: 1px solid #ccd0d4;
    border-top: none;
}

/* Status indicators */
.kiplot-success {
    color: #46b450;
}

.kiplot-error {
    color: #dc3545;
}

/* Fields table */
#kiplot-fields-table {
    margin-top: 20px;
}

#kiplot-fields-table input[type="text"],
#kiplot-fields-table select {
    width: 100%;
    max-width: none;
}

#kiplot-fields-table .field-name {
    background-color: #f0f0f1;
}

#kiplot-add-field-row {
    background-color: #f9f9f9;
}

#kiplot-add-field-row input[type="text"],
#kiplot-add-field-row select {
    width: 100%;
    max-width: none;
}

/* Submissions table */
.kiplot-submissions-table {
    margin-top: 20px;
}

.kiplot-submissions-table .column-id {
    width: 60px;
}

.kiplot-submissions-table .column-status {
    width: 80px;
}

.kiplot-submissions-table .column-email {
    width: 200px;
}

.kiplot-submissions-table .column-form_id {
    width: 200px;
}

.kiplot-submissions-table .column-date {
    width: 150px;
}

.kiplot-submissions-table .column-actions {
    width: 150px;
}

/* Status badges */
.kiplot-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
}

.kiplot-status--partial {
    background-color: #fff3cd;
    color: #856404;
}

.kiplot-status--complete {
    background-color: #cce5ff;
    color: #004085;
}

.kiplot-status--synced {
    background-color: #d4edda;
    color: #155724;
}

.kiplot-status--failed {
    background-color: #f8d7da;
    color: #721c24;
}

.kiplot-status--blocked {
    background-color: #e2e3e5;
    color: #383d41;
}

/* Stats boxes */
.kiplot-stats {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.kiplot-stat-box {
    background: #f9f9f9;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 15px 20px;
    min-width: 120px;
    text-align: center;
}

.kiplot-stat-box .stat-value {
    font-size: 28px;
    font-weight: 600;
    color: #23282d;
    line-height: 1.2;
}

.kiplot-stat-box .stat-label {
    font-size: 12px;
    color: #666;
    text-transform: uppercase;
    margin-top: 5px;
}

.kiplot-stat-box.stat-partial .stat-value {
    color: #856404;
}

.kiplot-stat-box.stat-complete .stat-value {
    color: #004085;
}

.kiplot-stat-box.stat-synced .stat-value {
    color: #155724;
}

.kiplot-stat-box.stat-failed .stat-value {
    color: #721c24;
}

.kiplot-stat-box.stat-blocked .stat-value {
    color: #383d41;
}

/* Filters */
.kiplot-filters {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.kiplot-filters select,
.kiplot-filters input[type="search"] {
    min-width: 150px;
}

/* Sortable table columns */
/* Hide WordPress default sort indicators */
.kiplot-submissions-table th.sortable .sorting-indicator,
.kiplot-submissions-table th.sorted .sorting-indicator,
.kiplot-forms-table th.sortable .sorting-indicator,
.kiplot-forms-table th.sorted .sorting-indicator {
    display: block;
}

.kiplot-submissions-table th.sortable a::before,
.kiplot-submissions-table th.sortable a::after,
.kiplot-submissions-table th.sorted a::before,
.kiplot-submissions-table th.sorted a::after,
.kiplot-forms-table th.sortable a::before,
.kiplot-forms-table th.sortable a::after,
.kiplot-forms-table th.sorted a::before,
.kiplot-forms-table th.sorted a::after {
    display: none !important;
}

.kiplot-submissions-table th.sortable a,
.kiplot-submissions-table th.sorted a,
.kiplot-forms-table th.sortable a,
.kiplot-forms-table th.sorted a {
    display: flex;
    align-items: center;
    text-decoration: none;
    color: inherit;
}

.kiplot-submissions-table th.sortable:hover,
.kiplot-forms-table th.sortable:hover {
    background-color: #f0f0f1;
}

.kiplot-submissions-table .sorting-indicators,
.kiplot-forms-table .sorting-indicators {
    margin-left: 5px;
    display: flex;
    flex-direction: column;
}

.kiplot-submissions-table .sorting-indicator,
.kiplot-forms-table .sorting-indicator {
    display: block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
}

.kiplot-submissions-table .sorting-indicator.asc,
.kiplot-forms-table .sorting-indicator.asc {
    border-bottom: 4px solid #999;
    margin-bottom: 1px;
}

.kiplot-submissions-table .sorting-indicator.desc,
.kiplot-forms-table .sorting-indicator.desc {
    border-top: 4px solid #999;
}

.kiplot-submissions-table th.sorted.asc .sorting-indicator.asc,
.kiplot-forms-table th.sorted.asc .sorting-indicator.asc {
    border-bottom-color: #0073aa;
}

.kiplot-submissions-table th.sorted.desc .sorting-indicator.desc,
.kiplot-forms-table th.sorted.desc .sorting-indicator.desc {
    border-top-color: #0073aa;
}

/* Funnel display */
.kiplot-funnel {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.kiplot-funnel .kiplot-status {
    display: inline-block;
    font-size: 11px;
}

/* Conversion rate display */
.kiplot-conversion-rate {
    display: inline-block;
    font-size: 16px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 3px;
}

.kiplot-conversion-rate.good {
    background-color: #d4edda;
    color: #155724;
}

.kiplot-conversion-rate.average {
    background-color: #fff3cd;
    color: #856404;
}

.kiplot-conversion-rate.low {
    background-color: #f8d7da;
    color: #721c24;
}

/* Pagination */
.kiplot-pagination {
    margin-top: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.kiplot-pagination .pagination-info {
    color: #666;
    font-size: 13px;
}

.kiplot-pagination .pagination-links {
    display: flex;
    gap: 5px;
}

.kiplot-pagination .pagination-links a,
.kiplot-pagination .pagination-links span {
    padding: 5px 10px;
    border: 1px solid #ddd;
    background: #fff;
    text-decoration: none;
    color: #0073aa;
}

.kiplot-pagination .pagination-links span.current {
    background: #0073aa;
    color: #fff;
    border-color: #0073aa;
}

.kiplot-pagination .pagination-links a:hover {
    background: #f0f0f1;
}

/* Data details - expandable row */
.kiplot-data-row td {
    background: #f9f9f9;
    padding: 0 !important;
}

.kiplot-data-expanded {
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
}

.kiplot-data-expanded strong {
    display: block;
    margin-bottom: 10px;
    color: #23282d;
}

.kiplot-data-json {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 15px;
    margin: 0;
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

/* Action buttons */
.kiplot-submissions-table .button {
    margin-right: 5px;
}

.kiplot-submissions-table .button:last-child {
    margin-right: 0;
}

/* Verify credentials button */
.kiplot-forms-verify-credentials {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #ccd0d4;
}

#kiplot-verify-result {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 3px;
}

#kiplot-verify-result.kiplot-success {
    background-color: #d4edda;
}

#kiplot-verify-result.kiplot-error {
    background-color: #f8d7da;
}

/* Responsive adjustments */
@media screen and (max-width: 782px) {
    .kiplot-stats {
        flex-direction: column;
    }

    .kiplot-stat-box {
        width: 100%;
    }

    .kiplot-filters {
        flex-direction: column;
        align-items: stretch;
    }

    .kiplot-filters select,
    .kiplot-filters input[type="search"] {
        width: 100%;
    }

    .kiplot-pagination {
        flex-direction: column;
        gap: 10px;
    }

    #kiplot-fields-table th,
    #kiplot-fields-table td {
        padding: 8px 5px;
    }

    .kiplot-submissions-table th,
    .kiplot-submissions-table td {
        padding: 8px 5px;
    }
}

/* Dark mode support (if theme supports it) */
@media (prefers-color-scheme: dark) {
    .kiplot-forms-admin .kiplot-forms-tab-content {
        /* Inherits WordPress admin dark mode if enabled */
    }
}

/* ==========================================================================
   Modal Styles
   ========================================================================== */

.kiplot-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kiplot-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 0;
}

.kiplot-modal-content {
    position: relative;
    z-index: 1;
    background: #fff;
    border-radius: 4px;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.3);
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.kiplot-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid #ddd;
}

.kiplot-modal-header h3 {
    margin: 0;
    font-size: 18px;
    color: #23282d;
}

.kiplot-modal-close {
    background: none;
    border: none;
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kiplot-modal-close:hover {
    color: #23282d;
}

.kiplot-modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.kiplot-modal-meta {
    margin: 0 0 15px 0;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
    font-size: 14px;
    line-height: 1.8;
}

.kiplot-modal-json {
    background: #f5f5f5;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    padding: 15px;
    margin: 0;
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
}

.kiplot-modal-footer {
    padding: 15px 20px;
    border-top: 1px solid #ddd;
    text-align: right;
}

@media screen and (max-width: 600px) {
    .kiplot-modal-content {
        width: 95%;
        max-height: 90vh;
    }

    .kiplot-modal-header {
        padding: 12px 15px;
    }

    .kiplot-modal-body {
        padding: 15px;
    }

    .kiplot-modal-footer {
        padding: 12px 15px;
    }
}
