/**
 * Building Manager Modal Styles - Unified Modal Pattern
 * Matches level-manager and profile-manager glass morphism design
 */

/* Button in toolbar */
.building-manager-button {
    position: relative;
}

.building-manager-button img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 0;
}

/* Main Modal Container - Match unified-modal exactly */
.building-manager-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10000;
    /* No background here - use ::before like unified-modal */
}

/* Animated overlay background - same as unified-modal */
.building-manager-modal::before {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.4);
    animation: bmModalFadeIn 0.3s ease-out;
    pointer-events: none;
    z-index: -1;
}

@keyframes bmModalFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Modal Content - Match unified-modal transparency */
.building-manager-modal .modal-content {
    position: relative;
    z-index: 1;
    background: linear-gradient(145deg, 
        rgba(10, 25, 47, 0.3), 
        rgba(0, 15, 30, 0.3));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 0;
    border: 1px solid rgba(0, 212, 255, 0.3);
    border-radius: 20px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto; /* Changed from hidden to auto for unified scrolling */
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    box-shadow: 
        0 8px 32px rgba(0, 212, 255, 0.4),
        0 2px 20px rgba(0, 0, 0, 0.8),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Support for browsers that need more opacity */
@supports not (backdrop-filter: blur(20px)) {
    .building-manager-modal .modal-content {
        background: linear-gradient(145deg, 
            rgba(10, 25, 47, 0.9), 
            rgba(0, 15, 30, 0.9));
    }
}

/* Custom scrollbar for modal content */
.building-manager-modal .modal-content::-webkit-scrollbar {
    width: 10px;
}

.building-manager-modal .modal-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 5px;
}

.building-manager-modal .modal-content::-webkit-scrollbar-thumb {
    background: rgba(0, 212, 255, 0.5);
    border-radius: 5px;
}

.building-manager-modal .modal-content::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 212, 255, 0.7);
}

/* Modal Header - Clean without double safe area */
.building-manager-modal .modal-header-section {
    background: linear-gradient(135deg, 
        rgba(0, 212, 255, 0.1) 0%, 
        rgba(0, 150, 200, 0.05) 100%);
    border-bottom: 1px solid rgba(0, 212, 255, 0.2);
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
    border-radius: 20px 20px 0 0;
}

.building-manager-modal .modal-header {
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    color: #00d4ff;
    text-shadow: 0 0 20px rgba(0, 212, 255, 0.5);
    letter-spacing: 0.5px;
}

/* Close Button - Unified Style */
.building-manager-modal .unified-close-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
    border-radius: 50%;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.building-manager-modal .unified-close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    transform: rotate(90deg);
}

/* Content wrapper - no longer needs separate scrolling */
.building-manager-content-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Action Buttons Container */
.building-manager-actions {
    display: flex;
    gap: 16px;
    padding: 20px 24px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    flex-wrap: wrap;
    justify-content: center;
    flex-shrink: 0; /* Prevent shrinking when scrolling */
}

/* Modern Action Button Design */
.building-manager-actions .action-button {
    flex: 1;
    min-width: 260px;
    max-width: 380px;
    padding: 14px 20px;
    background: linear-gradient(135deg, 
        rgba(0, 212, 255, 0.08),
        rgba(0, 150, 200, 0.05));
    border: 1px solid rgba(0, 212, 255, 0.2);
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.building-manager-actions .action-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, 
        rgba(0, 212, 255, 0.1),
        transparent);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.building-manager-actions .action-button:hover::before {
    opacity: 1;
}

