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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    min-height: 100vh;
    color: #fff;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
}

header {
    text-align: center;
    padding: 30px 0;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    margin-bottom: 30px;
}

header h1 {
    font-size: 2.5rem;
    font-weight: 300;
    margin-bottom: 10px;
    color: #e8d5b7;
}

header p {
    color: rgba(255,255,255,0.6);
    font-size: 1rem;
}

.main-content {
    display: grid;
    grid-template-columns: 350px 1fr;
    gap: 25px;
    align-items: start;
}

.controls-panel {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Preview acompanha o scroll quando o usuario rola o painel esquerdo */
.preview-panel {
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

.control-section {
    background: rgba(255,255,255,0.05);
    border-radius: 12px;
    padding: 20px;
    border: 1px solid rgba(255,255,255,0.1);
}

.control-section h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #e8d5b7;
    margin-bottom: 15px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.7);
    margin-bottom: 5px;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: #fff;
    font-size: 0.9rem;
    transition: border-color 0.2s ease;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #e8d5b7;
}

.form-group select option {
    background: #1a1a2e;
}

/* Position Controls */
.position-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.position-control label {
    display: block;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    margin-bottom: 4px;
}

.position-control input[type="range"] {
    width: 100%;
    margin-bottom: 2px;
}

.position-value {
    font-size: 0.75rem;
    color: #e8d5b7;
    font-family: monospace;
}

/* Buttons */
.btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #e8d5b7 0%, #d4a574 100%);
    color: #1a1a2e;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(232, 213, 183, 0.3);
}

.btn-pdf {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
    color: #fff;
    margin-top: 10px;
}

.btn-pdf:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(231, 76, 60, 0.3);
}

.btn-secondary {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    margin-top: 10px;
}

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

.btn-save-model {
    background: linear-gradient(135deg, #27ae60 0%, #2ecc71 100%);
    color: #fff;
    margin-top: 10px;
}

.btn-save-model:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(39, 174, 96, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

/* Preview Panel */
.preview-panel {
    background: rgba(255,255,255,0.05);
    border-radius: 16px;
    padding: 25px;
    border: 1px solid rgba(255,255,255,0.1);
}

.preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.preview-header h3 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #e8d5b7;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.zoom-controls button {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(0,0,0,0.3);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
}

.zoom-controls button:hover {
    background: rgba(255,255,255,0.1);
}

.zoom-controls span {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.6);
    min-width: 50px;
    text-align: center;
}

.preview-container {
    background: #0a0a0a;
    border-radius: 8px;
    padding: 20px;
    overflow: auto;
    max-height: 70vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.canvas-wrapper {
    position: relative;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    transition: transform 0.3s ease;
}

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

.no-certificate {
    text-align: center;
    padding: 60px 20px;
    color: rgba(255,255,255,0.4);
}

.no-certificate svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.3;
}

/* Upload Area */
.upload-area {
    border: 2px dashed rgba(255,255,255,0.2);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 15px;
}

.upload-area:hover {
    border-color: #e8d5b7;
    background: rgba(232, 213, 183, 0.05);
}

.upload-area.dragover {
    border-color: #e8d5b7;
    background: rgba(232, 213, 183, 0.1);
}

.upload-area svg {
    width: 40px;
    height: 40px;
    margin-bottom: 10px;
    opacity: 0.5;
}

.upload-area p {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.6);
}

.upload-area input {
    display: none;
}

/* Status Messages */
.status-message {
    padding: 10px 15px;
    border-radius: 6px;
    font-size: 0.85rem;
    margin-top: 15px;
    display: none;
}

.status-message.success {
    background: rgba(39, 174, 96, 0.2);
    border: 1px solid rgba(39, 174, 96, 0.3);
    color: #27ae60;
    display: block;
}

.status-message.error {
    background: rgba(231, 76, 60, 0.2);
    border: 1px solid rgba(231, 76, 60, 0.3);
    color: #e74c3c;
    display: block;
}

.status-message.info {
    background: rgba(52, 152, 219, 0.2);
    border: 1px solid rgba(52, 152, 219, 0.3);
    color: #3498db;
    display: block;
}

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

::-webkit-scrollbar-track {
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255,255,255,0.3);
}

