/* ─── Reset & variáveis ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Paleta Kefraya */
  --kef-violet:  #6B72E8;
  --kef-violet-dk: #5158CC;
  --kef-indigo:  #383E7A;
  --kef-indigo-dk: #282E60;
  --kef-gray:    #7C7C80;
  --kef-light:   #C8D5E2;
  --kef-teal:    #3D5A6A;
  --kef-teal-dk: #2D4555;

  /* UI */
  --bg:        #E8EDF6;
  --surface:   #FFFFFF;
  --border:    #D0DAE8;
  --border-row:#EEF2F8;
  --text:      #1A2030;
  --text-muted:#6B7A90;
  --text-key:  #4A5568;

  /* Seções do documento — paleta Kefraya */
  --s-id:   #383E7A;   /* indigo */
  --s-srv:  #3D5A6A;   /* teal */
  --s-fin:  #2D4555;   /* teal-dk */
  --s-mov:  #6B72E8;   /* violet */
  --s-mat:  #5158CC;   /* violet-dk */
  --s-men:  #282E60;   /* indigo-dk */
  --s-chk:  #383E7A;   /* indigo */

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  --radius: 10px;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ─── Cabeçalho ─────────────────────────────────────── */
.app-header {
  background: var(--kef-indigo);
  border-bottom: 3px solid var(--kef-violet);
  position: sticky; top: 0; z-index: 20;
}

.header-inner {
  max-width: 1360px; margin: 0 auto;
  padding: 12px 32px;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}

/* Logo Kefraya */
.header-logo { flex-shrink: 0; }

.kef-logo {
  height: 52px; width: auto;
  color: #FFFFFF;
  display: block;
}

/* Título do sistema */
.header-app {
  display: flex; flex-direction: column; align-items: flex-end;
  border-left: 1px solid rgba(255,255,255,0.2);
  padding-left: 24px;
}

.header-app-name {
  color: #fff;
  font-size: 14px; font-weight: 600;
  letter-spacing: 0.3px;
  white-space: nowrap;
}

.header-app-sub {
  color: rgba(255,255,255,0.45);
  font-size: 11px; font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-top: 2px;
}

/* ─── Layout ────────────────────────────────────────── */
.app-layout {
  max-width: 1360px; margin: 28px auto 64px;
  padding: 0 32px;
  display: grid; grid-template-columns: 430px 1fr;
  gap: 24px; align-items: start;
}

@media (max-width: 980px) {
  .app-layout { grid-template-columns: 1fr; padding: 0 16px; margin-top: 20px; }
  .header-app { display: none; }
  .header-inner { justify-content: flex-start; }
}

/* ─── Painéis ───────────────────────────────────────── */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.07), 0 8px 24px rgba(0,0,0,0.05);
  padding: 26px;
}

.panel-title {
  font-size: 15px; font-weight: 700;
  color: var(--kef-indigo);
  margin-bottom: 18px; padding-bottom: 14px;
  border-bottom: 2px solid var(--border);
}

/* ─── Formulário ────────────────────────────────────── */
.form-group { margin-bottom: 14px; }

label {
  display: block;
  font-size: 11px; font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.6px;
  margin-bottom: 5px;
}

input[type=text], input[type=number], input[type=date], select {
  width: 100%; padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: 7px;
  font-size: 14px; font-family: var(--font);
  color: var(--text); background: #FAFBFD;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none; -webkit-appearance: none;
}

input.vazio {
  border-style: dashed;
  border-color: #B0A060;
  background: #FFFBEE;
}
input[type=date].vazio { color: var(--text-muted); }
input.vazio:focus { border-style: solid; }

input.campo-erro {
  border-style: solid;
  border-color: #C0392B;
  background: #FFF5F5;
  box-shadow: 0 0 0 3px rgba(192,57,43,0.15);
  animation: shake 0.3s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25%      { transform: translateX(-4px); }
  75%      { transform: translateX(4px); }
}

