/* =========================================
   META ADS DASHBOARD — style.css
   ========================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #090910;
  --surface:  #111119;
  --surface2: #17171f;
  --surface3: #1e1e28;
  --border:   #26263a;
  --border2:  #32324a;
  --text:     #e4e4f0;
  --text2:    #8888a8;
  --text3:    #52526a;
  --blue:     #1877F2;
  --blue-dim: #1877f230;
  --green:    #22c55e;
  --red:      #ef4444;
  --amber:    #f59e0b;
  --purple:   #a855f7;
  --r:        10px;
  --rl:       14px;
}

body { font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; }
a { text-decoration: none; color: inherit; }

/* ── LAYOUT ─────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

/* ── SIDEBAR ─────────────────────────────────── */
.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 1.2rem 0;
  position: sticky; top: 0; height: 100vh;
  overflow-y: auto;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 8px;
  padding: 0 1.2rem 1.4rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.brand-text { font-size: 15px; font-weight: 600; color: var(--text); }
.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 .6rem; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--r);
  font-size: 13px; color: var(--text2);
  transition: all .15s; cursor: pointer;
}
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--blue-dim); color: var(--blue); font-weight: 500; }
.nav-icon { font-size: 14px; width: 18px; text-align: center; }

.sidebar-bottom { padding: 1rem .8rem 0; border-top: 1px solid var(--border); margin-top: 1rem; }
.user-card { display: flex; align-items: center; gap: 8px; padding: .6rem .4rem; margin-bottom: 6px; }
.user-avatar { font-size: 20px; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.user-name { font-size: 12px; font-weight: 500; color: var(--text); }
.user-email { font-size: 10px; color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.logout-btn { display: block; text-align: center; font-size: 11px; color: var(--text3); padding: 6px; border-radius: var(--r); transition: all .15s; }
.logout-btn:hover { background: var(--surface2); color: var(--red); }

/* ── MAIN ─────────────────────────────────────── */
.main-content { flex: 1; min-width: 0; padding: 1.4rem 1.8rem; overflow-y: auto; }

/* ── TOPBAR ──────────────────────────────────── */
.topbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.4rem; flex-wrap: wrap; gap: 10px; }
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-right { display: flex; align-items: center; gap: 8px; }

.select-account {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 7px 12px; font-size: 13px;
  color: var(--text); cursor: pointer; outline: none; font-family: 'DM Sans', sans-serif;
  max-width: 220px;
}
.select-sm {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r); padding: 6px 10px; font-size: 12px;
  color: var(--text2); cursor: pointer; outline: none; font-family: 'DM Sans', sans-serif;
}
.live-badge { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text3); }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: blink 1.5s infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

.btn-sync {
  background: var(--blue-dim); border: 1px solid #1877f250;
  border-radius: var(--r); padding: 7px 14px; font-size: 12px; font-weight: 500;
  color: var(--blue); cursor: pointer; font-family: 'DM Sans', sans-serif;
  display: flex; align-items: center; gap: 5px; transition: all .2s;
}
.btn-sync:hover { background: #1877f240; }
.btn-sync.spinning #syncIcon { display: inline-block; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-add {
  background: var(--blue); border: none; border-radius: var(--r);
  padding: 7px 14px; font-size: 12px; font-weight: 600;
  color: #fff; cursor: pointer; font-family: 'DM Sans', sans-serif; transition: opacity .2s;
}
.btn-add:hover { opacity: .88; }
.btn-primary-lg {
  background: var(--blue); border: none; border-radius: var(--r);
  padding: 12px 28px; font-size: 14px; font-weight: 600;
  color: #fff; cursor: pointer; font-family: 'DM Sans', sans-serif; transition: opacity .2s;
  margin-top: 1rem;
}
.btn-primary {
  width: 100%; background: var(--blue); color: #fff; border: none;
  border-radius: var(--r); padding: 11px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: 'DM Sans', sans-serif; transition: opacity .2s; margin-top: .4rem;
}
.btn-primary:hover { opacity: .88; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }

/* ── KPI CARDS ───────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; margin-bottom: 1.4rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--rl); padding: 16px 18px; position: relative; overflow: hidden; }
.kpi::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 2px; border-radius: 2px 2px 0 0; }
.kpi.blue::before  { background: var(--blue); }
.kpi.green::before { background: var(--green); }
.kpi.amber::before { background: var(--amber); }
.kpi.red::before   { background: var(--red); }
.kpi.purple::before{ background: var(--purple); }
.kpi-label { font-size: 11px; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.kpi-val { font-size: 23px; font-weight: 600; color: var(--text); line-height: 1; margin-bottom: 5px; font-variant-numeric: tabular-nums; }
.kpi-delta { font-size: 11px; color: var(--text3); }
.kpi-skeleton { background: var(--surface2); border-radius: var(--rl); height: 90px; animation: shimmer 1.2s infinite; }
@keyframes shimmer { 0%,100%{opacity:.6} 50%{opacity:1} }

/* ── CHARTS ──────────────────────────────────── */
.charts-row { display: flex; gap: 14px; flex-wrap: wrap; }
.chart-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--rl); padding: 1.1rem 1.3rem; min-width: 0; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .8rem; flex-wrap: wrap; gap: 8px; }
.card-title { font-size: 13px; font-weight: 500; color: var(--text); }
.chart-wrap { position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; }
.leg { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text2); }
.leg-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* ── TABLE ───────────────────────────────────── */
.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--rl); overflow: hidden; }
.table-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 8px; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead { background: var(--surface2); }
th { padding: 9px 13px; text-align: left; font-size: 11px; font-weight: 500; color: var(--text2); border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; }
th:hover { color: var(--text); }
td { padding: 10px 13px; font-size: 12px; color: var(--text); border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover { background: var(--surface2); }
.num { font-family: 'DM Mono', monospace; font-size: 12px; }
.loading-cell { text-align: center; color: var(--text3); padding: 24px; }

.status-badge { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 500; padding: 3px 9px; border-radius: 20px; }
.dot { width: 5px; height: 5px; border-radius: 50%; }
.st-active { background: #22c55e15; color: var(--green); } .st-active .dot { background: var(--green); }
.st-paused { background: #f59e0b15; color: var(--amber); } .st-paused .dot { background: var(--amber); }
.st-ended  { background: #ffffff08; color: var(--text3); } .st-ended .dot  { background: var(--text3); }

.roas-good { color: var(--green); }
.roas-ok   { color: var(--amber); }
.roas-bad  { color: var(--red); }

/* ── HBARS ───────────────────────────────────── */
.hbar { margin-bottom: 8px; }
.hbar-top { display: flex; justify-content: space-between; font-size: 11px; color: var(--text2); margin-bottom: 3px; }
.hbar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 68%; }
.hbar-track { height: 5px; background: var(--surface3); border-radius: 3px; overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 3px; background: var(--blue); transition: width .5s ease; }

/* ── MODAL ───────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 100; }
.modal-overlay.open { display: block; }
.modal {
  display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%,-50%);
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 1.8rem; width: 90%; max-width: 460px; z-index: 101;
}
.modal.open { display: block; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 16px; cursor: pointer; }
.modal-steps { background: var(--surface2); border-radius: var(--r); padding: .9rem 1rem; margin-bottom: 1.2rem; font-size: 12px; color: var(--text2); display: flex; flex-direction: column; gap: 5px; }
.modal-steps code { background: var(--surface3); border-radius: 4px; padding: 1px 5px; font-family: 'DM Mono', monospace; font-size: 11px; color: var(--blue); }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 12px; font-weight: 500; color: var(--text2); margin-bottom: 5px; }
.form-group input { width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: 13px; color: var(--text); font-family: 'DM Sans', sans-serif; outline: none; transition: border .2s; }
.form-group input:focus { border-color: var(--blue); }
input::placeholder { color: var(--text3); }
.error-msg { background: #ef444415; border: 1px solid #ef444430; border-radius: 8px; padding: 10px 14px; font-size: 12px; color: #ef6a6a; margin-bottom: 1rem; }

/* ── SEARCH ──────────────────────────────────── */
.search-input { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 12px; color: var(--text); font-family: 'DM Sans', sans-serif; outline: none; width: 180px; }
.search-input:focus { border-color: var(--blue); }

/* ── EMPTY STATE ─────────────────────────────── */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60vh; text-align: center; gap: 12px; }
.empty-icon { font-size: 48px; }
.empty-state h2 { font-size: 20px; font-weight: 600; }
.empty-state p { font-size: 13px; color: var(--text2); max-width: 380px; }

/* ── BADGES ──────────────────────────────────── */
.badge-gray { background: var(--surface2); border: 1px solid var(--border); border-radius: 20px; font-size: 11px; color: var(--text2); padding: 3px 10px; }

/* ── TOAST ───────────────────────────────────── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
  padding: 12px 18px; font-size: 13px; color: var(--text);
  display: flex; align-items: center; gap: 8px;
  transform: translateY(60px); opacity: 0; transition: all .3s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-color: #22c55e40; }
.toast.error   { border-color: #ef444440; }

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { padding: .8rem; }
  .charts-row { flex-direction: column; }
}