/* Tabs */
.tabs {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
}

.tab {
    flex: 1;
    padding: 10px;
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 0.85rem;
    text-align: center;
    transition: all 0.2s ease;
}

.tab:hover {
    background: rgba(255,255,255,0.05);
}

.tab.active {
    background: rgba(232, 213, 183, 0.1);
    border-color: #e8d5b7;
    color: #e8d5b7;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Modelo salvo indicator */
.model-saved-badge {
    display: none;
    background: rgba(39, 174, 96, 0.2);
    border: 1px solid rgba(39, 174, 96, 0.3);
    color: #27ae60;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    margin-top: 10px;
    text-align: center;
}

.model-saved-badge.visible {
    display: block;
}

/* Batch (Lote) */
.batch-section {
    margin-top: 10px;
}

.batch-upload-area {
    border: 2px dashed rgba(255,255,255,0.2);
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 10px;
}

.batch-upload-area:hover {
    border-color: #3498db;
    background: rgba(52, 152, 219, 0.05);
}

.batch-upload-area.dragover {
    border-color: #3498db;
    background: rgba(52, 152, 219, 0.1);
}

.batch-upload-area p {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.6);
}

.batch-upload-area input {
    display: none;
}

.batch-info {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    margin-bottom: 10px;
    line-height: 1.4;
}

.batch-preview {
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: 10px;
    font-size: 0.8rem;
}

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

.batch-preview th,
.batch-preview td {
    padding: 4px 8px;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.batch-preview th {
    color: #e8d5b7;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.batch-preview td {
    color: rgba(255,255,255,0.7);
}

.batch-preview td.invalid {
    color: #e74c3c;
}

.batch-progress {
    display: none;
    margin-top: 10px;
}

.batch-progress-bar {
    width: 100%;
    height: 6px;
    background: rgba(0,0,0,0.3);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 5px;
}

.batch-progress-fill {
    height: 100%;
    background: linear-gradient(135deg, #e8d5b7 0%, #d4a574 100%);
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.batch-progress-text {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
    text-align: center;
}

.btn-batch {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
    color: #fff;
    margin-top: 10px;
}

.btn-batch:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 30px rgba(52, 152, 219, 0.3);
}

/* Undo/Redo */
.undo-redo-controls {
    display: flex;
    gap: 5px;
    margin-bottom: 10px;
}

.undo-redo-controls button {
    flex: 1;
    padding: 6px;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 6px;
    color: rgba(255,255,255,0.6);
    cursor: pointer;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.2s ease;
}

.undo-redo-controls button:hover:not(:disabled) {
    background: rgba(255,255,255,0.1);
    color: #fff;
}

.undo-redo-controls button:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* CPF validation */
.cpf-invalid {
    border-color: #e74c3c !important;
}

.cpf-valid {
    border-color: #27ae60 !important;
}

.cpf-hint {
    font-size: 0.7rem;
    margin-top: 3px;
    min-height: 14px;
}

.cpf-hint.invalid {
    color: #e74c3c;
}

.cpf-hint.valid {
    color: #27ae60;
}

/* Historico */
.history-list {
    max-height: 300px;
    overflow-y: auto;
}

.history-empty {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.4);
    text-align: center;
    padding: 15px 0;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 6px;
    background: rgba(0,0,0,0.2);
    margin-bottom: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.history-item:hover {
    background: rgba(255,255,255,0.08);
    border-color: rgba(232, 213, 183, 0.3);
}

.history-item-info {
    flex: 1;
    min-width: 0;
}

.history-item-name {
    font-size: 0.85rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-details {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.4);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 2px;
}

.history-item-course {
    font-size: 0.7rem;
    color: #e8d5b7;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 1px;
}

.history-item-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.history-item-actions button {
    width: 26px;
    height: 26px;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.15);
    background: rgba(0,0,0,0.3);
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.history-item-actions button:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

.history-item-actions button.delete-btn:hover {
    background: rgba(231, 76, 60, 0.3);
    border-color: rgba(231, 76, 60, 0.5);
    color: #e74c3c;
}

.history-count {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.3);
    text-align: center;
    margin-top: 5px;
}

/* Preview header layout */
.preview-header-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Preview Tabs (Frente/Verso) */
.preview-tabs {
    display: flex;
    gap: 4px;
    background: rgba(0,0,0,0.3);
    border-radius: 6px;
    padding: 3px;
}

.preview-tab {
    padding: 5px 14px;
    background: transparent;
    border: none;
    border-radius: 4px;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.2s ease;
}

.preview-tab:hover {
    color: rgba(255,255,255,0.8);
}

.preview-tab.active {
    background: rgba(232, 213, 183, 0.15);
    color: #e8d5b7;
}

/* Dynamic Text Preview */
.dynamic-text-preview {
    background: rgba(0,0,0,0.2);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 0.8rem;
    color: rgba(255,255,255,0.7);
    line-height: 1.5;
}

.dynamic-text-preview strong {
    color: #e8d5b7;
}

#certificateCanvasVerso,
#cardCanvas {
    display: block;
    max-width: 100%;
    height: auto;
}

