/* ═══════════════════════════════════════════════════════════════
   PACS Image Viewer — Dark PACS-Style Theme
   ═══════════════════════════════════════════════════════════════ */

/* Break out of WordPress theme content-width constraints */
.piv-viewer-wrap,
.piv-viewer-container,
.piv-playlist-container {
    max-width: none !important;
    width: 100% !important;
}

/* ── Viewer Wrap (contains viewer + teaching panel side by side) */
.piv-viewer-wrap {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    gap: 12px;
    margin: 20px 0;
}

/* When inside wrap, viewer takes remaining width */
.piv-viewer-wrap > .piv-viewer-container {
    flex: 1 1 0%;
    min-width: 0;
    margin: 0 !important;
}

/* Teaching panel sits on the right as its own window */
.piv-viewer-wrap > .piv-teaching-panel {
    flex: 0 0 380px;
    width: 380px !important;
    max-width: 380px;
    margin: 0 !important;
}

.piv-viewer-container {
    position: relative;
    background: #0a0a14;
    border: 1px solid #2a2a3e;
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    height: var(--piv-height, 800px);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: #c8c8d4;
    user-select: none;
    outline: none;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.piv-external-iframe {
    height: var(--piv-height, 800px);
}

/* Only add vertical margin when NOT inside a wrap */
.piv-viewer-container:not(.piv-viewer-wrap > *) {
    margin: 20px 0;
}

.piv-viewer-container:focus {
    border-color: #4a9eff;
    box-shadow: 0 0 0 2px rgba(74, 158, 255, 0.25), 0 4px 24px rgba(0, 0, 0, 0.5);
}

/* ── Top Bar ─────────────────────────────────────────────────── */
.piv-top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: #12122a;
    border-bottom: 1px solid #2a2a3e;
    font-size: 13px;
    flex-shrink: 0;
    z-index: 2;
    height: 40px;
    box-sizing: border-box;
}

.piv-info-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.piv-title {
    font-weight: 600;
    color: #e0e0ec;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.piv-modality-badge {
    background: #2d5a9e;
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.piv-slice-counter {
    color: #9ea0b8;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
}

/* ── Canvas Area ─────────────────────────────────────────────── */
.piv-canvas-wrap {
    flex: 1 1 0%;
    position: relative;
    background: #000;
    overflow: hidden;
    min-height: 200px;
}

.piv-canvas {
    display: block;
    width: 100%;
    height: 100%;
}

.piv-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    color: #7a8cff;
    font-size: 16px;
    font-weight: 500;
    z-index: 5;
    animation: pivPulse 1.5s ease-in-out infinite;
}

@keyframes pivPulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ── Bottom Toolbar (Tabbed) ─────────────────────────────────── */
.piv-toolbar {
    display: flex;
    flex-direction: column;
    background: #12122a;
    border-top: 1px solid #2a2a3e;
    flex-shrink: 0;
    z-index: 2;
}

