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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: #fff;
    min-height: 100vh;
}

.container {
    max-width: 1920px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 15px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.header-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.status-bar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 20px;
    flex: 1;
}

.layout-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.layout-label {
    font-size: 0.9rem;
    font-weight: 600;
    margin-right: 4px;
}

.layout-btn {
    background: rgba(255, 255, 255, 0.15);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.layout-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.05);
}

.layout-btn.active {
    background: rgba(76, 175, 80, 0.4);
    border-color: rgba(76, 175, 80, 0.8);
    box-shadow: 0 0 10px rgba(76, 175, 80, 0.5);
}

.layout-icon {
    width: 28px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-grid {
    display: grid;
    gap: 2px;
    width: 100%;
    height: 100%;
}

/* Auto icon - 2x2 with dashed border */
.auto-icon .icon-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.auto-icon .icon-grid span {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 2px;
    border: 1px dashed rgba(255, 255, 255, 0.5);
}

/* Single column icon */
.single-icon .icon-grid {
    grid-template-columns: 1fr;
    padding: 0 6px;
}

.single-icon .icon-grid span {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 2px;
    height: 100%;
}

/* Two columns icon */
.two-col-icon .icon-grid {
    grid-template-columns: repeat(2, 1fr);
}

.two-col-icon .icon-grid span {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 2px;
    height: 100%;
}

/* 2x2 Grid icon */
.grid-2x2-icon .icon-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: repeat(2, 1fr);
}

.grid-2x2-icon .icon-grid span {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 2px;
}

/* Three columns icon */
.three-col-icon .icon-grid {
    grid-template-columns: repeat(3, 1fr);
}

.three-col-icon .icon-grid span {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 2px;
    height: 100%;
}

/* Four columns icon */
.four-col-icon .icon-grid {
    grid-template-columns: repeat(4, 1fr);
}

.four-col-icon .icon-grid span {
    background: rgba(255, 255, 255, 0.7);
    border-radius: 2px;
    height: 100%;
}

.reset-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.reset-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.settings-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: white;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.settings-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.status-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255, 255, 255, 0.1);
    padding: 8px 16px;
    border-radius: 20px;
    backdrop-filter: blur(10px);
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ffd700;
    animation: pulse 2s ease-in-out infinite;
}

.status-dot.connected {
    background: #00ff00;
}

.status-dot.error {
    background: #ff4444;
    animation: none;
}

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

/* Default auto layout */
.grid-container {
    display: grid !important;
    gap: 20px;
    margin-bottom: 30px;
    grid-template-columns: repeat(auto-fit, minmax(600px, 1fr));
}

/* Layout options */
.grid-container.layout-auto {
    grid-template-columns: repeat(auto-fit, minmax(600px, 1fr)) !important;
}

.grid-container.layout-1x1 {
    grid-template-columns: 1fr !important;
}

.grid-container.layout-2x1 {
    grid-template-columns: repeat(2, 1fr) !important;
}

.grid-container.layout-2x2 {
    grid-template-columns: repeat(2, 1fr) !important;
    grid-template-rows: repeat(2, 1fr) !important;
}

.grid-container.layout-3x1 {
    grid-template-columns: repeat(3, 1fr) !important;
}

.grid-container.layout-4x1 {
    grid-template-columns: repeat(4, 1fr) !important;
}

@media (max-width: 1400px) {
    .grid-container.layout-auto {
        grid-template-columns: repeat(auto-fit, minmax(500px, 1fr)) !important;
    }
}

@media (max-width: 768px) {
    .grid-container,
    .grid-container.layout-2x1,
    .grid-container.layout-2x2,
    .grid-container.layout-3x1,
    .grid-container.layout-4x1 {
        grid-template-columns: 1fr !important;
    }

    header h1 {
        font-size: 1.8rem;
    }

    .header-controls {
        flex-direction: column;
        gap: 10px;
    }

    .status-bar {
        justify-content: center;
    }

    .layout-controls {
        width: 100%;
        justify-content: center;
        flex-wrap: wrap;
    }

    .layout-label {
        width: 100%;
        text-align: center;
        margin-bottom: 4px;
    }
}

.camera-card {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    overflow: hidden;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.camera-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.camera-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
}

.camera-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.stream-status {
    font-size: 1.5rem;
    color: #ffd700;
    animation: pulse 2s ease-in-out infinite;
}

.stream-status.connected {
    color: #00ff00;
    animation: none;
}

.stream-status.error {
    color: #ff4444;
    animation: none;
}

.video-container {
    position: relative;
    width: 100%;
    padding-top: 56.25%; /* 16:9 aspect ratio */
    background: #000;
}

.camera-video {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    background: #000;
}

.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 15px;
    z-index: 10;
}

.loading-overlay.hidden {
    display: none;
}

.fullscreen-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 100;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.7;
    transition: all 0.3s ease;
    backdrop-filter: blur(5px);
}

.fullscreen-btn:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.8);
    border-color: rgba(255, 255, 255, 0.6);
    transform: scale(1.1);
}

.fullscreen-btn:active {
    transform: scale(0.95);
}

.status-overlay {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.95), transparent);
    padding: 15px;
    transform: translateY(100%);
    transition: transform 0.3s ease;
    z-index: 50;
    pointer-events: none;
}

.status-overlay.active {
    transform: translateY(0);
}