/* ===== Carteirinha ===== */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    color: rgba(255,255,255,0.85);
    font-size: 0.85rem;
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: #c1b274;
    cursor: pointer;
}

.hint {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.4);
    margin-top: 4px;
}

.photo-upload-area {
    border: 2px dashed rgba(255,255,255,0.2);
    border-radius: 10px;
    padding: 22px 14px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s ease;
    color: rgba(255,255,255,0.55);
}

.photo-upload-area:hover {
    border-color: rgba(193, 178, 116, 0.5);
    background: rgba(193, 178, 116, 0.05);
}

.photo-upload-area svg {
    width: 32px;
    height: 32px;
    margin: 0 auto 8px;
    display: block;
    opacity: 0.7;
}

.photo-upload-area p {
    font-size: 0.78rem;
    margin: 0;
}

.photo-upload-area input[type="file"] {
    display: none;
}

.photo-upload-area.dragover {
    border-color: #c1b274;
    background: rgba(193, 178, 116, 0.08);
}

.photo-crop-controls {
    margin-top: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

#photoCropCanvas {
    background: #0d1a30;
    border-radius: 10px;
    cursor: grab;
    touch-action: none;
    max-width: 100%;
    box-shadow: 0 4px 14px rgba(0,0,0,0.35);
}

#photoCropCanvas:active {
    cursor: grabbing;
}

.crop-instructions {
    font-size: 0.72rem;
    color: rgba(255,255,255,0.45);
    text-align: center;
}

.crop-actions {
    display: flex;
    gap: 8px;
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.78rem;
}

/* ===== Botoes carteirinha / zip ===== */
.btn-card {
    background: linear-gradient(135deg, #143430, #122c29);
    color: #c1b274;
    border: 1px solid #c1b274;
}

.btn-card:hover:not(:disabled) {
    background: linear-gradient(135deg, #1a4039, #143430);
}

.btn-card-pdf {
    background: linear-gradient(135deg, #2a3454, #1a1a2e);
    color: #c1b274;
    border: 1px solid rgba(193, 178, 116, 0.4);
}

.btn-card-pdf:hover:not(:disabled) {
    background: linear-gradient(135deg, #344066, #2a3454);
}

.btn-zip {
    background: linear-gradient(135deg, #c1b274, #af9e54);
    color: #122c29;
    font-weight: 700;
}

.btn-zip:hover:not(:disabled) {
    background: linear-gradient(135deg, #d0c187, #b8a76a);
}

/* ===== Painel de posicoes da carteirinha ===== */
.card-positions {
    margin-top: 14px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    background: rgba(0,0,0,0.18);
}

.card-positions summary {
    cursor: pointer;
    padding: 10px 14px;
    font-size: 0.85rem;
    color: #e8d5b7;
    user-select: none;
    list-style: none;
}

.card-positions summary::before {
    content: '\25B6';
    display: inline-block;
    margin-right: 8px;
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.card-positions[open] summary::before {
    transform: rotate(90deg);
}

.card-positions-body {
    padding: 4px 14px 14px;
}

.card-pos-group {
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px dashed rgba(255,255,255,0.06);
}

.card-pos-group:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
}

.card-pos-group strong {
    display: block;
    color: #c1b274;
    font-size: 0.75rem;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
