/* ============================================================
   Panel Layout Utilities (sp- prefix = "sliding panel")
   Shared internal layout for SlidingPanel consumers.
   ============================================================ */

/* Flex column container — fills panel height */
.sp-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

/* Scrollable content area */
.sp-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0.75rem;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

/* Sticky footer with buttons */
.sp-footer {
    flex-shrink: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    border-top: 1px solid var(--bs-border-color, #dee2e6);
    padding: 0.75rem;
    background: var(--bs-white, #fff);
    padding-bottom: calc(0.75rem + env(safe-area-inset-bottom));
}

/* Content block with bottom divider */
.sp-section {
    flex-shrink: 0;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 0.75rem;
}

.sp-section:last-child {
    border-bottom: none;
}

/* Uppercase muted heading for sections */
.sp-section-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
    margin-bottom: 0.5rem;
}

/* Column heading (form columns) */
.sp-col-heading {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #6c757d;
    border-bottom: 1px solid #e9ecef;
    padding-bottom: 0.25rem;
    margin-bottom: 0.5rem;
}

/* Consistent form label */
.sp-form-label {
    font-size: 0.8rem;
    font-weight: 500;
    color: #495057;
}

/* Label-value pair grid */
.sp-info-grid {
    display: grid;
    gap: 0.35rem;
}

/* Single label-value row */
.sp-info-row {
    display: flex;
    gap: 0.75rem;
}

/* Label in info row */
.sp-info-label {
    font-weight: 600;
    min-width: 100px;
    color: #495057;
    font-size: 0.85rem;
}

/* Value in info row */
.sp-info-value {
    flex: 1;
    font-size: 0.85rem;
}

/* Centered spinner */
.sp-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 2rem;
    color: #6c757d;
    gap: 0.5rem;
}

/* Empty state message */
.sp-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 2rem;
    color: var(--bs-secondary, #6c757d);
    font-size: 0.9rem;
    text-align: center;
}

.sp-empty i {
    font-size: 2rem;
    opacity: 0.5;
}

.sp-empty small {
    font-size: 0.8rem;
    color: var(--bs-secondary, #6c757d);
}

/* Validation icon (shared pattern) */
.sp-check {
    font-size: 0.75rem;
    margin-left: 0.25rem;
}

/* ============================================================
   Sidebar Layout (COLA, Label, Profile panels)
   ============================================================ */

/* Grid layout for sidebar + body */
.sp-sidebar-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    flex: 1;
    min-height: 0;
}

