/* ==========================================================================
   DESIGN SYSTEM & CUSTOM PROPERTIES
   ========================================================================== */
:root {
    --bg-primary: #040d1a;
    --bg-secondary: #0a182b;
    --color-primary: #004d99; /* Azul do Deputado */
    --color-primary-light: #0d6efd;
    --color-accent: #c5a059;   /* Dourado */
    --color-accent-light: #dfc28d;
    --text-main: #ffffff;
    --text-muted: #a0b2c6;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: rgba(0, 0, 0, 0.5);
    
    --radius-sm: 8px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-circle: 50%;
    
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: 'Inter', sans-serif;
    --font-display: 'Montserrat', sans-serif;
}

/* Reset básico */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-primary);
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(0, 77, 153, 0.15) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(197, 160, 89, 0.1) 0%, transparent 40%);
    background-attachment: fixed;
    color: var(--text-main);
    font-family: var(--font-sans);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

/* Scrollbar estilizado */
::-webkit-scrollbar {
    width: 8px;
}
::-webkit-scrollbar-track {
    background: var(--bg-primary);
}
::-webkit-scrollbar-thumb {
    background: var(--color-primary);
    border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--color-accent);
}

/* ==========================================================================
   LAYOUT CONTAINER
   ========================================================================== */
.app-container {
    width: 100%;
    max-width: 600px;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    min-height: 100vh;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 8px;
}

.header-logo {
    display: inline-flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.logo-icon {
    font-size: 2.5rem;
    color: var(--color-accent);
    filter: drop-shadow(0 0 10px rgba(197, 160, 89, 0.4));
    animation: pulse 3s infinite ease-in-out;
}

.logo-text h1 {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1.8rem;
    line-height: 1.1;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, var(--text-main) 40%, var(--color-accent-light) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-transform: uppercase;
}

.logo-text span {
    font-family: var(--font-sans);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 4px;
    color: var(--color-primary-light);
    display: block;
    margin-top: 2px;
}

.header-subtitle {
    font-size: 0.95rem;
    color: var(--text-muted);
    line-height: 1.5;
    max-width: 480px;
    margin: 0 auto;
}

/* ==========================================================================
   OPÇÕES DE UPLOAD E CÂMERA (PASSO 1)
   ========================================================================== */
.upload-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-top: 16px;
}

.btn-option {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--radius-md);
    padding: 32px 16px;
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition-smooth);
    box-shadow: 0 8px 32px var(--glass-shadow);
    text-align: center;
    outline: none;
}

.btn-option:hover {
    transform: translateY(-5px);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
}

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

.btn-upload:hover {
    border-color: var(--color-accent);
}

.option-icon {
    font-size: 2.2rem;
    margin-bottom: 16px;
    transition: var(--transition-smooth);
}

.btn-camera .option-icon {
    color: var(--color-primary-light);
}

.btn-upload .option-icon {
    color: var(--color-accent);
}

.btn-option:hover .option-icon {
    transform: scale(1.15);
}

.option-title {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 6px;
}

.option-desc {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.3;
}

/* ==========================================================================
   SEÇÃO DO EDITOR (PASSO 2)
   ========================================================================== */
.section-editor {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: 0 16px 48px var(--glass-shadow);
    display: flex;
    flex-direction: column;
    gap: 24px;
    animation: fadeIn 0.5s ease-out;
}

/* Workspace do Canvas */
.editor-workspace {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.editor-canvas-container {
    width: 350px;
    height: 350px;
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.8);
    cursor: grab;
    user-select: none;
    border: 2px solid rgba(197, 160, 89, 0.2);
}

.editor-canvas-container:active {
    cursor: grabbing;
}

.editor-canvas-container.circular {
    border-radius: 50% !important;
}

/* Foto do usuário manipulável */
.photo-wrapper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transform-origin: center center;
    display: flex;
    align-items: center;
    justify-content: center;
}

#user-photo {
    position: absolute;
    max-width: none;
    max-height: none;
    pointer-events: none; /* A interação é gerenciada pelo container */
    user-select: none;
}

/* Overlay da Moldura */
.frame-overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Crucial para o drag passar para o photo-wrapper */
    z-index: 10;
}

#active-frame {
    width: 100%;
    height: 100%;
    object-fit: fill;
}

.workspace-tip {
    font-size: 0.8rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0.8;
}

/* Controles do Editor */
.editor-controls {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
}

.control-label i {
    margin-right: 4px;
}

#zoom-value, #rotate-value {
    color: var(--color-accent-light);
    font-weight: 700;
}

/* Estilização personalizada dos Sliders */
.custom-slider {
    -webkit-appearance: none;
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: rgba(255, 255, 255, 0.1);
    outline: none;
    transition: var(--transition-smooth);
}

.custom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: var(--radius-circle);
    background: var(--color-accent);
    cursor: pointer;
    box-shadow: 0 0 10px rgba(197, 160, 89, 0.5);
    transition: var(--transition-smooth);
}

