/* Hat Designer - Mobile-First Single Page Design */

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

:root {
    --primary: #1a2b5c;
    --primary-light: #2a4080;
    --secondary: #6c757d;
    --success: #28a745;
    --danger: #dc3545;
    --bg: #f8f9fa;
    --white: #ffffff;
    --border: #dee2e6;
    --text: #212529;
    --text-muted: #6c757d;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 20px rgba(0,0,0,0.15);
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* Page Container */
.designer-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.page-header {
    background: var(--primary);
    color: var(--white);
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}

.page-header h1 {
    font-size: 1.1rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(255,255,255,0.15);
    color: var(--white);
    border-radius: 8px;
    font-size: 1.1rem;
    cursor: pointer;
    transition: background 0.2s;
}

.icon-btn:hover:not(:disabled) {
    background: rgba(255,255,255,0.25);
}

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

/* Main Content - Scrollable */
.main-content {
    flex: 1;
    padding: 16px;
    padding-bottom: 100px; /* Space for floating controls */
}

/* Design Sections */
.design-section {
    background: var(--white);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    position: relative;
}

.section-badge {
    position: absolute;
    top: -8px;
    left: 16px;
    background: var(--primary);
    color: var(--white);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
    margin-top: 8px;
    color: var(--text);
}

.section-desc {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 16px;
}

/* Preview Section */
.preview-section {
    padding: 16px;
    background: linear-gradient(135deg, #e8eef5 0%, #f8f9fa 100%);
}

.preview-section .section-badge {
    background: var(--success);
}

.canvas-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.canvas-wrapper {
    background: var(--white);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    max-width: 100%;
}

#designer-canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.canvas-tools {
    width: 100%;
    max-width: 300px;
}

.layer-dropdown {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    background: var(--white);
    cursor: pointer;
}

.layer-dropdown:focus {
    outline: none;
    border-color: var(--primary);
}

/* Form Elements */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input[type="text"],
.form-group input[type="email"] {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-large {
    font-size: 1.1rem !important;
    padding: 14px 16px !important;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Color Pickers */
.color-pickers {
    margin: 20px 0;
}

.color-pickers h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text);
}

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

.color-picker-item {
    text-align: center;
}

.color-picker-item label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.color-picker-item input[type="color"] {
    width: 50px;
    height: 50px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    padding: 2px;
}

.color-picker-item .color-name {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Color Preview */
.color-preview-container {
    margin: 20px 0;
}

.color-preview-container > label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.color-preview {
    background: #f0f0f0;
    border-radius: 10px;
    padding: 15px;
    text-align: center;
}

.color-preview-svg {
    width: 100%;
    max-width: 250px;
    height: auto;
}

.preview-outer {
    stroke: #000000;
}

.preview-middle {
    stroke: #ffffff;
}

.preview-inner {
    fill: #1a2b5c;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--primary-light);
}

.btn-secondary {
    background: var(--white);
    color: var(--primary);
    border: 2px solid var(--primary);
}

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

.btn-generate {
    width: 100%;
    padding: 16px;
    font-size: 1.1rem;
}

.btn-small {
    padding: 8px 16px;
    font-size: 0.85rem;
}

.btn-danger {
    background: var(--danger);
    color: var(--white);
}

.button-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

/* Loading Indicator */
.loading-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 20px;
    color: var(--text-muted);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Checkbox Row */
.checkbox-row {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    padding: 8px 0;
    font-size: 0.95rem;
}

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

/* Slider Group */
.slider-group {
    margin-top: 16px;
}

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

.slider-item label {
    font-size: 0.85rem;
    color: var(--text-muted);
    min-width: 80px;
}

.slider-item input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    background: var(--border);
    border-radius: 3px;
    outline: none;
}

.slider-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 20px;
    height: 20px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

.slider-item span {
    font-size: 0.85rem;
    min-width: 35px;
    text-align: right;
    color: var(--text-muted);
}

/* Hat Color Grid */
.hat-color-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.hat-color-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.hat-color-option:hover {
    border-color: var(--primary);
}

.hat-color-option.selected {
    border-color: var(--primary);
    background: #f0f4ff;
}

.hat-color-option input {
    display: none;
}

.hat-swatch {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

.hat-name {
    font-size: 0.85rem;
    font-weight: 500;
}

/* Generate Section */
.generate-section {
    background: linear-gradient(135deg, #e8f5e9 0%, #ffffff 100%);
    border: 2px solid var(--success);
    text-align: center;
}

.generate-section .section-badge {
    background: var(--success);
}

.generate-section .section-title,
.generate-section .section-desc {
    text-align: center;
}

/* Save Section */
.save-section {
    background: linear-gradient(135deg, #f0f7ff 0%, #ffffff 100%);
    border: 2px solid var(--primary);
}

.save-success-box {
    background: #e8f5e9;
    border: 1px solid var(--success);
    border-radius: 10px;
    padding: 16px;
    margin-top: 16px;
    text-align: center;
}

.success-check {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: var(--success);
    color: var(--white);
    border-radius: 50%;
    font-size: 1.2rem;
    margin-bottom: 8px;
}

.share-link-row {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}

.share-link-row input {
    flex: 1;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.85rem;
}

/* Element Controls (Floating) */
.element-controls {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--white);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    width: calc(100% - 32px);
    max-width: 400px;
    max-height: 50vh;
    overflow: hidden;
}

.element-controls.visible {
    display: block;
}

.controls-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--primary);
    color: var(--white);
}

.controls-header span {
    font-weight: 600;
}

.controls-body {
    padding: 16px;
    max-height: 40vh;
    overflow-y: auto;
}

.close-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.2);
    color: inherit;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* D-pad */
