/**
 * AnswerRails Admin CSS - Grid Layout System
 * 12-column responsive grid for admin interface
 */

/* ========================================
   12-COLUMN GRID SYSTEM
   ======================================== */

.answerrails-grid-container {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    gap: 20px;
    margin-top: 20px;
    max-width: 100%;
}
.answerrails-span-3 { grid-column: span 3; }
.answerrails-span-4 { grid-column: span 4; }
.answerrails-span-6 { grid-column: span 6; }
.answerrails-span-8 { grid-column: span 8; }
/* There is no span-12 rule: nothing in the admin markup spans 12. */

/* ========================================
   CARD STYLING
   ======================================== */

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

.answerrails-card h3 {
    margin: 0 0 15px 0;
    font-size: 14px;
    font-weight: 600;
    color: #1d2327;
    border-bottom: 1px solid #f0f0f1;
    padding-bottom: 10px;
}

/* Time Range Toggle */
.time-range-toggle {
    display: flex;
    gap: 5px;
}

.time-range-toggle a {
    padding: 6px 12px;
    background: #f0f0f1;
    color: #50575e;
    text-decoration: none;
    border-radius: 3px;
    transition: all 0.2s;
}

.time-range-toggle a:hover {
    background: #e0e0e0;
    color: #2c3338;
}

.time-range-toggle a.active {
    background: #2271b1;
    color: #fff;
}

/* ========================================
   MASTER STATUS WIDGETS
   ======================================== */

.master-status-alert {
    background: #fcf0f1;
    border-left: 4px solid #dc3232;
    padding: 12px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: flex-start;
    gap: 12px;
}

.master-status-alert .dashicons {
    color: #dc3232;
    font-size: 20px;
}

.master-status-alert strong {
    display: block;
    margin-bottom: 5px;
}

.master-status-alert p {
    margin: 0;
    color: #50575e;
}

.master-status-active {
    background: #edfaef;
    border: 1px solid #46b450;
    border-radius: 3px;
    padding: 8px 12px;
    margin-bottom: 20px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #46b450;
    font-weight: 500;
}

.master-status-active .dashicons {
    font-size: 18px;
}

/* ========================================
   RESPONSIVE BREAKPOINTS
   ======================================== */

/* Tablet (1024px and below) */
@media (max-width: 1024px) {
    .answerrails-grid-container {
        grid-template-columns: repeat(8, 1fr);
    }
    
    /* Adjust spans for the 8-column layout. */
    .answerrails-span-3 { grid-column: span 4; }
    .answerrails-span-4 { grid-column: span 4; }
    .answerrails-span-6 { grid-column: span 4; }
    .answerrails-span-8 { grid-column: span 8; }
}

/* Mobile (768px and below) */
@media (max-width: 768px) {
    .answerrails-grid-container {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    /* All cards full width on mobile */
    [class*="answerrails-span-"] {
        grid-column: span 1;
    }
    
    .time-range-toggle {
        width: 100%;
    }
    
    .time-range-toggle a {
        flex: 1;
        text-align: center;
    }
}

.answerrails-avatar-control {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    max-width: 420px;
}

.answerrails-avatar-preview {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    background: #f0f0f1;
    border: 1px solid #dcdcde;
    display: flex;
    align-items: center;
    justify-content: center;
}

.answerrails-avatar-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.answerrails-avatar-actions {
    display: flex;
    gap: 8px;
}

.answerrails-settings-section {
    display: none;
}

.answerrails-settings-section.active {
    display: block;
}

.answerrails-settings-section h2 {
    margin-top: 0;
    padding-bottom: 10px;
    border-bottom: 1px solid #f0f0f1;
}

/* ========================================
   LOADING STATES
   ======================================== */

.answerrails-loading {
    opacity: 0.6;
    pointer-events: none;
}

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

/* ========================================
   WORDPRESS ADMIN COMPATIBILITY
   ======================================== */

/* Ensure our styles work within WP Admin */
.wrap .answerrails-grid-container {
    margin-left: 0;
    margin-right: 0;
}

/* Override WP default margins */
.answerrails-card .notice {
    margin: 10px 0;
}

/* Ensure proper spacing with WP notices */
.wrap > .notice,
.wrap > div.updated,
.wrap > div.error {
    margin: 15px 0 20px 0;
}

/* --- #122: visually hidden (admin twin of the widget utility) ---
   Keeps text in the accessibility tree while rendering nothing (badge SR
   twins, live confirmations). NEVER swap for display:none — that removes
   it from the accessibility tree entirely. */
.ar-visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0);
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0 !important;
}

/* --- #122: contrast guard warning (settings colour fields) --- */
.ar-contrast-warning {
    margin: 6px 0 0;
    padding: 6px 10px;
    border-left: 4px solid #996800;
    background: #fcf9e8;
    color: #1d2327;
    max-width: 480px;
}

.ar-contrast-warning[hidden] {
    display: none;
}

.ar-contrast-warning .ar-contrast-fix {
    text-decoration: underline;
    cursor: pointer;
}

