:root {
  --ink: #152027;
  --muted: #5d6b75;
  --paper: #f3efe6;
  --panel: #fffdf8;
  --line: #d7d0c3;
  --accent: #0f6b5c;
  --accent-ink: #083f37;
  --rail: #1b2a33;
  --danger: #8f1d1d;
  --shadow: 0 18px 40px rgba(21, 32, 39, 0.08);
  --font-ui: "Manrope", "Segoe UI", sans-serif;
  --font-display: "Source Serif 4", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  background:
    radial-gradient(circle at 12% 10%, rgba(15, 107, 92, 0.12), transparent 40%),
    radial-gradient(circle at 90% 0%, rgba(138, 75, 18, 0.10), transparent 35%),
    linear-gradient(180deg, #efe9dc 0%, var(--paper) 45%, #e7e1d4 100%);
}

body {
  display: grid;
  grid-template-columns: 72px 1fr;
  min-height: 100vh;
}

.hidden { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.rail {
  background: var(--rail);
  color: #dce6ec;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 18px 0;
  gap: 18px;
}

.brand-mark {
  width: 58px;
  height: 42px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #f3efe6;
  padding: 6px 7px;
  border: 1px solid rgba(215, 208, 195, 0.55);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.login-brand {
  margin: 0 0 18px;
  padding: 16px 18px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-logo {
  display: block;
  width: min(230px, 78%);
  height: auto;
}

.login-title {
  margin: 0;
  text-align: center;
  font-family: var(--font-display);
  font-size: clamp(1.15rem, 2vw, 1.35rem);
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.login-lead {
  margin: 8px 0 22px;
  color: var(--muted);
  line-height: 1.45;
  font-size: 14px;
  text-align: center;
}

.rail-nav { display: flex; flex-direction: column; gap: 10px; flex: 1; }

.rail-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  font-size: 18px;
  cursor: default;
}

.rail-btn.is-active { background: rgba(255, 255, 255, 0.12); }

.rail-foot {
  font-size: 11px;
  letter-spacing: 0.04em;
  opacity: 0.7;
}

.stage {
  padding: 28px 36px 40px;
  max-width: 1100px;
}

.stage-login {
  display: grid;
  place-items: center;
  max-width: none;
  padding: 40px 20px;
}

.login-panel {
  width: min(440px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 28px 26px 22px;
}

.login-panel label {
  display: block;
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.login-panel input[type="text"],
.login-panel select {
  width: 100%;
  height: 46px;
  margin-bottom: 14px;
  border: 1px solid #cfc6b6;
  border-radius: 12px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  font: inherit;
}

.login-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.check-row {
  display: flex !important;
  align-items: center;
  gap: 8px;
  margin: 2px 0 16px !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 14px !important;
  font-weight: 600 !important;
  color: var(--ink) !important;
}

#btnLogin {
  width: 100%;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

#btnLogin:hover { background: var(--accent-ink); }
#btnLogin:disabled { opacity: 0.65; cursor: wait; }

.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 2.4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
  max-width: min(420px, 48vw);
}

.company-card {
  width: 100%;
  padding: 12px 14px 12px;
  border: 1px solid #d2c7b4;
  border-radius: 14px;
  background:
    linear-gradient(145deg, rgba(255, 253, 248, 0.98), rgba(244, 236, 220, 0.95));
  box-shadow: 0 10px 24px rgba(21, 32, 39, 0.06);
}

.company-label {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.company-name {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: clamp(0.95rem, 1.4vw, 1.15rem);
  font-weight: 700;
  line-height: 1.25;
  color: var(--accent-ink);
  word-break: break-word;
}

.company-name.is-muted {
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
}

.company-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-start;
}

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

.chip {
  border: 1px solid var(--line);
  background: rgba(255, 253, 248, 0.9);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.chip.muted { color: var(--muted); font-weight: 600; }

.btn-ghost {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 10px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  cursor: pointer;
}

.btn-ghost:hover { color: var(--ink); border-color: #b9b0a0; }

.search-panel,
.result-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.search-panel {
  padding: 20px 20px 14px;
  margin-bottom: 18px;
}

.panel-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
}

.search-row {
  display: grid;
  grid-template-columns: 140px 1fr 150px;
  gap: 10px;
}

select,
input,
button { font: inherit; }

.search-row select,
.search-row input {
  height: 46px;
  border: 1px solid #cfc6b6;
  border-radius: 12px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
}

.search-row select:focus,
.search-row input:focus,
.login-panel input:focus,
.login-panel select:focus {
  outline: 2px solid rgba(15, 107, 92, 0.35);
  border-color: var(--accent);
}

button[type="submit"] {
  height: 46px;
  border: 0;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

button[type="submit"]:hover { background: var(--accent-ink); }
button[type="submit"]:disabled { opacity: 0.65; cursor: wait; }

.hint {
  margin: 12px 2px 4px;
  color: var(--muted);
  font-size: 13px;
}

.result-panel { padding: 18px 20px 8px; }

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  margin-bottom: 8px;
}

.result-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-family: var(--font-display);
}

.produto-box {
  margin: 4px 0 14px;
  padding: 12px 12px 10px;
  border: 1px solid #e4dccf;
  border-radius: 12px;
  background: #faf7f0;
}

.produto-box label {
  display: block;
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.produto-box input {
  width: 100%;
  height: 44px;
  border: 1px solid #cfc6b6;
  border-radius: 10px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
}

.matches-box {
  margin: 0 0 14px;
  border: 1px solid #e4dccf;
  border-radius: 12px;
  background: #faf7f0;
  overflow: hidden;
}

.matches-head {
  padding: 12px 14px 8px;
  border-bottom: 1px solid #e4dccf;
}

.matches-title {
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.matches-hint {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink);
}

.matches-list {
  max-height: min(42vh, 360px);
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.match-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 16px;
  align-items: start;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid #ece5d8;
  background: transparent;
  padding: 12px 14px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

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

.match-item:hover,
.match-item:focus-visible {
  background: rgba(15, 107, 92, 0.08);
  outline: none;
}

.match-item.is-loading {
  opacity: 0.6;
  pointer-events: none;
}

.match-desc {
  font-weight: 600;
  line-height: 1.35;
}

.match-meta {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  font-size: 12px;
  color: var(--muted);
}

.match-meta span {
  font-variant-numeric: tabular-nums;
}

.match-pick {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  align-self: center;
}

.status {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  min-height: 1.2em;
}

.status.is-loading { color: var(--accent); }
.status.is-error { color: var(--danger); }
.status.is-ok { color: var(--accent-ink); }

.table-wrap {
  overflow: auto;
  max-height: min(58vh, 560px);
  border-top: 1px solid var(--line);
}

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

th, td {
  text-align: left;
  padding: 12px 8px;
  border-bottom: 1px solid #ece6da;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: #faf7f0;
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

td:first-child {
  width: 38%;
  font-weight: 600;
  color: #314049;
}

td:last-child {
  font-variant-numeric: tabular-nums;
  word-break: break-word;
}

tr.empty td {
  text-align: center;
  color: var(--muted);
  font-weight: 500;
  padding: 28px 8px;
}

tbody tr:nth-child(even) td { background: rgba(243, 239, 230, 0.45); }

@media (max-width: 820px) {
  body { grid-template-columns: 1fr; }
  .rail {
    flex-direction: row;
    justify-content: space-between;
    padding: 10px 14px;
  }
  .rail-nav { flex-direction: row; }
  .stage { padding: 18px 16px 28px; }
  .top { flex-direction: column; }
  .top-actions { align-items: stretch; max-width: none; }
  .company-card { width: 100%; }
  .context { justify-content: flex-start; }
  .search-row { grid-template-columns: 1fr; }
  .login-grid { grid-template-columns: 1fr; }
}
