/* styles.css — mobile-first, minimalista. */
:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #0f172a;
  --accent: #2563eb;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--brand); color: #fff;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.nav { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.nav a { color: #cbd5e1; font-size: .95rem; }
.nav a.active { color: #fff; font-weight: 600; }
.nav a.muted { color: #94a3b8; }

.container { max-width: 920px; margin: 0 auto; padding: 16px; }

.list-head, .pkg-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pkg-top { flex-wrap: wrap; }
.head-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.scrape-status { margin: -4px 0 12px; min-height: 1em; }
#scrapeBtn { min-width: 232px; text-align: center; white-space: nowrap; }
#scrapeBtn[disabled] { opacity: .65; cursor: default; }
#refreshAllBtn { min-width: 150px; text-align: center; white-space: nowrap; }
#refreshAllBtn[disabled] { opacity: .65; cursor: default; }
#refreshAllStatus.done { color: var(--ok); font-weight: 600; }
#refreshAllStatus.fail { color: var(--warn); font-weight: 600; }
h1 { font-size: 1.4rem; margin: .2em 0 .6em; }
h2 { font-size: 1.05rem; margin: .2em 0 .6em; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px;
}
.card.empty { text-align: center; color: var(--muted); }
.card.auth { max-width: 380px; margin: 8vh auto 0; }

.cards { display: flex; flex-direction: column; gap: 14px; }
.card.pkg { display: block; position: relative; margin: 0; transition: border-color .15s, transform .05s; }
.card.pkg:active { transform: scale(.997); }
.card.pkg:hover { border-color: #cbd5e1; }
/* link que cobre o card todo (clicar em qualquer lugar abre o pacote) */
.card.pkg .stretch { position: absolute; inset: 0; z-index: 1; border-radius: inherit; }
/* form de arquivar fica ACIMA do stretch p/ ser clicável */
.inline-archive { position: relative; z-index: 2; margin: 0; display: inline; }
.code-wrap { display: inline-flex; align-items: center; gap: 4px; }
.copy { position: relative; z-index: 2; background: none; border: 0; cursor: pointer; padding: 2px 4px; font-size: .9rem; line-height: 1; border-radius: 6px; }
.copy:hover { background: #e2e8f0; }
.copy.copied { color: var(--ok); }

.code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-weight: 600; letter-spacing: .3px; }
.code.big { font-size: 1.15rem; }

.pkg-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 0; }
.pkg-last { display: flex; gap: 10px; margin-top: 6px; }
.pkg-last .desc, .timeline .desc { font-weight: 500; }
.dot, .t-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex: none; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.xs { font-size: .72rem; }

.tag {
  font-size: .75rem; padding: 2px 8px; border-radius: 999px;
  background: #eef2ff; color: #3730a3; border: 1px solid #e0e7ff;
}
.tag.svc { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.tag.out { background: #fae8ff; color: #86198f; border-color: #f5d0fe; }
/* Boxes da linha de meta (modalidade Correios + sentido) — IDÊNTICOS ao box da
   transportadora ao lado (server/public/carriers/correios.svg, renderizado a 20px):
   rect rx=6 #FFE000, texto size 12 / weight 700 / #002F87. Mesmo formato p/ todos;
   o de Correios usa as MESMAS cores do box Correios. */
.tipo { display: inline-flex; align-items: center; height: 20px; box-sizing: border-box;
        padding: 0 7px; border-radius: 5px; font-size: 11px; font-weight: 700;
        line-height: 1; white-space: nowrap; }
.tipo.correios { background: #FFE000; color: #002F87; }
.tipo.dir { background: #eef2ff; color: #3730a3; }
.tipo.dir.out { background: #fae8ff; color: #86198f; }

.badge {
  font-size: .8rem; font-weight: 600; padding: 3px 10px; border-radius: 999px;
  background: #e2e8f0; color: #334155; white-space: nowrap;
}
/* DETALHE — o balão de status é filho DIRETO de .pkg-top; ali ele quebra linha
   pra mostrar o status inteiro. Na lista ele fica dentro de .badge-row (ver abaixo),
   então este seletor pega só o detalhe. */
.pkg-top > .badge.status { white-space: normal; overflow-wrap: anywhere; }
/* Lista: balão de status/retirada fica na MESMA linha do código e trunca com reticências */
.card.pkg .pkg-top { flex-wrap: nowrap; }
.card.pkg .code-wrap { flex: none; }
.card.pkg .badge-row { flex: 1 1 auto; min-width: 0; justify-content: flex-end; }
.card.pkg .badge-row .badge.status,
.card.pkg .badge-row .badge.pickup {
  min-width: 0; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.new { background: #dbeafe; color: #1d4ed8; }
.badge.tax { background: #fef3c7; color: #92400e; }        /* tributado, aguardando pagamento */
.badge.tax.paid { background: #dcfce7; color: #166534; }   /* tributo já pago */
.badge.pickup { background: #ede9fe; color: #6d28d9; }     /* disponível para retirada */

/* Barra de filtragem (busca client-side da lista) */
.filter-bar { margin: 0 0 14px; }
.filter-bar input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: .95rem; box-sizing: border-box; }
.card.pkg.hidden-filter { display: none; }

/* logo da transportadora (SVG em /public/carriers) */
.carrier { display: inline-flex; align-items: center; }
.carrier-logo { height: 20px; width: auto; display: block; }

/* itens do pacote na lista: ocultos; revelados quando o filtro casa por item */
.pkg-items { display: none; list-style: none; margin: 8px 0 0; padding: 8px 0 0; border-top: 1px dashed var(--line); }
.pkg-items.show { display: block; }
.pkg-items li { font-size: .85rem; color: var(--muted); padding: 1px 0; overflow-wrap: anywhere; word-break: break-word; }
.pkg-items li.item-match { color: var(--ink); font-weight: 600; background: #fef9c3; border-radius: 6px; padding: 1px 6px; }

.facts { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 4px; }
.items { margin: 0; padding-left: 18px; }

/* timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; }
.timeline li::before {
  content: ""; position: absolute; left: 4px; top: 14px; bottom: -2px; width: 2px; background: var(--line);
}
.timeline li:last-child::before { display: none; }
.timeline .t-dot { position: absolute; left: 0; top: 5px; background: #cbd5e1; }
.timeline li.now .t-dot { background: var(--accent); box-shadow: 0 0 0 3px #dbeafe; }

/* forms */
form { display: flex; flex-direction: column; gap: 12px; }
label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
input[type=text], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: 11px 12px; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
button, .btn {
  display: inline-block; text-align: center; cursor: pointer;
  padding: 11px 16px; font-size: 1rem; font-weight: 600;
  border: 0; border-radius: 10px; background: var(--accent); color: #fff;
}
.btn.secondary { background: #e2e8f0; color: var(--ink); }
button:active, .btn:active { filter: brightness(.95); }

.alert { padding: 10px 12px; border-radius: 10px; margin: 0 0 12px; font-size: .92rem; background: #e2e8f0; color: #334155; }
.alert.error { background: #fee2e2; color: #b91c1c; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }

/* tabs / filtros */
.tabs { display: flex; gap: 6px; margin: 0 0 14px; flex-wrap: wrap; }
.tabs a { padding: 7px 12px; border-radius: 999px; background: #fff; border: 1px solid var(--line); color: var(--muted); font-size: .9rem; }
.tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.tabs .count { font-weight: 700; margin-left: 4px; }
.bulk { margin: 0 0 14px; }
.card.pkg.archived { opacity: .7; }

/* arquivado por TROCA de rastreio (superseded): caixa amarelo-claro, sem esmaecer */
.card.pkg.superseded { background: #fefce8; border-color: #fde68a; opacity: 1; }
.card.pkg.superseded:hover { border-color: #fcd34d; }
.badge.superseded { background: #fef3c7; color: #92400e; }

/* "Não lido": movimentação notificada via Telegram e ainda não aberta. */
.card.pkg.unread { border-color: #fca5a5; box-shadow: 0 0 0 1px #fca5a5 inset; background: #fffafa; }
.card.pkg.unread:hover { border-color: #f87171; }
.unread-dot { position: absolute; top: 10px; right: 10px; z-index: 2; width: 10px; height: 10px;
  border-radius: 50%; background: #ef4444; box-shadow: 0 0 0 2px #fff; pointer-events: none; }
/* botão "marcar tudo como lido" empurrado p/ a direita na linha das abas */
.tabs .mark-read { margin: 0 0 0 auto; display: inline-flex; align-items: center; }

/* versão do app (SemVer) no rodapé da lista, alinhada à direita */
.list-version { display: block; text-align: right; margin-top: 16px; font-variant-numeric: tabular-nums; }
.superseded-note { margin-top: 6px; font-size: .85rem; color: #92400e; }
.superseded-note .code { color: #92400e; font-weight: 600; }

.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }

/* tela de status (T-003): saldo do CapSolver + janelas de consumo */
.status-balance { text-align: center; }
.balance-figure { font-size: 2.2rem; font-weight: 700; font-variant-numeric: tabular-nums; margin: 4px 0; }
.stat-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
.stat-grid .card { margin-bottom: 0; }
.back { color: var(--accent); }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.badge-row { display: flex; gap: 8px; align-items: center; }
.btn.sm { padding: 4px 10px; font-size: .78rem; }
.btn.danger { background: #fee2e2; color: #b91c1c; }
.token { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; overflow-x: auto; word-break: break-all; white-space: pre-wrap; }

/* input de código (recuperação de senha) — estilo dígito-a-dígito */
.code-input { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 2px 0 4px; }
.code-input .code-box {
  width: 44px; height: 52px; padding: 0; text-align: center;
  font-size: 1.4rem; font-weight: 600; font-family: ui-monospace, Menlo, Consolas, monospace;
}
.code-input .code-sep { color: var(--muted); font-size: 1.4rem; font-weight: 600; }

/* reset de senha pelo admin — form compacto na linha da tabela */
.inline-reset { display: flex; gap: 6px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.inline-reset input { width: auto; flex: 1; min-width: 140px; padding: 7px 10px; font-size: .85rem; }
.inline-reset .btn { padding: 7px 10px; font-size: .8rem; }

