/* ============================================================
   FINANCEL — CARTÕES V4 PREMIUM
   "Cada cartão é uma linha de crédito sob controle"
   
   Redesign decision-first, mobile-first
   Layer sobre cartoes-v3.css
   ============================================================ */

:root {
  --ct-radius: 1.2rem;
  --ct-border: rgba(148, 163, 184, 0.2);
  --ct-gold: rgba(250, 204, 21, 0.85);
  --ct-green: #22c55e;
  --ct-red: #ef4444;
  --ct-amber: #f59e0b;
  --ct-blue: #38bdf8;
  --ct-surface: rgba(15, 23, 42, 0.92);
  --ct-surface-elevated: rgba(17, 25, 45, 0.95);
}

/* ============================================================
   HIDE LEGACY ELEMENTS
   ============================================================ */

.dash-top-summary,
.fin-mini-saldo-card,
.lanc-grid,
.lanc-form-card,
.lanc-list-card,
#cartaoHistoricoPanel,
#diagnostics-banner {
  display: none !important;
}

/* ============================================================
   PAINEL DE IMPACTO — 3 Cards de decisão no topo
   ============================================================ */

.ct-impact-panel {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  margin: 1rem 0 0;
}

.ct-impact-card {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1.1rem 1.2rem;
  border-radius: var(--ct-radius);
  background: var(--ct-surface);
  border: 1px solid var(--ct-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
  overflow: hidden;
}

.ct-impact-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  border-radius: var(--ct-radius) 0 0 var(--ct-radius);
}

.ct-impact--limit::before  { background: var(--ct-blue); }
.ct-impact--available::before { background: var(--ct-green); }
.ct-impact--used::before    { background: var(--ct-amber); }

.ct-impact-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.ct-impact-icon {
  font-size: 1.5rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: 2px;
}

.ct-impact-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ct-impact-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fin-slate-400, #94a3b8);
}

.ct-impact-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--fin-slate-50, #f8fafc);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ct-impact-meta {
  font-size: 0.72rem;
  color: var(--fin-slate-400, #94a3b8);
  white-space: nowrap;
}

/* Semantic colors on values */
.ct-impact--limit .ct-impact-value  { color: var(--ct-blue); }
.ct-impact--available .ct-impact-value { color: var(--ct-green); }
.ct-impact--used .ct-impact-value   { color: var(--ct-amber); }

/* When usage is dangerous */
.ct-impact--used.ct-danger .ct-impact-value { color: var(--ct-red); }
.ct-impact--used.ct-danger::before { background: var(--ct-red); }

/* ============================================================
   ACTION BAR — Ações principais
   ============================================================ */

.ct-action-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.75rem;
  padding: 0.85rem 1.1rem;
  border-radius: var(--ct-radius);
  background: var(--ct-surface);
  border: 1px solid var(--ct-border);
  flex-wrap: wrap;
}

.ct-action-left,
.ct-action-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Buttons */
.ct-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border-radius: 0.65rem;
  font-size: 0.82rem;
  font-weight: 700;
  font-family: inherit;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  text-decoration: none;
  line-height: 1.2;
}

.ct-btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.ct-btn--primary {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.18), rgba(234, 179, 8, 0.12));
  border-color: rgba(250, 204, 21, 0.35);
  color: var(--fin-gold-300, #fcd34d);
}

.ct-btn--primary:hover {
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.3), rgba(234, 179, 8, 0.2));
  border-color: rgba(250, 204, 21, 0.55);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(250, 204, 21, 0.2);
}

.ct-btn--outline {
  background: transparent;
  border-color: var(--ct-border);
  color: var(--fin-slate-300, #cbd5e1);
}

.ct-btn--outline:hover {
  background: rgba(148, 163, 184, 0.1);
  border-color: rgba(148, 163, 184, 0.4);
  transform: translateY(-1px);
}

.ct-btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--fin-slate-400, #94a3b8);
  padding: 0.4rem 0.65rem;
  font-size: 0.78rem;
}

