:root {
  color-scheme: light;
  --bg: #f2f5f7;
  --surface: #ffffff;
  --surface-strong: #f8fafb;
  --text: #151719;
  --muted: #64727d;
  --border: #dce3e8;
  --accent: #087f6f;
  --accent-strong: #056458;
  --accent-soft: #e3f4f1;
  --brand: #102a2a;
  --header-accent: #0ca678;
  --legal: #1d8910;
  --value: #b5151f;
  --warn-soft: #fff4d6;
  --warn: #8a5a00;
  --danger-soft: #ffe6e0;
  --danger: #9a3412;
  --shadow: 0 10px 28px rgba(18, 32, 43, 0.08);
  --shadow-soft: 0 2px 10px rgba(18, 32, 43, 0.07);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, #ffffff 0, var(--bg) 190px),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease, box-shadow 140ms ease;
}

button:hover {
  background: var(--accent-strong);
  box-shadow: 0 8px 18px rgba(15, 118, 110, 0.18);
}

button:active {
  transform: translateY(1px);
}

button:disabled,
select:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

.secondary-button {
  background: #4a5561;
}

.secondary-button:hover {
  background: #343c44;
}

.ghost-button {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.82rem;
  box-shadow: none;
}

.ghost-button:hover {
  background: #ffffff;
  color: var(--accent-strong);
  box-shadow: none;
}

.shell {
  width: min(1120px, calc(100% - 32px));
  margin: 0 auto;
  padding: 14px 0 36px;
}

.app-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  min-height: 82px;
  padding: 18px 24px 18px 28px;
  border: 1px solid var(--border);
  border-left: 5px solid var(--header-accent);
  border-radius: 8px;
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.app-header::after {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 3px;
  background: linear-gradient(90deg, var(--header-accent), rgba(8, 127, 111, 0));
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 3vw, 2.15rem);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1rem;
  line-height: 1.25;
  letter-spacing: 0;
}

.tabs {
  display: flex;
  gap: 8px;
  min-height: 50px;
  margin: 14px auto 0;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: var(--shadow-soft);
  width: 100%;
}

.tab {
  flex: 1;
  min-width: 0;
  background: transparent;
  color: var(--muted);
  box-shadow: none;
}

.tab:hover {
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: none;
}

.tab.is-active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 8px 18px rgba(8, 127, 111, 0.18);
}

.tab-panel {
  display: none;
  padding: 14px 0 0;
}

.tab-panel.is-active {
  display: block;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  width: 100%;
  margin: 0 auto;
}

.side-stack {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.tool-panel,
.result-panel,
.history-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.tool-panel {
  padding: 18px;
}

.result-panel {
  min-height: 360px;
  overflow: hidden;
  background: #eef2f4;
}

.history-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: clamp(280px, calc(100vh - 330px), 720px);
  min-height: 0;
  padding: 14px;
}

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

.history-heading {
  align-items: flex-start;
  margin-bottom: 12px;
}

.route-label,
.muted {
  color: var(--muted);
  font-size: 0.84rem;
}

.route-label {
  max-width: 48%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

label {
  display: grid;
  gap: 7px;
  color: #394046;
  font-size: 0.9rem;
  font-weight: 700;
}

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

input,
select {
  padding: 0 12px;
}

textarea {
  min-height: 138px;
  margin-top: 7px;
  padding: 12px;
  resize: vertical;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.45;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

.inline-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 8px;
}

.inline-form.wide {
  grid-template-columns: minmax(0, 1fr) 110px;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.actions button:first-child {
  background: #4a5561;
}

.actions button:first-child:hover {
  background: #343c44;
}

.stack {
  display: grid;
  gap: 22px;
}

.result-panel > .panel-heading {
  display: none;
}

.result-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: #ffffff;
}

.result-toolbar h2 {
  margin-bottom: 2px;
}

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

.toolbar-actions button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 0.84rem;
}

.history-list {
  display: grid;
  align-content: start;
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

.history-empty {
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.35;
}

.history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  gap: 8px;
  align-items: stretch;
}

.history-open {
  display: grid;
  gap: 4px;
  min-height: 74px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  text-align: left;
  box-shadow: none;
}

.history-open:hover {
  border-color: rgba(0, 121, 107, 0.38);
  background: #f5fbfa;
  box-shadow: none;
}

.history-open.is-active {
  border-color: var(--accent);
  background: #f2fffc;
  box-shadow: inset 4px 0 0 var(--accent);
}

.history-top,
.history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.history-plate {
  color: var(--text);
  font-weight: 900;
}

.history-badge {
  flex: 0 0 auto;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 0.72rem;
  font-weight: 800;
}

.history-model,
.history-place,
.history-time {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-model {
  color: #1f2428;
  font-size: 0.88rem;
  font-weight: 800;
}

.history-place,
.history-time {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.history-delete {
  width: 34px;
  min-height: 34px;
  padding: 0;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--muted);
  font-size: 1.18rem;
  line-height: 1;
  box-shadow: none;
}

.history-delete:hover {
  border-color: rgba(154, 52, 18, 0.28);
  background: var(--danger-soft);
  color: var(--danger);
  box-shadow: none;
}

.empty-state {
  margin: 18px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: #ffffff;
  color: var(--muted);
}

.notice {
  margin: 18px;
  padding: 14px 16px;
  border-radius: 8px;
  line-height: 1.45;
}

.notice.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.notice.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 0 18px 18px;
}

