:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #5f6b7a;
  --line: #d9dee7;
  --primary: #166a6a;
  --primary-strong: #0f5151;
  --danger: #a33131;
  --danger-strong: #802323;
  --warning-bg: #fff7df;
  --warning-line: #e0bd5f;
  --error-bg: #fff0f0;
  --error-line: #d47a7a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.42 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 56px;
  padding: 0 24px;
  background: #17202a;
  color: #fff;
}

.topbar-main {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 20px;
}

.brand {
  color: #fff;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow-x: auto;
}

.tab {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 6px;
  padding: 6px 10px;
  color: #d8dde5;
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.tab:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.tab.active {
  background: #ffffff;
  color: #17202a;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
}

.user {
  color: #d8dde5;
  font-size: 15px;
}

.shell {
  width: min(1680px, calc(100vw - 40px));
  margin: 24px auto 32px;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 16px;
}

.page-heading h1 {
  margin-bottom: 4px;
  font-size: 26px;
}

.page-heading p {
  margin: 0;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.grid {
  display: grid;
  grid-template-columns: minmax(320px, 0.62fr) minmax(620px, 1.38fr);
  gap: 20px;
}

.dashboard-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.panel,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
}

.full {
  margin-top: 20px;
}

.panel + .panel {
  margin-top: 20px;
}

.login-panel {
  max-width: 420px;
  margin: 64px auto;
}

h1 {
  margin: 0 0 16px;
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  margin: 0 0 14px;
  font-size: 21px;
  line-height: 1.2;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-title h2 {
  margin: 0;
}

.panel-title > a {
  color: var(--primary-strong);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
}

.panel-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.form-stack,
.form-grid {
  display: grid;
  gap: 14px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.connection-form {
  grid-template-columns: repeat(4, minmax(180px, 1fr));
}

.connection-form .wide {
  grid-column: span 3;
}

.connection-form .half {
  grid-column: span 2;
}

.connection-form .wide + .button {
  grid-column: span 1;
  align-self: end;
}

.wide {
  grid-column: 1 / -1;
}

.edit-panel {
  max-width: 920px;
}

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

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
}

.field-hint {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font: inherit;
  background: #fff;
}

input[readonly],
.readonly-url {
  background: #f8fafc;
  color: #17202a;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

textarea {
  resize: vertical;
}

.search-select {
  position: relative;
  display: block;
  min-width: 0;
}

.search-select-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  color: var(--ink);
  font: inherit;
  text-align: left;
  background: #fff;
  cursor: pointer;
}

.search-select-trigger::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: translateY(-2px) rotate(45deg);
  flex: 0 0 auto;
}

.search-select-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 15;
  display: none;
  width: min(440px, calc(100vw - 48px));
  max-height: 320px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #fff;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
}

.search-select.open .search-select-menu {
  display: grid;
  gap: 8px;
}

.search-select-menu.wide-menu {
  width: min(760px, calc(100vw - 48px));
}

.search-select-filter {
  min-height: 36px;
}

.search-select-options {
  display: grid;
  max-height: 244px;
  overflow: auto;
}

.search-select-option {
  display: grid;
  gap: 2px;
  width: 100%;
  border: 0;
  border-radius: 6px;
  padding: 8px 9px;
  color: var(--ink);
  font: inherit;
  text-align: left;
  background: transparent;
  cursor: pointer;
}

.search-select-option:hover,
.search-select-option.selected {
  background: #eef6f6;
}

.search-select-option.recommended:not(.selected)::before {
  content: "Sugerido";
  justify-self: start;
  border-radius: 999px;
  padding: 1px 7px;
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 800;
  background: #e8f6ef;
}

.search-select-option strong {
  font-size: 14px;
}

.search-select-option span {
  color: var(--muted);
  font-size: 12px;
}

.scope-builder {
  display: grid;
  gap: 8px;
}

.scope-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.scope-pill {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  border: 1px solid #b9d6d6;
  border-radius: 999px;
  padding: 4px 9px;
  color: var(--primary-strong);
  font: 700 12px/1.2 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: #eef9f7;
  cursor: pointer;
}

