/**
 * Semtak Delivery Manager - Delivery Box Styles
 *
 * Optimized for Core Web Vitals:
 * - CLS: Reserved space with min-height
 * - LCP: Minimal CSS, server-rendered content
 * - INP: No blocking operations
 *
 * @package SemtakDelivery
 */

/* Container - reserve space to prevent CLS */
.stk-delivery-box {
    min-height: 120px;
    margin: 20px 0;
    padding: 16px;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.5;
    contain: layout;
}

/* Loading state */
.stk-delivery-loading {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stk-delivery-loading[hidden] {
    display: none;
}

/* Skeleton loader */
.stk-delivery-skeleton {
    height: 80px;
    background: linear-gradient(90deg, #e9ecef 25%, #dee2e6 50%, #e9ecef 75%);
    background-size: 200% 100%;
    border-radius: 4px;
    animation: stk-skeleton-pulse 1.5s ease-in-out infinite;
}

@keyframes stk-skeleton-pulse {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Content container */
.stk-delivery-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.stk-delivery-content[hidden] {
    display: none;
}

/* Status badge */
.stk-delivery-status {
    margin-bottom: 4px;
}

.stk-status-badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Delivery info rows */
.stk-delivery-time,
.stk-delivery-shipping,
.stk-delivery-manufacturer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    border-bottom: 1px solid #e9ecef;
}

.stk-delivery-manufacturer {
    border-bottom: none;
}

.stk-delivery-time[hidden],
.stk-delivery-shipping[hidden],
.stk-delivery-manufacturer[hidden] {
    display: none;
}

/* Icons */
.stk-delivery-icon {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    font-size: 20px;
    color: #6c757d;
}

/* Labels */
.stk-delivery-label {
    flex-shrink: 0;
    color: #6c757d;
    font-weight: 500;
}

/* Values */
.stk-delivery-value {
    color: #212529;
    font-weight: 600;
}

/* Shipping cost highlight */
.stk-delivery-cost {
    color: #198754;
}

/* Error message */
.stk-delivery-error {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    margin-top: 8px;
    background: #f8d7da;
    border: 1px solid #f5c6cb;
    border-radius: 4px;
    color: #721c24;
    font-size: 13px;
}

.stk-delivery-error[hidden] {
    display: none;
}

.stk-delivery-error .dashicons {
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    font-size: 16px;
}

/* Refresh button (debug mode only) */
.stk-delivery-refresh {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.stk-delivery-refresh:hover {
    background: #e9ecef;
}

.stk-delivery-refresh:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.stk-delivery-refresh .dashicons {
    font-size: 16px;
    width: 16px;
    height: 16px;
    color: #6c757d;
}

/* Status-specific colors */
.stk-status-in_stock {
    background-color: #198754;
}

.stk-status-on_order {
    background-color: #fd7e14;
}

.stk-status-production {
    background-color: #dc3545;
}

.stk-status-unavailable {
    background-color: #6c757d;
}

/* Responsive adjustments */
@media screen and (max-width: 600px) {
    .stk-delivery-box {
        padding: 12px;
        margin: 16px 0;
    }

    .stk-delivery-time,
    .stk-delivery-shipping,
    .stk-delivery-manufacturer {
        flex-wrap: wrap;
    }

    .stk-delivery-label {
        flex-basis: 100%;
        margin-bottom: 4px;
    }

    .stk-delivery-value {
        margin-left: 28px;
    }
}

/* Print styles */
@media print {
    .stk-delivery-box {
        border: 1px solid #000;
        background: #fff;
    }

    .stk-delivery-refresh {
        display: none;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .stk-delivery-skeleton {
        animation: none;
        background: #e9ecef;
    }
}

/* High contrast mode */
@media (forced-colors: active) {
    .stk-status-badge {
        border: 2px solid currentColor;
    }

    .stk-delivery-box {
        border: 2px solid currentColor;
    }
}

/* ============================================
   DELIVERY INFO BOX (above add to cart)
   Design matching screenshot with expandable details
   ============================================ */
.stk-delivery-info-box {
    margin: 20px 0;
    padding: 0;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

/* Row base styles */
.stk-delivery-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
}

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

/* Row icon */
.stk-delivery-row-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stk-delivery-row-icon svg {
    width: 22px;
    height: 22px;
    stroke-width: 1.5;
}

/* Row text */
.stk-delivery-row-text {
    flex: 1;
    font-size: 14px;
}

.stk-delivery-row-text strong {
    font-weight: 600;
}

/* Status row - Available (green) */
.stk-delivery-row.stk-status-available {
    color: #059669;
}

.stk-delivery-row.stk-status-available .stk-delivery-row-icon svg {
    color: #059669;
}

/* Status row - On order (orange) */
.stk-delivery-row.stk-status-on-order {
    color: #d97706;
}

.stk-delivery-row.stk-status-on-order .stk-delivery-row-icon svg {
    color: #d97706;
}

/* Expandable delivery details */
.stk-delivery-details {
    border-bottom: 1px solid #f3f4f6;
}

.stk-delivery-details summary {
    cursor: pointer;
    list-style: none;
}

.stk-delivery-details summary::-webkit-details-marker {
    display: none;
}

.stk-delivery-details summary::marker {
    display: none;
}

.stk-delivery-expandable {
    border-bottom: none;
}

/* Arrow icon for expandable */
.stk-delivery-arrow {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    transition: transform 0.2s ease;
}

.stk-delivery-arrow svg {
    width: 16px;
    height: 16px;
}

.stk-delivery-details[open] .stk-delivery-arrow {
    transform: rotate(90deg);
}

/* Expanded content */
.stk-delivery-expanded {
    padding: 0 20px 16px 56px;
    background: #f9fafb;
    border-top: 1px solid #f3f4f6;
}

.stk-delivery-note {
    margin: 12px 0 0;
    padding: 0;
    font-size: 13px;
    color: #6b7280;
    line-height: 1.5;
}

.stk-delivery-note.stk-delivery-production {
    color: #92400e;
    background: #fffbeb;
    padding: 10px 12px;
    border-radius: 6px;
    border-left: 3px solid #f59e0b;
}

.stk-delivery-note.stk-delivery-production strong {
    color: #b45309;
}

.stk-delivery-carrier {
    margin: 10px 0 0;
    font-size: 13px;
    color: #4b5563;
}

.stk-delivery-more-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-top: 12px;
    font-size: 13px;
    font-weight: 500;
    color: #be185d;
    text-decoration: none;
    transition: color 0.15s ease;
}

.stk-delivery-more-link:hover {
    color: #9d174d;
    text-decoration: underline;
}

.stk-delivery-more-link svg {
    flex-shrink: 0;
}

/* Cost row */
.stk-delivery-cost-row .stk-delivery-row-icon svg {
    color: #be185d;
}

.stk-delivery-price {
    color: #be185d;
    font-weight: 700;
}

/* Badges section */
.stk-delivery-badges {
    display: flex;
    gap: 0;
    border-top: 1px solid #e5e7eb;
    background: #fafafa;
}

.stk-delivery-badge {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 8px;
    text-align: center;
    border-right: 1px solid #e5e7eb;
}

.stk-delivery-badge:last-child {
    border-right: none;
}

.stk-delivery-badge svg {
    width: 24px;
    height: 24px;
    color: #6b7280;
    stroke-width: 1.5;
}

.stk-badge-label {
    font-size: 11px;
    color: #6b7280;
    font-weight: 400;
}

.stk-badge-value {
    font-size: 12px;
    color: #be185d;
    font-weight: 600;
}

/* Responsive delivery info box */
@media screen and (max-width: 480px) {
    .stk-delivery-info-box {
        margin: 16px 0;
    }

    .stk-delivery-row {
        padding: 12px 16px;
        gap: 10px;
    }

    .stk-delivery-expanded {
        padding: 0 16px 14px 46px;
    }

    .stk-delivery-badges {
        flex-wrap: wrap;
    }

    .stk-delivery-badge {
        flex: 1 1 calc(33.333% - 1px);
        min-width: 90px;
        padding: 12px 6px;
    }

    .stk-badge-label {
        font-size: 10px;
    }
}

/* ============================================
   DELIVERY TAB
   ============================================ */
.stk-delivery-tab {
    padding: 10px 0;
}

.stk-delivery-tab h3 {
    margin: 0 0 20px;
    padding-bottom: 10px;
    border-bottom: 2px solid #198754;
    font-size: 18px;
    font-weight: 600;
    color: #212529;
}

.stk-delivery-tab-table {
    width: 100%;
    max-width: 600px;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.stk-delivery-tab-table th,
.stk-delivery-tab-table td {
    padding: 12px 16px;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid #e9ecef;
}

.stk-delivery-tab-table th {
    width: 40%;
    font-weight: 600;
    color: #495057;
    background: #f8f9fa;
}

.stk-delivery-tab-table td {
    color: #212529;
}

.stk-delivery-tab-table tr:last-child th,
.stk-delivery-tab-table tr:last-child td {
    border-bottom: none;
}

.stk-delivery-tab-table .description {
    color: #6c757d;
    font-style: italic;
}

.stk-delivery-tab-info {
    padding: 12px 16px;
    background: #e7f5ff;
    border: 1px solid #74c0fc;
    border-radius: 6px;
    font-size: 13px;
    color: #1971c2;
}

.stk-delivery-tab-info p {
    margin: 0;
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.stk-delivery-tab-info .dashicons {
    flex-shrink: 0;
    margin-top: 2px;
}

/* Responsive tab table */
@media screen and (max-width: 600px) {
    .stk-delivery-tab-table th,
    .stk-delivery-tab-table td {
        display: block;
        width: 100%;
        padding: 8px 12px;
    }

    .stk-delivery-tab-table th {
        padding-bottom: 4px;
        border-bottom: none;
    }

    .stk-delivery-tab-table td {
        padding-top: 0;
    }
}

/* ============================================
   CLICKABLE ROW (opens side panel)
   ============================================ */
.stk-delivery-clickable {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid #f3f4f6;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
    font-size: inherit;
    transition: background-color 0.15s ease;
}

.stk-delivery-clickable:hover {
    background-color: #f9fafb;
}

.stk-delivery-clickable:focus {
    outline: 2px solid #be185d;
    outline-offset: -2px;
}

/* ============================================
   SIDE DRAWER using native <dialog>
   Full-height panel sliding from right
   Better accessibility with built-in focus trap
   ============================================ */
dialog.stk-delivery-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    width: 420px;
    max-width: 90vw;
    height: 100%;
    max-height: 100%;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: #fff;
    border: none;
    border-left: 1px solid #e5e7eb;
    box-shadow: -4px 0 30px rgba(0, 0, 0, 0.15);
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
                opacity 0.3s ease,
                overlay 0.3s allow-discrete,
                display 0.3s allow-discrete;
    will-change: transform;
}

/* Open state */
dialog.stk-delivery-drawer[open] {
    transform: translateX(0);
}

/* Starting style for open animation */
@starting-style {
    dialog.stk-delivery-drawer[open] {
        transform: translateX(100%);
    }
    dialog.stk-delivery-drawer[open]::backdrop {
        opacity: 0;
    }
}

/* Native backdrop - replaces manual overlay */
dialog.stk-delivery-drawer::backdrop {
    background: rgba(0, 0, 0, 0.5);
    opacity: 1;
    transition: opacity 0.3s ease,
                overlay 0.3s allow-discrete,
                display 0.3s allow-discrete;
    cursor: pointer;
}

/* Drawer Header - sticky at top */
.stk-drawer-header {
    position: sticky;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    background: #fff;
    border-bottom: 1px solid #f3f4f6;
    z-index: 1;
}

.stk-drawer-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
    letter-spacing: -0.01em;
}

/* Form wrapper for native close button */
.stk-drawer-header form {
    margin: 0;
    padding: 0;
}

.stk-drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.15s ease;
}

.stk-drawer-close:hover {
    background: #f3f4f6;
    border-color: #d1d5db;
}

.stk-drawer-close:focus {
    outline: 2px solid #be185d;
    outline-offset: 2px;
}

.stk-drawer-close svg {
    width: 18px;
    height: 18px;
    color: #6b7280;
}

/* Drawer Content */
.stk-drawer-content {
    padding: 24px;
}

/* Drawer List - with circular icon badges */
.stk-drawer-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.stk-drawer-list li {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    padding: 16px 0;
    border-bottom: 1px solid #f5f5f5;
    font-size: 14px;
    line-height: 1.6;
    color: #4b5563;
}

.stk-drawer-list li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.stk-drawer-list li:first-child {
    padding-top: 0;
}

/* Circular icon badge like competitor */
.stk-drawer-list li svg {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    padding: 10px;
    background: #fdf2f8;
    border-radius: 50%;
    color: #be185d;
    box-sizing: content-box;
}

.stk-drawer-list li span {
    flex: 1;
    padding-top: 8px;
}

.stk-drawer-list li strong {
    color: #1f2937;
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

/* Extra Content from info_content */
.stk-drawer-extra {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid #f3f4f6;
    font-size: 14px;
    line-height: 1.6;
    color: #6b7280;
}

.stk-drawer-extra h1,
.stk-drawer-extra h2,
.stk-drawer-extra h3,
.stk-drawer-extra h4 {
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    margin: 0 0 8px;
}

.stk-drawer-extra p {
    margin: 0 0 10px;
}

.stk-drawer-extra p:last-child {
    margin-bottom: 0;
}

.stk-drawer-extra strong {
    color: #374151;
    font-weight: 600;
}

.stk-drawer-extra a {
    color: #be185d;
    text-decoration: none;
}

.stk-drawer-extra a:hover {
    text-decoration: underline;
}

/* Responsive Drawer */
@media screen and (max-width: 768px) {
    dialog.stk-delivery-drawer {
        width: 100%;
        max-width: 100%;
        border-left: none;
    }

    .stk-drawer-header {
        padding: 16px 20px;
    }

    .stk-drawer-content {
        padding: 20px;
    }

    .stk-drawer-list li {
        padding: 14px 0;
    }

    .stk-drawer-list li svg {
        width: 16px;
        height: 16px;
        padding: 7px;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    dialog.stk-delivery-drawer {
        transition: none;
    }
    dialog.stk-delivery-drawer::backdrop {
        transition: none;
    }
}
