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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #0f172a;
    min-height: 100vh;
    padding: 20px;
}

.container {
    background: white;
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    max-width: 900px;
    width: 100%;
}

h1 {
    color: #333;
    margin-bottom: 5px;
    font-size: 1.5em;
}

.subtitle {
    color: #64748b;
    margin-bottom: 30px;
    font-size: 14px;
    border-bottom: 2px solid #f1f5f9;
    padding-bottom: 10px;
}

.dropdowns-container {
    display: flex;
    gap: 20px;
    margin-bottom: 25px;
}

.form-group {
    flex: 1;
}

label {
    display: block;
    margin-bottom: 8px;
    color: #555;
    font-weight: 600;
    font-size: 14px;
}

select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    color: #333;
    background-color: white;
    cursor: pointer;
    transition: all 0.3s ease;
}

select:hover {
    border-color: #667eea;
}

select:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

select option {
    padding: 10px;
}

.info-box {
    background: #f8f9fa;
    border-left: 4px solid #667eea;
    padding: 15px;
    border-radius: 8px;
    margin-top: 20px;
    display: none;
}

.info-box.show {
    display: block;
}

.info-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-value {
    font-size: 14px;
    color: #333;
    font-family: 'Courier New', monospace;
    word-break: break-all;
}

.loading {
    text-align: center;
    color: #666;
    padding: 20px;
}

.error {
    background: #fee;
    border-left: 4px solid #e53e3e;
    padding: 15px;
    border-radius: 8px;
    color: #c53030;
    font-size: 14px;
}

.status-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    margin-left: 8px;
}

.status-active {
    background: #d4edda;
    color: #155724;
}

.status-inactive {
    background: #f8d7da;
    color: #721c24;
}

.main-container {
    max-width: 900px;
    margin: 0 auto;
    padding-bottom: 40px;
}

.header {
    text-align: center;
    padding: 40px 20px;
    color: white;
}

.logo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 20px;
}

.logo {
    height: 130px;
    width: auto;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
    transition: transform 0.3s ease;
}

.logo:hover {
    transform: scale(1.05);
}

.header h1 {
    font-size: 2.5em;
    font-weight: 700;
    margin-bottom: 10px;
    background: linear-gradient(135deg, #60a5fa, #3b82f6);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header p {
    color: #94a3b8;
    font-size: 1.1em;
}

.connection-status {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.1);
    font-size: 0.9em;
    color: white;
}

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

.status-dot.connected {
    background: #22c55e;
    animation: none;
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.5;
    }
}

.section {
    background: white;
    border-radius: 20px;
    padding: 30px;
    margin-bottom: 24px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 1px solid #e2e8f0;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 2px solid #f1f5f9;
}

.section-title {
    flex: 1;
}

.section-title h2 {
    font-size: 1.5em;
    color: #1e293b;
    margin-bottom: 4px;
}

.section-title p {
    font-size: 0.9em;
    color: #64748b;
}

.status-badge {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
    background: #dbeafe;
    color: #1e40af;
}

.status-badge.disabled {
    background: #f1f5f9;
    color: #64748b;
}

.instruction-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    margin-bottom: 20px;
}

.instruction-box {
    background: #f8fafc;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 20px;
    transition: all 0.3s ease;
}

.instruction-box:hover {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.instruction-label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-weight: 600;
    color: #1e293b;
    font-size: 0.95em;
}

textarea {
    width: 100%;
    min-height: 100px;
    padding: 14px;
    border: none;
    border-radius: 8px;
    font-size: 0.95em;
    font-family: inherit;
    resize: vertical;
    background: white;
    color: #334155;
    transition: all 0.3s ease;
}

textarea:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.button-group {
    display: flex;
    gap: 12px;
    margin-top: 12px;
}

.btn {
    flex: 1;
    padding: 12px 24px;
    border: none;
    border-radius: 10px;
    font-size: 0.95em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
    background: white;
    color: #3b82f6;
    border: 2px solid #3b82f6;
}

.btn-secondary:hover:not(:disabled) {
    background: #f0f9ff;
}

.relay-groups {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.relay-group {
    background: #f8fafc;
    border-radius: 16px;
    padding: 20px;
    border: 2px solid #e2e8f0;
}

.group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid #e2e8f0;
}

.group-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.group-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7em;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    font-weight: 700;
}

.group-details h3 {
    font-size: 1.1em;
    color: #1e293b;
    margin-bottom: 2px;
}

.group-details p {
    font-size: 0.85em;
    color: #64748b;
}

.group-toggle {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.85em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.toggle-btn.on {
    background: linear-gradient(135deg, #22c55e, #16a34a);
    color: white;
}

.toggle-btn.off {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
}

.toggle-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.toggle-btn.disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    filter: grayscale(0.3);
}

.toggle-btn.disabled:hover {
    transform: none;
    box-shadow: none;
}

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

@media (min-width: 640px) {
    .relay-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .relay-grid {
        grid-template-columns: repeat(4, 1fr);
    }
}

.relay-card {
    background: white;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    padding: 16px;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    user-select: none;
}

.relay-card:hover {
    transform: translateY(-4px);
    border-color: #3b82f6;
    box-shadow: 0 8px 16px rgba(59, 130, 246, 0.15);
}

.relay-card.active {
    background: linear-gradient(135deg, #dbeafe, #bfdbfe);
    border-color: #3b82f6;
    box-shadow: 0 8px 16px rgba(59, 130, 246, 0.2);
}

.relay-card.disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
    pointer-events: none !important;
    filter: grayscale(0.3);
}

.relay-card.disabled:hover {
    transform: none;
    border-color: #e2e8f0;
    box-shadow: none;
}

.relay-visual {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #cbd5e0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    position: relative;
}

.relay-visual::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #94a3b8;
    transition: all 0.3s ease;
}