.custom-slider::-webkit-slider-thumb:hover {
    background: var(--color-accent-light);
    transform: scale(1.15);
}

/* Botões de ação rápida no editor */
.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr 1.2fr;
    gap: 10px;
    margin-top: 8px;
}

/* ==========================================================================
   CARROSSEL DE MOLDURAS (SELETOR)
   ========================================================================== */
.frame-selector-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-title {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 1px;
    text-transform: uppercase;
    color: var(--text-muted);
    border-left: 3px solid var(--color-accent);
    padding-left: 8px;
}

.frame-carousel {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 4px 8px 4px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Custom scrollbar for frame-carousel */
.frame-carousel::-webkit-scrollbar {
    height: 4px;
}
.frame-carousel::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.02);
    border-radius: var(--radius-sm);
}
.frame-carousel::-webkit-scrollbar-thumb {
    background: rgba(197, 160, 89, 0.3);
    border-radius: var(--radius-sm);
}
.frame-carousel::-webkit-scrollbar-thumb:hover {
    background: var(--color-accent);
}

.frame-thumb {
    flex: 0 0 90px;
    background: rgba(0, 0, 0, 0.3);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    padding: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    transition: var(--transition-smooth);
}

.frame-thumb img {
    width: 100%;
    aspect-ratio: 1;
    object-fit: contain;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.frame-thumb.active {
    border-color: var(--color-accent);
    background: rgba(197, 160, 89, 0.05);
    box-shadow: 0 0 12px rgba(197, 160, 89, 0.2);
}

.frame-thumb:hover:not(.active) {
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-2px);
}

.frame-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-muted);
}

.frame-thumb.active .frame-name {
    color: var(--color-accent-light);
}

/* ==========================================================================
   BOTÕES GERAIS E EFEITOS
   ========================================================================== */
.btn-primary {
    background: linear-gradient(135deg, var(--color-primary-light) 0%, var(--color-primary) 100%);
    border: none;
    color: var(--text-main);
    font-family: var(--font-display);
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(13, 110, 253, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(13, 110, 253, 0.5);
    filter: brightness(1.1);
}

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

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-smooth);
}

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

.btn-danger {
    color: #ff4d4d;
    border-color: rgba(255, 77, 77, 0.2);
}

.btn-danger:hover {
    background: rgba(255, 77, 77, 0.1);
    border-color: rgba(255, 77, 77, 0.4);
}

.btn-large {
    width: 100%;
    padding: 18px 24px;
    font-size: 1.1rem;
    border-radius: var(--radius-md);
}

.action-container {
    margin-top: 8px;
}

/* ==========================================================================
   MODAL DA CÂMERA
   ========================================================================== */
.camera-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(4, 13, 26, 0.95);
    z-index: 100;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
}

.camera-modal.active {
    display: flex;
    animation: fadeIn 0.3s ease-out;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.8);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--text-main);
}

.btn-close-modal {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    transition: var(--transition-smooth);
    padding: 4px;
}

.btn-close-modal:hover {
    color: var(--text-main);
    transform: rotate(90deg);
}

/* Viewport da câmera em tempo real */
.camera-view-container {
    width: 100%;
    aspect-ratio: 1; /* Quadrada igual ao editor */
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: #000;
    border: 2px solid rgba(197, 160, 89, 0.2);
}

#camera-stream {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Espelhar a câmera frontal para parecer um espelho natural */
}

/* Guia de enquadramento da moldura transparente sobre a câmera */
.camera-frame-guide {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    opacity: 0.6; /* Leve transparência na câmera para não atrapalhar visualmente */
}

.camera-frame-guide img {
    width: 100%;
    height: 100%;
    object-fit: fill;
}

/* Controles de captura do modal */
.camera-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
}

.btn-icon-only {
    border-radius: var(--radius-circle);
    width: 45px;
    height: 45px;
    padding: 0;
    font-size: 1.1rem;
}

.btn-circle {
    width: 70px;
    height: 70px;
    border-radius: var(--radius-circle);
    font-size: 1.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 4px solid var(--bg-secondary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
    outline: none;
}

.btn-circle:hover {
    transform: scale(1.05);
    box-shadow: 0 0 0 3px var(--color-accent);
}

/* ==========================================================================
   UTILITÁRIOS & ESTADOS
   ========================================================================== */
.hidden {
    display: none !important;
}

/* Rodapé institucional */
.app-footer {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: auto;
    padding-top: 16px;
    opacity: 0.6;
}

/* ==========================================================================
   ANIMAÇÕES E MEDIA QUERIES
   ========================================================================== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.9; }
    50% { transform: scale(1.03); opacity: 1; filter: drop-shadow(0 0 15px rgba(197, 160, 89, 0.7)); }
    100% { transform: scale(1); opacity: 0.9; }
}

/* Responsividade para telas muito pequenas */
@media (max-width: 400px) {
    .editor-canvas-container {
        width: 290px;
        height: 290px;
    }
    
    .quick-actions {
        grid-template-columns: 1fr;
    }
    
    .logo-text h1 {
        font-size: 1.5rem;
    }
}
