/* ========================================
   Lissabon - Azulejo Tile Generator
   Stylesheet
   ======================================== */

/* Keyboard shortcut styles */
kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: var(--font-body);
    font-size: 11px;
    font-weight: 600;
    color: #666;
    background: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 3px;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
    margin-left: 8px;
    vertical-align: middle;
}

.section-title kbd {
    font-size: 10px;
    padding: 1px 5px;
    margin-left: 4px;
    opacity: 0.8;
}

label kbd {
    font-size: 10px;
    padding: 1px 4px;
    margin-left: 4px;
}

/* Shortcut display in buttons */
.btn .shortcut {
    display: inline-block;
    padding: 1px 5px;
    font-size: 10px;
    font-weight: 600;
    color: inherit;
    background: rgba(255,255,255,0.2);
    border-radius: 3px;
    margin-left: 6px;
    opacity: 0.8;
}

.btn-secondary .shortcut {
    background: rgba(0,0,0,0.1);
    color: inherit;
}

.btn-primary .shortcut {
    background: rgba(255,255,255,0.2);
}

/* Footer shortcuts hint */
.footer .shortcuts-hint {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-secondary);
}

.footer .shortcuts-hint kbd {
    margin-left: 4px;
    margin-right: 4px;
}

/* Shortcuts modal styles */
.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 24px;
}

.shortcut-section h3 {
    font-family: var(--font-heading);
    font-size: 14px;
    color: var(--primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

.shortcut-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.shortcut-row kbd {
    min-width: 40px;
    text-align: center;
    margin-left: 0;
}

/* CSS Variables */
:root {
    /* Colors */
    --primary: #1e3c72;
    --primary-light: #2a5298;
    --secondary: #3b82f6;
    --accent: #d4af37;
    --accent-light: #f4d03f;
    --background: #f5f5f0;
    --surface: #ffffff;
    --surface-elevated: #ffffff;
    --text-primary: #2c3e50;
    --text-secondary: #5c6b7a;
    --border: #d1d5db;
    --border-light: #e5e7eb;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;

    /* Typography */
    --font-heading: 'Playfair Display', Georgia, serif;
    --font-body: 'Source Sans Pro', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* Border Radius */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);

    /* Transitions */
    --transition: 200ms ease-out;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-body);
    background-color: var(--background);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
    font-weight: 600;
    line-height: 1.3;
}

h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }

/* Header */
.header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    padding: var(--space-md) var(--space-lg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
}

.header h1 {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.85;
    font-weight: 400;
}

.header-actions {
    display: flex;
    gap: var(--space-sm);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    white-space: nowrap;
}

.btn svg {
    flex-shrink: 0;
}

.btn-primary {
    background-color: var(--accent);
    color: var(--text-primary);
}

.btn-primary:hover {
    background-color: var(--accent-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.25);
}

.btn-outline {
    background-color: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

.btn-outline:hover {
    background-color: var(--primary);
    color: white;
}

.btn-generate {
    background: linear-gradient(135deg, var(--accent) 0%, #c9a227 100%);
    color: var(--text-primary);
    padding: var(--space-md) var(--space-xl);
    font-size: 16px;
    box-shadow: var(--shadow-md);
}

.btn-generate:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-generate:active {
    transform: translateY(0);
}

.btn-small {
    padding: var(--space-xs) var(--space-sm);
    font-size: 12px;
}

.btn-large {
    padding: var(--space-md) var(--space-lg);
    font-size: 16px;
}

.btn-icon {
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.btn-icon:hover {
    background-color: var(--border-light);
    color: var(--error);
}

/* Main Container */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Control Panel */
.control-panel {
    width: 320px;
    background-color: var(--surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    max-height: calc(100vh - 150px);
}

.panel-section {
    background-color: var(--surface-elevated);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    box-shadow: var(--shadow-sm);
}

.section-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: var(--space-md);
    padding-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-light);
}

.section-title svg {
    opacity: 0.8;
}

/* Form Controls */
.control-group {
    margin-bottom: var(--space-md);
}

.control-group:last-child {
    margin-bottom: 0;
}

.control-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-xs);
}

.text-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-body);
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: white;
    transition: all var(--transition);
}

.text-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 60, 114, 0.1);
}

.select-input {
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    font-family: var(--font-body);
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: white;
    cursor: pointer;
    transition: all var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%235c6b7a' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.select-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(30, 60, 114, 0.1);
}

.range-input {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background-color: var(--border-light);
    appearance: none;
    cursor: pointer;
}

.range-input::-webkit-slider-thumb {
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: var(--primary);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}

.range-input::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-md);
}

.color-picker-group {
    display: flex;
    gap: var(--space-sm);
    align-items: center;
}

.color-input {
    width: 40px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    overflow: hidden;
}

.color-input::-webkit-color-swatch-wrapper {
    padding: 0;
}

.color-input::-webkit-color-swatch {
    border: none;
    border-radius: var(--radius-sm);
}

.color-text {
    width: 90px;
    font-size: 12px;
    text-transform: uppercase;
}

.btn-eyedropper {
    padding: 4px;
    background: var(--border-light);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: all var(--transition);
}

.btn-eyedropper:hover {
    background: var(--border);
    color: var(--primary);
}

.btn-eyedropper.active {
    background: var(--accent);
    color: var(--text-primary);
    border-color: var(--primary);
}

.eyedropper-active {
    cursor: crosshair !important;
}

.eyedropper-active * {
    cursor: crosshair !important;
}

.palette-colors {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    margin-bottom: var(--space-sm);
}

.palette-color-row {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.palette-color-row .palette-color {
    flex: 1;
}

.palette-color-row .remove-color {
    opacity: 0;
    transition: opacity var(--transition);
}

.palette-color-row:hover .remove-color {
    opacity: 1;
}

/* Radio & Checkbox */
.radio-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.radio-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
    font-size: 13px;
}

