:host {
  --brand: #E33DCF;
  --blue: #030FAA;
  --text: #111214;
  --muted: rgba(17, 18, 20, 0.65);

  --success-bg: rgba(25, 135, 84, 0.1);
  --success-text: #198754;
  --warn-bg: rgba(255, 193, 7, 0.15);
  --warn-text: #b58100;

  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-card: 0 22px 46px rgba(17, 18, 20, 0.10);
  --glass-bg: rgba(255, 255, 255, 0.82);
  --glass-border: 1px solid rgba(227, 61, 207, 0.16);

  --swap-bg: rgba(227, 61, 207, 0.12);
  --swap-text: #E33DCF;
  --same-bg: rgba(3, 15, 170, 0.08);
  --same-text: #030FAA;

  display: block;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  box-sizing: border-box;
}

/* PAGE */
.troca-page {
  min-height: 100vh;
  padding: 0 12px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  position: relative;
  overflow-y: auto;
  background:
    radial-gradient(900px 420px at 20% 10%, rgba(227, 61, 207, 0.14), transparent 60%),
    radial-gradient(820px 380px at 80% 30%, rgba(227, 61, 207, 0.08), transparent 60%),
    linear-gradient(180deg, #ffffff 0%, #f5f5f7 70%);

  &::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background: rgba(255, 255, 255, 0.25);
  }
}

.page-blob {
  position: fixed;
  pointer-events: none;
  border-radius: 999px;
  filter: blur(34px);
  opacity: 0.55;
  z-index: 0;
  background: radial-gradient(circle at 30% 30%, rgba(227,61,207,0.55), rgba(227,61,207,0.06));
  animation: floaty 10s ease-in-out infinite;

  &.blob-1 { width: 420px; height: 420px; top: -140px; left: -140px; }
  &.blob-2 { width: 520px; height: 520px; top: -220px; right: -240px; animation-duration: 12s; }
  &.blob-3 { width: 360px; height: 360px; bottom: -180px; left: 25%; animation-duration: 14s; }
  &.blob-4 { width: 520px; height: 520px; bottom: -260px; right: -260px; animation-duration: 16s; opacity: .45; }
}

@keyframes floaty {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(18px, 10px) scale(1.03); }
  100% { transform: translate(0, 0) scale(1); }
}

.container-troca {
  width: 100%;
  max-width: 1180px;
  position: relative;
  z-index: 1;
  margin-top: 40px;
  margin-bottom: 200px;
}

.troca-card {
  border-radius: var(--radius-xl);
  overflow: hidden;
  background: var(--glass-bg);
  border: var(--glass-border);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-card);
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);

  &::before {
    content: '';
    position: absolute;
    inset: 1px;
    border-radius: calc(var(--radius-xl) - 1px);
    pointer-events: none;
    border: 1px solid rgba(255, 255, 255, 0.65);
    opacity: 0.75;
  }
}

/* HEADER */
.troca-header {
  padding: 16px 24px;
  border-bottom: 1px solid rgba(17, 18, 20, 0.06);
  background: linear-gradient(180deg, rgba(227,61,207,0.06), rgba(255,255,255,0.2));
  flex-shrink: 0;
}

.header-row-top {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;

  @media (max-width: 768px) {
    grid-template-columns: 1fr;
    text-align: center;
    gap: 16px;

    .title-badge { justify-self: center; margin-bottom: 8px; }
    .header-actions { justify-self: center; }
  }
}

.title-badge {
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(227, 61, 207, 0.22);
  backdrop-filter: blur(10px);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;

  i { color: var(--brand); }
}

.header-title {
  justify-self: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.title {
  font-size: 26px;
  font-weight: 950;
  letter-spacing: -0.3px;
  color: var(--text);
  margin-top: 10px;
  margin-bottom: 0;
}

.subtitle { color: rgba(17, 18, 20, 0.65); font-weight: 700; }
.header-actions { justify-self: end; }

/* BUTTONS */
.btn-brand {
  background-color: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 900;
  border-radius: 12px;
  transition: transform 0.2s, box-shadow 0.2s;

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(227, 61, 207, 0.25);
    filter: brightness(1.05);
  }

  &:disabled { opacity: 0.7; cursor: not-allowed; transform: none; }
}

.btn-glass {
  border-radius: 12px;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(3, 15, 170, 0.25);
  color: var(--blue);

  &:hover { transform: translateY(-2px); border-color: var(--brand); background: #fff; }
}

/* KPIS */
.troca-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-top: 20px;
  margin-bottom: 16px;
  width: 100%;

  @media (max-width: 992px) { grid-template-columns: repeat(2, 1fr); }
  @media (max-width: 576px) { grid-template-columns: 1fr; }
}