/* Sidebar column */
.sp-sidebar {
    display: flex;
    flex-direction: column;
    background: var(--bs-light, #f8f9fa);
    border-right: 1px solid var(--bs-border-color, #dee2e6);
    min-height: 0;
}

.sp-sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
    background: var(--bs-white, #fff);
    flex-shrink: 0;
}

.sp-sidebar-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--bs-primary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.sp-sidebar-title i {
    margin-right: 0.25rem;
}

.sp-sidebar-count {
    font-size: 0.65rem;
    color: var(--bs-secondary);
}

.sp-sidebar-body {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

/* ============================================================
   Date Cards (sidebar items for COLA/Label panels)
   ============================================================ */

.sp-date-card {
    position: relative;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.35rem;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 6px;
    cursor: pointer;
    background: white;
    transition: all 0.15s;
}

.sp-date-card:last-child {
    margin-bottom: 0;
}

.sp-date-card:hover {
    background: var(--bs-gray-100);
    border-color: var(--bs-primary);
}

.sp-date-card.selected {
    border-color: var(--bs-primary);
    border-left: 4px solid var(--bs-primary);
    background: var(--bs-primary-bg-subtle);
    box-shadow: 0 0 0 2px rgba(var(--bs-primary-rgb), 0.15);
}

.sp-date-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 500;
    font-size: 0.85rem;
}

.sp-date-card-header i {
    font-size: 0.75rem;
}

.sp-date-card-name {
    flex: 1;
}

.sp-date-card-sub {
    font-size: 0.75rem;
    color: var(--bs-secondary);
    margin-top: 0.15rem;
    padding-left: 1.25rem;
}

/* ============================================================
   Card Grid (COLA / Label / Glass panels)
   ============================================================ */

.sp-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #dee2e6;
}

.sp-card {
    background: white;
    border: 2px solid #dee2e6;
    border-radius: 8px;
    padding: 0.5rem;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.sp-card:hover {
    border-color: #0d6efd;
    box-shadow: 0 2px 8px rgba(13, 110, 253, 0.2);
}

.sp-card.selected {
    border-color: #0d6efd;
    background: #e7f1ff;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
}

.sp-card-thumbnail {
    width: 100%;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--nwc-bg-muted);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.sp-card-thumbnail img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.sp-card-thumbnail .no-image {
    color: var(--nwc-text-light);
    font-size: 0.75rem;
    text-align: center;
}

.sp-card-info {
    width: 100%;
    text-align: center;
    font-size: 0.75rem;
    line-height: 1.3;
}

.sp-card-info .brand {
    font-weight: 600;
    color: var(--nwc-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sp-card-info .details {
    color: var(--nwc-text-muted);
    font-size: 0.7rem;
}

.sp-card-info .client-hint {
    color: #0d6efd;
    font-size: 0.65rem;
    margin-top: 0.15rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   Search & Filter Bar
   ============================================================ */

.sp-search-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 0.75rem;
}

.sp-search-input {
    flex: 1;
    min-width: 200px;
    display: flex;
    align-items: center;
    background: white;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 4px;
    padding: 0 0.5rem;
}

.sp-search-input i {
    color: var(--bs-secondary);
    font-size: 0.85rem;
}

.sp-search-input input {
    border: none;
    background: transparent;
    padding: 0.35rem 0.5rem;
    flex: 1;
}

.sp-search-input input:focus {
    outline: none;
    box-shadow: none;
}

.sp-btn-clear-search {
    background: transparent;
    border: none;
    color: var(--bs-secondary);
    padding: 0.25rem;
    cursor: pointer;
}

.sp-btn-clear-search:hover {
    color: var(--bs-danger);
}

.sp-filter-controls {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sp-sort-select {
    width: auto;
    min-width: 130px;
}

.sp-all-clients-toggle {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    margin: 0;
    font-size: 0.8rem;
    cursor: pointer;
}

.sp-result-count {
    font-size: 0.75rem;
    color: var(--bs-secondary);
    white-space: nowrap;
}

.sp-view-toggle-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.sp-load-more {
    text-align: center;
    padding: 0.75rem;
    margin-top: 0.5rem;
}

/* ============================================================
   Preview Panel (COLA / Label detail preview)
   ============================================================ */

.sp-preview-panel {
    background: linear-gradient(135deg, #f8f9fa 0%, #fff 100%);
    border: 1px solid #dee2e6;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    flex: 1;
    display: flex;
    flex-direction: column;
}

.sp-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    flex-shrink: 0;
}

.sp-preview-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sp-preview-title .brand-name {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.sp-preview-title .fanciful-name {
    font-size: 0.8rem;
    opacity: 0.8;
    font-style: italic;
}

.sp-preview-actions {
    display: flex;
    gap: 0.35rem;
}

.sp-preview-header .btn-outline-light {
    border-color: rgba(255,255,255,0.5);
}

.sp-preview-header .btn-outline-light:hover {
    background: rgba(255,255,255,0.2);
}

.sp-preview-header .btn-outline-danger {
    background: rgba(255,255,255,0.15);
    border-color: rgba(255,255,255,0.4);
    color: white;
}

.sp-preview-header .btn-outline-danger:hover {
    background: rgba(220,53,69,0.9);
    border-color: transparent;
}

.sp-preview-body {
    display: flex;
    gap: 1rem;
    padding: 0.75rem;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.sp-preview-images {
    flex: 0 0 200px;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
}

.sp-preview-image-wrapper {
    position: relative;
    cursor: zoom-in;
}

.sp-preview-image-wrapper .preview-image {
    width: 100%;
    max-height: 180px;
    object-fit: contain;
    border-radius: 4px;
    border: 1px solid #dee2e6;
    background: #f8f9fa;
}

.sp-no-preview-image {
    color: var(--nwc-text-light);
    text-align: center;
    padding: 2rem 0;
}

.sp-preview-details {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 0;
    font-size: 0.8rem;
}

.sp-header-context {
    font-size: 0.8rem;
    font-weight: normal;
    color: var(--bs-secondary);
    margin-left: 0.5rem;
}

/* ============================================================
   Spec Groups (label/value detail cards)
   ============================================================ */

.sp-spec-group {
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 6px;
    padding: 0.4rem 0.5rem;
}

.sp-spec-group-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
    margin-bottom: 0.25rem;
    padding-bottom: 0.2rem;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.sp-spec-group-title i {
    color: #667eea;
}

.sp-spec-grid {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sp-spec-item {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
    font-size: 0.75rem;
    line-height: 1.3;
}

.sp-spec-label {
    font-weight: 500;
    color: #6c757d;
    flex-shrink: 0;
    min-width: 95px;
}

.sp-spec-value {
    color: #212529;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sp-spec-value.mono {
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    font-size: 0.75rem;
    background: #f1f3f4;
    padding: 1px 4px;
    border-radius: 3px;
}

.sp-spec-value.status-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.sp-spec-value.status-badge.approved {
    background: #d1e7dd;
    color: #155724;
}

.sp-spec-value.status-badge.pending {
    background: #fff3cd;
    color: #856404;
}

/* ============================================================
   Form Grid (label-above-input layout for panel forms)
   ============================================================ */

/* 2-column grid — default for 550px panels */
.sp-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

/* 4-column variant for wider panels */
.sp-form-grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.75rem;
}

/* Stacked field: label above input */
.sp-form-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sp-form-field > label {
    font-size: 0.8rem;
    font-weight: 600;
    color: #495057;
    margin: 0;
}

.sp-form-field > input,
.sp-form-field > select,
.sp-form-field > textarea {
    min-height: 44px;
    font-size: 16px; /* iOS zoom prevention */
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 6px;
    -webkit-appearance: none;
}

.sp-form-field > textarea {
    min-height: 80px;
    resize: vertical;
}

.sp-form-field > input:focus,
.sp-form-field > select:focus,
.sp-form-field > textarea:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Column spanning */
.sp-form-field.span-2 { grid-column: span 2; }
.sp-form-field.span-3 { grid-column: span 3; }
.sp-form-field.span-4 { grid-column: span 4; }

/* Input + adjacent button (e.g., select + gear icon) */
.sp-input-group {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.sp-input-group > select,
.sp-input-group > input {
    flex: 1;
    min-height: 44px;
    font-size: 16px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--bs-border-color, #dee2e6);
    border-radius: 6px;
    -webkit-appearance: none;
}

.sp-input-group > select:focus,
.sp-input-group > input:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* ============================================================
   Scan Panel Upload / Results (Label, COLA, Permit, BOL scans)
   ============================================================ */

/* Upload card (bordered container with header) */
.sp-upload-card {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    overflow: hidden;
}

.sp-upload-card-header {
    background: #f8f9fa;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #dee2e6;
    font-size: 0.9rem;
}

/* Upload area (center-aligned drop zone) */
.sp-upload-area {
    padding: 1.5rem;
    text-align: center;
    transition: background 0.2s;
    min-height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sp-upload-area:hover:not(.has-file) {
    background: rgba(13, 110, 253, 0.05);
}

.sp-upload-area.has-file {
    background: #d1e7dd;
    padding: 1rem;
}

/* Upload label (clickable column layout) */
.sp-upload-label {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
    margin: 0;
    width: 100%;
}

.sp-upload-icon {
    font-size: 2rem;
    color: #0d6efd;
}

.sp-upload-text {
    font-size: 0.95rem;
    font-weight: 500;
    color: #495057;
}

.sp-upload-hint {
    font-size: 0.8rem;
    color: #6c757d;
}

/* File selected state */
.sp-file-selected {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.sp-file-selected span {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Centered processing spinner */
.sp-scan-processing {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 2rem;
    text-align: center;
}

/* Results header and footer */
.sp-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #dee2e6;
    margin-bottom: 0.75rem;
}

.sp-results-footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #dee2e6;
}

/* Confidence badge (scan field accuracy indicator) */
.sp-confidence-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.35rem;
    border-radius: 0.25rem;
}

.sp-confidence-badge.low {
    background: #fff3cd;
    color: #856404;
}

/* Raw JSON debug section */
.sp-raw-json {
    padding: 0.5rem;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px dashed #dee2e6;
    margin-top: 0.5rem;
}

.sp-raw-json summary {
    cursor: pointer;
    user-select: none;
}

.sp-raw-json pre {
    margin-top: 0.5rem;
    padding: 0.5rem;
    background: #1e1e1e;
    color: #d4d4d4;
    border-radius: 4px;
    font-size: 0.75rem;
    max-height: 200px;
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============================================================
   Mobile Responsive
   ============================================================ */

@media (max-width: 768px) {
    .sp-form-grid,
    .sp-form-grid-4 {
        grid-template-columns: 1fr;
    }

    .sp-form-field.span-2,
    .sp-form-field.span-3,
    .sp-form-field.span-4 {
        grid-column: span 1;
    }

    .sp-sidebar-layout {
        grid-template-columns: 1fr;
    }

    .sp-sidebar {
        max-height: 160px;
        border-right: none;
        border-bottom: 1px solid var(--bs-border-color, #dee2e6);
    }

    .sp-sidebar-body {
        display: flex;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 0.5rem;
        padding: 0.5rem;
    }

    .sp-date-card {
        flex: 0 0 auto;
        min-width: 120px;
        margin-bottom: 0;
    }

    .sp-search-bar {
        flex-direction: column;
        align-items: stretch;
    }

    .sp-search-input {
        min-width: 100%;
    }

    .sp-filter-controls {
        flex-wrap: wrap;
    }

    .sp-card-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .sp-preview-body {
        flex-direction: column;
    }

    .sp-preview-images {
        flex: none;
        flex-direction: row;
        justify-content: center;
        gap: 0.5rem;
        max-height: none;
    }

    .sp-preview-image-wrapper .preview-image {
        max-width: 150px;
    }

    .sp-upload-area {
        padding: 1rem;
    }

    .sp-results-footer {
        flex-direction: column;
    }

    .sp-results-footer button {
        width: 100%;
    }
}
