/* Painel administrativo — base: layout, navegação e componentes compartilhados.
   CSS específico de cada tela fica em css/painel-<tela>.css. */

body.painel { min-height: 100vh; font-size: 15px; }

/* ---------- Login ---------- */
.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-left, 0px)); background: radial-gradient(ellipse 60% 50% at 50% 0%, rgba(232, 169, 58, .14), transparent 70%), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 28px 24px; display: grid; gap: 16px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 34px; line-height: 1; text-transform: uppercase; }
.auth-card h1 span { color: var(--gold); }
.auth-card p { margin: 0; color: var(--muted); font-size: 14px; }
.auth-note { font-size: 12.5px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 18px 12px; gap: 18px; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; }
.brand-mark { width: 38px; height: 42px; flex: none; }
.brand b { display: block; font-family: var(--font-display); font-weight: 400; font-size: 22px; line-height: 1; letter-spacing: .01em; }
.brand small { display: block; color: var(--muted); font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; }
.nav { display: grid; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius); color: var(--muted); text-decoration: none; font-weight: 500; font-size: 14.5px; }
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: rgba(232, 169, 58, .12); color: var(--gold); }
.nav .nav-sep { height: 1px; background: var(--line); margin: 8px 4px; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; font-size: 12px; color: var(--muted); padding: 0 6px; }
.storage-pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; font-size: 11.5px; color: var(--bulb); width: fit-content; }
.storage-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--bulb); }
.storage-pill[data-estado="ok"] { color: var(--green); }
.storage-pill[data-estado="ok"]::before { background: var(--green); }
.storage-pill[data-estado="envio"] { color: var(--gold); }
.storage-pill[data-estado="envio"]::before { background: var(--gold); }
.storage-pill[data-estado="off"], .storage-pill[data-estado="erro"] { color: var(--red); border-color: rgba(255, 90, 90, .45); }
.storage-pill[data-estado="off"]::before, .storage-pill[data-estado="erro"]::before { background: var(--red); }
.sidebar-user { color: var(--muted); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px 20px; background: rgba(14, 13, 12, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-family: var(--font-cond); font-weight: 700; font-size: 22px; letter-spacing: .01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .spacer { flex: 1; }
.token-search { display: flex; align-items: center; gap: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0 8px; min-width: 0; width: min(320px, 40vw); }
.token-search input { border: 0; background: transparent; outline: none; padding: 8px 2px; width: 100%; min-width: 0; font-family: var(--font-mono); font-size: 13.5px; text-transform: uppercase; }
.token-search input::placeholder { text-transform: none; font-family: var(--font-body); color: var(--muted); }
.token-search svg { width: 16px; height: 16px; color: var(--muted); flex: none; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(61, 220, 132, .6); animation: live 2s infinite; }
@keyframes live { 70% { box-shadow: 0 0 0 7px rgba(61, 220, 132, 0); } 100% { box-shadow: 0 0 0 0 rgba(61, 220, 132, 0); } }
.view { padding: 20px max(16px, env(safe-area-inset-right, 0px)) 40px max(20px, env(safe-area-inset-left, 0px)); display: grid; gap: 18px; align-content: start; min-width: 0; }

.menu-btn { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); padding-top: calc(18px + env(safe-area-inset-top, 0px)); }
  .shell.nav-open .sidebar { transform: none; }
  .shell.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 40; }
  .menu-btn { display: inline-grid; }
  .topbar { padding-left: max(12px, env(safe-area-inset-left, 0px)); top: env(safe-area-inset-top, 0px); }
  .token-search { width: auto; flex: 1; }
  .topbar h1 { display: none; }
  .live span { display: none; }
  .view { padding-left: max(12px, env(safe-area-inset-left, 0px)); padding-right: max(12px, env(safe-area-inset-right, 0px)); }
}

