:root {
  --navy: #16324f;
  --navy-2: #1d4568;
  --navy-deep: #0e2238;
  --gold: #b98a2f;
  --gold-2: #d9ab52;
  --gold-soft: #f7edd4;
  --bg: #eef1f5;
  --panel: #ffffff;
  --line: #dfe5ec;
  --text: #1c2b38;
  --muted: #64748b;
  --danger: #a94436;
  --ok: #1e7a4f;
  font-family: 'Segoe UI', 'Aptos', system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100vh; }
body {
  background:
    radial-gradient(1100px 500px at 85% -10%, #dde7f0 0, transparent 60%),
    radial-gradient(900px 420px at -10% 108%, #f1e9d6 0, transparent 55%),
    var(--bg);
  display: flex; flex-direction: column; min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--navy); }
::selection { background: rgba(185, 138, 47, .25); }

svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Cabeçalho ---------- */
.topbar {
  display: flex; align-items: center; gap: 22px; flex-wrap: wrap;
  padding: 12px clamp(16px, 3.5vw, 44px);
  background: rgba(255,255,255,.94); backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
  box-shadow: 0 8px 30px rgba(22,50,79,.06);
}
.topbar::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--navy) 0 30%, var(--gold) 55%, var(--gold-2) 75%, var(--navy-2));
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand img { border-radius: 12px; box-shadow: 0 10px 26px rgba(14,34,56,.3); }
.brand strong { display: block; font-size: 17.5px; letter-spacing: -.02em; color: var(--navy-deep); line-height: 1.15; }
.brand span { font-size: 9.5px; font-weight: 800; letter-spacing: .17em; text-transform: uppercase; color: var(--gold); }

.tabs {
  display: flex; gap: 3px; flex-wrap: wrap; margin: 0 auto;
  background: #eaeef3; border: 1px solid var(--line); border-radius: 14px; padding: 4px;
}
.tab {
  display: inline-flex; align-items: center; gap: 8px;
  border: 0; background: transparent; cursor: pointer;
  padding: 9px 15px; border-radius: 10px;
  font-size: 13px; font-weight: 650; color: var(--muted);
  transition: .16s ease;
}
.tab svg { width: 16px; height: 16px; stroke-width: 2.1; }
.tab:hover { color: var(--navy-deep); background: #fff; }
.tab.active {
  color: #fff; background: linear-gradient(140deg, var(--navy-2), var(--navy-deep));
  box-shadow: 0 8px 20px rgba(22,50,79,.32);
}
.tab.active svg { color: var(--gold-2); }

.live-pill {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 11px; font-weight: 700; color: var(--ok);
  border: 1px solid #cde5d7; background: #eefaf3; border-radius: 30px; padding: 7px 14px;
}
.live-pill span { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); animation: pulse 1.8s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(30,122,79,.35); } 55% { box-shadow: 0 0 0 6px rgba(30,122,79,0); } }

/* ---------- Layout ---------- */
.layout { flex: 1; width: min(1280px, 100%); margin: 0 auto; padding: clamp(18px, 3vw, 34px); }
.panel { display: none; }
.panel.active { display: block; animation: rise .22s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
  padding: clamp(18px, 2.6vw, 28px);
  box-shadow: 0 24px 60px rgba(20,42,66,.07);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 8px; }
.card-head h2 { margin: 0; font: 700 18px/1.3 Georgia, 'Times New Roman', serif; color: var(--navy-deep); }
.card-note { color: var(--muted); font-size: 12.5px; line-height: 1.55; margin: 6px 0 16px; }
.badge {
  font-size: 10px; font-weight: 800; letter-spacing: .05em; white-space: nowrap;
  color: #8a6413; background: var(--gold-soft); border: 1px solid #e8d5a5;
  padding: 5px 11px; border-radius: 20px;
}
.fine { color: var(--muted); font-size: 11px; line-height: 1.55; margin: 12px 0 0; }