.dpad-container {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.dpad-label {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.dpad {
    display: grid;
    grid-template-columns: 44px 44px 44px;
    grid-template-rows: 44px 44px;
    gap: 4px;
    grid-template-areas:
        ". up ."
        "left down right";
}

.dpad-btn {
    width: 44px;
    height: 44px;
    border: 2px solid var(--border);
    background: var(--white);
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    touch-action: manipulation;
}

.dpad-up { grid-area: up; }
.dpad-down { grid-area: down; }
.dpad-left { grid-area: left; }
.dpad-right { grid-area: right; }

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

.dpad-btn:active {
    background: var(--primary);
    color: var(--white);
    border-color: var(--primary);
}

/* Control Slider */
.control-slider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.control-slider label {
    font-size: 0.85rem;
    min-width: 60px;
    color: var(--text-muted);
}

.control-slider input[type="range"] {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    background: var(--border);
    border-radius: 3px;
}

.control-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px;
    height: 22px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
}

.control-slider span {
    font-size: 0.85rem;
    min-width: 45px;
    text-align: right;
}

/* Control Buttons */
.control-buttons {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.ctrl-btn {
    flex: 1;
    padding: 10px;
    border: 2px solid var(--border);
    background: var(--white);
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

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

.ctrl-btn.btn-danger {
    color: var(--danger);
    border-color: var(--danger);
    background: var(--white);
}

.ctrl-btn.btn-danger:hover {
    background: #fff5f5;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 300;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    padding: 20px;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--white);
    border-radius: 16px;
    width: 100%;
    max-width: 400px;
    max-height: 80vh;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.visible .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    background: var(--primary);
    color: var(--white);
}

.modal-header h2 {
    font-size: 1.1rem;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

/* Price Table */
.price-info {
    margin-bottom: 20px;
}

.price-info h3 {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.price-table {
    width: 100%;
    border-collapse: collapse;
}

.price-table td {
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.price-table .price {
    text-align: right;
    font-weight: 600;
    color: var(--primary);
}

/* Quantity Selector */
.quantity-selector {
    margin-bottom: 20px;
}

.quantity-selector label {
    display: block;
    font-weight: 600;
    margin-bottom: 10px;
}

.qty-input {
    display: flex;
    align-items: center;
    gap: 8px;
}

.qty-btn {
    width: 48px;
    height: 48px;
    border: 2px solid var(--border);
    background: var(--white);
    border-radius: 8px;
    font-size: 1.3rem;
    cursor: pointer;
    transition: all 0.2s;
}

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

.qty-input input {
    width: 80px;
    height: 48px;
    text-align: center;
    border: 2px solid var(--border);
    border-radius: 8px;
    font-size: 1.1rem;
    font-weight: 600;
}

/* Order Total */
.order-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg);
    border-radius: 10px;
    margin-bottom: 20px;
}

.total-amount {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.btn-checkout {
    width: 100%;
    padding: 16px;
    font-size: 1.1rem;
}

/* Desktop Layout - Side by Side */
@media (min-width: 900px) {
    .main-content {
        display: grid;
        grid-template-columns: 1fr 420px;
        gap: 24px;
        max-width: 1400px;
        margin: 0 auto;
        padding: 24px;
    }

    .preview-section {
        grid-column: 1;
        grid-row: 1 / 4;
        position: sticky;
        top: 80px;
        align-self: start;
        height: fit-content;
    }

    .design-section:not(.preview-section) {
        grid-column: 2;
    }

    .element-controls {
        max-width: 450px;
        left: auto;
        right: 460px;
        transform: none;
    }

    .form-row {
        grid-template-columns: 1fr 1fr;
    }
}

/* Small Mobile Adjustments */
@media (max-width: 400px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .color-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .color-picker-item input[type="color"] {
        width: 44px;
        height: 44px;
    }

    .hat-color-grid {
        grid-template-columns: 1fr;
    }

    .button-row {
        grid-template-columns: 1fr;
    }
}

/* Ensure proper spacing on very small screens */
@media (max-width: 350px) {
    .main-content {
        padding: 12px;
    }

    .design-section {
        padding: 16px;
    }

    .btn-generate {
        padding: 14px;
        font-size: 1rem;
    }
}

/* Generation Info */
.generation-info {
    text-align: center;
    margin-bottom: 12px;
    padding: 10px;
    background: rgba(255,255,255,0.7);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.generation-info .warning {
    color: var(--danger);
    font-weight: 600;
}

/* Past Generations */
.past-generations {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

.past-generations h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.past-gen-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.past-gen-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
}

.past-gen-item {
    position: relative;
    background: #f8f8f8;
    border: 2px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: all 0.2s;
    aspect-ratio: 1;
}

.past-gen-item:hover {
    border-color: var(--primary);
    transform: scale(1.02);
}

.past-gen-item.selected {
    border-color: var(--success);
    box-shadow: 0 0 0 2px var(--success);
}

.past-gen-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 4px;
}

.past-gen-item .gen-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0,0,0,0.7);
    color: white;
    font-size: 0.65rem;
    padding: 3px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* No past generations message */
.no-generations {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* Link sections in save success box */
.link-section {
    text-align: left;
}

.link-section label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    font-weight: 500;
}
