/* ================================================
   META ACCOUNTS MONITOR — ESTILOS
   ================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:          #09090B;
  --bg-card:     #18181B;
  --bg-card2:    #27272A;
  --border:      #3F3F46;
  --primary:     #7C3AED;
  --accent:      #22C55E;
  --warning:     #FDE047;
  --danger:      #FB7185;
  --gold:        #FCD34D;
  --cyan:        #06b6d4;
  --text:        #FAFAFA;
  --text-muted:  #A1A1AA;
  --radius:      16px;
  --shadow:      0 4px 32px rgba(0,0,0,.6);
  --transition:  .22s cubic-bezier(.4,0,.2,1);

  /* Status colors */
  --status-active:        #22C55E;
  --status-active-bg:     rgba(34,197,94,.1);
  --status-active-border: rgba(34,197,94,.3);

  --status-payment:        #FB7185;
  --status-payment-bg:     rgba(251,113,133,.1);
  --status-payment-border: rgba(251,113,133,.3);

  --status-error:        #FB7185;
  --status-error-bg:     rgba(251,113,133,.08);
  --status-error-border: rgba(251,113,133,.25);

  --status-warning:        #FDE047;
  --status-warning-bg:     rgba(253,224,71,.1);
  --status-warning-border: rgba(253,224,71,.3);

  --status-unknown:        #A1A1AA;
  --status-unknown-bg:     rgba(161,161,170,.08);
  --status-unknown-border: rgba(161,161,170,.2);
}

body {
  font-family: 'Inter', sans-serif;
  background:
    radial-gradient(ellipse 60% 40% at 100% 0%,   rgba(124,58,237,.12) 0%, transparent 55%),
    radial-gradient(ellipse 50% 35% at 0%   100%, rgba(34,197,94,.07)  0%, transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Header ── */
.dashboard-header {
  background: rgba(9,9,11,.95);
  border-bottom: 1px solid rgba(124,58,237,.3);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  position: sticky; top: 0; z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 4px 28px rgba(0,0,0,.55), 0 1px 0 rgba(34,197,94,.1);
}

.header-brand {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.brand-icon {
  width: 44px; height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
  box-shadow: 0 2px 14px rgba(124,58,237,.45);
  flex-shrink: 0;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: -.4px;
}

.brand-title span { color: var(--primary); }

.brand-subtitle {
  font-size: .72rem;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: .02em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

.last-updated {
  font-size: .75rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: .4rem;
}

.last-updated-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 2.5s ease infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.8); }
}

.btn-refresh {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .55rem 1.1rem;
  background: rgba(124,58,237,.12);
  border: 1px solid rgba(124,58,237,.3);
  border-radius: 10px;
  color: #a78bfa;
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-refresh:hover {
  background: rgba(124,58,237,.22);
  border-color: var(--primary);
  color: #c4b5fd;
}

.btn-refresh:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.btn-refresh .refresh-icon {
  display: inline-block;
  transition: transform .5s ease;
}

.btn-refresh.spinning .refresh-icon {
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Body ── */
.dashboard-body {
  padding: 2rem;
  max-width: 1440px;
  margin: 0 auto;
}

/* ── Summary Bar ── */
.summary-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
  animation: fadeUp .4s ease both;
}

.summary-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem 1.4rem;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition);
}

.summary-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}