.print-info {
    color: white;
}

.print-file {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.print-progress {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #8bc34a);
    border-radius: 4px;
    transition: width 0.5s ease;
}

.progress-text {
    font-weight: 600;
    font-size: 0.85rem;
    min-width: 40px;
    text-align: right;
}

.print-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    margin-bottom: 8px;
}

.detail-item {
    display: flex;
    gap: 5px;
}

.detail-item .label {
    opacity: 0.7;
}

.detail-item .value {
    font-weight: 600;
}

.temp-info {
    display: flex;
    justify-content: space-around;
    font-size: 0.75rem;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
}

.temp-item {
    display: flex;
    align-items: center;
    gap: 5px;
}

.temp-icon {
    font-size: 1rem;
}

.temp-value {
    font-weight: 600;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Printer Status Section */
.printer-status {
    padding: 20px;
    background: rgba(0, 0, 0, 0.3);
    min-height: 120px;
}

.status-loading {
    text-align: center;
    opacity: 0.6;
    font-size: 0.9rem;
    padding: 20px;
}

/* Printing Status */
.status-printing {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.status-state {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    width: fit-content;
}

.status-state.printing {
    background: linear-gradient(135deg, #4caf50, #66bb6a);
    color: white;
    box-shadow: 0 2px 8px rgba(76, 175, 80, 0.4);
}

.status-state.idle {
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.print-file-name {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: white;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.print-file-name svg {
    flex-shrink: 0;
    opacity: 0.8;
}

.progress-section {
    display: flex;
    align-items: center;
    gap: 15px;
}

.progress-bar-container {
    flex: 1;
    height: 10px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #4caf50, #66bb6a, #4caf50);
    background-size: 200% 100%;
    border-radius: 10px;
    transition: width 0.5s ease;
    animation: shimmer 2s linear infinite;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.progress-percentage {
    font-size: 1.1rem;
    font-weight: 700;
    color: #66bb6a;
    min-width: 50px;
    text-align: right;
}

.status-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.08);
    padding: 10px;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.status-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    flex-shrink: 0;
}

.status-icon.nozzle {
    background: linear-gradient(135deg, #ff6b6b, #ff8e53);
}

.status-icon.bed {
    background: linear-gradient(135deg, #4facfe, #00f2fe);
}

.status-info {
    flex: 1;
    min-width: 0;
}

.status-label {
    font-size: 0.7rem;
    opacity: 0.7;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.status-value {
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Idle Status */
.status-idle {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.idle-temps {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.temp-reading {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.9rem;
}

.temp-reading svg {
    opacity: 0.7;
}

/* AMS Color Display */
.ams-section {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0 0 0;
    margin-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    flex-wrap: wrap;
}

.ams-label {
    font-size: 0.8rem;
    font-weight: 600;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    min-width: 40px;
}

.ams-trays {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ams-humidity {
    font-size: 0.85rem;
    padding: 4px 10px;
    background: rgba(33, 150, 243, 0.2);
    border: 1px solid rgba(33, 150, 243, 0.4);
    border-radius: 12px;
    color: #64b5f6;
    font-weight: 600;
}

.ams-tray {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.ams-color {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    transition: all 0.3s ease;
}

.ams-tray.active .ams-color {
    border-color: #66bb6a;
    border-width: 3px;
    box-shadow: 0 0 12px rgba(102, 187, 106, 0.6);
    transform: scale(1.1);
}

.ams-tray.empty .ams-color {
    opacity: 0.4;
    border-style: dashed;
}

.ams-indicator {
    font-size: 0.7rem;
    color: #66bb6a;
    font-weight: bold;
    animation: bounce 2s ease-in-out infinite;
}

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

@media (max-width: 768px) {
    .status-grid {
        grid-template-columns: 1fr;
    }

    .idle-temps {
        flex-direction: column;
        gap: 10px;
    }

    .ams-section {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .ams-color {
        width: 28px;
        height: 28px;
    }
}

footer {
    text-align: center;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    backdrop-filter: blur(10px);
}

footer p {
    font-size: 0.9rem;
    opacity: 0.8;
}

/* Resizable cards */
.camera-card.resizable {
    position: relative;
    min-width: 300px;
    min-height: 250px;
    transition: none; /* Disable transition during drag/resize */
}


.resize-handle {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    cursor: nwse-resize;
    background: linear-gradient(135deg, transparent 0%, transparent 50%, rgba(255,255,255,0.3) 50%, rgba(255,255,255,0.3) 100%);
    border-bottom-right-radius: 15px;
    z-index: 10;
}

.resize-handle:hover {
    background: linear-gradient(135deg, transparent 0%, transparent 50%, rgba(255,255,255,0.5) 50%, rgba(255,255,255,0.5) 100%);
}

/* No printers message */
.no-printers {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    backdrop-filter: blur(10px);
    font-size: 1.2rem;
    opacity: 0.8;
}

/* Dynamic grid adjustments for different numbers of printers */
.grid-container {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 20px;
    align-items: flex-start;
}

.grid-container .camera-card {
    flex: 1 1 auto;
    max-width: 100%;
}

@media (max-width: 768px) {
    .grid-container {
        grid-template-columns: 1fr;
    }
    
    .camera-card.resizable {
        min-width: 100%;
    }
    
    .resize-handle {
        display: none; /* Hide resize on mobile */
    }
}