/* --- #129: built-in default preview + restore control --- */
.ar-default-preview {
    margin: 6px 0 2px;
    max-width: 640px;
}

.ar-default-preview summary {
    cursor: pointer;
    color: #2271b1;
}

.ar-default-preview .ar-default-text {
    white-space: pre-wrap;
    background: #f6f7f7;
    border: 1px solid #dcdcde;
    padding: 8px 10px;
    margin: 6px 0 0;
    font-family: inherit;
    font-size: 12px;
}

.ar-restore-default {
    cursor: pointer;
}

/* ================================================================
   #139 Batch 5 — merged from assets/css/admin-ajax.css.
   Debt-tracker Low #4 (Asset Organization): the two stylesheets were
   enqueued together on every AnswerRails screen as a duplicate pair.
   One file, one enqueue. Orphan rules were pruned BEFORE the merge.
   ================================================================ */

/**
 * AnswerRails Admin AJAX Styles
 * 
 * Styles for the admin interface including API health dashboard,
 * status indicators, and interactive elements
 */

/* === API HEALTH DASHBOARD === */

.api-health-widget {
    background: #fff;
    border: 1px solid #c3c4c7;
    border-radius: 4px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 1px rgba(0,0,0,.04);
}

.api-health-widget h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 600;
}

/* #382 D4: the heading row carries the panel's guide link */
.api-health-widget .ar-health-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 4px 12px;
    margin-bottom: 15px;
}

.api-health-widget .ar-health-heading h3 {
    margin-bottom: 0;
}

.api-health-widget .ar-health-guide-link .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    vertical-align: text-bottom;
}

.api-status-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

.api-status-card {
    background: #f8f9fa;
    border: 1px solid #e1e5e9;
    border-radius: 6px;
    padding: 20px;
    position: relative;
}

.api-status-card h4 {
    margin: 0 0 15px 0;
    font-size: 14px;
    font-weight: 600;
    color: #1e1e1e;
}

.api-status-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 500;
    margin-bottom: 15px;
}

.api-status-healthy {
    background: #d1e7dd;
    color: #0f5132;
    border: 1px solid #badbcc;
}

/* #377 D6: requests succeed again; the counted calls still hold the outage. WordPress's info blue. */
.api-status-recovering {
    background: #e7f1fa;
    color: #2271b1;
    border: 1px solid #c5d9ed;
}

.api-status-degraded {
    background: #fff3cd;
    color: #664d03;
    border: 1px solid #ffecb5;
}

.api-status-down {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c2c7;
}

.api-metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 15px;
    margin-bottom: 15px;
}

.api-metric {
    text-align: center;
    padding: 10px;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.api-metric-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
}

.api-metric-value {
    font-size: 16px;
    font-weight: 600;
    color: #1e1e1e;
}

.api-error-details {
    margin-top: 15px;
    padding: 10px;
    background: #fff5f5;
    border: 1px solid #fed7d7;
    border-radius: 4px;
    font-size: 12px;
    color: #742a2a;
    display: none;
}

.api-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #e1e5e9;
}

.api-actions .button {
    font-size: 13px;
    padding: 6px 12px;
    height: auto;
}

.button-test-apis {
    background: #007cba;
    border-color: #005a87;
    color: #fff;
}

.button-test-apis:hover {
    background: #005a87;
    border-color: #004065;
}

/* === OVERALL STATUS INDICATOR === */

#api-overall-status {
    display: inline-flex;
    align-items: center;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 20px;
}

#api-status-updated {
    font-size: 12px;
    color: #666;
    margin-left: 15px;
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    color: #1e1e1e;
    line-height: 1;
}


/* === SETTINGS VALIDATION === */

.field-status {
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 13px;
    display: none;
}

.field-status-success {
    background: #d1e7dd;
    color: #0f5132;
    border: 1px solid #badbcc;
}

.field-status-warning {
    background: #fff3cd;
    color: #664d03;
    border: 1px solid #ffecb5;
}

.field-status-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c2c7;
}

.field-status .dashicons {
    margin-right: 5px;
}

.field-status .spinner {
    float: none;
    margin: 0 5px 0 0;
    vertical-align: middle;
}

/* === CONNECTION TEST RESULTS === */

#connection-test-result {
    margin-top: 15px;
    padding: 15px;
    border-radius: 4px;
    background: #f8f9fa;
    border: 1px solid #e1e5e9;
    font-size: 13px;
    display: none;
}

#connection-test-result.success {
    background: #d1e7dd;
    border-color: #badbcc;
    color: #0f5132;
}

#connection-test-result.error {
    background: #f8d7da;
    border-color: #f5c2c7;
    color: #721c24;
}

/* === LOADING OVERLAY === */

.answerrails-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999999;
    display: none;
}

.answerrails-loading-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    min-width: 250px;
}

.answerrails-loading-content .spinner {
    float: none;
    margin: 0 auto 15px auto;
    display: block;
}

.answerrails-loading-content p {
    margin: 0;
    font-size: 14px;
    color: #666;
}

/* === ADMIN NOTICES === */

