﻿:root {
  --bg: #f7f4ef;
  --ink: #1f1c18;
  --card: rgba(255, 255, 255, 0.72);
  --line: rgba(31, 28, 24, 0.12);
  --accent: #270a8f;
  --accent-2: #157a6e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Space Grotesk', sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 12%, rgba(54, 118, 255, 0.35) 0%, transparent 32%),
    radial-gradient(circle at 82% 18%, rgba(138, 208, 255, 0.42) 0%, transparent 34%),
    linear-gradient(135deg, #031538 0%, #114a9c 46%, #eef7ff 100%);
  min-height: 100vh;
}

.bg-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(60px);
  opacity: .42;
  z-index: -1;
}

.orb-a { width: 260px; height: 260px; background: #1d6dff; top: -60px; left: -40px; }
.orb-b { width: 320px; height: 320px; background: #8ed8ff; bottom: -100px; right: -80px; }

.layout { width: 98vw; max-width: none; margin: 1rem auto; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 46px rgba(0, 0, 0, 0.08);
  padding: 1.2rem;
}

.auth-panel { max-width: 500px; margin: 10vh auto; }

h1, h2, h3 {
  font-family: 'Sora', sans-serif;
  margin: 0 0 .8rem;
}

.form-grid { display: grid; gap: .45rem; }

input, button, select, textarea {
  border-radius: 12px;
  border: 1px solid var(--line);
  font: inherit;
  padding: .68rem .9rem;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
}

button.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.topbar-actions { display: flex; gap: .5rem; }

.tabs { display: flex; gap: .45rem; margin-bottom: 1rem; }
.tab { background: rgba(255, 255, 255, .6); color: var(--ink); border: 1px solid var(--line); }
.tab.active { background: var(--ink); color: #fff; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: .8rem;
  margin-bottom: 1rem;
}

.stat strong { font-size: 1.6rem; }
.stat {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.grid.two-col {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr 1fr;
  margin-bottom: 1rem;
}

.dashboard-main-grid {
  align-items: start;
}

.dashboard-stack {
  display: grid;
  gap: 1rem;
}

.card.span-2 {
  grid-column: 1 / -1;
}

.card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: .9rem;
  background: rgba(255, 255, 255, .68);
}

#dashboardView .grid.two-col {
  align-items: stretch;
}

.dashboard-frame {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.dashboard-frame-list {
  min-height: 360px;
  max-height: 360px;
}

.dashboard-frame-form {
  min-height: 340px;
}

.backup-status-ok {
  border-color: rgba(17, 133, 66, 0.5) !important;
  box-shadow: 0 0 0 1px rgba(17, 133, 66, 0.2) inset;
}

.backup-status-warn {
  border-color: rgba(199, 138, 0, 0.55) !important;
  box-shadow: 0 0 0 1px rgba(199, 138, 0, 0.22) inset;
}

.backup-status-error {
  border-color: rgba(188, 43, 43, 0.6) !important;
  box-shadow: 0 0 0 1px rgba(188, 43, 43, 0.24) inset;
}

.backup-status-unknown {
  border-color: rgba(82, 96, 124, 0.5) !important;
  box-shadow: 0 0 0 1px rgba(82, 96, 124, 0.2) inset;
}

#backupHealthMessage.backup-status-ok {
  background: rgba(17, 133, 66, 0.08);
}

#backupHealthMessage.backup-status-warn {
  background: rgba(199, 138, 0, 0.1);
}

#backupHealthMessage.backup-status-error {
  background: rgba(188, 43, 43, 0.1);
}

#backupHealthMessage.backup-status-unknown {
  background: rgba(82, 96, 124, 0.1);
}

.nlq-card {
  min-height: 620px;
}

.list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: .6rem;
  max-height: 260px;
  overflow: auto;
}

.dashboard-frame .list {
  max-height: none;
  min-height: 0;
  flex: 1;
}

.list li {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: .58rem .65rem;
  background: rgba(255, 255, 255, .82);
}

.doc-preview-frame {
  width: 100%;
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: .7rem;
}