.ct-btn--ghost:hover {
  color: var(--fin-slate-200, #e2e8f0);
  background: rgba(148, 163, 184, 0.08);
}

/* ═══ HERO CTA — Importar fatura PDF ═══ */
.ct-btn--hero {
  background: linear-gradient(135deg, var(--ct-green), #16a34a);
  border-color: transparent;
  color: #fff;
  font-weight: 800;
  padding: 0.65rem 1.3rem;
  font-size: 0.88rem;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(34, 197, 94, 0.3);
}

.ct-btn--hero:hover {
  background: linear-gradient(135deg, #16a34a, #15803d);
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(34, 197, 94, 0.45);
}

.ct-btn--hero::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  animation: ctHeroShine 3s ease-in-out infinite;
}

@keyframes ctHeroShine {
  0% { left: -100%; }
  50% { left: 100%; }
  100% { left: 100%; }
}

.ct-btn-badge {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.6rem;
  font-weight: 900;
  background: rgba(255, 255, 255, 0.25);
  color: #fff;
  letter-spacing: 0.06em;
  margin-left: 2px;
}

/* ============================================================
   CHART SECTION — Barras de utilização
   ============================================================ */

.ct-chart-section {
  margin-top: 0.75rem;
  padding: 1.1rem 1.2rem;
  border-radius: var(--ct-radius);
  background: var(--ct-surface);
  border: 1px solid var(--ct-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.ct-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}

.ct-section-title {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--fin-slate-100, #f1f5f9);
  margin: 0;
}

.ct-section-title svg {
  color: var(--fin-gold-400, #facc15);
  flex-shrink: 0;
}

.ct-section-subtitle {
  font-size: 0.72rem;
  color: var(--fin-slate-400, #94a3b8);
}

.ct-chart-container {
  width: 100%;
  height: 240px;
  min-height: 200px;
}

/* ============================================================
   CARDS SECTION — Grid de cartões visuais
   ============================================================ */

.ct-cards-section {
  margin-top: 0.75rem;
}

.ct-cards-count {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--fin-slate-400, #94a3b8);
  background: rgba(15, 23, 42, 0.6);
  padding: 0.25rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--ct-border);
}

.ct-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.85rem;
  margin-top: 0.65rem;
}

/* ── Card individual ── */

.ct-card {
  position: relative;
  border-radius: var(--ct-radius);
  background: var(--ct-surface-elevated);
  border: 1px solid var(--ct-border);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease;
  animation: ctCardFadeUp 0.35s ease both;
}

.ct-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 16px 44px rgba(0, 0, 0, 0.5);
  border-color: rgba(250, 204, 21, 0.25);
}

@keyframes ctCardFadeUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stripe de cor do cartão (borda esquerda) */
.ct-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--ct-card-color, #facc15);
}

/* Header visual com dados do cartão */
.ct-card-visual {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 1rem 1.1rem 0.65rem;
}

.ct-card-chip {
  width: 48px;
  height: 36px;
  border-radius: 8px;
  background: var(--ct-card-color, #facc15);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}

.ct-card-chip::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.3), transparent 60%);
  pointer-events: none;
}

.ct-card-chip span {
  font-size: 1.1rem;
  position: relative;
  z-index: 1;
}

.ct-card-info {
  flex: 1;
  min-width: 0;
}