.kpi {
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(17,18,20,0.08);
  border-radius: 16px;
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(8px);
  transition: transform 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 5px rgba(0,0,0,0.02);

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(227, 61, 207, 0.1);
    background: #fff;
    border-color: var(--brand);
  }

  .lbl {
    font-size: 0.72rem;
    font-weight: 900;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);

    &.text-success { color: var(--success-text) !important; }
    &.text-brand { color: var(--brand) !important; }
  }

  .val {
    font-size: 1.25rem;
    font-weight: 950;
    color: var(--text);

    &.text-success { color: var(--success-text) !important; }
    &.text-brand { color: var(--brand) !important; }
  }
}

/* CONTROLS */
.controls { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; }

.search-group {
  max-width: 270px;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: stretch;
  background: #fff;
  border: 1px solid rgba(17, 18, 20, 0.15);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  transition: all 0.2s ease;

  &:focus-within {
    border-color: var(--brand);
    box-shadow: 0 4px 12px rgba(227, 61, 207, 0.15);
    transform: translateY(-1px);
  }

  .input-group-text {
    background: transparent;
    border: none;
    color: var(--muted);
    padding-left: 14px;
    padding-right: 8px;
    display: flex;
    align-items: center;

    i { font-size: 1rem; }
  }

  .form-control {
    border: none;
    background: transparent;
    padding: 10px 0;
    font-size: 0.9rem;
    color: var(--text);
    box-shadow: none;

    &::placeholder { color: rgba(17, 18, 20, 0.4); font-weight: 500; }
    &:focus { outline: none; }
  }

  .btn-clear {
    background: transparent;
    border: none;
    color: var(--muted);
    padding: 0 12px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: color 0.2s;

    &:hover { color: #dc3545; }
    i { font-size: 1rem; }
  }
}

.page-size {
  margin-left: auto;
  @media (max-width: 500px) { margin-left: 0; width: 100%; justify-content: space-between; }
}

.select-wrapper { position: relative; display: inline-block; min-width: 90px; }

.select-glass {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(17, 18, 20, 0.15);
  border-radius: 12px;
  color: var(--blue);
  font-weight: 800;
  font-size: 0.9rem;
  text-align: left;
  padding: 8px 36px 8px 14px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: all 0.2s ease;
  width: 100%;

  &:hover {
    background: #fff;
    border-color: var(--blue);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(3, 15, 170, 0.1);
  }

  &:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(227, 61, 207, 0.15);
  }
}

.select-icon {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--muted);
  font-size: 0.75rem;
}

.select-wrapper:hover .select-icon { color: var(--blue); }

/* BODY */
.troca-body { padding: 0; background: transparent; flex: 1; overflow: hidden; display: flex; flex-direction: column; }
.groups-container { padding: 16px; overflow-y: auto; height: 100%; }
.group-list { display: flex; flex-direction: column; gap: 12px; }

.empty-group {
  background: rgba(255,255,255,0.7);
  border: 1px dashed rgba(17,18,20,0.12);
  border-radius: 16px;
  padding: 18px;
  text-align: center;
  font-weight: 800;
  color: var(--muted);
}

.client-group-card {
  background: #fff;
  border-radius: 16px;
  border: 1px solid rgba(17,18,20,0.08);
  overflow: hidden;
  transition: all 0.3s ease;

  &:hover { border-color: var(--brand); box-shadow: 0 4px 12px rgba(227,61,207,0.1); }
  &.expanded { border-color: var(--brand); box-shadow: 0 8px 24px rgba(227,61,207,0.12); }
}