.building-manager-actions .action-button:hover {
    transform: translateY(-2px);
    box-shadow: 
        0 8px 25px rgba(0, 212, 255, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    border-color: rgba(0, 212, 255, 0.4);
}

.action-icon {
    font-size: 24px;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

.action-text {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    letter-spacing: 0.3px;
}

.diamond-cost {
    font-size: 16px;
    font-weight: 700;
    color: #00d4ff;
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.3);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Free Token Badge */
.free-token-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 700;
    color: #1a1a2e;
    background: linear-gradient(135deg, #ffd700, #ffed4e);
    padding: 6px 14px;
    border-radius: 12px;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
    letter-spacing: 0.5px;
    animation: goldGlow 2s ease-in-out infinite;
}

@keyframes goldGlow {
    0%, 100% {
        box-shadow: 0 0 12px rgba(255, 215, 0, 0.4);
    }
    50% {
        box-shadow: 0 0 20px rgba(255, 215, 0, 0.6);
    }
}

.action-button.has-free-token {
    background: linear-gradient(135deg,
        rgba(76, 175, 80, 0.1),
        rgba(56, 142, 60, 0.05));
    border-color: rgba(76, 175, 80, 0.3);
}

.action-button.has-free-token::after {
    content: '✨';
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 18px;
    animation: sparkle 2s ease-in-out infinite;
}

@keyframes sparkle {
    0%, 100% { 
        opacity: 1;
        transform: scale(1);
    }
    50% { 
        opacity: 0.7;
        transform: scale(1.2);
    }
}

/* Factory Orders Container */
.factory-orders-container {
    padding: 24px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 20px;
    align-content: start;
    flex: 1; /* Allow container to grow */
    min-height: 0; /* Allow shrinking for scroll */
}

/* Factory Card - Clean Glass Design */
.factory-card {
    background: linear-gradient(135deg,
        rgba(30, 40, 60, 0.4),
        rgba(20, 30, 45, 0.3));
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 212, 255, 0.15);
    border-radius: 16px;
    overflow: hidden;
    transition: all 0.3s ease;
    position: relative;
}

.factory-card:hover {
    box-shadow: 
        0 8px 30px rgba(0, 212, 255, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    border-color: rgba(0, 212, 255, 0.25);
    transform: translateY(-2px);
}

/* Factory Header */
.factory-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.15);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.factory-miniature {
    width: 64px;
    height: 64px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.factory-miniature img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}

.factory-emoji {
    font-size: 36px;
}

.factory-info {
    flex: 1;
}

.factory-name {
    font-size: 18px;
    font-weight: 600;
    color: #00d4ff;
    margin-bottom: 4px;
    text-shadow: 0 0 10px rgba(0, 212, 255, 0.2);
}

.factory-order-count {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.6);
    letter-spacing: 0.3px;
}

/* Factory Orders */
.factory-orders {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Order Row */
.order-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 10px;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    position: relative;
    z-index: 1;
}

.order-row:hover {
    background: rgba(0, 212, 255, 0.05);
    border-color: rgba(0, 212, 255, 0.1);
    transform: translateX(4px);
}

/* Order Product */
.order-product {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.product-emoji {
    font-size: 24px;
    flex-shrink: 0;
}

.product-name {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.85);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Order Time */
.order-time {
    font-size: 13px;
    font-family: 'SF Mono', 'Monaco', 'Inconsolata', monospace;
    color: rgba(255, 255, 255, 0.6);
    min-width: 70px;
    text-align: center;
    background: rgba(0, 0, 0, 0.2);
    padding: 5px 10px;
    border-radius: 8px;
    font-weight: 500;
}

.order-time.ready {
    color: #4caf50;
    background: rgba(76, 175, 80, 0.1);
    font-weight: 600;
    text-shadow: 0 0 8px rgba(76, 175, 80, 0.3);
}

/* Speedup Button - Ensure clickable */
.order-row .speedup-btn {
    padding: 6px 14px;
    background: linear-gradient(135deg,
        rgba(0, 212, 255, 0.15),
        rgba(0, 150, 200, 0.1));
    border: 1px solid rgba(0, 212, 255, 0.25);
    border-radius: 8px;
    color: #00d4ff;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    position: relative;
    z-index: 10;
    pointer-events: auto;
}

.order-row .speedup-btn:hover:not(:disabled) {
    background: linear-gradient(135deg,
        rgba(0, 212, 255, 0.25),
        rgba(0, 150, 200, 0.2));
    box-shadow: 0 4px 12px rgba(0, 212, 255, 0.2);
    transform: scale(1.05);
}

.order-row .speedup-btn:active {
    transform: scale(0.98);
}

.order-row .speedup-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.order-row .speedup-btn.ready {
    background: linear-gradient(135deg,
        rgba(76, 175, 80, 0.15),
        rgba(56, 142, 60, 0.1));
    border-color: rgba(76, 175, 80, 0.25);
    color: #4caf50;
}

.order-row .speedup-btn span {
    display: inline-flex;
    align-items: center;
}

/* Loading Spinner */
.loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px;
    grid-column: 1 / -1;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(0, 212, 255, 0.1);
    border-radius: 50%;
    border-top-color: #00d4ff;
    animation: spin 0.8s linear infinite;
}

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

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
}