.ct-card-name {
  font-size: 0.92rem;
  font-weight: 800;
  color: var(--fin-slate-100, #f1f5f9);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ct-card-meta {
  font-size: 0.72rem;
  color: var(--fin-slate-400, #94a3b8);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-top: 2px;
}

.ct-card-flag {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 0.65rem;
  font-weight: 700;
  background: rgba(250, 204, 21, 0.15);
  color: var(--fin-gold-300, #fcd34d);
  border: 1px solid rgba(250, 204, 21, 0.25);
}

.ct-card-final {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--fin-slate-300, #cbd5e1);
  letter-spacing: 0.12em;
  white-space: nowrap;
}

/* ── Barra de utilização ── */

.ct-card-usage {
  padding: 0.5rem 1.1rem 0.75rem;
}

.ct-usage-bar-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.12);
  overflow: hidden;
  position: relative;
}

.ct-usage-bar-fill {
  height: 100%;
  border-radius: 999px;
  transition: width 0.6s ease, background 0.3s ease;
  min-width: 2px;
}

/* Color semantic */
.ct-usage-bar-fill.ct-safe       { background: linear-gradient(90deg, var(--ct-green), #4ade80); }
.ct-usage-bar-fill.ct-moderate   { background: linear-gradient(90deg, var(--ct-amber), #fbbf24); }
.ct-usage-bar-fill.ct-danger     { background: linear-gradient(90deg, var(--ct-red), #f87171); }

.ct-usage-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.68rem;
  color: var(--fin-slate-400, #94a3b8);
}

.ct-usage-labels strong {
  font-weight: 700;
}

.ct-usage-labels .ct-val-available { color: var(--ct-green); }
.ct-usage-labels .ct-val-used      { color: var(--ct-amber); }

/* ── Dados de fechamento e vencimento ── */

.ct-card-dates {
  display: flex;
  gap: 1rem;
  padding: 0 1.1rem;
  margin-bottom: 0.65rem;
}

.ct-card-date {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.7rem;
  color: var(--fin-slate-400, #94a3b8);
}

.ct-card-date svg {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
  color: var(--fin-slate-500, #64748b);
}

.ct-card-date strong {
  color: var(--fin-slate-200, #e2e8f0);
  font-weight: 700;
}

/* ── Ações do card ── */

.ct-card-actions {
  display: flex;
  border-top: 1px solid var(--ct-border);
}

.ct-card-action {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.6rem 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  background: transparent;
  color: var(--fin-slate-400, #94a3b8);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ct-card-action:not(:last-child) {
  border-right: 1px solid var(--ct-border);
}

.ct-card-action svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

.ct-card-action:hover {
  background: rgba(148, 163, 184, 0.08);
  color: var(--fin-slate-200, #e2e8f0);
}

.ct-card-action--edit:hover {
  color: var(--ct-blue);
  background: rgba(56, 189, 248, 0.08);
}

.ct-card-action--delete:hover {
  color: var(--ct-red);
  background: rgba(239, 68, 68, 0.08);
}

.ct-card-action--history:hover {
  color: var(--ct-green);
  background: rgba(34, 197, 94, 0.08);
}

.ct-card-action--buy:hover {
  color: var(--fin-gold-400, #facc15);
  background: rgba(250, 204, 21, 0.08);
}

/* ── Empty state ── */

.ct-empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 1.5rem;
  border-radius: var(--ct-radius);
  background: var(--ct-surface);
  border: 2px dashed rgba(148, 163, 184, 0.2);
}

.ct-empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  display: block;
}

.ct-empty-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--fin-slate-200, #e2e8f0);
  margin-bottom: 0.35rem;
}

.ct-empty-text {
  font-size: 0.82rem;
  color: var(--fin-slate-400, #94a3b8);
  max-width: 360px;
  margin: 0 auto 1rem;
  line-height: 1.5;
}

/* ============================================================
   HISTORY SECTION
   ============================================================ */

.ct-history-section {
  margin-top: 0.75rem;
  padding: 1.1rem 1.2rem;
  border-radius: var(--ct-radius);
  background: var(--ct-surface);
  border: 1px solid var(--ct-border);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.ct-history-content {
  font-size: 0.88rem;
  color: var(--fin-slate-300, #cbd5e1);
}

/* ============================================================
   MODAL V4 — Cadastro/Edição de Cartão (Slide-up)
   ============================================================ */

.ct-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(2, 6, 23, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 9000;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

.ct-modal-overlay.active {
  display: flex;
}

.ct-modal-panel {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--ct-surface-elevated);
  border: 1px solid var(--ct-border);
  border-radius: var(--ct-radius) var(--ct-radius) 0 0;
  padding: 1.5rem 1.4rem 2rem;
  box-shadow: 0 -12px 44px rgba(0, 0, 0, 0.65);
  animation: ctModalSlideUp 0.3s ease;
}

@keyframes ctModalSlideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.ct-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
}

.ct-modal-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--fin-slate-100, #f1f5f9);
}

.ct-modal-close {
  background: none;
  border: none;
  font-size: 1.3rem;
  color: var(--fin-slate-400, #94a3b8);
  cursor: pointer;
  padding: 0.3rem;
  line-height: 1;
  transition: color 0.2s ease;
}

.ct-modal-close:hover {
  color: var(--fin-slate-200, #e2e8f0);
}

.ct-modal-form {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.ct-modal-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.ct-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ct-field label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fin-slate-400, #94a3b8);
}

.ct-field input,
.ct-field select {
  padding: 0.6rem 0.8rem;
  border-radius: 0.55rem;
  border: 1px solid var(--ct-border);
  background: rgba(15, 23, 42, 0.6);
  color: var(--fin-slate-100, #f1f5f9);
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 600;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  outline: none;
}

.ct-field input:focus,
.ct-field select:focus {
  border-color: rgba(250, 204, 21, 0.5);
  box-shadow: 0 0 0 3px rgba(250, 204, 21, 0.1);
}

.ct-field input::placeholder {
  color: var(--fin-slate-500, #64748b);
  font-weight: 500;
}

.ct-field small {
  font-size: 0.68rem;
  color: var(--fin-slate-500, #64748b);
}

/* Color picker row */
.ct-color-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.ct-color-chip {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.ct-color-chip:hover {
  transform: scale(1.15);
}

.ct-color-chip.active {
  border-color: var(--fin-gold-400, #facc15);
  box-shadow: 0 0 8px rgba(250, 204, 21, 0.3);
}

.ct-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--ct-border);
}

.ct-modal-btn-cancel {
  padding: 0.55rem 1.2rem;
  border-radius: 0.55rem;
  border: 1px solid var(--ct-border);
  background: transparent;
  color: var(--fin-slate-300, #cbd5e1);
  font-size: 0.82rem;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
}

.ct-modal-btn-cancel:hover {
  background: rgba(148, 163, 184, 0.1);
}

.ct-modal-btn-save {
  padding: 0.55rem 1.5rem;
  border-radius: 0.55rem;
  border: 1px solid transparent;
  background: linear-gradient(135deg, rgba(250, 204, 21, 0.85), rgba(234, 179, 8, 0.75));
  color: #0f172a;
  font-size: 0.82rem;
  font-weight: 800;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 16px rgba(250, 204, 21, 0.2);
}

.ct-modal-btn-save:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(250, 204, 21, 0.35);
}

.ct-modal-btn-save:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ============================================================
   RESPONSIVE — MOBILE FIRST
   ============================================================ */

@media (max-width: 768px) {
  .ct-impact-panel {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .ct-impact-card {
    padding: 0.85rem 1rem;
  }

  .ct-impact-value {
    font-size: 1.15rem;
  }

  .ct-action-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .ct-action-left,
  .ct-action-right {
    justify-content: center;
  }

  .ct-btn--hero {
    width: 100%;
    justify-content: center;
    font-size: 0.92rem;
    padding: 0.75rem 1rem;
  }

  .ct-chart-container {
    height: 200px;
  }

  .ct-cards-grid {
    grid-template-columns: 1fr;
  }

  .ct-modal-panel {
    max-width: 100%;
    border-radius: 1.2rem 1.2rem 0 0;
    padding: 1.2rem 1rem 1.5rem;
  }

  .ct-modal-row {
    grid-template-columns: 1fr;
  }

  .ct-card-dates {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
}

@media (max-width: 480px) {
  .ct-impact-card {
    padding: 0.75rem 0.85rem;
    gap: 0.65rem;
  }

  .ct-impact-icon {
    font-size: 1.2rem;
  }

  .ct-impact-value {
    font-size: 1rem;
  }

  .ct-btn {
    font-size: 0.78rem;
    padding: 0.5rem 0.8rem;
  }

  .ct-card-visual {
    padding: 0.85rem 0.9rem 0.55rem;
  }

  .ct-card-actions {
    flex-wrap: wrap;
  }

  .ct-card-action {
    flex: 1 1 45%;
    padding: 0.5rem 0.35rem;
    font-size: 0.68rem;
  }
}

/* ============================================================
   ANIMATIONS
   ============================================================ */

.ct-impact-panel,
.ct-action-bar,
.ct-chart-section,
.ct-cards-section,
.ct-history-section {
  animation: ctFadeUp 0.4s ease both;
}

.ct-action-bar      { animation-delay: 0.05s; }
.ct-chart-section   { animation-delay: 0.1s; }
.ct-cards-section   { animation-delay: 0.15s; }

@keyframes ctFadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Stagger cards */
.ct-card:nth-child(1) { animation-delay: 0.05s; }
.ct-card:nth-child(2) { animation-delay: 0.1s; }
.ct-card:nth-child(3) { animation-delay: 0.15s; }
.ct-card:nth-child(4) { animation-delay: 0.2s; }
.ct-card:nth-child(5) { animation-delay: 0.25s; }
.ct-card:nth-child(6) { animation-delay: 0.3s; }