.scope-pill::after {
  content: "x";
  margin-left: 7px;
  color: var(--muted);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.scope-string-field {
  display: grid;
  gap: 6px;
}

.scope-string-field > span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.scope-string-field input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.button.compact {
  min-height: 34px;
  padding: 6px 11px;
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.primary {
  background: var(--primary);
  color: #fff;
}

.primary:hover {
  background: var(--primary-strong);
}

.secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}

.danger {
  background: var(--danger);
  color: #fff;
}

.danger:hover {
  background: var(--danger-strong);
}

.notice,
.error {
  border-radius: 6px;
  padding: 10px 12px;
}

.notice {
  background: var(--warning-bg);
  border: 1px solid var(--warning-line);
}

.error {
  background: var(--error-bg);
  border: 1px solid var(--error-line);
}

.muted {
  color: var(--muted);
}

.eyebrow {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  display: grid;
  gap: 8px;
  min-height: 92px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  background: #fff;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.metric strong {
  font-size: 36px;
  line-height: 1;
}

.entity-cell {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.entity-cell span {
  color: var(--muted);
  font-size: 14px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-top: 1px solid var(--line);
  padding: 5px 9px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 15px;
}

td strong {
  font-size: 15px;
}

.compact-table td {
  height: 34px;
}

.compact-table td,
.compact-table th {
  padding-top: 5px;
  padding-bottom: 5px;
}

.project-table {
  min-width: 920px;
}

.project-link-cell,
.project-description {
  white-space: normal;
}

.project-link-cell {
  min-width: 220px;
}

.project-link-cell a {
  color: var(--primary-strong);
  font-weight: 800;
  text-decoration: none;
}

.project-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}

.project-description {
  min-width: 280px;
  color: var(--muted);
}

.customer-table {
  table-layout: fixed;
}

.customer-table .col-name {
  width: 36%;
}

.customer-table .col-slug {
  width: 18%;
}

.customer-table .col-notes {
  width: auto;
}

.customer-table .col-date {
  width: 140px;
}

.customer-table .col-actions {
  width: 96px;
}

.name-cell strong {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.notes-cell {
  min-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

td code {
  display: inline-block;
  max-width: 760px;
  overflow-wrap: anywhere;
  white-space: normal;
  color: #334155;
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.status {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 700;
}

.status.valid {
  background: #e8f6ef;
  color: #21613d;
}

.status.expired {
  background: #fff5d9;
  color: #7a5411;
}

.status.missing {
  background: #eceff3;
  color: #53606f;
}

.status.reusable {
  background: #e8f3ff;
  color: #235a91;
}

.status.inactive {
  background: #f1f5f9;
  color: #64748b;
}

.actions {
  text-align: right;
}

.row-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

.row-actions form {
  margin: 0;
}

.row-actions .button.compact,
.table-button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 13px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.pagination-summary {
  font-weight: 700;
  white-space: nowrap;
}

.page-size-form {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.page-size-form label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.page-size-form select {
  width: auto;
  min-height: 28px;
  border-radius: 6px;
  padding: 3px 24px 3px 7px;
  font-size: 13px;
}

.pagination-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 9px;
  color: var(--ink);
  font-weight: 700;
  text-decoration: none;
  background: #fff;
}

.page-link.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.page-link.disabled {
  color: var(--muted);
  opacity: 0.48;
}

.connections-workspace {
  display: grid;
  grid-template-columns: minmax(820px, 1fr) minmax(420px, 540px);
  gap: 20px;
  align-items: stretch;
}

.connections-list-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.connections-list-panel .table-wrap {
  flex: 1;
}

.connection-editor {
  align-self: stretch;
  position: sticky;
  top: 76px;
  height: 100%;
}

.connection-editor .panel-title p {
  margin: 4px 0 0;
}

.connection-editor .connection-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.connection-editor .connection-form .wide {
  grid-column: 1 / -1;
}

.connection-editor .connection-form .half {
  grid-column: span 1;
}

.connections-table {
  min-width: 980px;
}

.connections-table th:first-child,
.connections-table td:first-child {
  width: 130px;
}

.connections-table .row-actions {
  flex-wrap: nowrap;
}

.customer-group-row td {
  border-top: 1px solid #c8d0dc;
  padding-top: 10px;
  padding-bottom: 6px;
  background: #f8fafc;
}

.customer-group-row strong {
  color: #334155;
  font-size: 14px;
}

.selected-row td {
  background: #f2fbf9;
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.oauth-start-panel {
  max-width: 900px;
  margin: 48px auto;
}

.oauth-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.oauth-summary div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
  background: #f8fafc;
}

.oauth-summary dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.oauth-summary dd {
  margin: 4px 0 0;
  overflow-wrap: anywhere;
  font-weight: 700;
}

.oauth-copy-row {
  align-items: stretch;
}

.oauth-url {
  min-height: 128px;
  overflow-wrap: anywhere;
}

.modal {
  display: none;
}

.modal:target {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.64);
}

.modal-panel {
  position: relative;
  z-index: 1;
  width: min(1080px, calc(100vw - 48px));
  max-height: min(760px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px;
  background: #fff;
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.modal-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.modal-title h2 {
  margin: 2px 0 0;
}

.guide-layout {
  display: grid;
  grid-template-columns: minmax(380px, 1fr) minmax(320px, 460px);
  gap: 20px;
  align-items: start;
}

.guide-steps {
  display: grid;
  gap: 12px;
}

.guide-steps ol {
  margin: 0;
  padding-left: 24px;
}

.guide-steps li {
  margin: 0 0 8px;
}

.guide-steps a {
  color: var(--primary-strong);
  font-weight: 700;
}

.guide-steps code {
  color: #334155;
  font: 13px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.guide-shot {
  margin: 0;
}

.guide-shot img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.guide-shot figcaption {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 16px;
  }

  .topbar-main {
    width: 100%;
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .tabs {
    width: 100%;
  }

  .logout-form {
    width: 100%;
    justify-content: space-between;
  }

  .grid,
  .connections-workspace,
  .form-grid,
  .connection-form,
  .dashboard-grid,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .connection-form .wide,
  .connection-form .half,
  .connection-form .wide + .button {
    grid-column: 1;
  }

  .connection-editor {
    position: static;
  }

  .page-heading {
    align-items: start;
    flex-direction: column;
  }

  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-tools {
    justify-content: flex-start;
    width: 100%;
  }

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

  .form-actions .button {
    flex: 1;
  }

  .pagination {
    align-items: flex-start;
    flex-direction: column;
  }

  .pagination-controls {
    justify-content: flex-start;
  }

  .search-select-menu,
  .search-select-menu.wide-menu {
    position: fixed;
    inset: auto 12px 12px;
    width: auto;
    max-height: min(70vh, 520px);
  }

  .search-select-options {
    max-height: min(54vh, 420px);
  }

  .copy-row {
    grid-template-columns: 1fr;
  }

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

  .modal:target {
    align-items: start;
    padding: 12px;
  }

  .modal-panel {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
    padding: 16px;
  }

  .modal-title,
  .guide-layout {
    grid-template-columns: 1fr;
  }

  .modal-title {
    flex-direction: column;
  }

  .guide-layout {
    display: grid;
  }

  .shell {
    width: min(100vw - 20px, 1180px);
    margin: 10px auto;
  }
}
