/* ═══════════ LAYOUT ═══════════ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--form-w) 1fr;
  grid-template-rows: var(--nav-h) 1fr;
  grid-template-areas:
    "nav nav nav"
    "sidebar form preview";
  height: 100vh;
  overflow: hidden;
}

/* ── NAVBAR ── */
.nav {
  grid-area: nav;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 12px;
  z-index: 50;
}
.nav-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.nav-logo .icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--accent), #6d5dfc);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #fff;
  font-weight: 800;
  flex-shrink: 0;
}
.nav-logo .brand {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.nav-logo .brand strong {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.2px;
}
.nav-logo .brand span {
  font-size: 10px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.nav-spacer { flex: 1; }
.nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── SIDEBAR ── */
.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.sidebar-head {
  padding: 14px 14px 10px;
  border-bottom: 1px solid var(--line);
}
.sidebar-head .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.sidebar-head h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
}
.sidebar-head .badge {
  background: var(--surface3);
  color: var(--text2);
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 10px;
}
.chips {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text2);
  font-size: 10.5px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 14px;
  transition: all 0.15s;
  white-space: nowrap;
}
.chip:hover {
  border-color: var(--line2);
  color: var(--text);
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.search {
  position: relative;
  margin: 0 14px 10px;
}
.search input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12px;
  background: var(--surface2);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.search input::placeholder { color: var(--muted); }
.search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--surface3);
}
.search .ic {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
}
.list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 16px;
}
.list .group-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.9px;
  color: var(--muted);
  padding: 14px 10px 6px;
}
.list .item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px 10px 14px;
  border-radius: var(--radius-sm);
  transition: background 0.12s;
  cursor: pointer;
  position: relative;
  border: none;
  background: transparent;
}
.list .item::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 2px;
  background: var(--line2);
  transition: background 0.15s;
}
.list .item:hover {
  background: var(--surface2);
}
.list .item.active {
  background: var(--surface3);
}
.list .item.active .item-name {
  color: var(--text);
  font-weight: 600;
}
.list .item.c-assacao::before { background: var(--cass); }
.list .item.c-suspensao::before { background: var(--susp); }
.list .item.c-ppd::before { background: var(--ppd); }
.list .item.c-advertencia::before { background: var(--adv); }
.list .item.c-multa::before { background: var(--multa); }
.list .item.c-reciclagem::before { background: var(--recic); }
.list .item.c-renovacao::before { background: var(--renov); }
.list .item.c-outros::before { background: var(--outro); }
.list .item-name {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  line-height: 1.45;
}
.list-empty {
  padding: 24px 12px;
  text-align: center;
  color: var(--muted);
  font-size: 11.5px;
}

/* ── FORM PANEL ── */
.formpanel {
  grid-area: form;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.formpanel-head {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.formpanel-head h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text2);
}
.formpanel-head p {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: 3px;
  line-height: 1.4;
}
.formscroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px 16px;
}
.field {
  margin-bottom: 12px;
}
.field label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin-bottom: 5px;
}
.field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  background: var(--surface2);
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input::placeholder { color: var(--muted); }
.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--surface3);
}
.field .hint {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}
.divider {
  border-top: 1px dashed var(--line);
  margin: 16px 0 14px;
  position: relative;
}
.divider span {
  position: absolute;
  top: -7px;
  left: 0;
  background: var(--surface);
  padding-right: 8px;
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
}
.formfoot {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
}
.autosave {
  font-size: 10px;
  color: var(--green);
  font-weight: 600;
}

/* ── PREVIEW ── */
.preview {
  grid-area: preview;
  overflow: auto;
  padding: 28px 28px 48px;
  background: var(--bg);
  min-height: 0;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}
.preview-inner {
  max-width: fit-content;
}
.sheet {
  width: 210mm;
  min-height: 297mm;
  background: #fff;
  box-shadow: var(--shadow-lg);
  padding: 22mm 20mm;
  font-family: 'Times New Roman', Times, serif;
  color: #101010;
  font-size: 12.5pt;
  line-height: 1.6;
}

/* ── BOTOES ── */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 12px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
}
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { filter: brightness(1.1); }
.btn-ghost {
  background: transparent;
  color: var(--text2);
  padding: 7px 12px;
  border: 1px solid var(--line);
}
.btn-ghost:hover {
  color: var(--text);
  border-color: var(--line2);
  background: var(--surface2);
}
.btn-gold {
  background: var(--gold);
  color: #000;
}
.btn-gold:hover { filter: brightness(1.08); }

/* ── PRINT ── */
@media print {
  @page { size: A4; margin: 0; }
  body { background: #fff; }
  body * { visibility: hidden; }
  .preview, .preview * { visibility: visible; }
  .preview {
    position: absolute;
    left: 0; top: 0;
    padding: 0;
    overflow: visible;
  }
  .preview-inner { margin: 0; max-width: none; }
  .sheet { width: 210mm; min-height: 297mm; box-shadow: none; margin: 0; }
}

/* ── RESPONSIVO ── */
@media (max-width: 1100px) {
  .app {
    grid-template-columns: 260px 300px 1fr;
  }
}
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--nav-h) 1fr;
    grid-template-areas: "nav" "preview";
    height: auto;
    min-height: 100vh;
  }
  .sidebar, .formpanel { display: none; }
  .preview { padding: 16px 10px 40px; }
  .sheet { width: 100%; max-width: 210mm; padding: 10mm 8mm; }
}
