/* Modern Mobile-First Dark Theme for Meta Ads Live Dashboard */

:root {
  --bg-main: #070b14;
  --bg-card: #0f172a;
  --bg-card-hover: #162238;
  --bg-card-glass: rgba(15, 23, 42, 0.85);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-focus: #38bdf8;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --color-brand: #1877f2;
  --color-brand-glow: rgba(24, 119, 242, 0.25);
  --color-wpp: #25d366;
  --color-wpp-glow: rgba(37, 211, 102, 0.2);

  --health-green: #10b981;
  --health-green-bg: rgba(16, 185, 129, 0.12);
  --health-green-border: rgba(16, 185, 129, 0.35);

  --health-yellow: #f59e0b;
  --health-yellow-bg: rgba(245, 158, 11, 0.12);
  --health-yellow-border: rgba(245, 158, 11, 0.35);

  --health-red: #ef4444;
  --health-red-bg: rgba(239, 68, 68, 0.15);
  --health-red-border: rgba(239, 68, 68, 0.4);

  --health-gray: #94a3b8;
  --health-gray-bg: rgba(148, 163, 184, 0.1);
  --health-gray-border: rgba(148, 163, 184, 0.25);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;
  
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-primary);
  min-height: 100vh;
  padding-bottom: 60px;
  line-height: 1.5;
}

/* Container */
.container {
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-card-glass);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 0;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-badge {
  background: linear-gradient(135deg, #1877f2, #0d5cb6);
  color: white;
  font-weight: 800;
  font-size: 0.85rem;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  box-shadow: 0 0 12px var(--color-brand-glow);
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.btn-primary {
  background: #1877f2;
  color: #fff;
  border: none;
  font-weight: 600;
  box-shadow: 0 2px 10px var(--color-brand-glow);
}

.btn-primary:hover {
  background: #2583fa;
}

.btn-primary.loading .btn-spin {
  animation: spin 0.8s linear infinite;
}

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

/* Control Bar (Account + Preset + Refresh) */
.controls-bar {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

@media (min-width: 640px) {
  .controls-bar {
    grid-template-columns: 2fr 1.5fr auto auto;
    align-items: center;
  }
}

.form-select {
  background: #090f1e;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

.form-select:focus {
  border-color: var(--border-focus);
}

/* Sync Status Bar */
.sync-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 0;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}

.sync-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.dot-live {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--color-wpp);
  box-shadow: 0 0 8px var(--color-wpp);
}

.badge-mode {
  background: rgba(56, 189, 248, 0.1);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.3);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 0.7rem;
}

/* Quick Filter & Toggle Bar */
.filter-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  background: var(--bg-card);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.toggle-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 38px;
  height: 20px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  transition: 0.25s;
  border-radius: 20px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: 0.25s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: #10b981;
}

input:checked + .toggle-slider:before {
  transform: translateX(18px);
}

.search-input {
  background: #090f1e;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  width: 100%;
  max-width: 240px;
  outline: none;
}

/* KPI Summary Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 20px;
}

@media (min-width: 768px) {
  .kpi-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s, border-color 0.2s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,255,255,0.18);
}

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  font-weight: 600;
  margin-bottom: 6px;
}

.kpi-value {
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.kpi-wpp {
  color: var(--color-wpp);
}

.kpi-sub {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Tabs Navigation */
.tabs-nav {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 18px;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs-nav::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-secondary);
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: #38bdf8;
  border-bottom-color: #38bdf8;
}

.tab-badge {
  background: rgba(255,255,255,0.08);
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-size: 0.7rem;
}

/* Health Badge Component */
.health-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 9px;
  border-radius: var(--radius-full);
}

.health-pill.green {
  background: var(--health-green-bg);
  border: 1px solid var(--health-green-border);
  color: #34d399;
}

.health-pill.yellow {
  background: var(--health-yellow-bg);
  border: 1px solid var(--health-yellow-border);
  color: #fbbf24;
}

.health-pill.red {
  background: var(--health-red-bg);
  border: 1px solid var(--health-red-border);
  color: #f87171;
}

.health-pill.gray {
  background: var(--health-gray-bg);
  border: 1px solid var(--health-gray-border);
  color: #cbd5e1;
}

/* Status Badge */
.status-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.status-badge.ACTIVE {
  background: rgba(16, 185, 129, 0.15);
  color: #10b981;
}

.status-badge.PAUSED {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
}

/* Ads Grid (Criativos lado a lado) */
.ads-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 640px) {
  .ads-grid {
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  }
}

.ad-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
}

.ad-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255, 255, 255, 0.16);
  box-shadow: var(--shadow-md);
}

.ad-media-box {
  width: 100%;
  height: 180px;
  background: #090f1d;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ad-media-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ad-media-placeholder {
  color: var(--text-muted);
  font-size: 0.85rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.ad-overlay-tags {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 2;
}

.ad-content {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
}

.ad-title-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ad-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
}

.ad-hierarchy-meta {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* Health Reasoning Alert inside Card */
.ad-health-callout {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}

.ad-health-callout.green {
  background: var(--health-green-bg);
  border: 1px solid var(--health-green-border);
  color: #34d399;
}

.ad-health-callout.yellow {
  background: var(--health-yellow-bg);
  border: 1px solid var(--health-yellow-border);
  color: #fbbf24;
}

.ad-health-callout.red {
  background: var(--health-red-bg);
  border: 1px solid var(--health-red-border);
  color: #fca5a5;
}

.ad-health-callout.gray {
  background: var(--health-gray-bg);
  border: 1px solid var(--health-gray-border);
  color: #cbd5e1;
}

/* Ad Metrics Table/Grid */
.ad-metrics-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  background: #090f1d;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.metric-item {
  display: flex;
  flex-direction: column;
}

.metric-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-val {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.metric-val.green {
  color: #10b981;
}

/* Creative Copy Preview */
.creative-copy {
  font-size: 0.78rem;
  color: var(--text-secondary);
  background: rgba(255,255,255,0.02);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border-left: 2px solid #38bdf8;
  max-height: 75px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: pre-line;
}

/* Tables for Adsets and Campaigns */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow-x: auto;
  box-shadow: var(--shadow-sm);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.data-table th {
  background: #0b1120;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  color: var(--text-primary);
}

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

/* PIN Lock Screen Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(7, 11, 20, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal-overlay.hidden {
  display: none;
}

.pin-card {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

.pin-icon {
  font-size: 2.5rem;
  margin-bottom: 12px;
}

.pin-title {
  font-size: 1.3rem;
  font-weight: 800;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.pin-desc {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.pin-input {
  width: 100%;
  background: #090f1e;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 12px;
  font-size: 1.4rem;
  text-align: center;
  letter-spacing: 0.3em;
  color: var(--text-primary);
  margin-bottom: 14px;
  outline: none;
}

.pin-input:focus {
  border-color: #38bdf8;
}

.pin-error {
  font-size: 0.8rem;
  color: #ef4444;
  margin-bottom: 12px;
  display: none;
}

.pin-btn {
  width: 100%;
  padding: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-md);
  background: #1877f2;
  color: #fff;
  border: none;
  cursor: pointer;
}

/* Empty State / Loading State */
.loading-box, .empty-box {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-secondary);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
