:root {
  --bg: #f3f3f0;
  --surface: #ffffff;
  --sunken: #ecebe7;
  --line: #e1e0db;
  --line-strong: #cfcdc6;
  --text: #15171a;
  --muted: #5d6168;
  --dim: #8b8f96;
  --accent: #1e3fae;
  --accent-ink: #ffffff;
  --accent-soft: #e9edfa;
  --ok: #0f7a4f;
  --warn: #9a5b00;
  --warn-bg: #fdf3e1;
  --err: #b42318;
  --font: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "Cascadia Mono", Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- comuns ---------- */
.input {
  width: 100%; height: 46px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
  outline: none; font-size: 16px;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 44px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-weight: 600; font-size: 14px; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--sunken); }
.btn-primary { background: var(--text); border-color: var(--text); color: #fff; }
.btn-primary:hover { background: #2b2f35; }
.btn-sm { height: 38px; padding: 0 12px; }
.btn[disabled] { opacity: .55; cursor: default; }
.msg { min-height: 20px; margin: 10px 0 0; font-size: 13px; color: var(--err); }
.msg.ok { color: var(--ok); }
.code {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  background: var(--sunken); padding: 1px 6px; border-radius: 4px; white-space: nowrap;
}
.badge {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .2px;
  padding: 2px 7px; border-radius: 4px; white-space: nowrap;
}
.b-mega { color: #5b2d91; background: #efe8f8; }
.b-master1 { color: #0b55a3; background: #e5effa; }
.b-master2 { color: #0b6b60; background: #e2f3f0; }
.logo { display: block; height: auto; }
.top .logo { width: 96px; }
.login-card .logo { width: 190px; margin: 0 auto; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--line); border-radius: 12px; padding: 32px 24px 24px;
}
.login-card .sub { margin: 18px 0 26px; color: var(--muted); font-size: 14px; text-align: center; }
.btn-block { width: 100%; height: 48px; margin-top: 4px; }
.login-foot { text-align: center; margin: 18px 0 0; color: var(--dim); font-size: 12px; }

/* ---------- topo ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.top-in { max-width: 1080px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 12px; }
.brand { flex: 1; min-width: 0; }
.brand { display: flex; align-items: center; gap: 14px; }
.tabela-info { font-size: 12px; color: var(--muted); padding-left: 14px; border-left: 1px solid var(--line); line-height: 1.35; white-space: pre-line; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { width: 38px; padding: 0; }
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: 46px; min-width: 240px; z-index: 30;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 10px; padding: 4px;
  box-shadow: 0 12px 32px rgba(20, 20, 20, .12);
}
.menu-pop button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 11px 12px; border-radius: 6px; font-size: 14px; }
.menu-pop button:hover { background: var(--sunken); }
.menu-pop .who { padding: 9px 12px; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }

/* ---------- busca e filtros ---------- */
main { max-width: 1080px; margin: 0 auto; padding: 16px 16px 64px; }
.search { position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--dim); pointer-events: none; }
.search .input { height: 52px; padding-left: 42px; border-radius: 10px; }
.search .input::-webkit-search-cancel-button { cursor: pointer; }
.seg {
  display: flex; margin: 12px 0 0; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none; gap: 2px;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  border: 0; background: none; padding: 12px 12px 10px; color: var(--muted);
  font-weight: 600; font-size: 14px; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.seg button.on { color: var(--text); border-bottom-color: var(--text); }
.seg button small { font-weight: 500; color: var(--dim); margin-left: 6px; font-size: 12px; }
.filters { display: flex; gap: 10px; margin: 12px 0 0; align-items: center; justify-content: space-between; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; min-width: 0; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--muted);
  height: 34px; padding: 0 12px; border-radius: 17px; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.chip.on { background: var(--text); border-color: var(--text); color: #fff; }
.sort {
  flex: none; height: 34px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--surface); padding: 0 8px; font-size: 13px; color: var(--text);
}
.count { color: var(--dim); font-size: 12px; margin: 14px 2px 8px; text-transform: uppercase; letter-spacing: .6px; font-weight: 600; }

/* ---------- lista ---------- */
.list { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.row {
  display: grid; grid-template-columns: 1fr auto 16px; gap: 14px; align-items: center;
  width: 100%; text-align: left; background: none; border: 0; border-bottom: 1px solid var(--line);
  padding: 14px 14px 14px 16px; min-height: 68px;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: #fafaf8; }
.row:active { background: var(--sunken); }
.row-main { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.row-title { font-weight: 600; font-size: 15px; line-height: 1.25; }
.row-sub { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row-nums { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.credit { font-weight: 700; font-size: 16px; letter-spacing: -.2px; }
.from { font-size: 12px; color: var(--muted); white-space: nowrap; }
.from b { color: var(--text); font-weight: 600; }
.chev { color: var(--dim); }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); line-height: 1.8; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; }

/* ---------- detalhe ---------- */
.sheet-bg { position: fixed; inset: 0; background: rgba(15, 17, 20, .38); z-index: 40; }
.sheet {
  position: fixed; z-index: 41; right: 0; top: 0; bottom: 0; width: min(520px, 100%);
  background: var(--bg); overflow-y: auto; overscroll-behavior: contain;
  box-shadow: -8px 0 32px rgba(0, 0, 0, .12);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(24px); opacity: .4; } }
.sheet-bar {
  position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px 8px 6px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.x { display: inline-flex; align-items: center; gap: 4px; height: 40px; padding: 0 10px; background: none; border: 0; font-weight: 600; font-size: 14px; border-radius: 8px; }
.x:hover { background: var(--sunken); }
.sheet-in { padding: 20px 20px 48px; }
.sheet h2 { margin: 10px 0 0; font-size: 22px; line-height: 1.2; letter-spacing: -.4px; }
.hero-credit { margin: 18px 0 12px; }
.lbl { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.hero-credit .credit { font-size: 34px; font-weight: 800; letter-spacing: -1px; line-height: 1.1; }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
.facts div { padding: 10px 12px; border-left: 1px solid var(--line); min-width: 0; }
.facts div:first-child { border-left: 0; }
.facts dt { font-size: 11px; color: var(--muted); font-weight: 600; }
.facts dd { margin: 2px 0 0; font-weight: 700; font-size: 14px; }
h4 { margin: 24px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted); }
.plans { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.plans th { text-align: left; font-size: 11px; font-weight: 600; color: var(--muted); padding: 9px 10px; border-bottom: 1px solid var(--line); background: #fafaf8; }
.plans td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; font-size: 13px; white-space: nowrap; }
.plans tr:last-child td { border-bottom: 0; }
.plans th:first-child, .plans td:first-child { padding-left: 14px; }
.plans .pz { font-weight: 800; font-size: 17px; letter-spacing: -.3px; }
.plans .val { display: block; font-size: 17px; font-weight: 700; letter-spacing: -.3px; }
.plans .meta { display: block; font-size: 11px; color: var(--muted); margin-top: 1px; }
.plans tr.best td { background: #f1f8f4; }
.tag-low { color: var(--ok); font-weight: 700; margin-left: 8px; }
.past { color: var(--warn) !important; }
.notice { font-size: 13px; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 10px 12px; margin: 10px 0 0; }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 16px; }
.alt { display: grid; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.alt button {
  display: flex; justify-content: space-between; gap: 12px; align-items: center; text-align: left;
  background: none; border: 0; border-bottom: 1px solid var(--line); padding: 11px 14px;
}
.alt button:last-child { border-bottom: 0; }
.alt button:hover { background: #fafaf8; }
.alt button > span:first-child { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; min-width: 0; }
.alt-t { font-size: 14px; font-weight: 600; }
.alt-n { display: flex; flex-direction: column; align-items: flex-end; font-size: 12px; color: var(--muted); white-space: nowrap; }
.alt-n b { font-size: 14px; color: var(--text); }
.rules { margin: 0; padding: 0 0 0 18px; display: grid; gap: 4px; color: var(--muted); font-size: 13px; }

/* ---------- modal ---------- */
.modal {
  position: fixed; z-index: 41; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(520px, calc(100% - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto;
  background: var(--surface); border-radius: 12px; padding: 22px 20px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .2);
}
.modal h3 { margin: 0 0 4px; font-size: 18px; }
.modal h3.mt { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--line); }
.modal .sub { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.drop { display: flex; flex-direction: column; gap: 2px; align-items: center; border: 1.5px dashed var(--line-strong); border-radius: 10px; padding: 20px; color: var(--muted); font-size: 13px; cursor: pointer; }
.drop b { color: var(--text); font-size: 14px; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.hist { font-size: 12px; color: var(--muted); margin-top: 6px; display: grid; gap: 3px; }
.hist span { color: var(--dim); }
.users { display: grid; margin: 10px 0 16px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.user-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--line); font-size: 14px; min-height: 52px; }
.user-row:last-child { border-bottom: 0; }
.tag-admin { font-size: 11px; font-weight: 700; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 4px; margin-left: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 0 0 14px; }
.check input { width: 18px; height: 18px; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; white-space: nowrap;
}

@media (max-width: 640px) {
  .btn-label { display: none; }
  .top-actions .btn-sm { width: 40px; padding: 0; }
  .row { grid-template-columns: 1fr auto; padding: 12px 14px; gap: 10px; }
  .chev { display: none; }
  .credit { font-size: 15px; }
  .sheet-in { padding: 18px 16px 40px; }
  .plans th, .plans td { padding-left: 7px; padding-right: 7px; }
  .plans td { font-size: 12px; }
  .plans .val { font-size: 15px; }
  .plans .pz { font-size: 15px; }
  .row2 { grid-template-columns: 1fr; }
  .facts dd { font-size: 13px; }
}

/* filtros de prazo e parcela */
.filters-2 { justify-content: flex-start; flex-wrap: wrap; }
.filters-2 .sort { height: 38px; }
.max {
  display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 0 0 10px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px; font-size: 13px; color: var(--muted);
}
.max:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.max input { border: 0; outline: 0; background: none; width: 110px; height: 100%; font-size: 14px; color: var(--text); font-weight: 600; }
.count .link { text-transform: none; letter-spacing: 0; margin-left: 8px; font-size: 12px; }
@media (max-width: 640px) {
  .filters-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .max { min-width: 0; }
  .max span { white-space: nowrap; }
  .max input { flex: 1; width: 100%; min-width: 0; font-size: 16px; }
  .filters-2 .sort { width: 100%; min-width: 0; }
  .filters-2 .max { grid-column: auto; order: 0; }
}

.count-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin: 14px 2px 8px; }
.count-row .count { margin: 0; }
.sort-inline { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); font-weight: 600; }
.sort-inline select { border: 0; background: none; font-size: 13px; font-weight: 600; color: var(--text); padding: 4px 0; cursor: pointer; }
