:root {
  --ink: #18212d;
  --muted: #637080;
  --line: #dce2e8;
  --surface: #ffffff;
  --canvas: #f3f5f7;
  --navy: #142b43;
  --navy-2: #1f405f;
  --red: #c5212e;
  --red-dark: #9e1923;
  --focus: #146da1;
  --shadow: 0 10px 35px rgb(26 45 65 / 9%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }

body { margin: 0; min-width: 320px; background: var(--canvas); }

button, input, select { font: inherit; }

button, a { -webkit-tap-highlight-color: transparent; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent); outline-offset: 2px; }

.topbar {
  min-height: 72px;
  padding: 10px clamp(18px, 4vw, 56px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: white;
  background: var(--navy);
  border-bottom: 4px solid var(--red);
}

.brand-lockup { display: flex; align-items: center; gap: 12px; }
.brand-lockup > div { display: grid; gap: 2px; }
.brand-lockup strong { font-size: .98rem; letter-spacing: .01em; }
.brand-lockup span { color: #b7c7d7; font-size: .76rem; }

.brand-mark {
  width: 58px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
  letter-spacing: -.06em;
  border-radius: 16px 16px 16px 4px;
  background: var(--red);
  box-shadow: 0 8px 22px rgb(197 33 46 / 24%);
}

.brand-mark.small { width: 43px; border-radius: 12px 12px 12px 3px; font-size: .85rem; }
.text-button { color: #fff; background: transparent; border: 0; padding: 10px; cursor: pointer; }

.page-container { width: min(100% - 32px, 1560px); margin: 0 auto; padding: 42px 0 64px; }

.hero-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.hero-row h1 { margin: 4px 0 8px; font-size: clamp(1.75rem, 4vw, 2.6rem); letter-spacing: -.04em; line-height: 1.05; }
.hero-row p:last-child { margin: 0; color: var(--muted); max-width: 740px; }
.eyebrow { margin: 0; color: var(--red); font-size: .72rem; font-weight: 800; letter-spacing: .14em; text-transform: uppercase; }
.hero-actions { flex: none; }

.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  color: var(--navy);
  background: #fff;
  border: 1px solid #bac5cf;
  border-radius: 9px;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.button:hover { border-color: #8795a3; background: #f8fafb; }
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .48; cursor: not-allowed; transform: none; }
.button-primary { color: #fff; background: var(--red); border-color: var(--red); }
.button-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.button-muted { background: #edf1f4; border-color: #d5dce3; }
.button-small { min-height: 32px; padding: 5px 9px; border-radius: 7px; font-size: .76rem; }
.button-icon { width: 34px; padding: 5px; color: var(--navy); background: #fff; }
.button-icon svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; }

.alert { margin: 18px 0; padding: 13px 16px; border-radius: 10px; border: 1px solid; }
.alert-success { color: #185c43; background: #e9f8f1; border-color: #b4e2ce; }
.alert-error { color: #7d2028; background: #fff0f1; border-color: #f0bec2; }
.alert-info { color: #194f70; background: #edf7fc; border-color: #b9dceb; }
.alert h1 { margin-top: 0; }
.import-issues { margin-top: 10px; }
.import-issues summary { cursor: pointer; font-weight: 800; }
.import-issues ul { margin: 8px 0 0; padding-left: 22px; }

.overview-strip {
  display: flex;
  width: fit-content;
  margin: 0 0 16px auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgb(26 45 65 / 5%);
}
.overview-strip div { min-width: 128px; padding: 12px 18px; display: flex; align-items: center; gap: 10px; border-right: 1px solid var(--line); }
.overview-strip div:last-child { border-right: 0; }
.overview-strip span { color: var(--muted); font-size: .75rem; }
.overview-strip strong { margin-left: auto; font-size: 1.15rem; }

.status-grid { display: grid; grid-template-columns: repeat(5, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.status-card-form { min-width: 0; }
.status-card { width: 100%; min-height: 132px; display: grid; align-content: center; gap: 2px; padding: 18px; color: var(--ink); text-align: left; font: inherit; cursor: pointer; background: #fff; border: 1px solid var(--line); border-top: 5px solid #7d8792; border-radius: 11px; box-shadow: 0 5px 20px rgb(26 45 65 / 5%); transition: transform .15s ease, box-shadow .15s ease, background-color .15s ease; }
.status-card span { font-size: .76rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.status-card strong { margin: 3px 0; font-size: 2rem; line-height: 1; }
.status-card small { color: var(--muted); }
.status-card:hover { transform: translateY(-2px); box-shadow: 0 9px 24px rgb(26 45 65 / 12%); }
.status-card:focus-visible { outline: 3px solid rgb(29 103 155 / 35%); outline-offset: 3px; }
.status-card.is-selected { background: #f2f7fb; border-color: var(--status, #2776a8); box-shadow: 0 0 0 3px rgb(39 118 168 / 18%), 0 8px 24px rgb(26 45 65 / 10%); }
.status-comunique-se { --status: #d68a16; }
.status-deferido { --status: #298457; }
.status-em-analise { --status: #2776a8; }
.status-indeferido { --status: #c13a42; }
.status-termo-encerramento { --status: #74589e; }
.status-aguardando-consulta { --status: #74808c; }
.status-desconhecido { --status: #74808c; }
.status-card[class*="status-"] { border-top-color: var(--status, #74808c); }

.control-panel { margin: 18px 0 30px; }
.filter-form { display: flex; align-items: end; gap: 10px; padding: 16px; background: #fff; border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 5px 20px rgb(26 45 65 / 4%); }
.filter-form label { display: grid; gap: 5px; min-width: 155px; color: #465361; font-size: .75rem; font-weight: 750; }
.filter-form .search-field { flex: 1; }

input, select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid #bfc9d3;
  border-radius: 8px;
}
input[type="file"] { padding: 7px; }
input[type="checkbox"] { width: 19px; min-height: 19px; accent-color: var(--red); }
input[readonly] { color: #52606d; background: #eef2f5; cursor: not-allowed; }

.results-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 0 2px 11px; }
.results-heading h2 { margin: 3px 0 0; font-size: 1.25rem; }
.results-heading > p { margin: 0; color: var(--muted); font-size: .8rem; }
.table-scroll { max-width: 100%; overflow: auto; isolation: isolate; scrollbar-gutter: stable; background: #fff; border: 1px solid #cad3dc; border-radius: 11px; box-shadow: var(--shadow); }
table { width: 100%; min-width: 2520px; border-collapse: separate; border-spacing: 0; font-size: .79rem; }
th { position: sticky; top: 0; z-index: 2; padding: 13px 12px; color: #fff; background: var(--navy); border-right: 1px solid #37516b; text-align: left; text-transform: uppercase; letter-spacing: .035em; font-size: .68rem; white-space: nowrap; }
td { max-width: 250px; padding: 12px; border-right: 1px solid #e4e8ec; border-bottom: 1px solid #e4e8ec; vertical-align: top; overflow-wrap: anywhere; }
tbody tr:nth-child(even) td { background: #f8fafb; }
tbody tr:hover td { background: #f1f6f9; }
.inactive-row td { box-shadow: inset 0 3px 0 #aeb9c3; }
.mono { font-family: "Cascadia Mono", Consolas, monospace; white-space: nowrap; }
.sticky-actions { position: sticky; right: 0; z-index: 1; width: 112px; min-width: 112px; max-width: 112px; padding-inline: 10px; background: #fff; border-right: 0; border-left: 1px solid #d5dde5; box-shadow: -10px 0 18px rgb(21 39 56 / 10%); }
th.sticky-actions { z-index: 4; background: var(--navy-2); text-align: center; }
tbody tr:nth-child(even) .sticky-actions { background: #f8fafb; }
tbody tr:hover .sticky-actions { background: #eaf2f7; }
.row-actions { display: flex; align-items: center; justify-content: center; gap: 8px; }
.action-button { width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border: 1px solid #cbd6df; border-radius: 10px; color: var(--navy); background: #fff; box-shadow: 0 2px 7px rgb(20 39 57 / 8%); cursor: pointer; transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .15s ease, box-shadow .15s ease; }
.action-button:hover { transform: translateY(-1px); border-color: #8da2b4; background: #f4f8fb; box-shadow: 0 5px 12px rgb(20 39 57 / 13%); }
.action-button:active { transform: translateY(0); }
.action-button:focus-visible { outline: 3px solid rgb(36 112 168 / 28%); outline-offset: 2px; }
.action-button svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.action-edit { color: #fff; border-color: var(--navy); background: var(--navy); }
.action-edit:hover { color: #fff; border-color: var(--navy-2); background: var(--navy-2); }
.action-label { display: none; }
.status-pill { display: inline-flex; padding: 5px 8px; color: color-mix(in srgb, var(--status, #64717e) 82%, #000); background: color-mix(in srgb, var(--status, #64717e) 12%, #fff); border: 1px solid color-mix(in srgb, var(--status, #64717e) 28%, #fff); border-radius: 999px; font-weight: 800; white-space: nowrap; }
.cell-meta { display: block; margin-top: 6px; color: var(--muted); font-size: .68rem; line-height: 1.35; }
.communication-message { min-width: 280px; max-width: 420px; line-height: 1.5; white-space: normal; }
.cedi-regular { color: #19734a; font-weight: 800; }
.cedi-irregular { color: #a72d36; font-weight: 800; }
.days-value.urgent { display: inline-grid; min-width: 28px; min-height: 28px; place-items: center; color: #a2222d; background: #ffeaec; border-radius: 50%; font-weight: 900; }
.empty-state { padding: 54px 24px; text-align: center; background: #fff; border: 1px dashed #bdc7d1; border-radius: 11px; }
.empty-state h2 { margin: 0 0 5px; }
.empty-state p { margin: 0; color: var(--muted); }

.process-dialog { width: min(980px, calc(100% - 28px)); max-height: calc(100vh - 36px); padding: 0; border: 0; border-radius: 14px; box-shadow: 0 26px 80px rgb(8 24 40 / 30%); }
.process-dialog::backdrop { background: rgb(12 30 48 / 62%); backdrop-filter: blur(3px); }
.process-dialog form { padding: 25px; }
.history-dialog { width: min(1200px, calc(100% - 28px)); }
.history-dialog-content { padding: 25px; }
.history-dialog .history-table { max-height: min(58vh, 620px); }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; margin-bottom: 20px; }
.dialog-heading h2 { margin: 4px 0 0; }
.icon-button { width: 38px; height: 38px; display: grid; place-items: center; border: 0; border-radius: 50%; background: #eef2f5; color: var(--ink); font-size: 1.45rem; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-grid label { display: grid; align-content: start; gap: 5px; color: #42505e; font-size: .77rem; font-weight: 750; }
.checkbox-field { display: flex !important; align-items: center; align-self: end; min-height: 42px; grid-template-columns: 20px 1fr; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 20% 15%, #294967 0, var(--navy) 32%, #0c1d2e 100%); }
.login-card { width: min(100%, 430px); padding: clamp(28px, 7vw, 45px); background: #fff; border-radius: 18px; box-shadow: 0 32px 100px rgb(0 0 0 / 32%); }
.login-card h1 { margin: 8px 0 10px; letter-spacing: -.035em; }
.login-intro { margin: 0 0 24px; color: var(--muted); line-height: 1.55; }
.stack-form { display: grid; gap: 15px; }
.stack-form label { display: grid; gap: 6px; font-size: .79rem; font-weight: 800; }
.stack-form .button { margin-top: 5px; }
.message-page { width: min(100% - 32px, 620px); margin: 12vh auto; display: grid; justify-items: start; gap: 18px; }
.history-page { max-width: 1280px; }
.history-back { display: inline-flex; margin-bottom: 22px; color: var(--navy); font-weight: 800; text-decoration: none; }
.history-back:hover { text-decoration: underline; }
.history-hero { margin-bottom: 18px; }
.history-hero .mono { color: var(--muted); }
.history-summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-bottom: 18px; }
.history-summary > div { min-height: 84px; display: grid; align-content: center; gap: 7px; padding: 15px 18px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 4px 16px rgb(26 45 65 / 5%); }
.history-summary span:first-child { color: var(--muted); font-size: .74rem; font-weight: 750; }
.history-summary strong { justify-self: start; }
.history-table table { min-width: 1400px; }
.history-outcome { font-weight: 800; }
.history-succeeded { color: #19734a; }
.history-failed, .history-circuit_open { color: #a72d36; }
.history-rate_limited, .history-retry_scheduled { color: #9a5d00; }
.history-empty { padding: 42px; color: var(--muted); text-align: center; }

@media (max-width: 1080px) {
  .status-grid { grid-template-columns: repeat(3, 1fr); }
  .control-panel { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 720px) {
  .page-container { width: min(100% - 22px, 1560px); padding-top: 28px; }
  .hero-row, .results-heading { align-items: stretch; flex-direction: column; }
  .hero-actions .button { width: 100%; }
  .overview-strip { width: 100%; margin-left: 0; }
  .overview-strip div { min-width: 0; flex: 1; padding: 11px; display: grid; gap: 1px; }
  .overview-strip strong { margin-left: 0; }
  .status-grid { grid-template-columns: repeat(2, 1fr); }
  .status-card { min-height: 116px; }
  .history-summary { grid-template-columns: 1fr; }
  .status-card-form:last-child { grid-column: 1 / -1; }
  .filter-form { align-items: stretch; flex-direction: column; }
  .filter-form label { min-width: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .process-dialog form { padding: 19px; }
  .dialog-actions { position: sticky; bottom: 0; margin-inline: -19px; padding: 14px 19px; background: #fff; }

  .table-scroll { overflow: visible; border: 0; box-shadow: none; background: transparent; }
  table { min-width: 0; display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody { display: grid; gap: 13px; }
  tr { display: block; overflow: hidden; background: #fff; border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 5px 18px rgb(26 45 65 / 6%); }
  td, .sticky-actions { position: static; max-width: none; min-width: 0; display: grid; grid-template-columns: minmax(115px, 39%) 1fr; gap: 10px; padding: 9px 12px; border: 0; border-bottom: 1px solid #e7ebef; box-shadow: none; background: #fff !important; }
  td::before { content: attr(data-label); color: var(--muted); font-size: .68rem; font-weight: 800; text-transform: uppercase; }
  td.sticky-actions { display: block; width: auto; max-width: none; padding: 12px; border-left: 0; }
  .row-actions { gap: 10px; }
  .action-button { width: auto; min-height: 42px; flex: 1; gap: 8px; padding: 0 14px; font-weight: 800; }
  .action-label { display: inline; }
}

@media (max-width: 430px) {
  .status-grid { grid-template-columns: 1fr; }
  .status-card-form:last-child { grid-column: auto; }
  .brand-lockup > div span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
