:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-muted: #edf2f0;
  --text: #242424;
  --muted: #60666c;
  --line: #d7dcdf;
  --teal: #00796f;
  --teal-dark: #005c55;
  --wine: #8a2f3f;
  --amber: #a86614;
  --focus: #0f7fbb;
  --shadow: 0 16px 40px rgba(36, 36, 36, 0.09);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 8px;
  background: var(--teal);
  color: #ffffff;
  font-weight: 700;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 1.15rem;
}

.brand p,
.results-toolbar p,
.empty-state p,
.loading-state p {
  color: var(--muted);
  font-size: 0.92rem;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.official-link,
.primary-button,
.secondary-button,
.result-action,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid transparent;
  text-decoration: none;
  white-space: nowrap;
}

.official-link {
  color: var(--teal-dark);
  border-color: var(--line);
  padding: 0 12px;
  background: #ffffff;
  font-size: 0.94rem;
}

.workspace {
  width: min(1240px, calc(100% - 36px));
  margin: 22px auto 36px;
  display: grid;
  gap: 18px;
}

.search-panel,
.results-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.search-panel {
  padding: 18px;
}

.panel-heading,
.results-toolbar,
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-heading {
  margin-bottom: 16px;
}

h2 {
  font-size: 1rem;
}

.mode-control,
.segmented {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(86px, auto);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-muted);
}

.segmented.wide {
  grid-auto-columns: minmax(116px, auto);
}

.segmented.compact {
  grid-auto-columns: minmax(68px, auto);
}

.mode-control input,
.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.mode-control span,
.segmented span {
  display: grid;
  place-items: center;
  min-height: 38px;
  padding: 0 12px;
  color: var(--muted);
  border-right: 1px solid var(--line);
  background: transparent;
}

.mode-control label:last-child span,
.segmented label:last-child span {
  border-right: 0;
}

.mode-control input:checked + span,
.segmented input:checked + span {
  color: #ffffff;
  background: var(--teal);
}

.search-form {
  display: grid;
  gap: 16px;
}

.home-disclaimer {
  max-width: 940px;
  margin: 16px auto 0;
  padding: 10px 12px 0;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
}

.primary-search {
  display: grid;
  gap: 7px;
}

.intent-panel {
  display: grid;
  gap: 8px;
}

.intent-panel > span {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

.intent-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.intent-chip {
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--text);
  font-size: 0.88rem;
  font-weight: 700;
}

.intent-chip:hover,
.intent-chip.is-active {
  border-color: var(--teal);
  color: var(--teal-dark);
  background: #e9f4f2;
}

.subsection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

.text-button {
  min-height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--teal-dark);
  font-weight: 700;
}

.history-panel {
  display: grid;
  gap: 8px;
}

.history-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.history-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 700;
}

label,
legend {
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 700;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.search-box:focus-within,
input:focus,
select:focus,
button:focus-visible,
a:focus-visible,
summary:focus-visible {
  outline: 3px solid rgba(15, 127, 187, 0.22);
  outline-offset: 2px;
}

.search-box input {
  width: 100%;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  align-items: end;
}

.textual-fields {
  grid-template-columns: repeat(2, max-content);
}

fieldset {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 7px;
}

.form-grid > label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #ffffff;
  color: var(--text);
}

.actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button {
  padding: 0 15px;
  font-weight: 700;
}

.primary-button {
  background: var(--teal);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--teal-dark);
}

