/**
 * Coagrisan Pedidos - Public Styles
 * Frontend CSS for forms, tables, and user interface
 *
 * @package CoagrisanPedidos
 * @version 1.0.0
 */

/* ==========================================================================
   Variables & Root Styles
   ========================================================================== */
:root {
    --cp-primary: #2271b1;
    --cp-primary-hover: #135e96;
    --cp-success: #00a32a;
    --cp-warning: #f0b849;
    --cp-error: #d63638;
    --cp-info: #72aee6;
    --cp-gray-100: #f9fafb;
    --cp-gray-200: #f3f4f6;
    --cp-gray-300: #e5e7eb;
    --cp-gray-400: #d1d5db;
    --cp-gray-500: #9ca3af;
    --cp-gray-600: #6b7280;
    --cp-gray-700: #4b5563;
    --cp-gray-800: #374151;
    --cp-gray-900: #1f2937;
    --cp-border-radius: 6px;
    --cp-box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
    --cp-box-shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --cp-transition: all 0.3s ease;
}

/* ==========================================================================
   Container & Layout
   ========================================================================== */
.coagrisan-pedidos-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.cp-section {
    background: #fff;
    border-radius: var(--cp-border-radius);
    box-shadow: var(--cp-box-shadow);
    margin-bottom: 30px;
    padding: 30px;
}

.cp-section-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--cp-gray-900);
    margin: 0 0 20px 0;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--cp-gray-200);
}

/* ==========================================================================
   Messages & Alerts
   ========================================================================== */
.cp-message {
    padding: 15px 20px;
    border-radius: var(--cp-border-radius);
    margin-bottom: 20px;
    border-left: 4px solid;
    display: flex;
    align-items: center;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cp-message-success {
    background-color: #ecfdf5;
    border-color: var(--cp-success);
    color: #065f46;
}

.cp-message-error {
    background-color: #fef2f2;
    border-color: var(--cp-error);
    color: #991b1b;
}

.cp-message-warning {
    background-color: #fffbeb;
    border-color: var(--cp-warning);
    color: #92400e;
}

.cp-message-info {
    background-color: #eff6ff;
    border-color: var(--cp-info);
    color: #1e40af;
}

.cp-message::before {
    content: '';
    display: inline-block;
    width: 20px;
    height: 20px;
    margin-right: 12px;
    background-size: contain;
    background-repeat: no-repeat;
    flex-shrink: 0;
}

.cp-message-success::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%2300a32a'%3E%3Cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

.cp-message-error::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23d63638'%3E%3Cpath fill-rule='evenodd' d='M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z' clip-rule='evenodd'/%3E%3C/svg%3E");
}

/* ==========================================================================
   Form Styles
   ========================================================================== */
.cp-form {
    display: grid;
    gap: 20px;
}

.cp-form-row {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr;
}

.cp-form-row.two-columns {
    grid-template-columns: 1fr 1fr;
}

.cp-form-row.three-columns {
    grid-template-columns: 1fr 1fr 1fr;
}

.cp-form-group {
    display: flex;
    flex-direction: column;
}

.cp-form-label {
    font-weight: 600;
    color: var(--cp-gray-700);
    margin-bottom: 8px;
    font-size: 14px;
    display: flex;
    align-items: center;
}

.cp-form-label .required {
    color: var(--cp-error);
    margin-left: 4px;
}

.cp-form-input,
.cp-form-select,
.cp-form-textarea {
    padding: 10px 14px;
    border: 1px solid var(--cp-gray-300);
    border-radius: var(--cp-border-radius);
    font-size: 14px;
    transition: var(--cp-transition);
    background: #fff;
    color: var(--cp-gray-900);
}

.cp-form-input:focus,
.cp-form-select:focus,
.cp-form-textarea:focus {
    outline: none;
    border-color: var(--cp-primary);
    box-shadow: 0 0 0 3px rgba(34, 113, 177, 0.1);
}

.cp-form-input:disabled,
.cp-form-select:disabled,
.cp-form-textarea:disabled {
    background-color: var(--cp-gray-100);
    cursor: not-allowed;
    opacity: 0.6;
}

.cp-form-input.error,
.cp-form-select.error,
.cp-form-textarea.error {
    border-color: var(--cp-error);
}

.cp-form-textarea {
    min-height: 100px;
    resize: vertical;
    font-family: inherit;
}

.cp-form-help {
    font-size: 13px;
    color: var(--cp-gray-600);
    margin-top: 6px;
}

.cp-form-error {
    font-size: 13px;
    color: var(--cp-error);
    margin-top: 6px;
    display: flex;
    align-items: center;
}

.cp-form-error::before {
    content: '⚠';
    margin-right: 4px;
}

/* ==========================================================================
   Buttons
   ========================================================================== */