.relay-card.active .relay-visual {
    background: #3b82f6;
    box-shadow: 0 0 20px rgba(59, 130, 246, 0.6), 0 0 40px rgba(59, 130, 246, 0.4);
}

.relay-card.active .relay-visual::before {
    background: #60a5fa;
    box-shadow: 0 0 10px rgba(96, 165, 250, 0.8);
}

.relay-label {
    font-weight: 600;
    color: #475569;
    font-size: 0.85em;
    text-align: center;
    line-height: 1.3;
}

/* The relay number stays visible: sequences, the API and the wiring all address relays by
   number, so an operator still needs it even though the name is what identifies the fixture. */
.relay-number {
    font-size: 0.72em;
    font-weight: 500;
    color: #94a3b8;
    text-align: center;
    letter-spacing: 0.02em;
    margin-top: -4px;
}

.relay-card.active .relay-number {
    color: #64748b;
}

.relay-card.active .relay-label {
    color: #1e40af;
}

.sequence-grid {
    display: grid;
    gap: 16px;
    margin-bottom: 24px;
}

.sequence-card {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-radius: 16px;
    padding: 24px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    text-align: left;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
    position: relative;
    overflow: hidden;
}

.sequence-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sequence-card:hover::before {
    opacity: 1;
}

.sequence-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(59, 130, 246, 0.4);
}

.sequence-card.active {
    background: linear-gradient(135deg, #1e40af, #1e3a8a);
    box-shadow: 0 8px 24px rgba(30, 64, 175, 0.5);
}

.sequence-card.sequence-2 {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
}

.sequence-card.sequence-2.active {
    background: linear-gradient(135deg, #0369a1, #075985);
}

.sequence-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.sequence-number {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1em;
}

.sequence-card h3 {
    font-size: 1.3em;
    margin-bottom: 8px;
}

.sequence-card p {
    opacity: 0.9;
    font-size: 0.9em;
    line-height: 1.6;
}

.presentation-controls {
    display: flex;
    gap: 12px;
}

.btn-stop {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-stop:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.status-message {
    margin-top: 16px;
    padding: 14px 18px;
    border-radius: 10px;
    font-size: 0.9em;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 10px;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.3s ease;
}

.status-message.show {
    opacity: 1;
    transform: translateY(0);
}

.status-message.success {
    background: #dcfce7;
    color: #166534;
    border: 1px solid #bbf7d0;
}

.status-message.error {
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.status-message.info {
    background: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

@media (max-width: 640px) {
    .header h1 {
        font-size: 2em;
    }

    .section {
        padding: 20px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .button-group {
        flex-direction: column;
    }

    .presentation-controls {
        flex-direction: column;
    }

    .group-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
}

/* User Devices Modal - Responsive Grid */
#userDevicesModal .devices-grid {
    display: grid;
    gap: 24px;
    padding: 8px 0;
}

/* Devices Summary Styling */
#userDevicesModal .devices-summary {
    margin-bottom: 24px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

#userDevicesModal .devices-summary-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

#userDevicesModal .devices-summary-label {
    color: #e2e8f0;
    font-size: 0.95em;
    font-weight: 600;
}

#userDevicesModal .devices-summary-count {
    color: #e2e8f0;
    font-size: 1.2em;
    font-weight: 700;
}

/* Mobile: Always 1 device per row */
@media (max-width: 640px) {
    #userDevicesModal .devices-grid {
        grid-template-columns: 1fr;
    }
}

/* Tablet and Desktop: Responsive based on device count */
@media (min-width: 641px) {
    /* Single device: centered, fills row */
    #userDevicesModal .devices-grid-single {
        grid-template-columns: 1fr;
        max-width: 100%;
    }
    
    /* Two devices: centered, fill full row */
    #userDevicesModal .devices-grid-double {
        grid-template-columns: repeat(2, 1fr);
        max-width: 100%;
    }
    
    /* Three devices: equal area */
    #userDevicesModal .devices-grid-triple {
        grid-template-columns: repeat(3, 1fr);
        max-width: 100%;
    }
    
    /* More than 3: max 3 per row, wrap to next row */
    #userDevicesModal .devices-grid-multiple {
        grid-template-columns: repeat(3, 1fr);
        max-width: 100%;
    }
    
    /* Default devices-grid (if no specific class) */
    #userDevicesModal .devices-grid:not(.devices-grid-single):not(.devices-grid-double):not(.devices-grid-triple):not(.devices-grid-multiple) {
        grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    }
}

/* User Filter Buttons */
.user-filter-btn {
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    background: rgba(255, 255, 255, 0.05);
    color: #cbd5e1;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.user-filter-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.user-filter-btn.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(99, 102, 241, 0.3));
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.user-filter-btn[data-filter="Honey Gallery"].active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(99, 102, 241, 0.3));
    color: #93c5fd;
    border-color: rgba(59, 130, 246, 0.5);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.2);
}

.user-filter-btn[data-filter="Evicenna"].active {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.3), rgba(139, 92, 246, 0.3));
    color: #c4b5fd;
    border-color: rgba(168, 85, 247, 0.5);
    box-shadow: 0 4px 12px rgba(168, 85, 247, 0.2);
}

.user-filter-btn[data-filter="Half Million"].active {
    background: linear-gradient(135deg, rgba(251, 146, 60, 0.3), rgba(249, 115, 22, 0.3));
    color: #fed7aa;
    border-color: rgba(251, 146, 60, 0.5);
    box-shadow: 0 4px 12px rgba(251, 146, 60, 0.2);
}