/*
 * Componentes do padrão visual do ArcaneLab. Cada seção corresponde a uma entrada em
 * /ui e docs/UI.md. Não usar hex direto aqui — sempre var(--token).
 */

/* ---------- Brand ---------- */
.brand {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  font-weight: 800;
  letter-spacing: -0.02em;
  font-size: var(--text-lg);
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, #a779ff, #6f49d8 60%, #3b2e78);
  box-shadow: 0 0 28px rgba(155, 108, 255, 0.28);
  font-weight: 900;
  color: #fff;
  flex-shrink: 0;
}

.muted {
  color: var(--muted);
}

/* ---------- Botão ---------- */
.btn {
  border: 0;
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: var(--text-base);
  font-weight: 600;
  background: var(--panel-3);
  color: var(--text);
  cursor: pointer;
  transition: transform var(--transition-fast), filter var(--transition-fast), background var(--transition-fast);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  line-height: 1.2;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.08);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  cursor: not-allowed;
  opacity: 0.5;
  transform: none;
  filter: none;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-strong));
  box-shadow: 0 12px 26px rgba(155, 108, 255, 0.2);
}

.btn-ghost {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.btn-danger {
  background: linear-gradient(135deg, var(--danger), var(--danger-strong));
  box-shadow: 0 12px 26px rgba(255, 111, 145, 0.18);
}

.btn-sm {
  padding: 8px 12px;
  font-size: var(--text-sm);
}

.btn-block {
  width: 100%;
}

/* ---------- Campo ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.field:first-child {
  margin-top: 0;
}

.field label {
  font-size: var(--text-sm);
  color: var(--muted-strong);
  font-weight: 600;
}

.field .field-hint {
  font-size: var(--text-xs);
  color: var(--muted);
}

.input,
select.input,
textarea.input {
  width: 100%;
  border: 1px solid var(--line);
  background: #0e131d;
  color: var(--text);
  outline: none;
  border-radius: var(--radius);
  padding: 13px 15px;
}

textarea.input {
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: var(--text-sm);
  resize: vertical;
  min-height: 160px;
}

.input::placeholder,
textarea.input::placeholder {
  color: var(--muted);
}

.input:focus-visible,
textarea.input:focus-visible {
  border-color: rgba(155, 108, 255, 0.65);
  box-shadow: 0 0 0 4px rgba(155, 108, 255, 0.1);
}

/* input[type=file]: mesma moldura do .input, mas o botão nativo do navegador não dá
   pra restilizar por completo entre browsers sem markup extra — aceitável aqui porque
   é usado só como atalho opcional (preencher a textarea de import a partir de um
   arquivo), nunca a única forma de inserir o conteúdo. */
.file-input {
  width: 100%;
  border: 1px dashed var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted-strong);
  border-radius: var(--radius);
  padding: 11px 15px;
  font-size: var(--text-sm);
}

.field.has-error .input {
  border-color: var(--danger);
}

.field-error {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  color: var(--danger);
  font-size: var(--text-sm);
}

.field-error .icon {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  color: var(--muted-strong);
}

/* ---------- Painel ---------- */
.panel {
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: rgba(18, 23, 34, 0.82);
  overflow: hidden;
}

.panel-head {
  padding: 17px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-3);
}

.panel-head h2,
.panel-head h3 {
  margin: 0;
  font-size: var(--text-base);
  font-weight: 700;
}

.panel-body {
  padding: 18px;
}

/* ---------- Layout: login ---------- */
.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.1fr 0.9fr;
}

.login-hero {
  position: relative;
  overflow: hidden;
  padding: 54px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.login-hero::after {
  content: "";
  position: absolute;
  width: 520px;
  height: 520px;
  right: -140px;
  bottom: -120px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    rgba(155, 108, 255, 0.2) 0 22%,
    transparent 23% 34%,
    rgba(90, 213, 201, 0.11) 35% 36%,
    transparent 37% 100%
  );
}

.hero-copy {
  max-width: 640px;
  position: relative;
  z-index: 2;
}

