/* Componentes: páginas, cartões, indicadores, tabelas, abas, modais, avisos. */

.page { max-width: 1320px; margin: 0 auto; }
/* ritmo vertical: blocos soltos dentro da página nunca ficam colados (indicadores, cartões, listas) */
.page > * + * { margin-top: 18px; }
.page > .page-head + * { margin-top: 0; }
.page-narrow { max-width: 880px; margin: 0 auto; }
.center-page { text-align: center; padding-top: 10vh; }
.page-head { margin-bottom: 22px; }
.page-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.page-head-text { min-width: 0; }
.page-title { font-size: clamp(24px, 2.6vw, 32px); line-height: 1.15; letter-spacing: -.02em; }
.page-sub { margin: 6px 0 0; color: var(--muted); font-size: 15px; max-width: 70ch; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; color: var(--muted); font-size: 13.5px; font-weight: 600; text-decoration: none; }
.back:hover { color: var(--ink); }

.stack { display: grid; gap: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }

/* ---------- cartões ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 20px; min-width: 0; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush > .card-head { padding: 18px 20px 14px; margin: 0; border-bottom: 1px solid var(--line); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.card-titles { display: flex; align-items: center; gap: 12px; min-width: 0; }
.card-ic { display: grid; place-items: center; width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--gold-soft); color: var(--gold-ink); }
.card-title { font-size: 16.5px; font-weight: 700; }
.card-sub { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card + .card { margin-top: 0; }

/* ---------- indicadores ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { display: flex; flex-direction: column; gap: 6px; padding: 16px 18px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit; transition: border-color .2s, box-shadow .2s, transform .2s; }
.stat-link:hover { border-color: var(--gold-2); box-shadow: var(--shadow-2); transform: translateY(-1px); }
.stat-top { display: flex; align-items: center; gap: 10px; }
.stat-ic { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 750; color: var(--ink); letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.stat-hint { font-size: 12.5px; color: var(--faint); }

/* ---------- avatar ---------- */
.avatar { display: inline-grid; place-items: center; flex: none; border-radius: 50%; font-weight: 750; color: hsl(var(--h) 45% 28%); background: hsl(var(--h) 60% 90%); letter-spacing: .02em; }
.avatar-dark { background: var(--ink); color: var(--gold-2); }
.avatar-img { display: block; object-fit: cover; background: var(--surface-3); border: 1px solid var(--line); }

/* ---------- vazio / erro / aviso ---------- */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 40px 20px; color: var(--muted); }
.empty-compact { padding: 22px 16px; }
.empty-ic { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--surface-3); color: var(--faint); margin-bottom: 12px; }
.empty-compact .empty-ic { width: 44px; height: 44px; border-radius: 12px; }
.empty-title { margin: 0 0 4px; font-weight: 700; color: var(--ink); }
.empty-text { margin: 0 0 14px; max-width: 42ch; font-size: 14px; }
.errorbox { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 16px 18px; border-radius: 14px; background: var(--bad-soft); color: var(--bad); }
.errorbox p { margin: 2px 0 0; color: var(--text); }
.errorbox .btn { margin-left: auto; }
.alert { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-radius: 14px; font-size: 14.5px; }
.alert > .ic { margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; }
.alert-body strong { display: block; color: inherit; }
.alert-body div { color: var(--text); }
.alert-action { align-self: center; }