#answerrails-admin-notices {
    margin: 20px 0;
}

#answerrails-admin-notices .notice {
    margin: 5px 0;
}

/* === FORM FIELD GROUPS === */
.form-field-group {
    display: flex;
    gap: 15px;
    align-items: end;
    margin-bottom: 15px;
}

.form-field-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-field-group select,
.form-field-group input[type="number"] {
    width: 120px;
}

/* === RESPONSIVE DESIGN === */

@media (max-width: 768px) {
    .api-status-overview {
        grid-template-columns: 1fr;
    }
    
    
    .api-metrics-grid {
        grid-template-columns: 1fr;
    }
    
    .form-field-group {
        flex-direction: column;
        align-items: stretch;
    }
    
    .form-field-group select,
    .form-field-group input[type="number"] {
        width: 100%;
    }
}

@media (max-width: 480px) {
    
    .api-actions {
        flex-direction: column;
    }
    
    .api-actions .button {
        width: 100%;
        margin-bottom: 10px;
    }
}

/* === ANIMATIONS === */

.api-status-card {
    transition: box-shadow 0.2s ease;
}

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

.api-status-badge {
    transition: all 0.3s ease;
}

.button {
    transition: all 0.2s ease;
}

.field-status {
    animation: slideDown 0.3s ease;
}

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

/* === ACCESSIBILITY === */

.api-status-badge:focus,
.button:focus {
    outline: 2px solid #005a87;
    outline-offset: 2px;
}

.field-status {
    /* Ensure sufficient color contrast */
    font-weight: 500;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .api-status-healthy {
        background: #000;
        color: #fff;
        border-color: #000;
    }
    
    .api-status-recovering {
        background: #003366;
        color: #fff;
        border-color: #003366;
    }

    .api-status-degraded {
        background: #663300;
        color: #fff;
        border-color: #663300;
    }
    
    .api-status-down {
        background: #990000;
        color: #fff;
        border-color: #990000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

.hidden {
    display: none !important;
}

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

/* WordPress admin compatibility */
.wrap .api-health-widget {
    margin-top: 0;
}

.wrap .api-health-widget:first-child {
    margin-top: 0;
}
/* === Retrieval resilience: pipeline strip + stage cards (#88/#89) === */
.ar-pipeline {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 16px;
    padding: 10px 12px;
    background: #f6f7f7;
    border: 1px solid #dcdcde;
    border-radius: 4px;
}

.ar-pipe-stage {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-start;
    font-weight: 600;
    font-size: 12px;
    line-height: 1.4;
    cursor: help;
}

.ar-pipe-stage small {
    font-weight: 400;
    color: #646970;
}

.ar-pipe-stage small.ar-pipe-fallback-live {
    color: #996800;
    font-weight: 600;
}

/* #99: owner-language failure diagnosis on the Chat card */
.ar-chat-diagnosis {
    margin: 8px 0 0;
    padding: 8px 10px;
    border-radius: 4px;
    background: #fcf9e8;
    border-left: 4px solid #dba617;
    font-size: 12px;
    color: #1d2327;
}

/* #92: unmissable testing-override badge on the Retrieval card */
.ar-override-badge {
    display: inline-block;
    background: #996800;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 3px;
    margin-left: 6px;
    vertical-align: middle;
}

.ar-pipe-arrow {
    color: #8c8f94;
    font-size: 14px;
}

.ar-pipe-dot {
    display: inline-block;
    width: 9px;
    height: 9px;
    border-radius: 50%;
    margin-right: 5px;
    vertical-align: baseline;
}

.ar-dot-healthy { background: #00a32a; }
.ar-dot-recovering { background: #2271b1; } /* #377 D6 */
.ar-dot-degraded { background: #dba617; }
.ar-dot-down { background: #d63638; }
.ar-dot-unknown { background: #8c8f94; }

.ar-model-badge {
    display: inline-block;
    font-family: Consolas, Monaco, monospace;
    font-size: 11px;
    font-weight: 400;
    color: #2271b1;
    background: #f0f6fc;
    border: 1px solid #c5d9ed;
    border-radius: 3px;
    padding: 1px 6px;
    margin-left: 6px;
}

.ar-fallback-note {
    font-weight: 600;
    font-style: italic;
}

.ar-fallback-count {
    margin: 8px 0 0;
    font-size: 12px;
    color: #996800;
    cursor: help;
}

.ar-store-state {
    margin: 6px 0 0;
    font-size: 12px;
    color: #646970;
}

.ar-api-details {
    margin-top: 10px;
    border-top: 1px solid #dcdcde;
    padding-top: 8px;
}

.ar-api-details summary {
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: #2271b1;
}

.ar-explainer-text {
    font-size: 12px;
    color: #50575e;
    margin: 8px 0;
}

.ar-subcards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px;
    margin-top: 8px;
}

.ar-subcard {
    margin: 0;
}

.api-metric {
    cursor: help;
}

.api-status-unknown {
    background: #f0f0f1;
    color: #50575e;
    border: 1px solid #dcdcde;
}
