/* ==========================================================================
   MCB Order Verificatie - Fluent UI Custom Styles
   Using Fluent UI Web Components with custom overrides
   ========================================================================== */

/* Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--body-font, 'Segoe UI'), -apple-system, BlinkMacSystemFont, 'Roboto', sans-serif;
    background: var(--neutral-layer-1, #F3F2F1);
    color: var(--neutral-foreground-rest, #323130);
}

.hidden {
    display: none !important;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.addin-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    width: 100%;
    max-width: 450px;
    margin: 0 auto;
}

/* ==========================================================================
   Header
   ========================================================================== */

.addin-header {
    background: var(--accent-fill-rest, #0078D4);
    color: white;
    padding: 12px 16px;
    border-bottom: 1px solid var(--accent-fill-hover, #106EBE);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.addin-header h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

/* Environment-specific header colors */
.addin-header[data-env="local"] {
    background: #1B5E20;
    border-bottom-color: #0D3B13;
}
.addin-header[data-env="dev"] {
    background: #4CAF50;
    border-bottom-color: #388E3C;
}
.addin-header[data-env="qas"] {
    background: #000000;
    border-bottom-color: #333333;
}
.addin-header:not([data-env="prod"]):not([data-env="local"]):not([data-env="dev"]):not([data-env="qas"]) {
    background: #E65100;
    border-bottom-color: #BF360C;
}

.admin-gear-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    line-height: 1;
    transition: color 0.15s, background 0.15s;
}
.admin-gear-btn:hover {
    color: white;
    background: rgba(255,255,255,0.15);
}

/* ==========================================================================
   Email ID Card
   ========================================================================== */

.email-id-card {
    margin: 0;
    padding: 10px 16px;
    background: #FFF4CE;
    border: 1px solid #FFE69C;
    border-radius: 0;
}

.email-id-display {
    font-size: 12px;
    color: #323130;
    overflow-wrap: break-word;
    word-break: break-all;
}

.email-id-display strong {
    color: #8A8886;
    font-family: 'Segoe UI', sans-serif;
    margin-right: 8px;
}

.email-id-display span {
    font-family: 'Courier New', monospace;
}

/* ==========================================================================
   Order Content Area
   ========================================================================== */

.order-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: var(--neutral-layer-1, #FAF9F8);
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 16px;
}

.order-content::-webkit-scrollbar {
    width: 10px;
}

.order-content::-webkit-scrollbar-track {
    background: var(--neutral-layer-2, #F3F2F1);
}

.order-content::-webkit-scrollbar-thumb {
    background: var(--neutral-fill-stealth-active, #C8C6C4);
    border-radius: 5px;
}

.order-content::-webkit-scrollbar-thumb:hover {
    background: var(--neutral-fill-stealth-hover, #A19F9D);
}

/* Success Message */
.order-success-message {
    margin: 0 auto;
    padding: 12px 20px;
    background: rgba(16, 124, 16, 0.15);
    color: #107C10;
    border: 1px solid rgba(16, 124, 16, 0.3);
    border-radius: 4px;
    font-size: 14px;
    text-align: center;
    font-weight: 600;
    width: fit-content;
    max-width: 90%;
    animation: slideDown 0.3s ease;
}

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

/* Order Data Wrapper */
.order-data-wrapper {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ==========================================================================
   Order Table Container
   ========================================================================== */

.order-table-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Order Type Toggle */
.order-type-toggle-container {
    display: flex;
    justify-content: center;
}

.order-type-toggle {
    display: inline-flex;
    gap: 4px;
}

/* AI Processing Info */
.ai-processing-info {
    background: var(--neutral-layer-3, #EDEBE9);
    color: var(--neutral-foreground-rest, #605E5C);
    font-size: 12px;
    padding: 8px 12px;
    border-radius: 4px;
    text-align: center;
}

/* Order Table */
.order-table {
    background: white;
    border-radius: 4px;
    overflow: hidden;
    box-shadow: var(--elevation-shadow-card-rest, 0 1px 3px rgba(0, 0, 0, 0.1));
}

.order-table-body {
    display: flex;
    flex-direction: column;
}

/* Product Row - Vertical Layout */
.product-row {
    border-bottom: 2px solid var(--neutral-stroke-divider-rest, #EDEBE9);
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.product-row:last-child {
    border-bottom: none;
}

/* Row 1: Article Number (full width) */
.product-row-article {
    display: flex;
}

.product-row-article fluent-text-field {
    width: 100%;
}

/* Row 2: Quantity, Unit, Price (side by side) */
.product-row-fields {
    display: grid;
    grid-template-columns: 1fr 1fr 1.2fr;
    gap: 8px;
}

.product-field {
    display: flex;
    align-items: center;
}

.product-field fluent-text-field,
.product-field fluent-number-field {
    width: 100%;
}

/* Price field with € symbol */
.product-field-price {
    position: relative;
}

.price-symbol {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    font-weight: 600;
    color: var(--neutral-foreground-rest, #605E5C);
    z-index: 1;
    pointer-events: none;
}

.product-field-price fluent-number-field {
    padding-left: 20px;
}

/* Price info icon and tooltip */
.price-info-icon {
    position: absolute;
    right: 4px;
    top: 4px;
    width: 16px;
    height: 16px;
    background: var(--accent-fill-rest, #0078D4);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    font-family: 'Segoe UI', sans-serif;
    z-index: 2;
}

.price-info-icon::before {
    content: 'i';
}

.price-tooltip {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    padding: 6px 10px;
    background: #323130;
    color: white;
    font-size: 12px;
    font-weight: 400;
    white-space: nowrap;
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    z-index: 1000;
}

.price-info-icon:hover .price-tooltip:not(:empty) {
    opacity: 1;
    visibility: visible;
}

/* Unit error styling */
.unit-error-field {
    --neutral-fill-input-rest: #FDE7E9;
    --neutral-stroke-rest: #D13438;
}

.unit-error-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #FDE7E9;
    border: 1px solid #D13438;
    border-radius: 4px;
    padding: 6px 10px;
}

.unit-error-icon {
    position: relative;
    width: 16px;
    height: 16px;
    min-width: 16px;
    background: #D13438;
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    cursor: default;
}

.unit-error-icon::before {
    content: '!';
}

.unit-error-tooltip {
    position: absolute;
    bottom: 100%;
    left: 0;
    margin-bottom: 8px;
    padding: 6px 10px;
    background: #323130;
    color: white;
    font-size: 12px;
    font-weight: 400;
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
    pointer-events: none;
    z-index: 1000;
    max-width: 250px;
    white-space: normal;
}

.unit-error-icon:hover .unit-error-tooltip {
    opacity: 1;
    visibility: visible;
}

.unit-error-message {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: #A4262C;
}

.btn-reload-unit {
    min-width: 28px;
    height: 28px;
    padding: 0;
    font-size: 14px;
}

/* Hide number field increment buttons */
fluent-number-field::part(controls) {
    display: none;
}

/* Row 3: Description and Delete Button */
.product-row-description {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.product-description-text {
    font-size: 13px;
    color: #323130;
    font-weight: 500;
    flex: 1;
}

/* Add Row Button Container */
.add-row-container {
    display: flex;
    justify-content: flex-end;
    margin-top: 8px;
    gap: 8px;
}

#btn-reload-cart {
    min-width: 28px;
    height: 28px;
    padding: 0;
    font-size: 14px;
}

/* Empty State */
.order-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--neutral-foreground-hint, #A19F9D);
    font-size: 14px;
    text-align: center;
}

/* CSS-only Loading Spinner */
.loading-spinner-css {
    width: 28px;
    height: 28px;
    border: 3px solid var(--neutral-stroke-rest, #E1DFDD);
    border-top-color: var(--accent-fill-rest, #0078D4);
    border-radius: 50%;
    animation: spin-loader 0.8s linear infinite;
}

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

/* Diagnostic Panel */
.diag-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 50vh;
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    overflow-y: auto;
    z-index: 9999;
    border-top: 2px solid #0078D4;
    display: none;
}

.diag-panel.visible {
    display: block;
}

.diag-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 8px;
    background: #252526;
    position: sticky;
    top: 0;
}

.diag-panel-header span {
    font-weight: 600;
    color: #0078D4;
}

.diag-panel-close {
    background: none;
    border: none;
    color: #d4d4d4;
    font-size: 14px;
    cursor: pointer;
    padding: 2px 6px;
}

.diag-panel-body {
    padding: 4px 8px;
    white-space: pre-wrap;
    word-break: break-all;
}

.diag-log { color: #d4d4d4; }
.diag-warn { color: #cca700; }
.diag-error { color: #f48771; }
.diag-info { color: #75beff; }

/* ==========================================================================
   Accordions (Leveringen, Klant Details, Feedback)
   ========================================================================== */

.section-accordion {
    border-radius: 4px;
    overflow: hidden;
}

.accordion-heading {
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.accordion-title {
    font-size: 14px;
    font-weight: 600;
}

.accordion-content {
    padding: 16px;
}

/* ==========================================================================
   Leveringen Section (Read-only)
   ========================================================================== */

/* Delivery Fields */
.delivery-field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.delivery-field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.delivery-field-label {
    font-size: 12px;
    color: var(--neutral-foreground-rest, #605E5C);
    font-weight: 600;
}

.delivery-field-value {
    font-size: 13px;
    color: var(--neutral-foreground-rest, #323130);
    font-weight: 500;
}

/* Accordion status styling */
.delivery-accordion-ok::part(heading) {
    background: rgba(16, 124, 16, 0.08);
}

.delivery-accordion-warning::part(heading) {
    background: rgba(209, 52, 56, 0.08);
}

.delivery-accordion-unknown::part(heading) {
    background: rgba(96, 94, 92, 0.08);
}

/* Delivery Status Unknown (Scenario 0 - cart failed) */
.delivery-status-unknown {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.delivery-status-message-unknown {
    color: #605E5C;
    background: rgba(96, 94, 92, 0.15);
    border: 1px solid rgba(96, 94, 92, 0.3);
}

/* Delivery Status OK (Scenario 1) */
.delivery-status-ok {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.delivery-status-message {
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 4px;
}

.delivery-status-message-ok {
    color: #107C10;
    background: rgba(16, 124, 16, 0.15);
    border: 1px solid rgba(16, 124, 16, 0.3);
}

/* Delivery Status Warning (Scenario 2) */
.delivery-status-warning {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.delivery-status-message-warning {
    color: #A4262C;
    background: #FDE7E9;
    border: 1px solid #D13438;
}

/* Per-product delivery rows */
.delivery-product-rows {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.delivery-product-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    background: var(--neutral-layer-2, #F3F2F1);
    border-radius: 4px;
    font-size: 12px;
}

.delivery-product-article {
    font-weight: 600;
    color: var(--neutral-foreground-rest, #323130);
    font-family: 'Courier New', monospace;
}

.delivery-product-date {
    color: var(--neutral-foreground-rest, #605E5C);
}

.delivery-location-blocks {
    display: flex;
    gap: 4px;
}

.delivery-location-block {
    padding: 3px 8px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 700;
    text-align: center;
    min-width: 30px;
}

.delivery-location-ok {
    background: rgba(16, 124, 16, 0.15);
    color: #107C10;
    border: 1px solid rgba(16, 124, 16, 0.3);
}

.delivery-location-error {
    background: #FDE7E9;
    color: #A4262C;
    border: 1px solid #D13438;
}

/* ==========================================================================
   Klant Details Section
   ========================================================================== */

.klant-details-row {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 13px;
}

.klant-details-row:last-child {
    margin-bottom: 0;
}

.klant-details-label {
    font-weight: 600;
    color: var(--neutral-foreground-rest, #605E5C);
    min-width: 60px;
    flex-shrink: 0;
}

.klant-details-value {
    color: var(--neutral-foreground-rest, #323130);
    word-break: break-word;
}

/* Klant Warning Banner */
.klant-warning {
    background: #FDE7E9;
    border: 1px solid #D13438;
    border-radius: 4px;
    padding: 12px;
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.klant-warning-text {
    font-size: 13px;
    font-weight: 600;
    color: #A4262C;
}

.btn-reload-customer {
    align-self: flex-start;
}

/* Order Status Banners */
.order-status-banner-success,
.order-status-banner-rejected {
    border-radius: 4px;
    padding: 14px 16px;
    text-align: center;
}

.order-status-banner-success {
    background: rgba(16, 124, 16, 0.15);
    border: 1px solid rgba(16, 124, 16, 0.3);
}

.order-status-banner-rejected {
    background: #FDE7E9;
    border: 1px solid #D13438;
}

.order-status-banner-text {
    font-size: 14px;
    font-weight: 600;
}

.order-status-banner-success .order-status-banner-text {
    color: #107C10;
}

.order-status-banner-rejected .order-status-banner-text {
    color: #A4262C;
}

.toon-data-container {
    display: flex;
    justify-content: center;
    margin-top: 12px;
}

/* ==========================================================================
   Action Buttons
   ========================================================================== */

.order-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.btn-verzenden {
    flex: 1;
    --accent-fill-rest: #107C10;
    --accent-fill-hover: #0E6B0E;
    --accent-fill-active: #0C5A0C;
    --focus-stroke-outer: #107C10;
    --focus-stroke-inner: #107C10;
}

.btn-verzenden::part(control) {
    border: none;
    outline: none;
}

.btn-afwijzen {
    flex: 1;
    --accent-fill-rest: #D13438;
    --accent-fill-hover: #B92B2F;
    --accent-fill-active: #A12327;
    --focus-stroke-outer: #D13438;
    --focus-stroke-inner: #D13438;
}

.btn-afwijzen::part(control) {
    border: none;
    outline: none;
}

.btn-icon {
    margin-right: 4px;
}

/* ==========================================================================
   Feedback Section
   ========================================================================== */

.feedback-section {
    flex-shrink: 0;
}

.feedback-rating {
    display: flex;
    justify-content: center;
    gap: 12px;
}

.feedback-btn {
    padding: 6px 6px;
    font-size: 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    background: transparent;
}

.feedback-btn.selected {
    background: var(--neutral-layer-3, #EDEBE9);
}

.feedback-btn-up.selected {
    background: rgba(16, 124, 16, 0.15);
}

.feedback-btn-down.selected {
    background: rgba(209, 52, 56, 0.15);
}

.btn-feedback-save {
    width: 100%;
    margin-top: 12px;
}

.feedback-success {
    margin-top: 12px;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    color: #107C10;
}

.feedback-section fluent-text-area {
    margin-top: 8px;
}

/* ==========================================================================
   Fluent UI Component Custom Styling
   ========================================================================== */

/* Make text fields and buttons full width in specific contexts */
fluent-text-field,
fluent-number-field {
    width: 100%;
}

fluent-text-area {
    width: 100%;
}

/* Button icon spacing */
fluent-button .btn-icon {
    display: inline-flex;
    align-items: center;
}

/* Accordion styling tweaks */
fluent-accordion-item::part(heading) {
    font-weight: 600;
}

/* Card tweaks */
fluent-card {
    --card-padding: 0;
}

/* ==========================================================================
   Processing Steps & Error State
   ========================================================================== */

.processing-steps {
    background: var(--neutral-layer-2, #F3F2F1);
    border-radius: 6px;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
}

.processing-step {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.processing-step .step-icon {
    width: 20px;
    height: 20px;
    min-width: 20px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
}

.step-done .step-icon {
    background: #107C10;
    color: white;
}

.step-done .step-icon::after {
    content: '\2713';
}

.step-active .step-icon {
    background: var(--accent-fill-rest, #0078D4);
    color: white;
    animation: pulse-step 1.2s ease-in-out infinite;
}

.step-active .step-icon::after {
    content: '\2026';
}

@keyframes pulse-step {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.step-pending .step-icon {
    background: var(--neutral-fill-stealth-active, #C8C6C4);
    color: white;
}

.step-label-done {
    color: #107C10;
    font-weight: 600;
}

.step-label-active {
    color: var(--accent-fill-rest, #0078D4);
    font-weight: 600;
}

.step-label-pending {
    color: var(--neutral-foreground-hint, #A19F9D);
}

/* Error State */
.processing-error-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px 20px;
    gap: 12px;
    text-align: center;
}

.processing-error-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #D13438;
    color: white;
    font-size: 22px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.processing-error-message {
    font-size: 14px;
    font-weight: 600;
    color: #A4262C;
    max-width: 300px;
    word-break: break-word;
}

/* Service error detail toggle & block */
.service-error-toggle {
    font-size: 12px;
    color: #0078D4;
    cursor: pointer;
    text-decoration: none;
}

.service-error-toggle:hover {
    text-decoration: underline;
}

.service-error-detail {
    max-width: 100%;
    max-height: 150px;
    overflow: auto;
    background: #F3F2F1;
    border: 1px solid #E1DFDD;
    border-radius: 4px;
    padding: 8px 10px;
    font-size: 11px;
    font-family: 'Courier New', monospace;
    color: #605E5C;
    white-space: pre-wrap;
    word-break: break-all;
    text-align: left;
}

/* ==========================================================================
   Webhook Display (NEW)
   ========================================================================== */

.webhook-display {
    padding: 20px;
    flex: 1;
}

.webhook-status {
    text-align: center;
    padding: 40px 20px;
}

.webhook-status h2 {
    font-size: 20px;
    color: var(--accent-fill-rest, #0078D4);
    margin-bottom: 12px;
}

.webhook-status p {
    font-size: 14px;
    color: var(--neutral-foreground-hint, #605E5C);
}

.webhook-content {
    margin-top: 20px;
}

.webhook-content h2 {
    font-size: 18px;
    margin-bottom: 16px;
    color: var(--neutral-foreground-rest, #323130);
}

#webhook-data-display {
    background: var(--neutral-layer-2, #FAF9F8);
    border: 1px solid var(--neutral-stroke-rest, #E1DFDD);
    border-radius: 4px;
    padding: 16px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 70vh;
    overflow-y: auto;
}
