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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    color: #333;
}

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

header {
    text-align: center;
    color: white;
    margin-bottom: 30px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 15px;
    backdrop-filter: blur(10px);
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

header p {
    font-size: 1.2em;
    opacity: 0.95;
}

.main-layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 30px;
    min-height: 600px;
}

/* Sidebar Styles */
.sidebar {
    background: white;
    border-radius: 15px;
    padding: 25px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
    height: fit-content;
}

.sidebar h2 {
    color: #667eea;
    margin-bottom: 20px;
    font-size: 1.4em;
}

.sidebar h3 {
    color: #555;
    margin-bottom: 15px;
    font-size: 1.1em;
}

.file-upload {
    margin-bottom: 20px;
}

.file-upload input[type="file"] {
    display: none;
}

.file-label {
    display: block;
    padding: 12px 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-radius: 8px;
    cursor: pointer;
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
}

.file-label:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

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

.image-info.active {
    display: block;
}

.grid-config {
    margin-top: 30px;
}

.grid-inputs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
}

.input-group {
    display: flex;
    flex-direction: column;
}

.input-group label {
    font-size: 0.9em;
    color: #666;
    margin-bottom: 5px;
}

.input-group input {
    padding: 8px 12px;
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    font-size: 1em;
    transition: border-color 0.3s;
}

.input-group input:focus {
    outline: none;
    border-color: #667eea;
}

.grid-hint {
    font-size: 0.85em;
    color: #666;
    text-align: center;
    margin: 10px 0;
    font-style: italic;
}

.grid-status {
    padding: 10px;
    background: #d4f4dd;
    border-radius: 6px;
    margin-bottom: 15px;
    color: #2e7d32;
    font-size: 0.9em;
    display: none;
}

.grid-status.active {
    display: block;
}

/* Button Styles */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1em;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
    margin-bottom: 10px;
    font-weight: 600;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #f0f0f0;
    color: #333;
}

.btn-secondary:hover {
    background: #e0e0e0;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.9em;
    width: auto;
    margin: 0;
}

/* Main Content Styles */
.content {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

.welcome {
    text-align: center;
    padding: 40px;
}

.info-box {
    max-width: 600px;
    margin: 0 auto;
}

.info-box h2 {
    color: #667eea;
    margin-bottom: 20px;
}

.instructions {
    text-align: left;
    margin-top: 40px;
    padding: 25px;
    background: #f8f9fa;
    border-radius: 10px;
}

.instructions h3 {
    color: #555;
    margin-bottom: 15px;
}

.instructions ol, .instructions ul {
    margin-left: 20px;
    line-height: 1.8;
}

.instructions li {
    margin-bottom: 10px;
}

/* Canvas Section */
.canvas-section {
    width: 100%;
}

.canvas-header {
    text-align: center;
    margin-bottom: 20px;
}

.canvas-header h2 {
    color: #667eea;
    margin-bottom: 10px;
}

.canvas-controls {
    display: flex;
    gap: 15px;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox input {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.instructions-banner {
    padding: 15px;
    background: #e3f2fd;
    border-radius: 8px;
    margin-bottom: 20px;
    color: #1976d2;
    border-left: 4px solid #1976d2;
}

.canvas-container {
    position: relative;
    display: inline-block;
    margin: 0 auto;
    width: 100%;
    text-align: center;
    background: #f5f5f5;
    border-radius: 10px;
    padding: 20px;
    overflow: auto;
}

#gridCanvas {
    display: block;
    margin: 0 auto;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    cursor: crosshair;
    max-width: 100%;
    height: auto;
}

.canvas-info {
    position: absolute;
    top: 30px;
    left: 30px;
    background: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 0.9em;
    font-family: monospace;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    pointer-events: none;
}

/* Results Section */
.results-section {
    margin-top: 30px;
}

.results-section h2 {
    color: #667eea;
    margin-bottom: 20px;
}

.results-controls {
    margin-bottom: 20px;
}

.panels-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.panel-card {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s, box-shadow 0.3s;
}

.panel-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.panel-image {
    width: 100%;
    height: auto;
    display: block;
}

.panel-info {
    padding: 15px;
    background: #f8f9fa;
}

.panel-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 10px;
}

.panel-download {
    display: block;
    width: 100%;
    padding: 8px;
    background: #667eea;
    color: white;
    text-decoration: none;
    text-align: center;
    border-radius: 6px;
    transition: background 0.3s;
}

.panel-download:hover {
    background: #764ba2;
}

/* Loading State */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 768px) {
    .main-layout {
        grid-template-columns: 1fr;
    }
    
    .sidebar {
        margin-bottom: 20px;
    }
    
    .panels-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    }
}