.cp-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: none;
    border-radius: var(--cp-border-radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--cp-transition);
    text-decoration: none;
    line-height: 1.5;
    gap: 8px;
}

.cp-button-primary {
    background-color: var(--cp-primary);
    color: #fff;
}

.cp-button-primary:hover {
    background-color: var(--cp-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--cp-box-shadow);
}

.cp-button-secondary {
    background-color: var(--cp-gray-200);
    color: var(--cp-gray-700);
}

.cp-button-secondary:hover {
    background-color: var(--cp-gray-300);
}

.cp-button-success {
    background-color: var(--cp-success);
    color: #fff;
}

.cp-button-success:hover {
    background-color: #008a24;
}

.cp-button-danger {
    background-color: var(--cp-error);
    color: #fff;
}

.cp-button-danger:hover {
    background-color: #b91c1c;
}

.cp-button:disabled,
.cp-button.loading {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.cp-button.loading::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.cp-button-block {
    display: flex;
    width: 100%;
}

.cp-button-large {
    padding: 12px 24px;
    font-size: 16px;
}

.cp-button-small {
    padding: 6px 12px;
    font-size: 12px;
}

/* ==========================================================================
   Estado Badges
   ========================================================================== */
.cp-estado {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cp-estado-pendiente {
    background-color: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
}

.cp-estado-procesando {
    background-color: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.cp-estado-completado {
    background-color: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.cp-estado-cancelado {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.cp-estado::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 6px;
}

.cp-estado-pendiente::before {
    background-color: #f59e0b;
}

.cp-estado-procesando::before {
    background-color: #3b82f6;
}

.cp-estado-completado::before {
    background-color: #10b981;
}

.cp-estado-cancelado::before {
    background-color: #ef4444;
}

/* ==========================================================================
   Tables
   ========================================================================== */
.cp-table-container {
    overflow-x: auto;
    margin: 20px 0;
}

.cp-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}

.cp-table thead {
    background-color: var(--cp-gray-100);
    border-bottom: 2px solid var(--cp-gray-300);
}

.cp-table th {
    padding: 12px 16px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--cp-gray-700);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.cp-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--cp-gray-200);
    font-size: 14px;
    color: var(--cp-gray-900);
}

.cp-table tbody tr {
    transition: background-color 0.2s;
}

.cp-table tbody tr:hover {
    background-color: var(--cp-gray-50);
}

.cp-table tbody tr:last-child td {
    border-bottom: none;
}

.cp-table .actions {
    display: flex;
    gap: 8px;
}

.cp-table .action-link {
    color: var(--cp-primary);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: color 0.2s;
}

.cp-table .action-link:hover {
    color: var(--cp-primary-hover);
    text-decoration: underline;
}

.cp-table-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--cp-gray-500);
}

.cp-table-empty-icon {
    font-size: 48px;
    margin-bottom: 10px;
    opacity: 0.3;
}

/* ==========================================================================
   Stats Widgets
   ========================================================================== */
.cp-stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin: 20px 0;
}

.cp-stat-widget {
    background: #fff;
    border-radius: var(--cp-border-radius);
    padding: 24px;
    box-shadow: var(--cp-box-shadow);
    border-left: 4px solid;
    transition: var(--cp-transition);
}

.cp-stat-widget:hover {
    box-shadow: var(--cp-box-shadow-lg);
    transform: translateY(-2px);
}

.cp-stat-widget.total {
    border-color: var(--cp-primary);
}

.cp-stat-widget.pendiente {
    border-color: #f59e0b;
}

.cp-stat-widget.procesando {
    border-color: #3b82f6;
}

.cp-stat-widget.completado {
    border-color: #10b981;
}

.cp-stat-widget-label {
    font-size: 13px;
    color: var(--cp-gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 8px;
}

.cp-stat-widget-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--cp-gray-900);
    margin-bottom: 4px;
}

.cp-stat-widget-description {
    font-size: 12px;
    color: var(--cp-gray-500);
}

/* ==========================================================================
   User Info Box
   ========================================================================== */
.cp-user-info {
    background: linear-gradient(135deg, var(--cp-primary) 0%, #135e96 100%);
    color: #fff;
    border-radius: var(--cp-border-radius);
    padding: 24px;
    margin-bottom: 30px;
    box-shadow: var(--cp-box-shadow);
}

.cp-user-info-name {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.cp-user-info-email {
    font-size: 14px;
    opacity: 0.9;
    margin-bottom: 4px;
}

.cp-user-info-role {
    font-size: 13px;
    opacity: 0.8;
    text-transform: capitalize;
}

/* ==========================================================================
   Pedido Details
   ========================================================================== */
.cp-pedido-details {
    display: grid;
    gap: 20px;
}

.cp-detail-group {
    background: var(--cp-gray-100);
    padding: 16px;
    border-radius: var(--cp-border-radius);
}

.cp-detail-label {
    font-size: 12px;
    color: var(--cp-gray-600);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    margin-bottom: 6px;
}

.cp-detail-value {
    font-size: 15px;
    color: var(--cp-gray-900);
    font-weight: 500;
}

/* ==========================================================================
   Loading States
   ========================================================================== */
.cp-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
    color: var(--cp-gray-500);
}

.cp-loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--cp-gray-300);
    border-top-color: var(--cp-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.cp-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ==========================================================================
   Pagination
   ========================================================================== */
.cp-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 30px;
}

