:root {
    --bg-color: #f0f4f8;
    --sidebar-bg: #ffffff;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #10b981;
    --success-hover: #059669;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: 380px;
    background-color: var(--sidebar-bg);
    padding: 2rem;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    overflow-y: auto;
    z-index: 10;
}

.brand h1 {
    font-size: 1.5rem;
    color: var(--primary);
    font-family: 'Montserrat', sans-serif;
    font-weight: 900;
}

.brand p {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.control-group.double {
    flex-direction: row;
    gap: 1rem;
}

.control-group.double > div {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

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

input[type="text"], input[type="number"], select, textarea {
    padding: 0.75rem;
    background-color: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    background-color: #fff;
}

input[type="color"] {
    width: 100%;
    height: 40px;
    padding: 2px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    background-color: #fff;
}

input[type="range"] {
    width: 100%;
    margin-top: 0.5rem;
    cursor: pointer;
}

input[type="password"] {
    padding: 0.75rem;
    background-color: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    transition: border-color 0.2s;
}

input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    background-color: #fff;
}

/* Custom Groups Container */
.custom-colors-group,
.bg-upload-group {
    background-color: #f1f5f9;
    padding: 1rem;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border: 1px dashed #cbd5e1;
}

button {
    padding: 1rem;
    border: none;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    font-family: 'Inter', sans-serif;
}

.btn-primary {
    background-color: var(--primary);
    color: white;
    margin-top: 0.5rem;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

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

.btn-success:hover {
    background-color: var(--success-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background-color: #e2e8f0;
    color: var(--text-main);
}

.btn-secondary:hover {
    background-color: #cbd5e1;
}

/* Preview Area */
.preview-area {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.preview-area h2 {
    margin-bottom: 2rem;
    color: var(--text-muted);
    font-family: 'Montserrat', sans-serif;
}

.preview-container {
    background: transparent;
    width: 100%;
    max-width: 900px;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: center;
}

/* Loading Overlay for PDF */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255, 255, 255, 0.9);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border-left-color: var(--primary);
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* ============================
   LOGIN SCREEN
   ============================ */
.login-screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: radial-gradient(circle at center, #013861 0%, #001f3f 70%, #000c1a 100%);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.login-screen::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: radial-gradient(rgba(174,220,227,0.15) 1.5px, transparent 1.5px),
                      radial-gradient(rgba(174,220,227,0.1) 1px, transparent 1px);
    background-size: 30px 30px, 20px 20px;
    background-position: 0 0, 15px 15px;
    pointer-events: none;
}

.login-container {
    background: white;
    padding: 2.5rem;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    width: 100%;
    max-width: 400px;
    z-index: 2001;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.login-brand {
    text-align: center;
    margin-bottom: 1rem;
}

.login-brand h1 {
    font-size: 1.6rem;
    color: var(--primary);
    font-family: 'Montserrat', sans-serif;
    font-weight: 900;
}

.login-brand p {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.login-error {
    background: #fee2e2;
    color: #ef4444;
    padding: 0.75rem;
    border-radius: 8px;
    font-size: 0.9rem;
    text-align: center;
    font-weight: 600;
    border: 1px solid #fca5a5;
}

/* ============================
   TICKET BASE STYLES 
   ============================ */
.ticket {
    background: #fff;
    display: flex;
    position: relative;
    overflow: hidden;
    font-family: 'Inter', sans-serif;
    box-sizing: border-box;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    border-radius: 8px; /* Rounded corners for preview */
}

.ticket-stub {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-width: 65px;
    position: relative;
    z-index: 2;
}

.ticket-number {
    font-family: 'Montserrat', sans-serif;
    font-weight: 900;
    font-size: 1.4rem;
    transform: rotate(-90deg);
    white-space: nowrap;
    letter-spacing: 1px;
}

.ticket-body {
    padding: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    z-index: 2;
    position: relative; /* Para posicionar decorações em absolute */
}

.ticket-logo {
    width: 60px;
    height: 60px;
    object-fit: contain;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
    z-index: 3;
    position: relative;
}

.ticket-content {
    display: flex;
    flex-direction: column;
    z-index: 3;
    position: relative;
}

.ticket-title {
    font-family: 'Montserrat', sans-serif;
    font-size: 1.15rem;
    font-weight: 800;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
}

.ticket-desc {
    font-size: 0.85rem;
    white-space: pre-line;
    line-height: 1.4;
    font-weight: 500;
}

/* ============================
   SIZES (PRESETS)
   ============================ */
.size-standard { width: 510px; height: 182px; } 
.size-small { width: 350px; height: 140px; }    
.size-large { width: 730px; height: 250px; }    
.size-square { width: 290px; height: 290px; flex-direction: column; } 

.size-square .ticket-stub { border-right: none !important; width: 100%; min-height: 50px; flex-direction: row;}
.size-square .ticket-number { transform: none; }
.size-square .ticket-body { flex-direction: column; text-align: center; justify-content: center; }

/* Scale adjustments based on size */
.size-small .ticket-title { font-size: 0.95rem; }
.size-small .ticket-desc { font-size: 0.75rem; }
.size-small .ticket-number { font-size: 1.1rem; }
.size-small .ticket-logo { width: 45px; height: 45px; }

.size-large .ticket-title { font-size: 1.6rem; }
.size-large .ticket-desc { font-size: 1.1rem; }
.size-large .ticket-number { font-size: 2rem; }
.size-large .ticket-logo { width: 90px; height: 90px; }


/* ============================
   THEMES
   ============================ */

/* 1. Theme Minimal */
.theme-minimal { border: 2px dashed #cbd5e1; background: #ffffff; color: #0f172a; }
.theme-minimal .ticket-stub { border-right: 2px dashed #cbd5e1; background: #f8fafc; }
.size-square.theme-minimal .ticket-stub { border-bottom: 2px dashed #cbd5e1; }
.theme-minimal .ticket-number { color: #ef4444; }
.theme-minimal .ticket-desc { color: #475569; }

/* 2. Theme Gold VIP */
.theme-gold { border: 2px solid #fbbf24; background: #111827; color: #fef3c7; }
.theme-gold .ticket-stub { border-right: 2px dashed #d97706; background: #1f2937; }
.size-square.theme-gold .ticket-stub { border-bottom: 2px dashed #d97706; }
.theme-gold .ticket-number { color: #fbbf24; }
.theme-gold .ticket-desc { color: #d1d5db; }
.theme-gold .ticket-title { color: #fbbf24; }

/* 3. Theme Neon Party */
.theme-neon { border: 3px solid #ec4899; background: #0f172a; color: #ffffff; }
.theme-neon .ticket-stub { border-right: 2px dashed #3b82f6; background: #1e1b4b; }
.size-square.theme-neon .ticket-stub { border-bottom: 2px dashed #3b82f6; }
.theme-neon .ticket-number { color: #06b6d4; }
.theme-neon .ticket-desc { color: #cbd5e1; }
.theme-neon .ticket-title { color: #ec4899; }

/* 4. Theme Ocean Gradient */
.theme-ocean { background: linear-gradient(135deg, #0284c7 0%, #06b6d4 100%); color: #ffffff; border: none; }
.theme-ocean .ticket-stub { border-right: 2px dashed rgba(255,255,255,0.4); background: rgba(0,0,0,0.1); }
.size-square.theme-ocean .ticket-stub { border-bottom: 2px dashed rgba(255,255,255,0.4); }
.theme-ocean .ticket-number { color: #ffffff; }
.theme-ocean .ticket-desc { color: #f0f9ff; }

/* 5. Theme Sunset Gradient */
.theme-sunset { background: linear-gradient(135deg, #f97316 0%, #db2777 100%); color: #ffffff; border: none; }
.theme-sunset .ticket-stub { border-right: 2px dashed rgba(255,255,255,0.4); background: rgba(0,0,0,0.15); }
.size-square.theme-sunset .ticket-stub { border-bottom: 2px dashed rgba(255,255,255,0.4); }
.theme-sunset .ticket-number { color: #ffffff; }
.theme-sunset .ticket-title { color: #fffbeb; }
.theme-sunset .ticket-desc { color: #fee2e2; }

/* ============================
   NEW THEME: GILGAL OFICIAL (BASEADO NA IMAGEM)
   ============================ */
.theme-gilgal {
    background: radial-gradient(circle at center, #013861 0%, #001f3f 70%, #000c1a 100%);
    color: #aedce3; 
    border: 3px solid #66b2c4;
    box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.5);
}

.theme-gilgal::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background-image: radial-gradient(rgba(174,220,227,0.15) 1.5px, transparent 1.5px),
                      radial-gradient(rgba(174,220,227,0.1) 1px, transparent 1px);
    background-size: 30px 30px, 20px 20px;
    background-position: 0 0, 15px 15px;
    pointer-events: none;
    z-index: 1;
    opacity: 0.8;
}

.theme-gilgal .ticket-stub {
    border-right: 2px dashed #66b2c4;
    background: rgba(174, 220, 227, 0.03);
}

.size-square.theme-gilgal .ticket-stub {
    border-bottom: 2px dashed #66b2c4;
}

.theme-gilgal .ticket-number {
    color: #aedce3;
    text-shadow: 0 0 12px rgba(174, 220, 227, 0.5);
}

.theme-gilgal .ticket-title {
    color: #aedce3;
    font-weight: 900;
    letter-spacing: 1px;
    font-size: 1.3rem;
}

.theme-gilgal .ticket-desc {
    color: #8abac2;
    font-weight: 600;
}

/* ============================
   NEW THEME: DEPTH (PROFUNDIDADE)
   ============================ */
.theme-depth {
    background: linear-gradient(180deg, #0f172a 0%, #022c43 40%, #004b73 100%);
    color: #f8fafc;
    border: 3px solid #0ea5e9;
    box-shadow: inset 0 0 20px rgba(14, 165, 233, 0.3);
}

.theme-depth .ticket-stub {
    border-right: 2px dashed #38bdf8;
    background: rgba(14, 165, 233, 0.1);
}

.size-square.theme-depth .ticket-stub {
    border-bottom: 2px dashed #38bdf8;
}

.theme-depth .ticket-number {
    color: #38bdf8;
    text-shadow: 0 0 8px rgba(56, 189, 248, 0.8);
}

.theme-depth .ticket-title {
    color: #7dd3fc;
    letter-spacing: 1px;
}

.theme-depth .ticket-desc {
    color: #bae6fd;
}

/* Bolhas de ar e fundo temático do mergulho (via SVG gerado no JS ou CSS) */
.diver-bg {
    position: absolute;
    right: -20px;
    bottom: -20px;
    opacity: 0.15;
    transform: rotate(-15deg);
    z-index: 1; /* Atrás do texto */
    pointer-events: none;
}

.size-small .diver-bg { width: 100px; right: -10px; bottom: -10px; }
.size-standard .diver-bg { width: 180px; }
.size-large .diver-bg { width: 250px; }
.size-square .diver-bg { width: 150px; left: 50%; transform: translateX(-50%) rotate(0deg); opacity: 0.1; }


/* ============================
   NEW THEME: CUSTOM COLORS (Inline Variables)
   ============================ */
.theme-custom {
    background-color: var(--custom-bg);
    color: var(--custom-text);
    border: 3px solid var(--custom-accent);
}

.theme-custom .ticket-stub {
    border-right: 2px dashed var(--custom-accent);
    /* Dá uma leve escurecida no fundo do canhotinho usando filter ou background misto, mas como não temos a cor exata rgba, usamos um overlay suave opaco */
    background-image: linear-gradient(rgba(0,0,0,0.1), rgba(0,0,0,0.1));
}

.size-square.theme-custom .ticket-stub {
    border-bottom: 2px dashed var(--custom-accent);
}

.theme-custom .ticket-number {
    color: var(--custom-accent);
}

.theme-custom .ticket-title {
    color: var(--custom-text);
}

.theme-custom .ticket-desc {
    color: var(--custom-text);
    opacity: 0.8;
}

/* ============================
   NEW THEME: IMAGE BACKGROUND
   ============================ */
.theme-image {
    /* O background-image real e size são inseridos via style inline no JS */
    background-position: center;
    background-repeat: no-repeat;
    color: #ffffff;
    border: none;
}

/* Adicionamos uma película escura sobre a imagem para o texto ficar sempre legível */
.theme-image::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4); /* Escurece a foto de fundo 40% */
    pointer-events: none;
    z-index: 1;
}

.theme-image .ticket-stub {
    border-right: 2px dashed rgba(255,255,255,0.5);
    background: rgba(0, 0, 0, 0.3);
}

.size-square.theme-image .ticket-stub {
    border-bottom: 2px dashed rgba(255,255,255,0.5);
    border-right: none;
}

.theme-image .ticket-number {
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.theme-image .ticket-title {
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.theme-image .ticket-desc {
    color: #e2e8f0;
    text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

/* ============================
   NEW THEME: TICKET PRONTO (READY)
   ============================ */
.theme-ready {
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    border: none;
    color: transparent; /* Oculta o texto padrão */
}

/* O canhoto ainda recebe a numeração, mas sem bordas invasivas, ou pode ser transparente se o usuario ja desenhou */
.theme-ready .ticket-stub {
    border-right: 2px dashed rgba(255,255,255,0.8);
    background: rgba(0, 0, 0, 0.4); /* Fundo escuro atrás apenas do número para garantir leitura */
}

.size-square.theme-ready .ticket-stub {
    border-bottom: 2px dashed rgba(255,255,255,0.8);
    border-right: none;
}

.theme-ready .ticket-number {
    color: #ffffff;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
    /* Mantém o número visível */
}

/* Oculta os textos do corpo para que mostre apenas a arte enviada pelo usuário */
.theme-ready .ticket-body .ticket-content,
.theme-ready .ticket-body .ticket-logo {
    display: none;
}

/* ============================
   PRINT / PDF STYLES Area
   ============================ */

#pdfContainer {
    background: white;
}

.print-area {
    display: block; /* html2pdf handles block/inline-block better for page margins */
    width: 760px; /* Reduzido de 794px para não cortar a margem direita */
    padding: 0; 
    margin: 0 auto; /* Centraliza a area de print */
    box-sizing: border-box;
    font-size: 0; /* Remove espassamentos invisíveis do inline-block */
    text-align: center; /* Centraliza os tickets no papel */
}

.print-area .ticket {
    display: inline-flex; /* Mantém o display flex interno mas o container os vê como blocos */
    margin: 5px; /* Margem reduzida para maximizar o tamanho do ticket no PDF */
    page-break-inside: avoid;
    break-inside: avoid;
    vertical-align: top;
    text-align: left; /* Restaura o alinhamento de texto local do ticket */
}
