/**
 * AGM Gutenberg Blocks - Frontend Styles
 * Styles for blocks on the frontend with responsive design
 */

/* Base Block Styles */
.agm-service-block {
    position: relative;
    margin-bottom: 2rem;
    border-radius: 4px;
    overflow: hidden;
}

.agm-service-block * {
    box-sizing: border-box;
}

/* Block Header */
.agm-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background-color: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}

.agm-service-title {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: #212529;
}

.agm-token-cost {
    font-size: 0.875rem;
    color: #dc3545;
    font-weight: 600;
    background-color: #fff;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    border: 1px solid #dc3545;
}

/* Block Content */
.agm-block-content {
    position: relative;
    transition: opacity 0.3s ease;
}

.agm-block-content.agm-loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Parameter Form */
.agm-parameter-form {
    padding: 1.5rem;
    background-color: #fff;
    border: 1px solid #dee2e6;
}

.agm-param-field {
    margin-bottom: 1.5rem;
}

.agm-param-field:last-child {
    margin-bottom: 1rem;
}

.agm-param-field label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #495057;
}

.agm-param-field .required {
    color: #dc3545;
    margin-left: 2px;
}

.agm-param-field input,
.agm-param-field textarea,
.agm-param-field select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid #ced4da;
    border-radius: 4px;
    font-size: 1rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.agm-param-field input:focus,
.agm-param-field textarea:focus,
.agm-param-field select:focus {
    outline: 0;
    border-color: #80bdff;
    box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}

.agm-param-field textarea {
    min-height: 100px;
    resize: vertical;
}

.agm-param-description {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.875rem;
    color: #6c757d;
    line-height: 1.4;
}

.agm-execute-button {
    background-color: #007cba;
    color: #fff;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

.agm-execute-button:hover {
    background-color: #005a87;
}

.agm-execute-button:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
}

/* Loading State */
.agm-loading-state {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 10;
}

.agm-spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #007cba;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.agm-loading-state span {
    margin-top: 0.75rem;
    color: #495057;
    font-weight: 500;
}

/* Error State */
.agm-error-state {
    padding: 1rem;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #721c24;
}

.agm-error-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.agm-error-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
}

.agm-error-text {
    flex: 1;
    line-height: 1.4;
}

.agm-retry-button {
    background-color: #dc3545;
    color: #fff;
    border: none;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    border-radius: 3px;
    cursor: pointer;
    flex-shrink: 0;
}

.agm-retry-button:hover {
    background-color: #c82333;
}

/* Output Container */
.agm-output-container {
    padding: 1.5rem;
    background-color: #fff;
    border: 1px solid #dee2e6;
}

/* Output Types */
.agm-image-output img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.agm-video-output video {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
}

.agm-audio-output audio {
    width: 100%;
    max-width: 400px;
}

.agm-document-output {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
}

.agm-document-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.agm-document-icon {
    font-size: 1.5rem;
}

.agm-document-name {
    font-weight: 600;
    color: #495057;
}

.agm-download-button {
    background-color: #28a745;
    color: #fff;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 500;
    transition: background-color 0.15s ease;
}

.agm-download-button:hover {
    background-color: #218838;
    color: #fff;
    text-decoration: none;
}

.agm-json-output pre {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 1rem;
    overflow-x: auto;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.4;
    position: relative;
}

.agm-text-output {
    line-height: 1.6;
    color: #495057;
}

.agm-xml-output pre {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 4px;
    padding: 1rem;
    overflow-x: auto;
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    font-size: 0.875rem;
    line-height: 1.4;
}

.agm-interactive-output {
    border: 1px solid #dee2e6;
    border-radius: 4px;
    overflow: hidden;
}

.agm-custom-output {
    padding: 1rem;
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 4px;
    text-align: center;
}