.cadastro-toolbar {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: .8rem;
}

.download-folder-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .55rem;
  align-items: center;
}

.download-folder-row button {
  min-width: 46px;
  font-weight: 700;
}

.entity-buttons {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}

.entity-btn {
  background: rgba(255, 255, 255, .75);
  color: var(--ink);
  border: 1px solid var(--line);
}

.entity-btn.active {
  background: var(--ink);
  color: #fff;
}

.table-wrap { overflow: auto; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem; border-bottom: 1px solid var(--line); }
th { font-size: .85rem; }
td.actions { display: flex; gap: .4rem; flex-wrap: wrap; }
th.sortable { cursor: pointer; user-select: none; }

.action-icon-btn {
  position: relative;
  width: 40px;
  height: 40px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.action-icon-btn svg {
  width: 20px;
  height: 20px;
}

.action-icon-btn.danger {
  background: #c62828;
  color: #fff;
}

.action-icon-btn::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  opacity: 0;
  pointer-events: none;
  white-space: nowrap;
  background: rgba(17, 22, 34, .95);
  color: #fff;
  font-size: .75rem;
  border-radius: 8px;
  padding: .3rem .45rem;
  transition: opacity .14s ease, transform .14s ease;
  z-index: 12;
}

.action-icon-btn:hover::after,
.action-icon-btn:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.pagination {
  margin-top: .8rem;
  display: flex;
  align-items: center;
  gap: .7rem;
  justify-content: flex-end;
}

.message {
  white-space: pre-wrap;
  background: rgba(0, 0, 0, 0.03);
  border-radius: 12px;
  padding: .7rem;
}

#nlqPergunta {
  min-height: 110px;
  font-size: 1.1rem;
  line-height: 1.4;
}

.nlq-hint {
  margin-top: -.25rem;
  color: rgba(31, 28, 24, 0.72);
  font-size: .92rem;
  line-height: 1.35;
}

#nlqResultado {
  min-height: 260px;
  max-height: 52vh;
  overflow: auto;
  font-size: 1.1rem;
  line-height: 1.55;
  padding: 1rem;
}

#nlqResultado .nlq-bubble {
  background: linear-gradient(180deg, rgba(39, 10, 143, 0.08) 0%, rgba(39, 10, 143, 0.04) 100%);
  border: 1px solid rgba(39, 10, 143, 0.22);
  border-radius: 14px;
  padding: .95rem 1rem;
}

#nlqResultado .nlq-bubble p {
  margin: 0 0 .55rem;
}

#nlqResultado .nlq-bubble p:last-child {
  margin-bottom: 0;
}

#nlqResultado .nlq-bubble ol {
  margin: .45rem 0 0 1.2rem;
  padding: 0;
  display: grid;
  gap: .45rem;
}

#nlqResultado .nlq-bubble li {
  padding-left: .1rem;
}

#nlqResultado .nlq-bubble-loading {
  border-style: dashed;
  opacity: .9;
}

#nlqResultado .nlq-bubble-error {
  background: rgba(198, 40, 40, 0.08);
  border-color: rgba(198, 40, 40, 0.28);
}

.nlq-actions {
  display: flex;
  gap: .6rem;
  margin-top: .7rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal {
  width: min(720px, 100%);
  max-height: 90vh;
  overflow: auto;
  background: #fff;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 1rem;
}

.modal.modal-sm {
  width: min(520px, 100%);
}

.modal.modal-andamentos {
  width: min(1360px, 98vw);
  max-height: 95vh;
}

.modal.modal-preview {
  width: min(96vw, 1800px);
  height: min(94vh, 1200px);
  max-height: 94vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: .8rem;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .6rem;
}

.modal-actions {
  margin-top: .8rem;
  display: flex;
  gap: .6rem;
  justify-content: flex-end;
}

.cep-inline {
  display: grid;
  grid-template-columns: minmax(140px, 1fr) auto;
  gap: .45rem;
  align-items: center;
}

.cep-search-btn {
  white-space: nowrap;
  padding: .58rem .85rem;
}

.doc-history {
  margin-top: 1rem;
  border-top: 1px solid var(--line);
  padding-top: .8rem;
}

.doc-history h4 {
  margin: 0 0 .6rem;
  font-family: 'Sora', sans-serif;
}

.doc-history-list {
  max-height: 260px;
  overflow: auto;
}

.doc-tree {
  display: grid;
  gap: .65rem;
}

.doc-tree-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, .7);
}