.eyebrow {
  display: inline-flex;
  gap: var(--space-2);
  align-items: center;
  padding: 8px 10px;
  border-radius: var(--radius-pill);
  background: rgba(155, 108, 255, 0.1);
  color: #c8b2ff;
  border: 1px solid rgba(155, 108, 255, 0.2);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.hero-copy h1 {
  font-size: clamp(38px, 5vw, 64px);
  line-height: 1.02;
  margin: var(--space-5) 0 var(--space-4);
  letter-spacing: -0.04em;
}

.hero-copy p {
  color: var(--muted-strong);
  font-size: var(--text-lg);
  line-height: 1.6;
  max-width: 520px;
}

.login-panel {
  display: grid;
  place-items: center;
  padding: var(--space-6);
}

.login-card {
  width: min(430px, 100%);
  padding: var(--space-6);
  border-radius: var(--radius-lg);
  background: rgba(18, 23, 34, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: var(--shadow);
}

.login-card h2 {
  margin: var(--space-4) 0 var(--space-2);
  font-size: var(--text-2xl);
  letter-spacing: -0.03em;
}

@media (max-width: 1050px) {
  .login-page {
    grid-template-columns: 1fr;
  }
  .login-hero {
    display: none;
  }
}

/* ---------- Layout: app logado ---------- */
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: var(--space-5) var(--space-4);
  background: rgba(10, 13, 19, 0.85);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  margin: 0 var(--space-2) var(--space-6);
}

.nav-label {
  margin: var(--space-5) var(--space-2) var(--space-2);
  color: var(--muted-strong);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: var(--text-xs);
  font-weight: 800;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 11px 12px;
  border-radius: 11px;
  color: var(--muted-strong);
  font-size: var(--text-sm);
  font-weight: 600;
}

a.nav-item:hover {
  background: rgba(255, 255, 255, 0.035);
  color: var(--text);
}

.nav-item.active {
  color: var(--text);
  background: linear-gradient(90deg, rgba(155, 108, 255, 0.17), rgba(155, 108, 255, 0.05));
  border: 1px solid rgba(155, 108, 255, 0.16);
}

.nav-item.disabled {
  color: var(--muted);
  cursor: default;
}

.nav-icon {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.045);
  flex-shrink: 0;
}

.nav-item .nav-icon .icon {
  width: 16px;
  height: 16px;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.sidebar-user {
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: #10151f;
  display: flex;
  gap: var(--space-3);
  align-items: center;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #62429c, #3a7e78);
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.user-copy {
  min-width: 0;
}

.user-copy strong {
  display: block;
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-copy span {
  font-size: var(--text-xs);
  color: var(--muted);
}

.sidebar-footer form {
  margin: 0;
}

.main {
  padding: var(--space-5) var(--space-6) var(--space-7);
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.page-head h1 {
  margin: 0 0 6px;
  font-size: var(--text-2xl);
  letter-spacing: -0.03em;
}

@media (max-width: 760px) {
  :root {
    --sidebar-width: var(--sidebar-width-collapsed);
  }
  .sidebar {
    padding: var(--space-4) 8px;
  }
  .sidebar .brand span:last-child,
  .nav-label,
  .nav-item span.nav-text,
  .sidebar-user .user-copy {
    display: none;
  }
  .nav-item {
    justify-content: center;
  }
  .sidebar-user {
    justify-content: center;
    padding: 10px 4px;
  }
  .main {
    padding: var(--space-4);
  }
  .page-head {
    align-items: flex-start;
    flex-direction: column;
  }
}

/* ---------- Métrica ---------- */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.metric {
  background: linear-gradient(180deg, rgba(23, 29, 41, 0.9), rgba(17, 22, 32, 0.9));
  border: 1px solid var(--line);
  padding: 18px;
  border-radius: var(--radius-lg);
}

.metric-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted-strong);
  font-size: var(--text-sm);
}

.metric-top .icon {
  width: 18px;
  height: 18px;
  color: var(--accent-2);
}

.metric strong {
  display: block;
  font-size: var(--text-2xl);
  margin: 12px 0 6px;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.metric small {
  color: var(--muted);
  font-size: var(--text-xs);
}

/* ---------- Tag ---------- */
.tag {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.07);
  color: #d4d8e2;
  font-size: var(--text-xs);
  font-weight: 600;
}

/* ---------- Badge de legalidade ---------- */
/* Cores propositalmente fora da paleta WUBRG: verde-menta de sucesso para "legal",
   rosa de perigo para "banida/não legal", âmbar para "fora da identidade/restrita". */
.legality-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.legality-badge .icon {
  width: 13px;
  height: 13px;
}

.legality-badge-legal {
  background: rgba(61, 220, 132, 0.14);
  color: var(--success);
}

.legality-badge-banned {
  background: rgba(255, 111, 145, 0.14);
  color: var(--danger);
}

.legality-badge-not_legal,
.legality-badge-outside {
  background: rgba(243, 201, 105, 0.14);
  color: var(--warning);
}

.legality-badge-restricted {
  background: rgba(108, 192, 255, 0.14);
  color: var(--info);
}

/* ---------- Custo de mana inline ---------- */
.mana-cost {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  vertical-align: middle;
}

.mana-symbol {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  display: inline-block;
}

.mana-symbol-text {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--panel-3);
  color: var(--muted-strong);
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Tile de carta ---------- */
.card-tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: var(--space-4);
  list-style: none;
  margin: 0;
  padding: 0;
}

.card-tile {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--panel-2);
  display: block;
  transition: transform var(--transition-fast), border-color var(--transition-fast);
}