.secondary-button {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

.secondary-button.is-active {
  border-color: var(--teal);
  color: var(--teal-dark);
  box-shadow: 0 0 0 3px var(--focus);
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.86rem;
}

.secondary-button:hover,
.official-link:hover,
.result-action:hover,
.icon-button:hover {
  border-color: var(--teal);
}

.results-shell {
  padding: 18px;
}

.results-toolbar {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.toolbar-controls {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.toolbar-controls label {
  display: grid;
  gap: 6px;
}

.result-filters {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.result-filter-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
}

.result-filter-grid label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.bulk-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
  padding: 12px;
  border: 1px solid #c9dcd8;
  border-radius: 8px;
  background: #f2faf8;
}

.bulk-bar strong {
  color: var(--teal-dark);
  white-space: nowrap;
}

.bulk-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

.download-dropdown {
  position: relative;
  display: inline-flex;
}

.download-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 30;
  min-width: 220px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.download-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  white-space: nowrap;
}

.download-menu button:hover,
.download-menu button:focus-visible {
  background: #e9f4f2;
  color: var(--teal-dark);
  outline: none;
}

.download-menu-separator {
  height: 1px;
  margin: 6px 4px;
  background: var(--line);
}

.empty-state,
.loading-state {
  min-height: 220px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  text-align: center;
}

.empty-state svg,
.loading-state svg {
  color: var(--teal);
}

.loader {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 4px solid var(--line);
  border-top-color: var(--wine);
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.results-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  overflow: hidden;
}

.result-card.is-selected {
  border-color: var(--teal);
  box-shadow: 0 0 0 2px rgba(0, 121, 111, 0.12);
}

.result-card-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  border-left: 4px solid var(--teal);
}