.empty-icon {
    font-size: 72px;
    margin-bottom: 16px;
    opacity: 0.3;
    filter: grayscale(0.5);
}

.empty-state h3 {
    font-size: 22px;
    color: rgba(255, 255, 255, 0.8);
    margin-bottom: 8px;
    font-weight: 600;
}

.empty-state p {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
}

/* Mobile - Full Screen Modal */
@media (max-width: 768px) {
    .building-manager-modal .modal-content {
        margin: 0;
        width: 100%;
        height: 100%;
        max-width: 100%;
        max-height: 100vh;
        border: none;
        border-radius: 0;
        /* More transparent for mobile */
        background: linear-gradient(145deg, 
            rgba(10, 25, 47, 0.25), 
            rgba(0, 15, 30, 0.25));
        backdrop-filter: blur(25px);
        -webkit-backdrop-filter: blur(25px);
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
        /* Ensure scrolling works on mobile */
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Fallback for browsers without backdrop-filter */
    @supports not (backdrop-filter: blur(25px)) {
        .building-manager-modal .modal-content {
            background: linear-gradient(145deg, 
                rgba(10, 25, 47, 0.95), 
                rgba(0, 15, 30, 0.95));
        }
    }
    
    .building-manager-modal .modal-header-section {
        padding: 16px 20px;
    }
    
    .building-manager-modal .modal-header {
        font-size: 20px;
    }
    
    .building-manager-actions {
        padding: 16px;
        gap: 12px;
    }
    
    .building-manager-actions .action-button {
        min-width: 100%;
        padding: 12px 16px;
    }
    
    .factory-orders-container {
        grid-template-columns: 1fr;
        padding: 16px;
        gap: 16px;
    }
    
    .factory-header {
        padding: 14px;
    }
    
    .factory-miniature {
        width: 56px;
        height: 56px;
    }
    
    .factory-name {
        font-size: 16px;
    }
    
    .order-row {
        flex-wrap: wrap;
        padding: 10px;
    }
    
    .order-product {
        width: 100%;
        margin-bottom: 8px;
    }
    
    .order-time {
        flex: 1;
    }
    
    .order-row .speedup-btn {
        flex: 1;
    }
}

/* Portrait Mode Safe Areas */
@media (orientation: portrait) {
    .building-manager-modal .modal-content {
        /* Safe area padding for notch and home indicator */
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: env(safe-area-inset-bottom, 0);
        /* Ensure scrolling works properly */
        overflow-y: auto;
        overflow-x: hidden;
    }
    
    .factory-orders-container {
        grid-template-columns: 1fr;
        /* Safe area + extra space so final row clears the home indicator */
        padding-bottom: calc(env(safe-area-inset-bottom, 0) + 50px);
    }
}

/* Landscape Mode */
@media (orientation: landscape) and (min-width: 768px) and (max-width: 1024px) {
    .factory-orders-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Small Landscape (iPhone) */
@media (max-width: 812px) and (orientation: landscape) {
    .building-manager-modal .modal-content {
        margin: 0;
        width: 100%;
        height: 100%;
        max-width: 100vw;
        max-height: 100vh;
        border-radius: 0;
        /* Very transparent with strong blur for landscape */
        background: linear-gradient(145deg, 
            rgba(10, 25, 47, 0.2), 
            rgba(0, 15, 30, 0.2));
        backdrop-filter: blur(30px);
        -webkit-backdrop-filter: blur(30px);
        /* Ensure scrolling works in landscape */
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
  
    
    .building-manager-actions {
        gap: 10px;
    }
    
    .building-manager-actions .action-button {
        min-width: 220px;
        padding: 10px 14px;
    }
    
    .factory-orders-container {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    }
}

/* Large Screens */
@media (min-width: 1400px) {
    .factory-orders-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 24px;
        padding: 32px;
    }
}

/* Dark mode optimization */
@media (prefers-color-scheme: dark) {
    .building-manager-modal .modal-content {
        background: linear-gradient(145deg, 
            rgba(10, 25, 47, 0.35), 
            rgba(0, 15, 30, 0.35));
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .building-manager-modal,
    .building-manager-modal::before,
    .action-button,
    .factory-card,
    .order-row,
    .speedup-btn {
        animation: none;
        transition: none;
    }
}

/* ===== CONFIRMATION DIALOG MODAL ===== */
/* Moved from style.css for better organization */

.confirmation-modal {
    z-index: 10100 !important; /* Higher than building manager modal (10000) */
}

.confirmation-content {
    max-width: 400px;
    width: 90%;
    background: linear-gradient(135deg, #1a1a2e 0%, #0f0f23 100%);
    border: 2px solid rgba(255, 165, 0, 0.3);
    border-radius: 20px;
    padding: 30px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8),
                0 0 60px rgba(255, 165, 0, 0.2);
    position: relative;
    overflow: hidden;
    z-index: 10101; /* Ensure content is above overlay */
}

.confirmation-content::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 165, 0, 0.1) 0%, transparent 70%);
    animation: pulse 3s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.1); opacity: 0.8; }
}