.label-erro { color: #C0392B; font-weight: 600; }

input:focus, select:focus {
  outline: none;
  border-color: var(--kef-violet);
  box-shadow: 0 0 0 3px rgba(107,114,232,0.15);
  background: #fff;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%236B7A90' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 32px; cursor: pointer;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ─── Autocomplete ──────────────────────────────────── */
.autocomplete-wrap { position: relative; }

#cursoInput { padding-right: 34px; }

.ac-clear {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%);
  width: 22px; height: 22px;
  background: none; border: none; color: var(--text-muted);
  font-size: 13px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  border-radius: 50%;
}
.ac-clear:hover { background: #EEF2F8; color: var(--text); }

.ac-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: #fff; border: 1.5px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  max-height: 240px; overflow-y: auto;
  z-index: 100; display: none;
}
.ac-dropdown.open { display: block; }

.ac-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 9px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border-row);
  font-size: 13px;
}
.ac-item:last-child { border-bottom: none; }
.ac-item:hover, .ac-item.ac-focused { background: #EEF4FF; }
.ac-item.ac-empty { color: var(--text-muted); font-style: italic; cursor: default; }
.ac-item.ac-empty:hover { background: none; }

.ac-nome { flex: 1; }
.ac-sigla {
  font-size: 11px; font-weight: 700; color: var(--kef-indigo);
  background: #ECEEFF; padding: 2px 7px; border-radius: 4px; white-space: nowrap;
}

.sigla-preview {
  font-size: 12px; font-weight: 600; color: var(--kef-indigo);
  margin-top: 5px; min-height: 16px;
}

/* ─── Toggle ────────────────────────────────────────── */
.toggle-row {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; background: #F8FAFC;
  margin-bottom: 14px; user-select: none;
  transition: border-color 0.15s;
}
.toggle-row:hover { border-color: var(--kef-violet); }
.toggle-row input[type=checkbox] { position: absolute; opacity: 0; width: 0; height: 0; }

.toggle-track {
  width: 36px; height: 20px; background: #C0CBD8;
  border-radius: 10px; position: relative; flex-shrink: 0;
  transition: background 0.2s;
}
.toggle-thumb {
  width: 16px; height: 16px; background: #fff; border-radius: 50%;
  position: absolute; top: 2px; left: 2px;
  transition: left 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.toggle-row input:checked ~ .toggle-track { background: var(--kef-violet); }
.toggle-row input:checked ~ .toggle-track .toggle-thumb { left: 18px; }
.toggle-label { font-size: 13px; font-weight: 500; color: var(--text); text-transform: none; letter-spacing: 0; }

/* ─── Blocos condicionais ───────────────────────────── */
.bloco-oculto { display: none; }

.highlight-group {
  background: #ECEEFF; border: 1.5px solid #B0B8F0;
  border-radius: 8px; padding: 12px; margin-bottom: 14px;
}
.highlight-group label { color: var(--kef-indigo); }
.highlight-group input { background: #fff; }

.hint-text { font-size: 12px; color: var(--kef-indigo); margin-top: 5px; min-height: 16px; font-weight: 500; }
.hint-text.error { color: #B52A2A; }

.preview-bar {
  font-size: 12px; color: var(--kef-indigo); font-weight: 600;
  background: #ECEEFF; border-left: 3px solid var(--kef-violet);
  padding: 7px 12px; border-radius: 0 6px 6px 0;
  margin-bottom: 14px; margin-top: -6px; display: none;
}

/* ─── Mensagens ─────────────────────────────────────── */
.msg { font-size: 13px; padding: 8px 12px; border-radius: 6px; margin-top: 8px; }
.msg:empty { display: none; }
.msg-erro { background: #FDECEA; color: #922; border: 1px solid #F5C6C6; }
.msg-ok   { background: #E8EEFF; color: var(--kef-indigo); border: 1px solid #C0C8F0; font-weight: 600; }

/* ─── Botão principal ───────────────────────────────── */
.btn-gerar {
  width: 100%; padding: 13px;
  background: var(--kef-indigo); color: #fff;
  border: none; border-radius: 8px;
  font-size: 14px; font-weight: 800; letter-spacing: 1.2px;
  cursor: pointer; transition: background 0.15s, transform 0.1s;
  margin-top: 4px;
}
.btn-gerar:hover  { background: var(--kef-indigo-dk); }
.btn-gerar:active { transform: scale(0.98); }
.btn-gerar:disabled { background: #9BA8B5; cursor: not-allowed; }

/* ─── Painel resultado ──────────────────────────────── */
.output-panel { min-height: 440px; }

.output-placeholder {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 400px; gap: 16px; text-align: center;
}
.placeholder-icon svg { stroke: #B8C8DA; }
.output-placeholder p { font-size: 14px; color: var(--text-muted); line-height: 1.6; }

#outputContent { display: none; }

.output-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px; padding-bottom: 14px; border-bottom: 2px solid var(--border);
}
.output-header .panel-title { margin-bottom: 0; padding-bottom: 0; border: none; }

.btn-action {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 13px; background: var(--bg);
  border: 1.5px solid var(--border); border-radius: 7px;
  font-size: 12px; font-weight: 700; color: var(--kef-indigo);
  cursor: pointer; transition: background 0.15s, border-color 0.15s;
}
.btn-action:hover { background: #D8DCF0; border-color: var(--kef-violet); }

/* Barra de dica de cópia */
.copy-hint-bar {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--kef-violet); font-weight: 600;
  background: #ECEEFF; border: 1px solid #C0C8F0;
  border-radius: 6px; padding: 7px 12px;
  margin-bottom: 14px;
}

/* ─── Seções do documento ───────────────────────────── */
.doc-section {
  margin-bottom: 10px; border-radius: 8px; overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.07);
  animation: entrar 0.2s ease both;
}

@keyframes entrar {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.doc-section:nth-child(1) { animation-delay: 0.00s; }
.doc-section:nth-child(2) { animation-delay: 0.04s; }
.doc-section:nth-child(3) { animation-delay: 0.08s; }
.doc-section:nth-child(4) { animation-delay: 0.12s; }
.doc-section:nth-child(5) { animation-delay: 0.16s; }
.doc-section:nth-child(6) { animation-delay: 0.20s; }
.doc-section:nth-child(7) { animation-delay: 0.24s; }

.doc-section-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; color: #fff;
  font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 0.8px;
}

/* Cores das seções */
.cor-id  { background: var(--s-id); }
.cor-srv { background: var(--s-srv); }
.cor-fin { background: var(--s-fin); }
.cor-mov { background: var(--s-mov); }
.cor-mat { background: var(--s-mat); }
.cor-men { background: var(--s-men); }
.cor-chk { background: var(--s-chk); }

/* Botão ? ajuda */
.btn-section-help {
  width: 22px; height: 22px;
  background: rgba(255,255,255,0.22); border: 1.5px solid rgba(255,255,255,0.45);
  border-radius: 50%; color: #fff; font-size: 12px; font-weight: 800;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s; line-height: 1;
}
.btn-section-help:hover { background: rgba(255,255,255,0.4); }

/* ─── Linhas do documento ───────────────────────────── */
.doc-rows { background: #fff; border: 1px solid rgba(0,0,0,0.06); border-top: none; }

.doc-row {
  display: grid; grid-template-columns: 200px 1fr;
  border-bottom: 1px solid var(--border-row);
}
.doc-row:last-child { border-bottom: none; }

.doc-row-key {
  padding: 8px 10px 8px 14px;
  font-size: 11.5px; font-weight: 600; color: var(--text-key);
  background: #F6F8FC;
  border-right: 1px solid var(--border-row);
  display: flex; align-items: center; gap: 6px;
}

.doc-row-val {
  padding: 8px 12px 8px 14px;
  font-size: 13px; color: var(--text); font-weight: 500;
}

.doc-row-val.destaque { font-weight: 700; font-size: 14px; color: var(--kef-indigo); }
.doc-row-val.alerta   { color: #904000; font-weight: 700; }
.doc-row-val.alerta-arred {
  color: #B52A2A; font-weight: 700; background: #FFF0EE;
}
.doc-row-val.calc-resumo {
  color: var(--text-muted); font-size: 12px; font-style: italic;
}

/* ─── Linhas copiáveis ──────────────────────────────── */
.doc-row-copy {
  cursor: pointer;
  transition: background 0.12s;
}
.doc-row-copy:hover { background: #F0F4FF; }
.doc-row-copy:hover .doc-row-key { background: #E8ECFA; }
.doc-row-copy:active { background: #E0E6FF; }

/* Ícone ⎘ sempre visível na coluna chave */
.copy-icon {
  color: var(--kef-violet);
  opacity: 0.35;
  font-size: 13px;
  flex-shrink: 0;
  transition: opacity 0.15s;
  line-height: 1;
}
.doc-row-copy:hover .copy-icon { opacity: 1; }

/* ─── Toast de cópia ────────────────────────────────── */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(16px);
  background: var(--kef-indigo); color: #fff;
  font-size: 13px; font-weight: 600;
  padding: 10px 20px; border-radius: 24px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap; z-index: 300;
}
.toast.show {
  opacity: 1; transform: translateX(-50%) translateY(0);
}

/* ─── Modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(10,18,40,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.modal-box {
  background: #fff; border-radius: 12px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
  width: min(860px, calc(100vw - 32px));
  max-height: calc(100vh - 60px); overflow: hidden;
  display: flex; flex-direction: column;
  transform: translateY(14px); transition: transform 0.2s;
}
.modal-overlay.open .modal-box { transform: translateY(0); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 15px; font-weight: 700; color: var(--kef-indigo); }

.modal-close {
  width: 30px; height: 30px; background: none; border: none;
  font-size: 16px; cursor: pointer; color: var(--text-muted);
  border-radius: 6px; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 20px; overflow: hidden; }

.modal-path {
  font-size: 13px; background: #F3F6FC;
  border: 1px solid var(--border); border-radius: 7px;
  padding: 10px 14px; margin-bottom: 16px; line-height: 1.6;
}
.modal-path-label { font-weight: 700; color: var(--kef-indigo); display: block; margin-bottom: 2px; }

.modal-img-area {
  border-radius: 8px; overflow: hidden;
  border: 1px solid var(--border);
  background: #F6F8FC; margin-bottom: 12px;
  text-align: center;
}
.modal-img-area img {
  display: block; width: 100%; height: auto;
  max-height: calc(100vh - 280px);
  object-fit: contain;
}

.img-placeholder {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  text-align: center; color: var(--text-muted);
  font-size: 13px; line-height: 1.8;
}
.img-placeholder code {
  font-size: 12px; background: var(--bg);
  padding: 2px 6px; border-radius: 4px; color: var(--kef-indigo);
}

.modal-hint {
  font-size: 13px; color: var(--text-muted); line-height: 1.6;
  padding-top: 10px; border-top: 1px solid var(--border-row);
}

/* ─── Impressão ─────────────────────────────────────── */
@media print {
  .app-header, .form-panel, .output-header, .copy-hint-bar,
  .btn-section-help, .copy-icon, .toast { display: none !important; }
  .app-layout { grid-template-columns: 1fr; margin: 0; padding: 0; }
  .output-panel { box-shadow: none; padding: 0; }
  .doc-section-header { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .doc-section { animation: none; break-inside: avoid; }
}

@media (prefers-reduced-motion: reduce) { .doc-section { animation: none; } }