.cp-pagination-button {
    padding: 8px 14px;
    border: 1px solid var(--cp-gray-300);
    background: #fff;
    border-radius: var(--cp-border-radius);
    font-size: 14px;
    cursor: pointer;
    transition: var(--cp-transition);
    color: var(--cp-gray-700);
}

.cp-pagination-button:hover:not(:disabled) {
    background: var(--cp-gray-100);
    border-color: var(--cp-gray-400);
}

.cp-pagination-button.active {
    background: var(--cp-primary);
    color: #fff;
    border-color: var(--cp-primary);
}

.cp-pagination-button:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ==========================================================================
   Responsive Design - Tablet
   ========================================================================== */
@media (max-width: 768px) {
    .coagrisan-pedidos-container {
        padding: 15px;
    }

    .cp-section {
        padding: 20px;
    }

    .cp-section-title {
        font-size: 20px;
    }

    .cp-form-row.two-columns,
    .cp-form-row.three-columns {
        grid-template-columns: 1fr;
    }

    .cp-stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    }

    .cp-stat-widget {
        padding: 16px;
    }

    .cp-stat-widget-value {
        font-size: 28px;
    }

    .cp-table {
        font-size: 13px;
    }

    .cp-table th,
    .cp-table td {
        padding: 10px 12px;
    }

    /* Stack table on smaller screens */
    .cp-table-responsive {
        display: block;
    }

    .cp-table-responsive thead {
        display: none;
    }

    .cp-table-responsive tbody,
    .cp-table-responsive tr,
    .cp-table-responsive td {
        display: block;
        width: 100%;
    }

    .cp-table-responsive tr {
        margin-bottom: 15px;
        border: 1px solid var(--cp-gray-300);
        border-radius: var(--cp-border-radius);
        padding: 10px;
    }

    .cp-table-responsive td {
        text-align: right;
        padding: 8px 10px;
        position: relative;
        border: none;
    }

    .cp-table-responsive td::before {
        content: attr(data-label);
        position: absolute;
        left: 10px;
        font-weight: 600;
        color: var(--cp-gray-700);
        text-align: left;
    }
}

/* ==========================================================================
   Responsive Design - Mobile
   ========================================================================== */
@media (max-width: 480px) {
    .coagrisan-pedidos-container {
        padding: 10px;
    }

    .cp-section {
        padding: 15px;
        margin-bottom: 20px;
    }

    .cp-section-title {
        font-size: 18px;
        padding-bottom: 10px;
        margin-bottom: 15px;
    }

    .cp-stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .cp-message {
        padding: 12px 15px;
        font-size: 13px;
    }

    .cp-button {
        padding: 10px 16px;
        font-size: 13px;
    }

    .cp-button-block {
        width: 100%;
    }

    .cp-user-info {
        padding: 16px;
    }

    .cp-user-info-name {
        font-size: 20px;
    }

    .cp-form-label {
        font-size: 13px;
    }

    .cp-form-input,
    .cp-form-select,
    .cp-form-textarea {
        font-size: 16px; /* Prevent zoom on iOS */
    }

    .cp-table .actions {
        flex-direction: column;
        gap: 4px;
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */
@media print {
    .cp-button,
    .cp-form,
    .cp-pagination {
        display: none !important;
    }

    .cp-section {
        box-shadow: none;
        border: 1px solid var(--cp-gray-300);
    }

    .cp-table {
        font-size: 12px;
    }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */
.cp-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.cp-form-input:focus-visible,
.cp-form-select:focus-visible,
.cp-form-textarea:focus-visible,
.cp-button:focus-visible {
    outline: 2px solid var(--cp-primary);
    outline-offset: 2px;
}

/* ==========================================================================
   Utilities
   ========================================================================== */
.cp-text-center {
    text-align: center;
}

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

.cp-mt-0 { margin-top: 0; }
.cp-mt-10 { margin-top: 10px; }
.cp-mt-20 { margin-top: 20px; }
.cp-mt-30 { margin-top: 30px; }

.cp-mb-0 { margin-bottom: 0; }
.cp-mb-10 { margin-bottom: 10px; }
.cp-mb-20 { margin-bottom: 20px; }
.cp-mb-30 { margin-bottom: 30px; }

.cp-hidden {
    display: none !important;
}

.cp-visible {
    display: block !important;
}