.confirmation-icon {
    font-size: 64px;
    margin-bottom: 20px;
    filter: drop-shadow(0 0 20px rgba(255, 165, 0, 0.5));
    animation: iconFloat 2s ease-in-out infinite;
    position: relative;
    z-index: 1;
}

@keyframes iconFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.confirmation-message {
    font-size: 18px;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 30px;
    line-height: 1.5;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    position: relative;
    z-index: 1;
}

.confirmation-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
    position: relative;
    z-index: 1;
}

.confirm-btn {
    padding: 12px 30px;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
    position: relative;
    overflow: hidden;
}

.confirm-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.confirm-btn:hover::before {
    left: 100%;
}

.confirm-yes {
    background: linear-gradient(135deg, #FF6F00, #FFB300);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 165, 0, 0.4);
}

.confirm-yes:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(255, 165, 0, 0.6);
}

.confirm-no {
    background: linear-gradient(135deg, #2a2a3e, #1f1f33);
    color: rgba(255, 255, 255, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.2);
}

.confirm-no:hover {
    background: linear-gradient(135deg, #3a3a4e, #2f2f43);
    border-color: rgba(255, 255, 255, 0.4);
    transform: translateY(-2px);
}

/* Mobile responsive for confirmation dialog */
@media (max-width: 480px) {
    .confirmation-content {
        padding: 20px;
    }
    
    .confirmation-icon {
        font-size: 48px;
    }
    
    .confirmation-message {
        font-size: 16px;
    }
    
    .confirm-btn {
        padding: 10px 20px;
        font-size: 14px;
    }
}

/* ===== Confirmation Modal: Safe Areas + Prevent Fullscreen on iPhone ===== */
/* Keep confirmation dialog as a centered card on small screens (override unified fullscreen) */
@media (max-width: 768px) {
    .confirmation-modal .unified-modal-content {
        /* Do NOT go fullscreen; keep it centered and sized to content */
        margin: max(20px, env(safe-area-inset-top)) auto max(20px, env(safe-area-inset-bottom));
        width: auto;
        height: auto;
        max-width: 420px;
        max-height: calc(100vh - max(env(safe-area-inset-top), 20px) - max(env(safe-area-inset-bottom), 20px));
        border: 2px solid rgba(255, 165, 0, 0.3);
        border-radius: 20px;
        box-sizing: border-box;
        /* Ensure scrolling inside if content grows */
        overflow: auto;
    }
}

/* Landscape phones/tablets: override aggressive fullscreen rules with a card layout */
@media (max-width: 1024px) and (orientation: landscape) {
    .confirmation-modal .unified-modal-content {
        margin: max(16px, env(safe-area-inset-top)) auto max(16px, env(safe-area-inset-bottom)) !important;
        width: auto !important;
        height: auto !important;
        max-width: 520px !important;
        max-height: calc(100vh - max(env(safe-area-inset-top), 16px) - max(env(safe-area-inset-bottom), 16px)) !important;
        border: 2px solid rgba(255, 165, 0, 0.3) !important;
        border-radius: 20px !important;
        box-sizing: border-box !important;
        overflow: auto !important;
    }
}

/* ===== iPhone Landscape: remove unintended cyan border on fullscreen modals ===== */
/* The building manager uses a fullscreen layout in landscape; hide its edge border */
@media (max-width: 1024px) and (orientation: landscape) {
    .building-manager-modal .modal-content {
        /* Avoid a cyan stroke around the entire viewport */
        border: none !important;
        /* Keep content within safe areas for notches/indicators */
        padding-left: max(env(safe-area-inset-left), 0px);
        padding-right: max(env(safe-area-inset-right), 0px);
        box-sizing: border-box;
    }
}