/* ---------- Componentes ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 0 14px; border-radius: var(--radius); border: 1px solid var(--line-strong); background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--orange); border-color: var(--orange); color: var(--on-accent); }
.btn-primary:hover { background: var(--orange-hover); border-color: var(--orange-hover); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: var(--on-accent); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--text); border-color: var(--line); }
.btn-danger { background: transparent; border-color: rgba(255, 90, 78, .5); color: var(--red); }
.btn-danger:hover { background: rgba(255, 90, 78, .1); border-color: var(--red); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 38px; padding: 0; }
.btn-block { width: 100%; }

.field { display: grid; gap: 5px; min-width: 0; }
.field > span, .field > label { font-size: 12.5px; color: var(--muted); font-weight: 500; }
.input, .select, .textarea { width: 100%; min-height: 38px; background: var(--bg); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 8px 10px; color: var(--text); font-size: 15px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--gold); outline: none; box-shadow: 0 0 0 3px rgba(232, 169, 58, .18); }
.textarea { min-height: 72px; resize: vertical; }
.input.money { text-align: right; font-variant-numeric: tabular-nums; }
.input-group { display: flex; align-items: stretch; }
.input-group > .addon { display: grid; place-items: center; padding: 0 9px; border: 1px solid var(--line-strong); border-right: 0; border-radius: var(--radius) 0 0 var(--radius); color: var(--muted); font-size: 13px; background: var(--surface); }
.input-group > .input { border-radius: 0 var(--radius) var(--radius) 0; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; accent-color: var(--orange); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.form-grid > * { min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 16px; display: grid; gap: 12px; align-content: start; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.card-head h2, .card h2 { margin: 0; font-family: var(--font-cond); font-weight: 700; font-size: 19px; letter-spacing: .01em; }
.card-head .hint, .hint { color: var(--muted); font-size: 13px; }
.section-title { margin: 0; font-family: var(--font-cond); font-weight: 700; font-size: 13px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 12px 14px; display: grid; gap: 2px; min-width: 0; }
.kpi .k-label { font-size: 11.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.kpi .k-value { font-family: var(--font-cond); font-weight: 700; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-sub { font-size: 12px; color: var(--muted); }
.kpi.accent .k-value { color: var(--gold); }
.kpi.good .k-value { color: var(--green); }
.kpi.warn .k-value { color: var(--bulb); }
.kpi.bad .k-value { color: var(--red); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { font-size: 11.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
.table thead th { position: sticky; top: 0; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr.clickable { cursor: pointer; }
.table tbody tr.clickable:hover { background: var(--surface-2); }
.table td.r, .table th.r { text-align: right; font-variant-numeric: tabular-nums; }
.table td.token, .token { font-family: var(--font-mono); font-size: 13px; letter-spacing: .02em; white-space: nowrap; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); display: grid; gap: 8px; justify-items: center; }
.empty b { color: var(--text); font-size: 15px; }

/* Status */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; border: 1px solid currentColor; line-height: 1.6; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-novo { color: var(--blue); }
.st-em_negociacao { color: var(--violet); }
.st-confirmado { color: var(--gold); }
.st-em_preparo { color: var(--orange); }
.st-finalizado { color: var(--green); }
.st-cancelado { color: var(--red); }
.pay-pago { color: var(--green); }
.pay-parcial { color: var(--bulb); }
.pay-pendente { color: var(--muted); }
.pay-excedente { color: var(--blue); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 4px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 7px 12px; color: var(--muted); cursor: pointer; font-weight: 600; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--text); box-shadow: inset 0 -2px 0 var(--gold); }

.notice { border: 1px solid rgba(255, 211, 107, .35); background: rgba(255, 211, 107, .07); color: var(--text); border-radius: var(--radius); padding: 10px 12px; font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.notice.info { border-color: rgba(108, 180, 255, .35); background: rgba(108, 180, 255, .07); }
.notice.danger { border-color: rgba(255, 90, 78, .4); background: rgba(255, 90, 78, .08); }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 1px; color: var(--bulb); }

/* Drawer / modal */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 80; display: flex; justify-content: flex-end; animation: fade .15s ease; }
.overlay.center { justify-content: center; align-items: center; padding: 16px; }
@keyframes fade { from { opacity: 0; } }
.drawer { width: min(760px, 100%); height: 100%; background: var(--bg); border-left: 1px solid var(--line); display: flex; flex-direction: column; animation: slide .18s ease; }
@keyframes slide { from { transform: translateX(30px); opacity: .6; } }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: calc(14px + env(safe-area-inset-top, 0px)) 18px 14px; border-bottom: 1px solid var(--line); background: var(--surface); }
.drawer-head h2 { margin: 0; font-family: var(--font-cond); font-weight: 700; font-size: 20px; flex: 1; min-width: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px; display: grid; gap: 16px; align-content: start; }
.drawer-foot { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; padding: 12px 18px calc(12px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); background: var(--surface); }
.modal { width: min(480px, 100%); max-height: 90vh; overflow-y: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); display: grid; }
.modal-head { padding: 16px 18px 0; }
.modal-head h2 { margin: 0; font-family: var(--font-cond); font-weight: 700; font-size: 20px; }
.modal-body { padding: 12px 18px; display: grid; gap: 12px; }
.modal-foot { padding: 12px 18px 16px; display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

/* Toast */
.versao-nova { position: fixed; z-index: 90; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: flex; flex-wrap: wrap; align-items: center; gap: 10px; width: max-content; max-width: calc(100vw - 32px); background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); font-size: 14px; }
.toasts { position: fixed; z-index: 100; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 8px; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--surface-2); border: 1px solid var(--line-strong); border-left: 4px solid var(--green); border-radius: var(--radius); padding: 10px 14px; box-shadow: var(--shadow); font-size: 14px; animation: slide .2s ease; }
.toast.error { border-left-color: var(--red); }
.toast.warn { border-left-color: var(--bulb); }
.toast.info { border-left-color: var(--blue); }

/* Gráficos SVG */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font-body); }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .bar { fill: var(--gold); }
.chart .bar.alt { fill: var(--orange); }
.chart .bar:hover { fill: var(--bulb); }

@media print {
  body.painel { background: #fff; color: #000; }
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  .shell { display: block; }
  .card, .kpi, .table-wrap { background: #fff; border-color: #bbb; color: #000; break-inside: avoid; }
  .table th { background: #eee; color: #000; }
  .kpi .k-value, .kpi.accent .k-value { color: #000; }
}
