:root {
  --primary: #f59e0b;
  --primary-hover: #d97706;
  --primary-light: #fef3c7;
  --secondary: #008f89;
  --secondary-hover: #00746f;
  --bg-main: #0f172a;
  --bg-card: #1e293b;
  --bg-card-subtle: #334155;
  --bg-input: #0f172a;
  --border: #334155;
  --border-focus: #f59e0b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-ddm: #ff5722;
  --success: #10b981;
  --danger: #ef4444;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.4);
}

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

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

/* Header */
.app-header {
  background-color: rgba(30, 41, 59, 0.95);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-container {
  max-width: 1500px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-badge {
  background: linear-gradient(135deg, #f59e0b, #e59c00);
  color: #000;
  font-weight: 800;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.brand-title {
  font-size: 1.35rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

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

.brand-partner span {
  color: var(--accent-ddm);
  font-weight: 700;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 0.35rem 0.85rem;
  border-radius: 9999px;
}

.status-dot {
  width: 8px;
  height: 8px;
  background-color: var(--success);
  border-radius: 50%;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
  70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
  100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

/* Layout Principal */
.main-wrapper {
  max-width: 1500px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.editor-grid {
  display: grid;
  grid-template-columns: 1fr 480px;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .editor-grid {
    grid-template-columns: 1fr;
  }
}

/* Painel de Formulário e Edição */
.panel {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.panel-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #fff;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.75rem;
}

.panel-title i {
  color: var(--primary);
}

/* Grupos de Formulário */
.form-section {
  margin-bottom: 1.5rem;
}

.section-subtitle {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  font-weight: 700;
  margin-bottom: 0.85rem;
}

.form-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

@media (max-width: 600px) {
  .form-grid-2 {
    grid-template-columns: 1fr;
  }
}

.form-group {
  margin-bottom: 1rem;
}

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

.form-group label .hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: normal;
}

.form-control {
  width: 100%;
  padding: 0.75rem 0.9rem;
  font-size: 0.95rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: #fff;
  transition: all 0.2s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.2);
}

.form-control::placeholder {
  color: #64748b;
}

/* Área de Upload e Foto */
.upload-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.6);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.upload-dropzone:hover, .upload-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(245, 158, 11, 0.05);
}

.upload-icon {
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
  display: inline-block;
}

.upload-text {
  font-weight: 600;
  color: #fff;
  margin-bottom: 0.25rem;
}

.upload-subtext {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.rule-alert {
  margin-top: 0.75rem;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
}

/* Controles de Foto (Pan/Zoom) */
.photo-controls {
  margin-top: 1rem;
  background: var(--bg-card-subtle);
  padding: 1rem;
  border-radius: var(--radius-md);
  display: none;
}

.photo-controls.active {
  display: block;
}

.slider-group {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}

.slider-group label {
  font-size: 0.8rem;
  width: 70px;
  color: var(--text-muted);
}

.slider-group input[type="range"] {
  flex: 1;
  accent-color: var(--primary);
  cursor: pointer;
}

.slider-val {
  font-size: 0.8rem;
  width: 45px;
  text-align: right;
  color: var(--text-main);
  font-family: monospace;
}

.photo-actions-row {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
}

/* Logo da Prestadora */
.logo-partner-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border);
  padding: 0.85rem;
  border-radius: var(--radius-md);
}

.partner-logo-preview {
  background: #ffffff;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  height: 50px;
  width: 120px;
}

.partner-logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.partner-details {
  flex: 1;
}

.partner-name {
  font-weight: 700;
  font-size: 0.95rem;
  color: #fff;
}

.partner-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
}

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

.btn-primary {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #000;
  font-weight: 700;
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  transform: translateY(-1px);
}

.btn-secondary {
  background-color: var(--bg-card-subtle);
  color: #fff;
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background-color: #475569;
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: linear-gradient(135deg, #34d399, #10b981);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.actions-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

@media (max-width: 500px) {
  .actions-main {
    grid-template-columns: 1fr;
  }
}

.actions-download {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

/* Preview do Crachá */
.preview-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: sticky;
  top: 6rem;
}

.badge-card-holder {
  background: #0b1120;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.badge-lanyard-hole {
  width: 60px;
  height: 12px;
  background: #1e293b;
  border: 2px solid #334155;
  border-radius: 9999px;
  margin-bottom: 1rem;
}

.badge-canvas-wrapper {
  width: 100%;
  max-width: 360px;
  aspect-ratio: 936 / 1446;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  background: #fff;
  position: relative;
}

#badgeCanvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
}

.badge-dimensions-tag {
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: monospace;
}

/* Tabela e Seção de Colaboradores */
.database-section {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  box-shadow: var(--shadow);
}

.table-header-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  min-width: 280px;
}

.search-box input {
  padding-left: 2.2rem;
}

.search-box-icon {
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.colab-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.colab-table th {
  background-color: var(--bg-card-subtle);
  color: var(--text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.colab-table td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: middle;
}

.colab-table tr:hover {
  background-color: rgba(255, 255, 255, 0.02);
}

.avatar-mini {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  object-fit: cover;
  background-color: #334155;
}

.colab-name-cell {
  font-weight: 600;
  color: #fff;
}

.colab-badge-name {
  font-size: 0.8rem;
  color: var(--primary);
  display: block;
}

.colab-matricula-badge {
  font-family: monospace;
  background: var(--bg-card-subtle);
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  color: #cbd5e1;
}

.table-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon:hover {
  color: #fff;
  border-color: #cbd5e1;
  background-color: var(--bg-card-subtle);
}

.btn-icon.delete:hover {
  color: var(--danger);
  border-color: var(--danger);
  background-color: rgba(239, 68, 68, 0.1);
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

/* Toast de Notificação */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  background: var(--bg-card);
  color: #fff;
  border: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideIn 0.3s ease;
  min-width: 260px;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Modal de corte de foto */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(4px);
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  max-width: 600px;
  width: 90%;
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

/* Estilos de Impressão */
@media print {
  body * {
    visibility: hidden;
  }
  .preview-container, .preview-container * {
    visibility: visible;
  }
  .preview-container {
    position: absolute;
    left: 0;
    top: 0;
    width: 55mm;
    height: 85mm;
    padding: 0;
    margin: 0;
  }
  .badge-card-holder {
    background: transparent;
    padding: 0;
    border: none;
    box-shadow: none;
  }
  .badge-lanyard-hole, .badge-dimensions-tag {
    display: none;
  }
  .badge-canvas-wrapper {
    width: 55mm;
    height: 85mm;
    box-shadow: none;
    border-radius: 0;
  }
}

/* ================= MODAL DE LOGIN / SEGURANÇA ================= */
.login-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 15, 29, 0.92);
  backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  padding: 1rem;
}

.login-overlay.active {
  display: flex;
}

.login-card {
  background: #1e293b;
  border: 1px solid rgba(245, 158, 11, 0.3);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8), 0 0 20px rgba(245, 158, 11, 0.15);
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 100%;
  padding: 2.25rem;
  animation: modalPop 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPop {
  0% { transform: scale(0.92); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.login-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.login-logo-badge {
  display: inline-block;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #000;
  font-weight: 800;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 0.85rem;
}

.login-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  margin-bottom: 0.35rem;
}

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

.login-form .form-group {
  margin-bottom: 1.25rem;
}

.input-icon-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.input-icon {
  position: absolute;
  left: 0.85rem;
  font-size: 1rem;
  color: var(--text-muted);
  pointer-events: none;
}

.input-icon-wrapper .form-control {
  padding-left: 2.6rem;
  padding-right: 2.5rem;
}

.btn-toggle-password {
  position: absolute;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.2rem;
  transition: color 0.2s;
}

.btn-toggle-password:hover {
  color: #fff;
}

.login-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 0.65rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  text-align: center;
}

.login-btn {
  width: 100%;
  padding: 0.85rem;
  font-size: 1rem;
  margin-top: 0.5rem;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
}

.login-footer-info {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 1rem;
}