/* ---------- progresso ---------- */
.progress-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 7px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.progress-row strong { color: var(--ink); font-size: 14px; font-variant-numeric: tabular-nums; }
.progress-track { height: 10px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress-fill { display: block; height: 100%; border-radius: inherit; background: var(--grad-gold); transition: width .8s var(--ease); }
.progress-sm .progress-track { height: 6px; }
.progress-lg .progress-track { height: 14px; }
.progress-lg .progress-row strong { font-size: 22px; }

/* ---------- abas ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 4px; margin-bottom: 20px; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: 8px; flex: none; min-height: 40px; padding: 0 14px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 650; white-space: nowrap; }
.tab:hover { color: var(--ink); background: var(--surface-2); }
.tab[aria-selected="true"] { background: var(--ink); color: #fff; }
.tab[aria-selected="true"] .ic { color: var(--gold-2); }
.tab-count { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--surface-3); color: var(--muted); font-size: 11.5px; font-weight: 750; line-height: 20px; text-align: center; }
.tab-count.is-alert { background: var(--gold-2); color: #1a1206; }
.tab[aria-selected="true"] .tab-count { background: rgba(255, 255, 255, .16); color: #fff; }

/* ---------- tabelas ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.search { display: flex; align-items: center; gap: 8px; flex: 1 1 240px; max-width: 380px; height: 42px; padding: 0 12px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--surface); color: var(--muted); }
.search:focus-within { border-color: var(--gold); box-shadow: var(--focus); }
.search-input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font-size: 14.5px; color: var(--ink); }
.toolbar .select { width: auto; min-width: 170px; min-height: 42px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 13px; border-radius: 999px; border: 1px solid var(--line-2); background: var(--surface); color: var(--muted); font-size: 13.5px; font-weight: 650; }
.chip:hover { border-color: var(--gold); color: var(--ink); }
.chip[aria-checked="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip-count { font-size: 11.5px; opacity: .75; }
.table-wrap { overflow-x: auto; transition: opacity .2s; }
.table-wrap.is-refreshing { opacity: .6; }
.table-skel { padding: 16px 20px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { position: sticky; top: 0; padding: 11px 16px; text-align: left; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; color: var(--text); }
.table tbody tr:last-child td { border-bottom: 0; }
.table tr.is-clickable { cursor: pointer; }
.table tr.is-clickable:hover td { background: #fffcf4; }
.table-dense td { padding: 9px 14px; }
.td-primary, .table .row-link { font-weight: 650; color: var(--ink); }
.row-link { text-decoration: none; }
.row-link:hover { text-decoration: underline; }
.t-right { text-align: right; }
.cell-sub { display: block; font-size: 12.5px; color: var(--muted); font-weight: 450; }
/* enquadramento das tabelas: o nome tem espaço; a coluna de botões ocupa só o que precisa */
@media (min-width: 721px) {
  .table td.td-primary { min-width: 200px; }
  .table td:has(> .row-actions) { width: 1%; white-space: nowrap; }
  .table td:has(> .row-actions) .row-actions { flex-wrap: nowrap; }
}
.cell-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--line); }
.pager-info { margin: 0; font-size: 13px; color: var(--muted); padding: 12px 16px; }
.pager .pager-info { padding: 0; }
.pager-btns { display: flex; align-items: center; gap: 6px; }
.pager-cur { font-size: 13.5px; font-weight: 650; color: var(--ink); min-width: 54px; text-align: center; }

/* ---------- lista "rótulo: valor" ---------- */
.kv { display: grid; gap: 14px 20px; margin: 0; }
.kv-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kv-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.kv-1 { grid-template-columns: 1fr; }
.kv-item { min-width: 0; }
.kv dt { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--faint); margin-bottom: 3px; }
.kv dd { margin: 0; color: var(--ink); font-weight: 550; overflow-wrap: anywhere; }
.ext-link { display: inline-flex; align-items: center; gap: 5px; font-weight: 650; }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 20px; background: rgba(22, 18, 12, .5); animation: fade .18s; overflow-y: auto; }
.modal { width: 100%; max-height: calc(100vh - 40px); display: flex; flex-direction: column; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow-3); outline: none; animation: rise .22s var(--ease); }
@keyframes rise { from { opacity: 0; transform: translateY(12px) scale(.98); } }
.modal-sm { max-width: 460px; } .modal-md { max-width: 640px; } .modal-lg { max-width: 880px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { font-size: 19px; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.confirm-msg { color: var(--text); font-size: 15px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 300; display: grid; gap: 10px; width: min(380px, calc(100vw - 36px)); }
.toast { display: flex; align-items: flex-start; gap: 10px; padding: 13px 14px; border-radius: 14px; background: var(--ink); color: #fff; box-shadow: var(--shadow-3); font-size: 14px; font-weight: 550; animation: rise .22s var(--ease); }
.toast.tone-ok .ic:first-child { color: #7ee2a4; }
.toast.tone-bad { background: #3a100d; }
.toast.tone-bad .ic:first-child { color: #ff9b8f; }
.toast.tone-info .ic:first-child { color: var(--gold-2); }
.toast span { flex: 1; }
.toast button { border: 0; background: none; color: rgba(255, 255, 255, .6); padding: 2px; }

@media (max-width: 1100px) {
  .grid-main { grid-template-columns: minmax(0, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .kv-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat { padding: 14px; }
  .stat-value { font-size: 22px; }
  .card { padding: 16px; border-radius: 14px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .toasts { left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom)); width: auto; }
  .modal-wrap { padding: 0; align-items: flex-end; }
  .modal { max-height: calc(92vh - var(--safe-t)); border-radius: 20px 20px 0 0; padding-bottom: var(--safe-b); }
  .modal-foot .btn { flex: 1; }
  .search { max-width: none; }
  .toolbar .select { flex: 1; min-width: 0; }
  /* tabela vira lista de cartões */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; text-align: right; }
  .table td::before { content: attr(data-label); font-size: 12px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; text-align: left; flex: none; }
  .table td.td-primary, .table td:first-child { justify-content: flex-start; text-align: left; font-size: 15px; padding-bottom: 6px; }
  .table td.td-primary::before, .table td:first-child::before { display: none; }
  .table .hide-sm { display: none; }
  .t-right { text-align: right; }
}

/* itens de grade não podem crescer além da coluna por causa de textos longos */
.grid-main > *, .grid-2 > *, .grid-3 > *, .stack > * { min-width: 0; }