.radio-label:hover {
    background-color: var(--border-light);
}

.radio-label input[type="radio"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: 13px;
}

.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

/* Seed Group */
.seed-group {
    display: flex;
    gap: var(--space-sm);
}

.seed-group .text-input {
    flex: 1;
}

/* Generate Section */
.generate-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    padding-top: var(--space-md);
    border-top: 2px solid var(--primary);
    margin-top: auto;
}

/* Canvas Area */
.canvas-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-xl);
    background-color: var(--background);
    background-image:
        linear-gradient(45deg, #e8e8e3 25%, transparent 25%),
        linear-gradient(-45deg, #e8e8e3 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #e8e8e3 75%),
        linear-gradient(-45deg, transparent 75%, #e8e8e3 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    overflow: auto;
}

.canvas-container {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 100%;
    max-height: calc(100vh - 200px);
}

.tile-preview {
    background-color: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: var(--space-md);
    max-width: 100%;
    max-height: 100%;
    overflow: hidden;
}

.tile-preview svg {
    display: block;
    width: 600px;
    height: 600px;
    max-width: 90vw;
    max-height: 70vh;
}

.grid-preview {
    display: grid;
    gap: 4px;
    padding: var(--space-md);
    background-color: white;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.grid-preview svg {
    display: block;
    width: 100%;
    height: auto;
}

.tile-info {
    margin-top: var(--space-md);
    padding: var(--space-sm) var(--space-md);
    background-color: var(--surface);
    border-radius: var(--radius-sm);
    font-size: 12px;
    color: var(--text-secondary);
}

/* Footer */
.footer {
    background-color: var(--surface);
    border-top: 1px solid var(--border);
    padding: var(--space-sm) var(--space-lg);
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 18px;
}

.modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.modal-close:hover {
    background-color: var(--border-light);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-lg);
    overflow-y: auto;
}

.saved-config-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.saved-config-item:hover {
    border-color: var(--primary);
    background-color: rgba(30, 60, 114, 0.05);
}

.saved-config-info {
    flex: 1;
}

.saved-config-name {
    font-weight: 600;
    font-size: 14px;
}

.saved-config-date {
    font-size: 11px;
    color: var(--text-secondary);
}

.saved-config-actions {
    display: flex;
    gap: var(--space-xs);
}

.empty-state {
    text-align: center;
    padding: var(--space-xl);
    color: var(--text-secondary);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    z-index: 1100;
}

.toast {
    padding: var(--space-md) var(--space-lg);
    background-color: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    animation: slideIn 0.3s ease-out;
    max-width: 350px;
}

.toast-success {
    border-left: 4px solid var(--success);
}

.toast-error {
    border-left: 4px solid var(--error);
}

.toast-warning {
    border-left: 4px solid var(--warning);
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Responsive */
@media (max-width: 1024px) {
    .control-panel {
        width: 280px;
    }
    
    .header-actions-main {
        order: 3;
        flex-basis: 100%;
    }
}

@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        height: auto;
        min-height: calc(100vh - var(--header-height));
    }

    .control-panel {
        width: 100%;
        max-height: none;
        border-right: none;
        border-bottom: 1px solid var(--border);
        order: 2;
    }

    .canvas-area {
        padding: var(--space-md);
        min-height: 400px;
        order: 1;
    }

    .header {
        flex-wrap: wrap;
        gap: var(--space-sm);
    }

    .header-left {
        width: 100%;
        justify-content: center;
    }

    .header-actions {
        width: auto;
    }
    
    .header-actions-main {
        order: 2;
    }
    
    .header-actions:not(.header-actions-main) {
        order: 3;
    }

    .tile-preview svg {
        max-width: 300px;
        max-height: 300px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--border-light);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Disabled states */
.control-group.disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Focus visible */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* Selection */
::selection {
    background-color: var(--primary);
    color: white;
}

/* ========================================
   Canvas View Styles
   ======================================== */

/* Tile Gallery */
.tile-gallery {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
}

.gallery-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-md);
}

.gallery-title {
    font-size: 18px;
    color: var(--primary);
}

.gallery-actions {
    display: flex;
    gap: var(--space-sm);
}

.tile-gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--space-md);
    max-height: 400px;
    overflow-y: auto;
    padding: var(--space-md);
    background-color: var(--surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.gallery-tile {
    position: relative;
    aspect-ratio: 1;
    background: white;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: all var(--transition);
    border: 3px solid transparent;
    overflow: hidden;
}

.gallery-tile:hover {
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.gallery-tile.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent), var(--shadow-md);
}

.gallery-tile svg {
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.gallery-tile-check {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    background: var(--accent);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity var(--transition);
}

.gallery-tile.selected .gallery-tile-check {
    opacity: 1;
}

.gallery-tile-check svg {
    width: 12px;
    height: 12px;
    color: var(--text-primary);
}

/* Canvas Preview */
.canvas-preview-container {
    width: 100%;
    max-width: 100%;
    overflow: auto;
}

.canvas-preview {
    background-color: white;
    box-shadow: var(--shadow-lg);
    max-width: 100%;
    overflow: auto;
    line-height: 0; /* Remove any whitespace between tiles if they were inline */
}

.canvas-preview svg {
    display: block;
    max-width: 100%;
    height: auto;
}

/* Hint text */
.hint-text {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

/* Selected count */
.selected-count {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    padding: var(--space-sm);
    background: rgba(30, 60, 114, 0.1);
    border-radius: var(--radius-sm);
    text-align: center;
}

/* Canvas-specific header actions */
.header-actions canvas-hidden {
    display: none;
}

.loading {
    padding: var(--space-xl);
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    width: 100%;
}
