: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;
}

.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;
}

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

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: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;
}

.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-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 14px;
  border-left: 4px solid 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);
}

.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 {
  width: min(760px, calc(100% - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  color: var(--text);
  box-shadow: var(--shadow);
}

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

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

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

.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;
}

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,
  .mode-control,
  .actions .primary-button,
  .actions .secondary-button {
    width: 100%;
  }

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

  .result-card-header {
    grid-template-columns: 1fr;
  }

  .result-actions {
    justify-content: flex-start;
  }
}

@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 {
    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 {
    width: 100%;
  }

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