.official-result {
  display: grid;
  gap: 8px;
  padding: 0;
}

.legal-banner {
  min-height: 88px;
  display: grid;
  place-items: center;
  margin: 0;
  background: var(--legal);
  color: #ffffff;
  font-size: clamp(2rem, 4.3vw, 3.15rem);
  font-weight: 900;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
}

.vehicle-card,
.fipe-card {
  margin: 0;
  border: 1px solid var(--border);
  background: #ffffff;
  box-shadow: 0 2px 10px rgba(18, 32, 43, 0.08);
}

.vehicle-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 22px 26px;
}

.vehicle-main {
  min-width: 0;
  font-size: clamp(1.05rem, 2.2vw, 1.42rem);
  line-height: 1.34;
}

.vehicle-main p,
.vehicle-place p {
  margin: 0;
}

.vehicle-main strong,
.vehicle-place strong {
  font-weight: 900;
}

.vehicle-place {
  display: grid;
  align-content: start;
  justify-items: end;
  gap: 6px;
  min-width: 132px;
  font-size: clamp(1.05rem, 2.2vw, 1.4rem);
  line-height: 1.18;
  text-align: right;
}

.fipe-card-list {
  display: grid;
  gap: 8px;
}

.fipe-card {
  display: grid;
  gap: 6px;
  padding: 18px 26px 16px;
  font-size: clamp(1.03rem, 2.1vw, 1.32rem);
  line-height: 1.18;
}

.fipe-card-top,
.fipe-card-bottom {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.fipe-value {
  color: var(--value);
  font-weight: 900;
  white-space: nowrap;
}

.fipe-model {
  font-weight: 900;
}

.fipe-card-bottom {
  color: #101316;
}

.official-empty {
  display: grid;
  gap: 8px;
  margin: 18px;
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #ffffff;
}

.official-empty strong {
  color: var(--danger);
  font-size: 1.1rem;
}

.summary-item {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-strong);
}

.summary-item span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.summary-item strong {
  display: block;
  min-height: 24px;
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 1rem;
}

.json-block {
  margin: 0;
  padding: 16px 18px 18px;
  border-top: 1px solid var(--border);
  background: #202326;
  color: #e8f0ea;
  overflow: auto;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.86rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.json-details {
  margin: 10px 0 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}

.json-details summary {
  cursor: pointer;
  padding: 12px 14px;
  color: var(--muted);
  font-weight: 800;
}

.json-details .json-block {
  border-top: 1px solid var(--border);
}

.table-wrap {
  padding: 0 18px 18px;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 0.88rem;
}

th,
td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.loading {
  opacity: 0.7;
  pointer-events: none;
}

.is-hidden {
  display: none !important;
}

@media (max-width: 900px) {
  .tool-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .side-stack {
    order: 1;
  }

  .tool-panel {
    order: initial;
  }

  .result-panel {
    order: 2;
  }

  .result-panel {
    min-height: 300px;
  }

  .history-panel {
    height: auto;
    max-height: none;
  }

  .history-list {
    max-height: 300px;
  }
}

@media (max-width: 640px) {
  .shell {
    width: calc(100% - 18px);
    padding-top: 9px;
    padding-bottom: 24px;
  }

  .app-header {
    min-height: 66px;
    padding: 13px 16px 14px 18px;
    border-left-width: 4px;
  }

  .eyebrow {
    font-size: 0.64rem;
  }

  h1 {
    max-width: 260px;
    font-size: 1.45rem;
    line-height: 1.05;
  }

  .tabs {
    width: 100%;
    margin-top: 9px;
    min-height: 44px;
    gap: 4px;
    padding: 4px;
  }

  .tab {
    min-height: 36px;
    font-size: 0.84rem;
  }

  .tool-grid {
    gap: 10px;
  }

  .inline-form,
  .inline-form.wide {
    grid-template-columns: 1fr;
  }

  .actions {
    display: grid;
  }

  .result-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

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

  .route-label {
    max-width: 42%;
    font-size: 0.74rem;
  }

  .tab-panel {
    padding-top: 10px;
    padding-inline: 0;
  }

  .tool-panel,
  .history-panel {
    padding: 14px;
  }

  .history-list {
    max-height: 250px;
  }

  .history-row {
    grid-template-columns: minmax(0, 1fr) 36px;
  }

  .history-open {
    min-height: 70px;
  }

  .history-model {
    font-size: 0.84rem;
  }

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

  .legal-banner {
    min-height: 86px;
    font-size: 1.95rem;
    line-height: 1.05;
  }

  .vehicle-card {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px 18px;
  }

  .vehicle-main {
    font-size: 1rem;
  }

  .vehicle-place {
    grid-row: 1;
    display: flex;
    justify-content: space-between;
    justify-items: stretch;
    min-width: 0;
    font-size: 1.04rem;
    text-align: left;
  }

  .fipe-card {
    padding: 16px 18px 14px;
    font-size: 1rem;
  }

  .fipe-card-top,
  .fipe-card-bottom {
    gap: 10px;
  }

  .fipe-value {
    font-size: 1.04rem;
  }

  .json-details {
    margin-top: 10px;
  }
}
