/* Dark app-like template layout */
body {
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #1a1a1a;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    max-width: 600px;
    width: 100%;
}

.template-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.template-option {
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 12px;
    padding: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 80px;
    height: 80px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}

.template-option:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    border-color: #4a9eff;
}

.template-option.selected {
    border-color: #4a9eff;
    background-color: #3a3a3a;
}

.template-icon {
    font-size: 2.5rem;
    margin-bottom: 0;
    opacity: 0.8;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
}

.template-icon img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.template-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: #ffffff;
    line-height: 1.3;
    word-break: break-word;
    text-align: center;
    width: 100%;
    max-width: 80px;
}

.loading {
    color: #b3b3b3;
    font-style: italic;
    text-align: center;
    padding: 2rem;
}

/* Modal styling */
dialog {
    background: #2d2d2d;
    border: 1px solid #404040;
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
    padding: 0;
    max-width: 400px;
    width: 90%;
}

dialog::backdrop {
    background-color: rgba(0, 0, 0, 0.7);
}

dialog article {
    padding: 2rem;
}

dialog h3 {
    margin: 0 0 1rem 0;
    color: #ffffff;
    font-size: 1.25rem;
}

dialog p {
    color: #b3b3b3;
    margin-bottom: 2rem;
    line-height: 1.5;
}

dialog footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

dialog button {
    background: #4a9eff;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

dialog button:hover {
    background: #3a7bd5;
}

dialog .secondary {
    background: #6c757d;
    color: white;
}

dialog .secondary:hover {
    background: #545b62;
}

#create_result {
    margin-top: 2rem;
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
    max-width: 600px;
    width: 100%;
    color: #ffffff;
}

/* Loading animations */
.template-option.loading {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    animation: centerAndScale 0.5s ease-out forwards;
}

.template-option.loading .template-icon {
    position: relative;
}

.template-option.loading .template-icon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 64px;
    height: 64px;
    margin: -32px 0 0 -32px;
    border: 4px dotted #FFF;
    border-style: solid solid dotted dotted;
    border-radius: 50%;
    box-sizing: border-box;
    animation: rotation 2s linear infinite;
}

.template-option.loading .template-icon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 32px;
    height: 32px;
    margin: -16px 0 0 -16px;
    border: 4px dotted #ff0000;
    border-style: solid solid dotted;
    border-radius: 50%;
    box-sizing: border-box;
    animation: rotationBack 1s linear infinite;
    transform-origin: center center;
}

.template-option.loading {
    pointer-events: none;
    cursor: not-allowed;
}

.template-option.loading .template-name {
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease-out;
}

.template-grid.loading .template-item:not(.selected) {
    opacity: 0;
    transform: scale(0.8);
    transition: all 0.3s ease-out;
}

.template-grid.loading .template-item.selected {
    position: relative;
    z-index: 1001;
}

@keyframes centerAndScale {
    0% {
        transform: translate(-50%, -50%) scale(1);
    }
    100% {
        transform: translate(-50%, -50%) scale(1.2);
    }
}

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

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

/* Error overlay and message styling */
.error-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1999;
    animation: fadeIn 0.3s ease-out;
}

.error-message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: #ff4444;
    color: white;
    padding: 1.5rem 2rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 500;
    text-align: center;
    z-index: 2000;
    box-shadow: 0 10px 25px rgba(255, 68, 68, 0.3);
    animation: errorSlideIn 0.3s ease-out;
}

@keyframes fadeIn {
    0% {
        opacity: 0;
    }
    100% {
        opacity: 1;
    }
}

@keyframes errorSlideIn {
    0% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.8);
    }
    100% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}