.card-tile:hover {
  transform: translateY(-2px);
  border-color: rgba(155, 108, 255, 0.4);
}

.card-tile-image {
  aspect-ratio: 5 / 7;
  background: var(--panel-3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.card-tile-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-tile-image .card-tile-fallback {
  color: var(--muted);
  font-size: var(--text-xs);
  text-align: center;
  padding: var(--space-2);
}

.card-tile-body {
  padding: 10px 12px 12px;
}

.card-tile-name {
  font-size: var(--text-sm);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 6px;
}

/* ---------- Card de deck (arte como protagonista) ---------- */
/* Ainda sem dados reais de deck (ARC-5) — componente cadastrado em /ui para as
   próximas issues não reinventarem isso; a arte do comandante (art_crop) ocupa o
   espaço que no conceito original era só gradiente roxo. */
.deck-card {
  min-height: 220px;
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background-color: var(--panel-3);
  background-size: cover;
  background-position: center 30%;
}

.deck-card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(11, 15, 22, 0.05) 0%, rgba(11, 15, 22, 0.55) 55%, rgba(11, 15, 22, 0.96) 100%);
}

.deck-card-body {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: var(--space-4);
  z-index: 1;
}

.deck-tags {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  margin-bottom: var(--space-2);
}

.deck-card h4 {
  margin: 0 0 4px;
  font-size: var(--text-lg);
}

.deck-meta {
  color: var(--muted-strong);
  font-size: var(--text-xs);
  display: flex;
  justify-content: space-between;
}

/* ---------- Tabela densa ---------- */
.table-scroll {
  overflow-x: auto;
}

.table-dense {
  width: 100%;
  min-width: 480px;
  font-size: var(--text-sm);
}

.table-dense th {
  text-align: left;
  color: var(--muted-strong);
  font-weight: 700;
  text-transform: uppercase;
  font-size: var(--text-xs);
  letter-spacing: 0.06em;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.table-dense td {
  padding: 9px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.table-dense tbody tr:hover {
  background: rgba(255, 255, 255, 0.02);
}

.table-dense .num {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* ---------- Aviso / flash ---------- */
.flash {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: 13px 16px;
  border-radius: var(--radius);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
  border: 1px solid transparent;
}

.flash .icon {
  flex-shrink: 0;
  margin-top: 1px;
}

.flash-success {
  background: rgba(61, 220, 132, 0.1);
  border-color: rgba(61, 220, 132, 0.28);
  color: var(--success);
}

.flash-error {
  background: rgba(255, 111, 145, 0.1);
  border-color: rgba(255, 111, 145, 0.28);
  color: var(--danger);
}

.flash-info {
  background: rgba(108, 192, 255, 0.1);
  border-color: rgba(108, 192, 255, 0.28);
  color: var(--info);
}

/* ---------- Estado vazio ---------- */
.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--muted-strong);
}

.empty-state .icon {
  width: 34px;
  height: 34px;
  color: var(--muted);
  margin: 0 auto var(--space-3);
}

.empty-state h3 {
  color: var(--text);
  font-size: var(--text-lg);
  margin-bottom: var(--space-2);
}

.empty-state p {
  font-size: var(--text-sm);
  max-width: 360px;
  margin: 0 auto;
}

/* ---------- Paginação ---------- */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  margin: var(--space-5) 0;
  font-size: var(--text-sm);
  color: var(--muted-strong);
}

.pagination .btn {
  padding: 8px 12px;
}

.pagination .btn .icon {
  width: 16px;
  height: 16px;
}

/* ---------- Confirmação de ação destrutiva ---------- */
/* Progressive enhancement: sem JS, o form some direto (comportamento atual); com
   /js/confirm.js carregado, um `window.confirm()` nativo intercepta o submit — acessível
   por teclado e leitor de tela sem exigir framework algum. */
.confirm-form {
  display: inline;
}

/* ---------- Utilidades de grade para /ui e telas largas ---------- */
.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: var(--space-4);
}