.doc-tree-group summary {
  cursor: pointer;
  padding: .6rem .8rem;
  font-weight: 600;
}

.doc-tree-group .group-content {
  padding: .3rem .8rem .8rem;
}

.doc-tree-item {
  display: grid;
  gap: .35rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .55rem .6rem;
  margin-top: .5rem;
  background: rgba(255, 255, 255, .9);
}

.doc-tree-item .meta {
  font-size: .9rem;
  color: rgba(31, 28, 24, .8);
}

.doc-tree-item .actions {
  display: flex;
  flex-wrap: wrap;
  gap: .45rem;
}

.modal.modal-andamentos .doc-history-list {
  overflow-x: hidden;
  max-height: 420px;
}

.modal.modal-andamentos .andamentos-table {
  table-layout: fixed;
  width: 100%;
}

.modal.modal-andamentos .andamentos-table th:nth-child(1),
.modal.modal-andamentos .andamentos-table td:nth-child(1) {
  width: 16%;
}

.modal.modal-andamentos .andamentos-table th:nth-child(2),
.modal.modal-andamentos .andamentos-table td:nth-child(2) {
  width: 28%;
}

.modal.modal-andamentos .andamentos-table th:nth-child(3),
.modal.modal-andamentos .andamentos-table td:nth-child(3) {
  width: 28%;
}

.modal.modal-andamentos .andamentos-table th:nth-child(4),
.modal.modal-andamentos .andamentos-table td:nth-child(4) {
  width: 18%;
}

.modal.modal-andamentos .andamentos-table th:nth-child(5),
.modal.modal-andamentos .andamentos-table td:nth-child(5) {
  width: 10%;
}

.modal.modal-andamentos .modal-grid {
  grid-template-columns: minmax(180px, 0.65fr) minmax(560px, 1.35fr);
  column-gap: .9rem;
  row-gap: .7rem;
  align-items: start;
}

.modal.modal-andamentos .modal-grid > label {
  padding-top: .5rem;
}

.modal.modal-andamentos .modal-grid input,
.modal.modal-andamentos .modal-grid textarea,
.modal.modal-andamentos .modal-grid select {
  width: 100%;
}

.modal.modal-andamentos .andamentos-table th,
.modal.modal-andamentos .andamentos-table td {
  white-space: normal;
  word-break: break-word;
  vertical-align: top;
}

.modal.modal-andamentos .andamentos-table td.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: .4rem;
}

.modal.modal-andamentos .andamentos-table td.actions button {
  white-space: nowrap;
}

.doc-preview-frame-lg {
  flex: 1;
  min-height: 0;
  height: 100%;
}

.peticao-editor-layout {
  display: grid;
  gap: .7rem;
}

.peticao-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  padding: .45rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(247, 244, 239, .6);
}

.peticao-toolbar button {
  padding: .45rem .6rem;
}

.peticao-toolbar select {
  min-width: 100px;
}

.peticao-toolbar .toolbar-break {
  flex-basis: 100%;
  height: 0;
}

.peticao-editor {
  min-height: 52vh;
  height: 56vh;
  max-height: 56vh;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 1.4rem;
  font-family: "Times New Roman", serif;
  font-size: 12pt;
  line-height: 1.5;
  background: #fff;
  overflow-y: auto;
  overflow-x: hidden;
}

.peticao-editor:focus {
  outline: 2px solid rgba(227, 74, 47, .25);
  border-color: rgba(227, 74, 47, .35);
}

.peticao-autosave {
  color: rgba(31, 28, 24, .7);
}

.hidden { display: none; }

@media (max-width: 900px) {
  .grid.two-col { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .modal-grid { grid-template-columns: 1fr; }
}