/* Tab row */
.piv-toolbar-tabs {
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid #2a2a3e;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.piv-toolbar-tabs::-webkit-scrollbar { display: none; }

.piv-toolbar-tab {
    flex: 1;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 7px 12px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: #6a6c88;
    font-size: 11.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.piv-toolbar-tab:hover {
    color: #b0b2c8;
    background: rgba(45, 90, 158, 0.1);
}

.piv-toolbar-tab.active {
    color: #e0e0ec;
    border-bottom-color: #4a8adf;
    background: rgba(45, 90, 158, 0.12);
}

.piv-tab-label {
    font-size: 10.5px;
    letter-spacing: 0.8px;
}

.piv-tab-value {
    font-size: 11.5px;
    color: #4a8adf;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: none;
}

.piv-toolbar-tab.active .piv-tab-value {
    color: #7ab4ff;
}

/* Panel row */
.piv-toolbar-panels {
    display: flex;
    justify-content: center;
    min-height: 44px;
}

.piv-tab-panel {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 8px 16px;
    flex-wrap: wrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.piv-tab-panel::-webkit-scrollbar { display: none; }

.piv-tab-panel.active {
    display: flex;
}

/* Legacy group styles */
.piv-plane-group,
.piv-window-group,
.piv-tool-group {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

.piv-toolbar-sep {
    display: none;
}

.piv-toolbar-label {
    display: none;
}

.piv-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 14px;
    border: 1px solid #3a3a52;
    border-radius: 6px;
    background: #1e1e36;
    color: #b0b2c8;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.piv-btn:hover {
    background: #2a2a48;
    color: #e0e0ec;
    border-color: #5a5a7a;
}

.piv-btn.active {
    background: #2d5a9e;
    color: #fff;
    border-color: #4a8adf;
    box-shadow: 0 0 8px rgba(74, 138, 223, 0.3);
}

.piv-btn svg {
    flex-shrink: 0;
}

/* ── Quick Fullscreen Button (canvas corner) ─────────────────── */
.piv-quick-fs {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 4;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 20, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: rgba(200, 220, 255, 0.7);
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.piv-quick-fs:hover {
    background: rgba(45, 90, 158, 0.7);
    color: #fff;
    border-color: rgba(74, 138, 223, 0.5);
}

.piv-fullscreen .piv-quick-fs .piv-fs-expand { display: none; }
.piv-fullscreen .piv-quick-fs .piv-fs-collapse { display: inline-block !important; }

/* ── Slider ──────────────────────────────────────────────────── */
.piv-slider-wrap {
    padding: 4px 12px 8px;
    background: #12122a;
    flex-shrink: 0;
}

.piv-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #2a2a3e;
    outline: none;
    cursor: pointer;
}

.piv-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #4a8adf;
    border: 2px solid #fff;
    cursor: pointer;
    box-shadow: 0 0 6px rgba(74, 138, 223, 0.5);
    transition: transform 0.1s;
}

.piv-slider::-webkit-slider-thumb:hover {
    transform: scale(1.2);
}

.piv-slider::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #4a8adf;
    border: 2px solid #fff;
    cursor: pointer;
}

/* ── Overlay Info (corners) ──────────────────────────────────── */
.piv-overlay-info {
    position: absolute;
    z-index: 3;
    font-size: 12px;
    color: rgba(200, 220, 255, 0.7);
    font-family: "SF Mono", "Consolas", "Monaco", monospace;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
    pointer-events: none;
    padding: 6px 10px;
}

.piv-overlay-tl {
    top: 48px;
    left: 10px;
}

.piv-overlay-tr {
    top: 48px;
    right: 10px;
}

.piv-overlay-bl {
    bottom: 110px;
    left: 10px;
    font-size: 11px;
    color: rgba(200, 220, 255, 0.4);
    transition: opacity 1s ease;
}

.piv-overlay-br {
    bottom: 110px;
    right: 10px;
    font-size: 12px;
    color: rgba(200, 220, 255, 0.7);
}

/* ── Window Dot (color indicator on window buttons) ──────────── */
.piv-window-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.piv-window-btn.active .piv-window-dot {
    box-shadow: 0 0 6px currentColor;
}

/* ── Fullscreen (on wrapper — side-by-side with teaching panel) ── */
.piv-viewer-wrap.piv-fullscreen,
.piv-viewer-wrap:-webkit-full-screen,
.piv-viewer-wrap:fullscreen {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 999999;
    display: flex !important;
    flex-direction: row !important;
    background: #000 !important;
    overflow: hidden !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    gap: 0 !important;
}

.piv-viewer-wrap.piv-fullscreen > .piv-viewer-container,
.piv-viewer-wrap:-webkit-full-screen > .piv-viewer-container,
.piv-viewer-wrap:fullscreen > .piv-viewer-container {
    flex: 1 1 0% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    height: 100vh !important;
    border-radius: 0 !important;
    border: none !important;
    margin: 0 !important;
    box-shadow: none !important;
    overflow: hidden !important;
}

.piv-viewer-wrap.piv-fullscreen > .piv-teaching-panel,
.piv-viewer-wrap:-webkit-full-screen > .piv-teaching-panel,
.piv-viewer-wrap:fullscreen > .piv-teaching-panel {
    flex: 0 0 400px !important;
    width: 400px !important;
    max-width: 400px !important;
    height: 100vh !important;
    max-height: none !important;
    overflow: hidden !important;
    border-radius: 0 !important;
    margin: 0 !important;
    border: none !important;
    border-left: 1px solid #2a2a3e !important;
    display: flex !important;
    flex-direction: column !important;
}

/* ── Fullscreen on mobile — viewer fills screen, hide teaching panel ── */
@media (max-width: 900px) {
    .piv-viewer-wrap.piv-fullscreen,
    .piv-viewer-wrap:-webkit-full-screen,
    .piv-viewer-wrap:fullscreen {
        flex-direction: column !important;
    }
    .piv-viewer-wrap.piv-fullscreen > .piv-viewer-container,
    .piv-viewer-wrap:-webkit-full-screen > .piv-viewer-container,
    .piv-viewer-wrap:fullscreen > .piv-viewer-container {
        height: 100% !important;
        width: 100% !important;
    }
    .piv-viewer-wrap.piv-fullscreen > .piv-teaching-panel,
    .piv-viewer-wrap:-webkit-full-screen > .piv-teaching-panel,
    .piv-viewer-wrap:fullscreen > .piv-teaching-panel {
        display: none !important;
    }
}

/* Legacy: standalone container fullscreen (without wrap) */
.piv-viewer-container.piv-fullscreen {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0;
    border-radius: 0;
    border: none;
    z-index: 999999;
}

.piv-fullscreen-btn .piv-fs-collapse {
    display: none;
}

.piv-fullscreen .piv-fullscreen-btn .piv-fs-expand {
    display: none;
}

.piv-fullscreen .piv-fullscreen-btn .piv-fs-collapse {
    display: inline-block !important;
}

/* ═══════════════════════════════════════════════════════════════
   Playlist — Series Navigation
   ═══════════════════════════════════════════════════════════════ */
.piv-playlist-container {
    margin: 20px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

.piv-playlist-container .piv-viewer-container {
    margin: 0;
    border-radius: 0;
    box-shadow: none;
    border: none;
    flex: 1;
    min-height: 0;
}

.piv-playlist-slot {
    position: relative;
    display: flex;
    flex-direction: column;
}

/* Teaching panel inside playlist needs to be visible outside slot */
.piv-playlist-slot .piv-teaching-panel {
    flex-shrink: 0;
}

/* ── Playlist Nav Bar ────────────────────────────────────────── */
.piv-playlist-nav {
    display: flex;
    align-items: stretch;
    background: #0c0c20;
    border-bottom: 2px solid #2d5a9e;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.piv-playlist-prev,
.piv-playlist-next {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    background: #12122a;
    border: none;
    color: #8a8ca8;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.piv-playlist-prev:hover:not(:disabled),
.piv-playlist-next:hover:not(:disabled) {
    background: #1e1e40;
    color: #e0e0ec;
}

.piv-playlist-prev:disabled,
.piv-playlist-next:disabled {
    opacity: 0.3;
    cursor: default;
}

.piv-playlist-tabs {
    display: flex;
    flex: 1;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.piv-playlist-tabs::-webkit-scrollbar {
    display: none;
}

.piv-playlist-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: #8a8ca8;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.piv-playlist-tab:hover {
    background: rgba(45, 90, 158, 0.15);
    color: #c8c8d4;
}

.piv-playlist-tab.active {
    color: #e0e0ec;
    border-bottom-color: #4a8adf;
    background: rgba(45, 90, 158, 0.2);
}

.piv-playlist-tab-modality {
    display: inline-block;
    background: #2d5a9e;
    color: #fff;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.piv-playlist-tab.active .piv-playlist-tab-modality {
    background: #4a8adf;
}

.piv-playlist-tab-title {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.piv-playlist-tab-num {
    font-size: 11px;
    color: #5a5c78;
    font-variant-numeric: tabular-nums;
}

.piv-playlist-tab.active .piv-playlist-tab-num {
    color: #9ea0b8;
}

/* ── Playlist Fullscreen ─────────────────────────────────────── */
.piv-playlist-container.piv-fullscreen {
    position: fixed !important;
    top: 0;
    left: 0;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0;
    border-radius: 0;
    z-index: 999999;
    display: flex;
    flex-direction: column;
}

.piv-playlist-container.piv-fullscreen .piv-playlist-slot {
    flex: 1;
    height: auto !important;
}

.piv-playlist-container.piv-fullscreen .piv-playlist-slot .piv-viewer-container {
    height: 100% !important;
}

/* ── Responsive ──────────────────────────────────────────────── */

/* Mobile: use viewport-based height instead of fixed px */
@media (max-width: 900px) {
    .piv-viewer-container {
        height: 70vh !important;
        height: 70dvh !important;
    }
    .piv-external-iframe {
        height: 70vh !important;
        height: 70dvh !important;
    }
}
@media (max-width: 480px) {
    .piv-viewer-container {
        height: 60vh !important;
        height: 60dvh !important;
    }
    .piv-external-iframe {
        height: 60vh !important;
        height: 60dvh !important;
    }
}

@media (max-width: 600px) {
    .piv-toolbar-tab {
        padding: 6px 8px;
        font-size: 10px;
        gap: 4px;
    }
    .piv-tab-label { font-size: 9px; }
    .piv-tab-value { font-size: 10px; }
    .piv-tab-panel { padding: 6px 10px; }
    .piv-btn {
        padding: 6px 10px;
        font-size: 11px;
    }
    .piv-top-bar {
        font-size: 12px;
    }
    .piv-title {
        max-width: 150px;
    }
    .piv-playlist-tab {
        padding: 8px 12px;
        font-size: 12px;
        gap: 5px;
    }
    .piv-playlist-tab-title {
        max-width: 100px;
    }
    .piv-playlist-prev,
    .piv-playlist-next {
        width: 36px;
    }
}

/* ── Touch-device tap targets (44px minimum) ─────────────────── */
@media (pointer: coarse) {
    .piv-btn {
        min-height: 44px;
        min-width: 44px;
        padding: 10px 14px;
        font-size: 13px;
    }
    .piv-toolbar-tab {
        min-height: 44px;
        padding: 10px 12px;
    }
    .piv-slider::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    .piv-slider::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }
    .piv-slider {
        height: 8px;
    }
}

/* ── W/L long-press indicator ────────────────────────────────── */
@keyframes pivWlPulse {
    0% { box-shadow: inset 0 0 0 2px rgba(74, 138, 223, 0.8); }
    100% { box-shadow: inset 0 0 0 2px transparent; }
}
.piv-canvas-wrap.piv-wl-active {
    animation: pivWlPulse 0.4s ease-out;
}