.summary-card.sc-total::before    { background: linear-gradient(90deg, var(--primary), var(--accent)); }
.summary-card.sc-active::before   { background: linear-gradient(90deg, #22C55E, #16A34A); }
.summary-card.sc-errors::before   { background: linear-gradient(90deg, #FB7185, #e11d48); }
.summary-card.sc-warnings::before { background: linear-gradient(90deg, #FDE047, #FBBF24); }
.summary-card.sc-spend::before    { background: linear-gradient(90deg, var(--gold), #F59E0B); }

.summary-card:hover { transform: translateY(-2px); }

.sc-label {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-muted);
  margin-bottom: .35rem;
}

.sc-value {
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: -.5px;
  line-height: 1;
}

.sc-value.color-active   { color: #4ADE80; }
.sc-value.color-error    { color: var(--danger); }
.sc-value.color-warning  { color: var(--warning); }
.sc-value.color-gold     { color: var(--gold); }

.sc-sub {
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: .3rem;
}

.sc-icon {
  position: absolute;
  top: 1rem; right: 1rem;
  font-size: 1.4rem;
  opacity: .12;
}

/* ── Section title ── */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1.2rem;
  display: flex;
  align-items: center;
  gap: .6rem;
}

.section-title .title-bar {
  width: 4px; height: 18px;
  background: linear-gradient(180deg, var(--primary), var(--accent));
  border-radius: 4px;
  flex-shrink: 0;
}

/* ── Accounts Grid ── */
.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 1.2rem;
}

/* ── Account Card ── */
.account-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition), border-color var(--transition);
  animation: fadeUp .4s ease both;
  cursor: default;
}

.account-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 40px rgba(0,0,0,.5);
}

/* Status-based card borders */
.account-card.status-active {
  border-color: rgba(34,197,94,.2);
}
.account-card.status-active:hover {
  border-color: rgba(34,197,94,.4);
  box-shadow: 0 10px 40px rgba(34,197,94,.08);
}

.account-card.status-payment_error,
.account-card.status-error {
  border-color: rgba(251,113,133,.25);
  box-shadow: 0 0 0 1px rgba(251,113,133,.08);
}
.account-card.status-payment_error:hover,
.account-card.status-error:hover {
  border-color: rgba(251,113,133,.45);
  box-shadow: 0 10px 40px rgba(251,113,133,.12);
}

.account-card.status-warning {
  border-color: rgba(253,224,71,.2);
}
.account-card.status-warning:hover {
  border-color: rgba(253,224,71,.38);
  box-shadow: 0 10px 40px rgba(253,224,71,.07);
}

.account-card.status-fetch_error {
  border-color: rgba(161,161,170,.15);
  opacity: .85;
}

/* Top accent bar per status */
.account-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}
.account-card.status-active::before       { background: linear-gradient(90deg, #22C55E, #16A34A); }
.account-card.status-payment_error::before{ background: linear-gradient(90deg, #FB7185, #e11d48); }
.account-card.status-error::before        { background: linear-gradient(90deg, #FB7185, #e11d48); }
.account-card.status-warning::before      { background: linear-gradient(90deg, #FDE047, #FBBF24); }
.account-card.status-unknown::before      { background: var(--border); }
.account-card.status-fetch_error::before  { background: var(--border); }

/* Card header */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: 1.2rem;
}

.card-account-name {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -.3px;
  line-height: 1.2;
}

/* Status badge */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .7rem;
  border-radius: 20px;
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: .04em;
  white-space: nowrap;
  flex-shrink: 0;
}

.status-badge .badge-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.badge-active {
  background: var(--status-active-bg);
  border: 1px solid var(--status-active-border);
  color: var(--status-active);
}
.badge-active .badge-dot { background: var(--status-active); }

.badge-payment_error {
  background: var(--status-payment-bg);
  border: 1px solid var(--status-payment-border);
  color: var(--status-payment);
  animation: badgePulse 2s ease infinite;
}
.badge-payment_error .badge-dot { background: var(--status-payment); }

.badge-error {
  background: var(--status-error-bg);
  border: 1px solid var(--status-error-border);
  color: var(--status-error);
}
.badge-error .badge-dot { background: var(--status-error); }

.badge-warning {
  background: var(--status-warning-bg);
  border: 1px solid var(--status-warning-border);
  color: var(--status-warning);
}
.badge-warning .badge-dot { background: var(--status-warning); }

.badge-fetch_error,
.badge-unknown {
  background: var(--status-unknown-bg);
  border: 1px solid var(--status-unknown-border);
  color: var(--status-unknown);
}
.badge-fetch_error .badge-dot,
.badge-unknown .badge-dot { background: var(--status-unknown); }

@keyframes badgePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251,113,133,.0); }
  50% { box-shadow: 0 0 0 4px rgba(251,113,133,.15); }
}

/* Spend section */
.card-spend {
  margin-bottom: 1rem;
}

.spend-row {
  display: flex;
  align-items: baseline;
  gap: .5rem;
  margin-bottom: .15rem;
}

.spend-label {
  font-size: .65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--text-muted);
  margin-bottom: .3rem;
}

.spend-today,
.spend-month {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -.6px;
  line-height: 1;
}

/* Month progress bar */
.month-progress {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-top: .65rem;
}

.month-progress-track {
  flex: 1;
  height: 4px;
  background: rgba(255,255,255,.08);
  border-radius: 4px;
  overflow: hidden;
}

.month-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  border-radius: 4px;
  transition: width .8s ease;
}

.month-progress-label {
  font-size: .62rem;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.spend-currency {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  align-self: flex-end;
  padding-bottom: .15rem;
}

/* Divider */
.card-divider {
  height: 1px;
  background: var(--border);
  margin: 1rem 0;
  opacity: .5;
}

/* Yesterday row */
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}

.meta-item {
  display: flex;
  flex-direction: column;
  gap: .1rem;
}

.meta-label {
  font-size: .62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
}

.meta-value {
  font-size: .9rem;
  font-weight: 700;
}

/* Delta between today and yesterday */
.spend-delta {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  font-size: .7rem;
  font-weight: 700;
  padding: .15rem .45rem;
  border-radius: 8px;
}

.delta-up   { color: #4ADE80; background: rgba(74,222,128,.1); }
.delta-down { color: #FB7185; background: rgba(251,113,133,.1); }
.delta-flat { color: var(--text-muted); background: rgba(161,161,170,.08); }

/* Stats row (impresiones, frecuencia, ROAS) */
.card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .5rem;
  margin-top: .8rem;
  padding-top: .8rem;
  border-top: 1px solid rgba(63,63,70,.5);
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: .1rem;
}

.stat-label {
  font-size: .6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
}

.stat-value {
  font-size: .88rem;
  font-weight: 700;
  color: var(--text);
}

/* Disable reason chip */
.disable-reason {
  margin-top: .75rem;
  padding: .4rem .7rem;
  background: rgba(251,113,133,.07);
  border: 1px solid rgba(251,113,133,.2);
  border-radius: 8px;
  font-size: .7rem;
  color: #fca5a5;
  display: flex;
  align-items: center;
  gap: .35rem;
}

/* Fetch error note */
.fetch-error-note {
  margin-top: .75rem;
  padding: .4rem .7rem;
  background: rgba(161,161,170,.06);
  border: 1px solid rgba(161,161,170,.15);
  border-radius: 8px;
  font-size: .7rem;
  color: var(--text-muted);
}

/* ── Loading ── */
.loading-overlay {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 55vh;
  gap: 1.5rem;
}

.spinner {
  width: 52px; height: 52px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

.loading-text { color: var(--text-muted); font-size: .95rem; }
.loading-sub  { color: var(--text-muted); font-size: .78rem; opacity: .6; }

/* ── Error state ── */
.error-box {
  background: rgba(251,113,133,.07);
  border: 1px solid rgba(251,113,133,.25);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  max-width: 520px;
  margin: 4rem auto;
}
.error-box .error-icon { font-size: 2.5rem; margin-bottom: .8rem; }
.error-box h3 { font-size: 1.1rem; margin-bottom: .5rem; }
.error-box p  { color: var(--text-muted); font-size: .88rem; }

/* ── Hidden ── */
.hidden { display: none !important; }

/* ── Animations ── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Staggered card delays */
.account-card:nth-child(1)  { animation-delay: .04s; }
.account-card:nth-child(2)  { animation-delay: .08s; }
.account-card:nth-child(3)  { animation-delay: .12s; }
.account-card:nth-child(4)  { animation-delay: .16s; }
.account-card:nth-child(5)  { animation-delay: .20s; }
.account-card:nth-child(6)  { animation-delay: .24s; }
.account-card:nth-child(7)  { animation-delay: .28s; }
.account-card:nth-child(8)  { animation-delay: .32s; }
.account-card:nth-child(9)  { animation-delay: .36s; }
.account-card:nth-child(10) { animation-delay: .40s; }
.account-card:nth-child(11) { animation-delay: .44s; }
.account-card:nth-child(12) { animation-delay: .48s; }
.account-card:nth-child(13) { animation-delay: .52s; }
.account-card:nth-child(14) { animation-delay: .56s; }
.account-card:nth-child(15) { animation-delay: .60s; }
.account-card:nth-child(16) { animation-delay: .64s; }
.account-card:nth-child(17) { animation-delay: .68s; }
.account-card:nth-child(18) { animation-delay: .72s; }
.account-card:nth-child(19) { animation-delay: .76s; }
.account-card:nth-child(20) { animation-delay: .80s; }
.account-card:nth-child(21) { animation-delay: .84s; }
.account-card:nth-child(22) { animation-delay: .88s; }
.account-card:nth-child(23) { animation-delay: .92s; }

/* ── Search ── */
.search-wrap {
  margin-bottom: 1rem;
}

.search-input {
  width: 100%;
  max-width: 320px;
  padding: .45rem 1.1rem;
  background: var(--bg-card2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-family: inherit;
  font-size: .82rem;
  outline: none;
  transition: all var(--transition);
}

.search-input::placeholder { color: var(--text-muted); }

.search-input:focus {
  border-color: rgba(124,58,237,.5);
  background: var(--bg-card);
  box-shadow: 0 0 0 3px rgba(124,58,237,.1);
}

/* ── Filter tabs ── */
.filter-tabs {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin-bottom: 1.4rem;
  flex-wrap: wrap;
}

.filter-tab {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .38rem .9rem;
  border-radius: 20px;
  font-family: inherit;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card2);
  color: var(--text-muted);
  transition: all var(--transition);
}

.filter-tab:hover {
  border-color: rgba(124,58,237,.4);
  color: var(--text);
}

.filter-tab.active {
  background: linear-gradient(135deg, var(--primary), #5B21B6);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 14px rgba(124,58,237,.4);
}

.filter-tab .tab-count {
  background: rgba(255,255,255,.15);
  border-radius: 10px;
  padding: .05rem .45rem;
  font-size: .67rem;
  font-weight: 800;
}

.filter-tab:not(.active) .tab-count {
  background: var(--border);
  color: var(--text-muted);
}

/* ── Footer ── */
.dashboard-footer {
  text-align: center;
  padding: 2rem 1rem;
  border-top: 1px solid var(--border);
  margin-top: 2rem;
}

.footer-text {
  font-size: .75rem;
  color: var(--text-muted);
}

.footer-text strong { color: var(--accent); }

/* ── Responsive ── */
@media (max-width: 1100px) {
  .summary-bar { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 760px) {
  .summary-bar { grid-template-columns: repeat(2, 1fr); }
  .dashboard-body { padding: 1rem; }
  .dashboard-header { padding: 1rem; }
  .sc-value { font-size: 1.5rem; }
}

@media (max-width: 500px) {
  .summary-bar { grid-template-columns: 1fr 1fr; }
  .accounts-grid { grid-template-columns: 1fr; }
  .header-right { width: 100%; justify-content: flex-start; }
}
