/* =========================================================
   Componentes reutilizáveis
   ========================================================= */

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 10px;
  font: inherit; font-weight: 600; font-size: .95rem; line-height: 1;
  text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s, box-shadow .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn .icon { width: 18px; height: 18px; }
.btn--sm { min-height: 34px; padding: 0 12px; font-size: .85rem; border-radius: 8px; }
.btn--lg { min-height: 50px; padding: 0 26px; font-size: 1rem; border-radius: 12px; }
.btn--block { width: 100%; }

.btn--primary { background: var(--navy); color: #fff; }
.btn--primary:hover { background: var(--navy-2); }
.btn--gold { background: var(--gold); color: var(--navy); }
.btn--gold:hover { background: #FFE94D; box-shadow: 0 6px 20px rgba(249, 225, 25, .35); }
.btn--outline-gold { background: transparent; color: var(--gold); border-color: var(--gold); }
.btn--outline-gold:hover { background: rgba(249, 225, 25, .12); }
.btn--ghost { background: var(--surface); color: var(--navy); border-color: var(--border-strong); }
.btn--ghost:hover { background: var(--surface-2); border-color: var(--navy); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: #B03030; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border: 0; border-radius: 10px;
  background: transparent; color: inherit; cursor: pointer;
}
.btn-icon:hover { background: rgba(2, 26, 100, .07); }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.link { background: none; border: 0; padding: 0; font: inherit; color: var(--navy); font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; }
.link:hover { text-decoration: underline; }
.link .icon { width: 16px; height: 16px; }
.link-light { color: rgba(255,255,255,.7); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.link-light:hover { color: var(--gold); }
.link-light .icon { width: 16px; height: 16px; }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: .75rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge--navy { background: var(--navy); color: #fff; border-color: var(--navy); }
.badge--gold { background: var(--gold-light); color: #7A5E00; border-color: #F3E27A; }
.badge--success { background: var(--success-bg); color: var(--success); border-color: #BFE6D1; }
.badge--danger { background: var(--danger-bg); color: var(--danger); border-color: #F2C4C4; }
.badge--warn { background: var(--warn-bg); color: var(--warn); border-color: #F1DC9F; }
.badge--info { background: var(--info-bg); color: var(--info); border-color: #C5D6F4; }
.chip { display: inline-block; padding: 8px 16px; border-radius: 999px; background: var(--gold-light); color: var(--navy); font-weight: 700; border: 1px solid #F3E27A; }

/* ---------- Cards ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 20px; margin-bottom: 18px; }
.card--flush { padding: 0; overflow: hidden; }
.card__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card__head h2 { font-size: 1.05rem; margin: 0; }

/* ---------- Alertas ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 16px; font-size: .92rem; border: 1px solid; }
.alert .icon { width: 18px; height: 18px; margin-top: 2px; }
.alert--info { background: var(--info-bg); color: #1E4A99; border-color: #C5D6F4; }
.alert--warn { background: var(--warn-bg); color: #6B4B00; border-color: #F1DC9F; }
.alert--danger { background: var(--danger-bg); color: #922; border-color: #F2C4C4; }
.alert a { color: inherit; font-weight: 700; }
.form-error[hidden] { display: none; }

/* ---------- Formulários ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px 16px; }
.field { display: flex; flex-direction: column; margin-bottom: 12px; min-width: 0; }
.field--full { grid-column: 1 / -1; }
.field label { font-size: .85rem; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  font: inherit; font-size: 16px; /* 16px evita zoom automático no iPhone */
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 10px;
  transition: border-color .15s, box-shadow .15s;
}
.field textarea { resize: vertical; min-height: 80px; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--navy); box-shadow: 0 0 0 3px rgba(2, 26, 100, .12); }
.field input[readonly] { background: var(--surface-2); }
.field__hint { color: var(--muted); font-size: .8rem; margin-top: 4px; }
.field__error { color: var(--danger); font-size: .8rem; margin-top: 4px; min-height: 0; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.field.has-error input:focus { box-shadow: 0 0 0 3px rgba(201, 59, 59, .15); }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.input-group { position: relative; display: flex; }
.input-group input { padding-right: 46px; }
.input-group__btn { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 42px; height: 40px; border: 0; background: none; color: var(--muted); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.input-group__btn:hover { color: var(--navy); }

.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; font-size: .92rem; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--navy); flex: none; }

/* ---------- Tabelas ---------- */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table--click tbody tr { cursor: pointer; }
.table--click tbody tr:hover, .table--click tbody tr:focus { background: var(--gold-light); outline: none; }
.table--compact th, .table--compact td { padding: 8px 10px; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.cell-user { display: flex; align-items: center; gap: 10px; }

/* ---------- Avatar ---------- */
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; flex: none; border-radius: 50%; background: var(--navy); color: var(--gold); font-weight: 800; font-size: .8rem; letter-spacing: .02em; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(0, 8, 32, .55); opacity: 0; transition: opacity .18s; }
.modal__dialog { position: relative; width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg); transform: translateY(12px) scale(.98); opacity: 0; transition: transform .18s, opacity .18s; }
.modal__dialog--sm { max-width: 420px; }
.modal__dialog--md { max-width: 580px; }
.modal__dialog--lg { max-width: 860px; }
.modal.is-open .modal__backdrop { opacity: 1; }
.modal.is-open .modal__dialog { transform: none; opacity: 1; }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal__title { font-size: 1.1rem; margin: 0; }
.modal__body { padding: 20px; overflow-y: auto; }
.modal__foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 16px 16px; }
.confirm-text { font-size: 1rem; margin: 0; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; z-index: 300; right: 16px; bottom: calc(16px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--navy); color: #fff; box-shadow: var(--shadow-lg); font-size: .92rem; transform: translateY(10px); opacity: 0; transition: transform .2s, opacity .2s; }
.toast.is-in { transform: none; opacity: 1; }
.toast .icon { width: 18px; height: 18px; margin-top: 1px; color: var(--gold); }
.toast--success .icon { color: #6FE0A6; }
.toast--error { background: #7E1F1F; }
.toast--error .icon { color: #FFC2C2; }

/* ---------- Loading / vazio ---------- */
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid rgba(2, 26, 100, .15); border-top-color: var(--navy); animation: spin .8s linear infinite; }
.spinner--gold { border-color: rgba(249, 225, 25, .25); border-top-color: var(--gold); }
.spinner--sm { width: 18px; height: 18px; border-width: 2px; border-color: rgba(255,255,255,.35); border-top-color: currentColor; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 48px 16px; color: var(--muted); }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty__icon { display: inline-flex; width: 56px; height: 56px; border-radius: 50%; align-items: center; justify-content: center; background: var(--gold-light); color: var(--gold-dark); margin-bottom: 12px; }
.empty__icon .icon { width: 28px; height: 28px; }
.empty h3 { color: var(--navy); margin-bottom: 4px; }

/* ---------- Abas ---------- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--border); margin-bottom: 18px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs__item { padding: 10px 14px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: .92rem; border-bottom: 3px solid transparent; white-space: nowrap; margin-bottom: -1px; }
.tabs__item:hover { color: var(--navy); }
.tabs__item.is-active { color: var(--navy); border-bottom-color: var(--gold); }

/* ---------- Diversos ---------- */
.dl { display: grid; grid-template-columns: 150px 1fr; gap: 8px 12px; margin: 0 0 18px; }
.dl dt { color: var(--muted); font-size: .85rem; font-weight: 600; }
.dl dd { margin: 0; min-width: 0; }
.temp-pw { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.6rem; font-weight: 800; letter-spacing: .12em; text-align: center; padding: 16px; margin: 12px 0; background: var(--gold-light); border: 2px dashed var(--gold); border-radius: 12px; color: var(--navy); user-select: all; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pager > div { display: flex; align-items: center; gap: 10px; }

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dd { margin-bottom: 8px; }
  .modal { align-items: flex-end; padding: 0; }
  .modal__dialog { max-height: 92vh; border-radius: 18px 18px 0 0; }
  .modal__foot { border-radius: 0; padding-bottom: calc(14px + var(--safe-bottom)); }
  .modal__foot .btn { flex: 1; }
  .form-actions .btn { width: 100%; }
  /* Avisos no topo no celular: não cobrem os botões das janelas (que abrem de baixo) */
  .toasts { top: calc(12px + var(--safe-top)); bottom: auto; left: 16px; right: 16px; max-width: none; }

  /* Tabela vira lista de cartões no celular */
  .table--responsive thead { display: none; }
  .table--responsive, .table--responsive tbody, .table--responsive tr, .table--responsive td { display: block; width: 100%; }
  .table--responsive tr { padding: 12px 16px; border-bottom: 1px solid var(--border); }
  .table--responsive tbody tr:last-child { border-bottom: 0; }
  .table--responsive td { border: 0; padding: 4px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right; }
  .table--responsive td::before { content: attr(data-label); font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); text-align: left; flex: none; }
  .table--responsive td.ta-r { justify-content: flex-end; flex-wrap: wrap; }
  .table--responsive td[data-label="Ações"]::before { display: none; }
  .table--responsive td[data-label="Nome"]::before { display: none; }
  .table--responsive td[data-label="Nome"] { font-weight: 700; justify-content: flex-start; text-align: left; }
}
.badges { display: inline-flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