.agm-custom-info {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.agm-custom-icon {
    font-size: 1.5rem;
}

.agm-custom-description {
    font-weight: 600;
    color: #856404;
}

.agm-custom-link {
    background-color: #ffc107;
    color: #212529;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 500;
    transition: background-color 0.15s ease;
}

.agm-custom-link:hover {
    background-color: #e0a800;
    color: #212529;
    text-decoration: none;
}

.agm-custom-data {
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    padding: 1rem;
    text-align: left;
    font-size: 0.875rem;
    overflow-x: auto;
}

/* Copy Code Button */
.agm-copy-code {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background-color: #6c757d;
    color: #fff;
    border: none;
    padding: 0.25rem 0.5rem;
    border-radius: 3px;
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.15s ease;
}

.agm-copy-code:hover {
    opacity: 1;
}

/* Execution Metadata */
.agm-execution-metadata {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-top: 1rem;
    margin-top: 1rem;
    border-top: 1px solid #dee2e6;
    font-size: 0.875rem;
    color: #6c757d;
}

.agm-tokens-used {
    font-weight: 600;
    color: #dc3545;
}

.agm-execution-time {
    margin-left: auto;
}

/* Placeholder States */
.agm-block-placeholder,
.agm-login-required {
    padding: 2rem;
    text-align: center;
    background-color: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
}

.agm-placeholder-icon,
.agm-login-icon {
    font-size: 2rem;
    margin-bottom: 1rem;
    display: block;
}

.agm-placeholder-message,
.agm-login-message {
    font-size: 1.125rem;
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
}

.agm-login-details {
    font-size: 0.875rem;
    color: #6c757d;
}

/* Error Output */
.agm-output-error {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #721c24;
}

.agm-image-error {
    padding: 1rem;
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #721c24;
    text-align: center;
}

/* Responsive Design */
@media (max-width: 768px) {
    .agm-block-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .agm-parameter-form {
        padding: 1rem;
    }
    
    .agm-document-output {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }
    
    .agm-execution-metadata {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .agm-execution-time {
        margin-left: 0;
    }
}

@media (max-width: 480px) {
    .agm-service-block {
        margin-bottom: 1.5rem;
    }
    
    .agm-parameter-form {
        padding: 0.75rem;
    }
    
    .agm-param-field input,
    .agm-param-field textarea,
    .agm-param-field select {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    .agm-execute-button {
        width: 100%;
        padding: 1rem;
    }
}

/* Responsive Tables */
.agm-table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
}

.agm-table-wrapper table {
    min-width: 600px;
    width: 100%;
    border-collapse: collapse;
}

.agm-table-wrapper th,
.agm-table-wrapper td {
    padding: 0.75rem;
    border: 1px solid #dee2e6;
    text-align: left;
}

.agm-table-wrapper th {
    background-color: #f8f9fa;
    font-weight: 600;
}

/* Responsive Iframes */
.agm-iframe-wrapper {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    overflow: hidden;
}

.agm-iframe-wrapper iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Accessibility */
.agm-service-block:focus-within {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

.agm-execute-button:focus,
.agm-download-button:focus,
.agm-retry-button:focus {
    outline: 2px solid #007cba;
    outline-offset: 2px;
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .agm-service-block {
        border: 2px solid #000;
    }
    
    .agm-block-header {
        border-bottom-width: 2px;
    }
    
    .agm-parameter-form {
        border-width: 2px;
    }
    
    .agm-param-field input,
    .agm-param-field textarea,
    .agm-param-field select {
        border-width: 2px;
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .agm-spinner {
        animation: none;
    }
    
    .agm-block-content {
        transition: none;
    }
    
    * {
        transition: none !important;
    }
}

/* Print Styles */
@media print {
    .agm-loading-state,
    .agm-error-state,
    .agm-parameter-form {
        display: none !important;
    }
    
    .agm-service-block {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    .agm-execute-button,
    .agm-download-button,
    .agm-retry-button,
    .agm-copy-code {
        display: none;
    }
}