.result-select {
  display: grid;
  justify-items: center;
  align-content: start;
  gap: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.result-select input {
  width: 20px;
  min-height: 20px;
  accent-color: var(--teal);
}

.result-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.resolution-number {
  font-weight: 800;
  color: var(--teal-dark);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: #f0f4f3;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.pill.wine {
  color: #ffffff;
  background: var(--wine);
}

.note-pill {
  color: var(--teal-dark);
  background: #e9f4f2;
}

.decision-pill {
  color: var(--text);
  background: #eef2f1;
}

.decision-granted {
  color: #ffffff;
  background: #1f7a4d;
}

.decision-denied {
  color: #ffffff;
  background: var(--wine);
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.meta-grid strong {
  display: block;
  color: var(--text);
  font-size: 0.82rem;
}

.result-actions {
  display: flex;
  align-items: start;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.result-action,
.icon-button {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

.result-action {
  min-height: 36px;
  padding: 0 10px;
  font-size: 0.88rem;
  font-weight: 700;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.ementa {
  padding: 0 14px 14px 18px;
}

.ementa summary {
  cursor: pointer;
  color: var(--teal-dark);
  font-weight: 700;
  margin-bottom: 8px;
}

.ementa-text {
  white-space: pre-wrap;
  color: var(--text);
  margin-top: 8px;
}

mark {
  background: #ffe7a8;
  color: var(--text);
  padding: 0 2px;
  border-radius: 4px;
}

.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
}

.pagination span {
  color: var(--muted);
  font-size: 0.92rem;
}

.process-dialog,
.help-dialog {
  width: min(760px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  box-shadow: var(--shadow);
}

.help-dialog {
  width: min(860px, calc(100vw - 28px));
}

.process-dialog::backdrop,
.help-dialog::backdrop {
  background: rgba(36, 36, 36, 0.45);
}

.dialog-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-header > div {
  display: grid;
  gap: 4px;
}

.dialog-header p {
  color: var(--muted);
  font-size: 0.92rem;
}

.dialog-header p,
.help-content p,
.home-disclaimer {
  text-align: justify;
  text-justify: inter-word;
  hyphens: auto;
}

.process-content {
  max-height: 70vh;
  overflow: auto;
  padding: 16px;
}

.help-content {
  display: grid;
  gap: 18px;
  max-height: 76vh;
  overflow: auto;
  overflow-x: hidden;
  padding: 16px;
}

.help-section {
  display: grid;
  gap: 10px;
}

.help-section h3 {
  margin: 0;
  font-size: 0.98rem;
}

.help-section p {
  color: var(--muted);
}

.help-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
}

.help-card {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  overflow-wrap: anywhere;
}

.help-card span {
  color: var(--teal-dark);
  font-weight: 700;
}

.help-list,
.format-list {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
}

.help-list strong,
.format-list strong {
  color: var(--text);
}

.help-disclaimer {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid #c7d8d5;
  border-left: 4px solid var(--teal);
  border-radius: 8px;
  background: #f0f7f5;
}

.help-disclaimer strong {
  color: var(--teal-dark);
}

.help-disclaimer p {
  color: var(--text);
}

.copy-fallback {
  width: 100%;
  min-height: 260px;
  margin-top: 12px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
  white-space: pre-wrap;
}

.download-progress,
.download-failures {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7faf9;
  color: var(--muted);
}

.download-failures {
  display: grid;
  gap: 4px;
  border-color: #e5c6cc;
  background: #fff6f7;
}

.download-failures strong {
  color: var(--wine);
}

.download-failures ul {
  display: grid;
  gap: 8px;
  margin: 4px 0 0;
  padding-left: 18px;
}

.download-failures li {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.download-failures li strong {
  display: inline;
  margin-right: 6px;
}

.inline-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: max-content;
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font-weight: 700;
}

.note-editor {
  width: 100%;
  min-height: 180px;
  margin-top: 12px;
  padding: 12px;
  resize: vertical;
  line-height: 1.45;
}

.note-hint {
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8faf9;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.process-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 14px;
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.process-summary div {
  min-width: 0;
}

.process-summary strong,
.process-item strong {
  display: block;
  color: var(--text);
}

.process-summary span,
.process-item p {
  color: var(--muted);
}

.process-movements {
  display: grid;
}

.process-item {
  display: grid;
  gap: 4px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.process-item:last-child {
  border-bottom: 0;
}

.process-item time {
  color: var(--wine);
  font-weight: 700;
}

.process-item p {
  margin: 0;
}

.similar-list {
  display: grid;
  gap: 12px;
}

.similar-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.similar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--teal-dark);
}

.similar-heading span,
.similar-citation {
  color: var(--muted);
  font-size: 0.88rem;
}

.similar-reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.similar-reasons span {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 8px;
  border-radius: 999px;
  background: #edf2f0;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 700;
}

.similar-item p {
  margin: 0;
}

body.is-loading .primary-button {
  pointer-events: none;
  opacity: 0.72;
}

body.mode-numero .textual-fields,
body.mode-numero .filter-fields,
body.mode-completa .textual-fields {
  display: none;
}

body.mode-completa .primary-search label::after {
  content: " opcional";
  color: var(--muted);
  font-weight: 400;
}

svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

@media (max-width: 900px) {
  .topbar,
  .panel-heading,
  .results-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .official-link,
  .topbar-actions,
  .mode-control,
  .actions .primary-button,
  .actions .secondary-button {
    width: 100%;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .form-grid,
  .textual-fields,
  .meta-grid,
  .result-filter-grid,
  .help-grid {
    grid-template-columns: 1fr 1fr;
  }

  .result-card-header {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .result-actions {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

  .bulk-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .bulk-actions,
  .bulk-actions .secondary-button {
    width: 100%;
  }

  .download-dropdown {
    width: 100%;
  }

  .download-menu {
    left: 0;
    right: 0;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 14px 16px;
  }

  .workspace {
    width: min(100% - 20px, 1240px);
    margin-top: 12px;
  }

  .search-panel,
  .results-shell {
    padding: 14px;
  }

  .mode-control,
  .segmented,
  .segmented.wide,
  .segmented.compact,
  .form-grid,
  .textual-fields,
  .meta-grid,
  .result-filter-grid,
  .help-grid {
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    grid-auto-columns: auto;
  }

  .mode-control span,
  .segmented span {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .mode-control label:last-child span,
  .segmented label:last-child span {
    border-bottom: 0;
  }

  .toolbar-controls,
  .toolbar-controls label,
  .toolbar-controls .secondary-button {
    width: 100%;
  }

  .result-select {
    justify-items: start;
  }

  .process-summary {
    grid-template-columns: 1fr;
  }
}