.group-header {
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  background: linear-gradient(180deg, #fff, #fdfdfd);

  &:hover .group-toggle-icon { color: var(--brand); }
}

.group-info { display: flex; flex-direction: column; gap: 6px; }
.group-badges { display: flex; gap: 8px; flex-wrap: wrap; }

.badge-pill {
  font-size: 0.7rem;
  padding: 4px 10px;
  border-radius: 999px;
  font-weight: 800;
  text-transform: uppercase;

  &.total { background: rgba(3,15,170,0.1); color: var(--blue); }
  &.swap { background: var(--swap-bg); color: var(--swap-text); }
  &.ok { background: var(--success-bg); color: var(--success-text); }
  &.warn { background: var(--warn-bg); color: var(--warn-text); }
}

.group-toggle-icon { font-size: 1.2rem; color: var(--muted); transition: transform 0.3s ease; }
.client-group-card.expanded .group-toggle-icon { transform: rotate(180deg); color: var(--brand); }

.group-body {
  border-top: 1px solid rgba(17,18,20,0.06);
  background: #fbfbfc;
}

.chip-muted {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  color: rgba(17,18,20,0.55);
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(17,18,20,0.04);
  border: 1px solid rgba(17,18,20,0.06);
}

.inner-table-wrap { max-height: 450px; overflow-y: auto; }

/* TABLE */
.table-wrap { overflow-x: auto; overflow-y: auto; height: 100%; }

.table-modern {
  width: 100%;
  min-width: 1100px;
  border-collapse: separate;
  border-spacing: 0;

  thead th {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    border-bottom: 2px solid rgba(227, 61, 207, 0.15);
    padding: 12px;
    color: rgba(17, 18, 20, 0.7);
    font-size: 0.8rem;
    font-weight: 950;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    white-space: nowrap;
    text-align: center !important;
  }

  tbody tr {
    transition: background-color 0.2s;
    border-bottom: 1px solid rgba(17,18,20,0.05);

    &:hover { background-color: rgba(227, 61, 207, 0.05); }
    td { border-bottom: 1px solid rgba(17,18,20,0.04); }
  }

  td {
    padding: 12px;
    vertical-align: middle;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.875rem;
    color: var(--text);
    text-align: center !important;
  }
}

.text-brand { color: var(--brand) !important; }
.text-blue { color: var(--blue) !important; }
.fw-black { font-weight: 950; }
.td-clip { overflow: hidden; text-overflow: ellipsis; max-width: 520px; }
.empty-state { background: rgba(255,255,255,0.4); }

/* ACTIONS */
.action-group { display: flex; justify-content: center; gap: 6px; }
.btn-icon {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(17,18,20,0.5);
  transition: all 0.2s;
  cursor: pointer;

  &:hover { background: rgba(17,18,20,0.05); color: var(--text); transform: translateY(-1px); }
  &.primary:hover { color: var(--blue); background: rgba(3,15,170,0.1); }
}

/* FOOTER */
.troca-footer {
  padding: 14px 24px;
  border-top: 1px solid rgba(17, 18, 20, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;

  @media (max-width: 768px) { justify-content: center; text-align: center; }
}

.pagination-modern .page-link {
  color: var(--blue);
  font-weight: 900;
  border-radius: 10px;
  border: 1px solid rgba(17,18,20,0.1);
  background: rgba(255,255,255,0.6);
  margin: 0 2px;

  &:hover { transform: translateY(-1px); border-color: var(--brand); color: var(--brand); }
}

.pagination-modern .page-item.active .page-link {
  background-color: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

/* MODALS */
.modal-backdrop-custom { position: fixed; inset: 0; background: rgba(0,0,0,0.45); z-index: 9990; backdrop-filter: blur(4px); }
.modal-custom { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 9995; padding: 16px; }

.modal-card {
  background: #ffffff;
  border: 1px solid rgba(255,255,255,0.8);
  border-radius: 20px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  width: min(900px, 100%);
  max-height: 90vh;
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  background: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;

  .modal-title {
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 12px;
  }

  .icon-bg {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;

    &.primary-soft { background: rgba(3, 15, 170, 0.1); color: var(--blue); }
    &.brand-soft { background: rgba(227, 61, 207, 0.1); color: var(--brand); }
  }
}

.modal-body { padding: 24px; overflow-y: auto; }
.bg-light-gray { background-color: #f8f9fa; }

.details-dashboard { display: grid; grid-template-columns: 1fr; gap: 20px; }
.detail-box { background: #fff; border-radius: 16px; border: 1px solid rgba(0,0,0,0.05); box-shadow: 0 2px 8px rgba(0,0,0,0.02); overflow: hidden; display: flex; flex-direction: column; }
.box-header { padding: 10px 16px; font-size: 0.8rem; font-weight: 800; text-transform: uppercase; color: var(--muted); border-bottom: 1px solid rgba(0,0,0,0.04); background: #fdfdfd; display: flex; align-items: center; }
.box-body { padding: 16px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;

  @media (max-width: 600px) { grid-template-columns: 1fr; }
}

.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;

  label {
    font-size: 0.75rem;
    font-weight: 900;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: rgba(17,18,20,0.65);
  }

  &.span-2 {
    grid-column: span 2;
    @media (max-width: 600px) { grid-column: span 1; }
  }
}

.form-control {
  border-radius: 8px;
  border: 1px solid rgba(17,18,20,0.15);

  &:focus { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(227,61,207,0.15); outline: none; }
}

/* ✅ HINTS do modal (carregando/avisos) */
.hint {
  margin-top: 6px;
  font-size: 0.75rem;
  font-weight: 800;
  color: rgba(17, 18, 20, 0.55);
  display: inline-flex;
  align-items: center;
  gap: 8px;

  &.warn {
    color: #b58100;
  }
}