/* ---------- Calculadora ---------- */
.calc-grid { display: grid; grid-template-columns: minmax(0, 1.02fr) minmax(0, .98fr); gap: 18px; align-items: start; }
.calc-display {
  background: linear-gradient(155deg, #123350 0%, var(--navy-deep) 70%);
  border-radius: 16px; padding: 22px 24px; min-height: 122px;
  display: flex; flex-direction: column; justify-content: center; gap: 7px;
  box-shadow: inset 0 2px 18px rgba(0,0,0,.35), 0 14px 34px rgba(14,34,56,.22);
  border: 1px solid #0b1c2e;
  position: relative; overflow: hidden;
}
.calc-display::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(120deg, rgba(255,255,255,.07), transparent 38%);
  pointer-events: none;
}
.calc-expression {
  color: #b7cbdd; font-size: 19px; font-variant-numeric: tabular-nums;
  word-break: break-all; line-height: 1.35; min-height: 26px;
}
.calc-result {
  color: #f2d492; font: 700 34px/1.1 'Segoe UI', sans-serif;
  font-variant-numeric: tabular-nums; text-align: right; min-height: 38px;
  text-shadow: 0 2px 14px rgba(242,212,146,.25);
}
.calc-hint { color: var(--muted); font-size: 11px; margin: 13px 2px 15px; }
.calc-hint code { background: #eef2f6; border: 1px solid var(--line); border-radius: 5px; padding: 1px 6px; font-size: 10.5px; }
.calc-keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; }
.key {
  border: 1px solid #dde4eb; border-radius: 13px;
  background: linear-gradient(180deg, #ffffff, #f4f7fa);
  min-height: 54px; font-size: 17px; font-weight: 650; cursor: pointer;
  transition: .12s ease; color: var(--text);
  box-shadow: 0 2px 0 #e2e8ef, 0 6px 14px rgba(22,50,79,.05);
}
.key:hover { background: #f2f6fa; }
.key:active { transform: translateY(1px); box-shadow: 0 1px 0 #e2e8ef; }
.key.op { color: var(--navy); background: linear-gradient(180deg, #f2f7fc, #e7eff6); border-color: #c9d8e5; font-size: 19px; }
.key.soft { color: var(--muted); font-size: 13px; }
.key.accent { color: #8a6413; border-color: #e8d5a5; background: linear-gradient(180deg, #fefaf0, #faf2dd); }
.key.danger { color: var(--danger); border-color: #e8c9c2; background: linear-gradient(180deg, #fef7f5, #fbeeea); }
.key.equals {
  color: #fff; background: linear-gradient(150deg, var(--gold-2), var(--gold) 55%, #96691c);
  border: 0; font-size: 21px; box-shadow: 0 12px 26px rgba(185,138,47,.38);
}
.memory-line { margin-top: 13px; color: var(--muted); font-size: 12px; }
.memory-line strong { color: var(--navy-deep); font-variant-numeric: tabular-nums; }

.tape-card { max-height: 660px; display: flex; flex-direction: column; }
.tape { list-style: none; margin: 6px 0 0; padding: 0; overflow-y: auto; flex: 1; }
.tape li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 8px; border-bottom: 1px dashed var(--line);
  font-variant-numeric: tabular-nums; border-radius: 9px;
}
.tape li:hover { background: #f4f7fa; }
.tape .tape-main { flex: 1; display: flex; justify-content: space-between; gap: 14px; align-items: baseline; cursor: pointer; min-width: 0; }
.tape .exp { color: var(--muted); font-size: 12px; word-break: break-all; }
.tape .val { color: var(--navy-deep); font-weight: 700; font-size: 13.5px; white-space: nowrap; }
.tape li.tape-tool .exp { color: #8a6413; }
.tape .tape-del {
  border: 0; background: transparent; cursor: pointer; color: #b3bfcb;
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  flex: 0 0 28px; transition: .14s ease;
}
.tape .tape-del svg { width: 14px; height: 14px; }
.tape .tape-del:hover { color: var(--danger); background: #fbeeea; }
.tape-empty { color: var(--muted); font-size: 12px; text-align: center; padding: 34px 10px; }

/* ---------- Ferramentas ---------- */
.tool-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 11.5px; font-weight: 700; color: #43535f; }
.field input, .field select, .field textarea {
  border: 1px solid #c9d4de; border-radius: 11px; padding: 12px 14px;
  background: #fff; font-size: 15px; font-variant-numeric: tabular-nums;
  transition: .15s ease;
}
.field textarea { resize: vertical; font-variant-numeric: normal; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--navy-2); box-shadow: 0 0 0 4px rgba(29,69,104,.1);
}
.field-row { display: flex; gap: 12px; }
.field-row .grow { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); margin-bottom: 14px; }

.segmented { display: flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 16px; background: #f6f8fa; }
.seg {
  flex: 1; border: 0; background: transparent; padding: 11px 8px; cursor: pointer;
  font-size: 12px; font-weight: 650; color: var(--muted); transition: .14s ease;
}
.seg + .seg { border-left: 1px solid var(--line); }
.seg.active { background: linear-gradient(140deg, var(--navy-2), var(--navy-deep)); color: #fff; }

.advanced { border: 1px dashed #ccd8e2; border-radius: 12px; padding: 11px 15px; margin-bottom: 16px; background: #fbfcfd; }
.advanced summary { cursor: pointer; font-size: 12px; font-weight: 700; color: var(--navy); }
.advanced[open] summary { margin-bottom: 12px; }

.primary-button {
  width: 100%; border: 0; cursor: pointer; border-radius: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  padding: 14px 18px; font-size: 14px; font-weight: 700; color: #fff;
  background: linear-gradient(140deg, var(--navy-2), var(--navy-deep));
  box-shadow: 0 14px 30px rgba(22,50,79,.3); transition: .15s ease;
}
.primary-button .btn-ico { width: 16px; height: 16px; color: var(--gold-2); }
.primary-button:hover { filter: brightness(1.12); }
.primary-button:disabled { opacity: .55; cursor: wait; }

.icon-button {
  border: 1px solid var(--line); background: #fff; cursor: pointer;
  width: 34px; height: 34px; border-radius: 10px; display: inline-grid; place-items: center;
  color: var(--muted); transition: .14s ease;
}
.icon-button svg { width: 15px; height: 15px; }
.icon-button:hover { color: var(--navy-deep); border-color: #b9c8d3; box-shadow: 0 4px 12px rgba(22,50,79,.1); }
.chip-button {
  border: 1px solid var(--line); background: #fff; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  border-radius: 10px; padding: 8px 12px; font-size: 11.5px; font-weight: 700; color: #44576a;
  transition: .14s ease;
}
.chip-button svg { width: 13px; height: 13px; }
.chip-button:hover { border-color: #b9c8d3; box-shadow: 0 4px 12px rgba(22,50,79,.1); color: var(--navy-deep); }
.chip-button.gold { color: #7c5a12; background: var(--gold-soft); border-color: #e8d5a5; }
.chip-button.gold:hover { background: #f3e3ba; color: #6a4c0d; }

/* ---------- Resultados ---------- */
.result-card {
  border-top: 3px solid var(--gold);
  position: sticky; top: 92px;
}
.result-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.result-head h2 { margin: 0; font: 700 18px/1.3 Georgia, 'Times New Roman', serif; color: var(--navy-deep); }
.result-actions { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; }

.result-body { margin-top: 6px; }
.result-empty {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  color: #93a3b3; font-size: 12.5px; text-align: center; padding: 44px 16px;
}
.result-empty svg { width: 38px; height: 38px; stroke-width: 1.4; color: #c3cfda; }

.result-list { margin: 4px 0 0; }
.result-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 10px; border-bottom: 1px dashed var(--line); border-radius: 8px; }
.result-list > div:nth-child(odd) { background: #fafbfc; }
.result-list dt { color: var(--muted); font-size: 12.5px; }
.result-list dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--navy-deep); white-space: nowrap; }
.result-list > div.total {
  background: linear-gradient(90deg, var(--gold-soft), #fdf9ef);
  border: 1px solid #ecdcb2; border-bottom: 1px solid #ecdcb2; margin: 6px 0;
}
.result-list > div.total dt { color: #6a4c0d; font-weight: 800; }
.result-list > div.total dd { color: #8a6413; font-size: 17px; }

.escalao-box {
  margin-top: 14px; padding: 13px 15px; border-radius: 11px;
  background: var(--gold-soft); border: 1px solid #e8d5a5;
  color: #6d5313; font-size: 12px; line-height: 1.55;
}

.assist-text {
  white-space: pre-wrap; background: #f8fafb; border: 1px solid var(--line);
  border-radius: 12px; padding: 16px; font: 13px/1.7 'Segoe UI', sans-serif; margin: 6px 0 0;
  max-height: 480px; overflow: auto;
}
.assistente-loading { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; padding: 14px 4px 0; }
.assistente-loading span { width: 7px; height: 7px; border-radius: 50%; background: var(--gold); animation: blink 1.1s infinite ease-in-out; }
.assistente-loading span:nth-child(2) { animation-delay: .18s; }
.assistente-loading span:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 100% { opacity: .25; } 45% { opacity: 1; } }

/* ---------- Rodapé / toast ---------- */
.foot {
  display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  padding: 16px clamp(16px, 3.5vw, 44px); border-top: 1px solid var(--line);
  color: var(--muted); font-size: 11.5px; background: rgba(255,255,255,.72);
}
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: var(--navy-deep); color: #fff; font-size: 13px; font-weight: 600;
  padding: 11px 20px; border-radius: 30px; opacity: 0; pointer-events: none;
  transition: .25s ease; box-shadow: 0 16px 40px rgba(0,0,0,.3); z-index: 60;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Responsivo ---------- */
@media (max-width: 1080px) {
  .tabs { order: 3; width: 100%; justify-content: center; }
  .live-pill { margin-left: auto; }
}
@media (max-width: 980px) {
  .calc-grid, .tool-grid { grid-template-columns: 1fr; }
  .tape-card { max-height: 430px; }
  .result-card { position: static; }
}
@media (max-width: 620px) {
  .tab span { display: none; }
  .tab { padding: 10px 13px; }
  .tab svg { width: 18px; height: 18px; }
  .field-row { flex-direction: column; gap: 0; }
  .calc-result { font-size: 27px; }
  .key { min-height: 48px; }
  .live-pill { display: none; }
}
