/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    height: 100vh;
    overflow: hidden;
}

/* Container setup for iframe compatibility */
.container {
    width: 100%;
    height: 450px; /* Default iframe height */
    padding: 10px;
    display: grid;
    grid-template-columns: 1fr 250px;
    grid-template-rows: auto 1fr auto;
    grid-template-areas: 
        "controls details"
        "table details"
        "legend analytics";
    gap: 10px;
    background: rgba(255, 255, 255, 0.95);
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
}

/* Adjust height for full browser view */
@media (min-height: 600px) {
    body:not(.iframe-mode) .container {
        height: 90vh;
    }
}

/* Control Panel */
.control-panel {
    grid-area: controls;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.filter-section {
    display: flex;
    align-items: center;
    gap: 8px;
}

.filter-section label {
    font-weight: 600;
    color: #495057;
    font-size: 14px;
}

#property-select {
    padding: 6px 12px;
    border: 2px solid #dee2e6;
    border-radius: 4px;
    font-size: 14px;
    background: white;
    min-height: 44px; /* Touch-friendly */
    cursor: pointer;
}

.group-filters {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.group-filters label {
    font-weight: 600;
    color: #495057;
    font-size: 14px;
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    cursor: pointer;
    min-height: 44px; /* Touch-friendly */
}

.checkbox-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.reset-button {
    padding: 8px 16px;
    background: #dc3545;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px; /* Touch-friendly */
    transition: all 0.3s ease;
}

.reset-button:hover {
    background: #c82333;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(220, 53, 69, 0.3);
}

/* Periodic Table Container */
.periodic-table-container {
    grid-area: table;
    overflow: auto;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 10px;
}

.periodic-table {
    display: grid;
    grid-template-columns: repeat(18, 1fr);
    gap: 2px;
    min-width: 600px;
}

/* Element cells */
.element {
    aspect-ratio: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    border: 2px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 10px;
    font-weight: 600;
    text-align: center;
    min-height: 44px; /* Touch-friendly */
    position: relative;
}

.element:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    z-index: 10;
}

.element.selected {
    border-color: #007bff;
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.25);
}

.element-symbol {
    font-size: 12px;
    font-weight: bold;
}

.element-number {
    font-size: 8px;
    color: #666;
}

.element-name {
    font-size: 7px;
    color: #666;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

/* Element group colors */
.alkali-metals { background: #ff6b6b; color: white; }
.alkaline-earth { background: #feca57; color: black; }
.transition-metals { background: #48dbfb; color: black; }
.metalloids { background: #ff9ff3; color: black; }
.nonmetals { background: #54a0ff; color: white; }
.noble-gases { background: #5f27cd; color: white; }
.other-metals { background: #00d2d3; color: black; }
.lanthanides { background: #ff3838; color: white; }
.actinides { background: #ff6348; color: white; }

/* Element Details Panel */
.element-details {
    grid-area: details;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 15px;
    overflow-y: auto;
}

.element-info h3 {
    color: #495057;
    margin-bottom: 15px;
    font-size: 18px;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 8px;
}

.element-properties {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.property-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px;
    background: #f8f9fa;
    border-radius: 4px;
}

.property-label {
    font-weight: 600;
    color: #495057;
    font-size: 14px;
}

/* Analytics Panel */
.analytics-panel {
    grid-area: analytics;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 15px;
}

.analytics-panel h4 {
    color: #495057;
    margin-bottom: 10px;
    font-size: 16px;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 5px;
}

.analytics-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 8px;
    background: #f8f9fa;
    border-radius: 4px;
    font-size: 12px;
}

.stat-label {
    font-weight: 600;
    color: #495057;
}

/* Legend */
.legend {
    grid-area: legend;
    background: white;
    border-radius: 6px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 15px;
}

.legend h4 {
    color: #495057;
    margin-bottom: 10px;
    font-size: 16px;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 5px;
}

.legend-items {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.legend-color {
    width: 16px;
    height: 16px;
    border-radius: 3px;
    border: 1px solid #dee2e6;
}

/* Tooltip */
.tooltip {
    position: absolute;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 8px 12px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s ease;
    max-width: 200px;
    text-align: center;
}

.tooltip.show {
    opacity: 1;
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-areas: 
            "controls"
            "table"
            "details"
            "legend"
            "analytics";
        height: auto;
        min-height: 100vh;
    }
    
    .control-panel {
        flex-direction: column;
        align-items: stretch;
    }
    
    .checkbox-group {
        flex-direction: column;
    }
    
    .periodic-table {
        grid-template-columns: repeat(9, 1fr);
        min-width: auto;
    }
    
    .element {
        font-size: 8px;
        min-height: 40px;
    }
    
    .element-symbol {
        font-size: 10px;
    }
    
    .element-number {
        font-size: 6px;
    }
    
    .element-name {
        font-size: 5px;
    }
    
    .legend-items {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Touch-specific enhancements */
@media (hover: none) and (pointer: coarse) {
    .element:hover {
        transform: none;
    }
    
    .element:active {
        transform: scale(0.95);
        background-color: rgba(0, 123, 255, 0.1);
    }
    
    .reset-button:hover {
        transform: none;
    }
    
    .reset-button:active {
        transform: scale(0.95);
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .element {
        border-width: 3px;
    }
    
    .element.selected {
        border-width: 4px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}