/* ── Reset & Variables ───────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-0: #0a0a0c;
  --bg-1: #111114;
  --bg-2: #18181d;
  --bg-3: #222228;
  --border: #2a2a32;
  --border-light: #333340;
  --text-0: #f0f0f5;
  --text-1: #a0a0b0;
  --text-2: #606070;
  --accent: #f5a623;
  --accent-dim: rgba(245,166,35,0.15);
  --accent-glow: rgba(245,166,35,0.4);
  --red: #ff4757;
  --green: #2ed573;
  --blue: #3d9ef8;
  --radius: 10px;
  --radius-lg: 16px;
  --font-display: 'Syne', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'DM Mono', monospace;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 12px 48px rgba(0,0,0,0.6);
}

html, body { height: 100%; }
body {
  font-family: var(--font-body);
  background: var(--bg-0);
  color: var(--text-0);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Views ───────────────────────────────────────────────────────────────── */
.view { display: none; height: 100vh; }
.view.active { display: flex; }
#app { height: 100vh; }

/* ── Login ───────────────────────────────────────────────────────────────── */
#view-login {
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.login-bg {
  position: absolute; inset: 0;
  background: radial-gradient(ellipse at 70% 50%, rgba(245,166,35,0.06) 0%, transparent 70%),
              radial-gradient(ellipse at 20% 80%, rgba(61,158,248,0.04) 0%, transparent 60%);
}

.login-grid {
  position: absolute; inset: 0;
  background-image:
    linear-gradient(rgba(245,166,35,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(245,166,35,0.04) 1px, transparent 1px);
  background-size: 60px 60px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
}

.login-card {
  position: relative;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px;
  width: 440px;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(245,166,35,0.05);
}

.brand {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 32px;
}
.brand-icon { color: var(--accent); font-size: 22px; }
.brand-name { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: 0.02em; }

.login-title {
  font-family: var(--font-display);
  font-size: 36px; font-weight: 800;
  line-height: 1.15;
  margin-bottom: 12px;
  background: linear-gradient(135deg, var(--text-0) 40%, var(--text-1));
  background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.login-sub { color: var(--text-1); font-size: 14px; margin-bottom: 32px; line-height: 1.5; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 20px; }
.form-group label {
  display: block;
  font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-2); margin-bottom: 8px;
}

input[type="text"], input[type="password"], input[type="url"],
input[type="number"], input[type="email"], select, textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--text-0);
  font-family: var(--font-body);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
input::placeholder, textarea::placeholder { color: var(--text-2); }
textarea { resize: vertical; font-family: var(--font-mono); font-size: 12px; }
select { cursor: pointer; }
select option { background: var(--bg-2); }

.form-row { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.form-hint {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-2);
  font-family: var(--font-mono);
  line-height: 1.45;
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent);
  color: #000;
  border: none; border-radius: var(--radius);
  padding: 13px 24px;
  font-family: var(--font-display);
  font-size: 14px; font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  width: 100%;
}
.btn-primary:hover { background: #ffb838; transform: translateY(-1px); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  background: transparent;
  color: var(--text-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 20px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-ghost:hover { background: var(--bg-2); color: var(--text-0); border-color: var(--border-light); }

.btn-icon {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-1);
  cursor: pointer;
  font-size: 16px;
  transition: all 0.15s;
}
.btn-icon:hover { background: var(--bg-2); color: var(--text-0); border-color: var(--border-light); }
.btn-icon.danger:hover { background: rgba(255,71,87,0.15); color: var(--red); border-color: var(--red); }

.demo-hint {
  margin-top: 20px;
  font-size: 11px; color: var(--text-2);
  text-align: center;
  line-height: 1.6;
}
.demo-hint code {
  background: var(--bg-3); padding: 1px 5px; border-radius: 4px;
  font-family: var(--font-mono); color: var(--accent);
}

.error-msg {
  background: rgba(255,71,87,0.1);
  border: 1px solid rgba(255,71,87,0.3);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--red);
  margin-bottom: 16px;
}
.hidden { display: none !important; }

/* ── Dashboard Layout ────────────────────────────────────────────────────── */
#view-dashboard {
  flex-direction: row;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 0 8px;
  margin-bottom: 32px;
  font-family: var(--font-display); font-weight: 700; font-size: 16px;
}
.sidebar-brand .brand-icon { color: var(--accent); }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-1);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.12s;
}
.nav-item:hover { background: var(--bg-2); color: var(--text-0); }
.nav-item.active { background: var(--accent-dim); color: var(--accent); }
.nav-icon { font-size: 14px; width: 18px; text-align: center; }

.sidebar-user {
  display: flex; align-items: center; gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
.user-avatar {
  width: 34px; height: 34px;
  background: var(--accent);
  color: #000;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 800; font-size: 14px;
  flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-2); }
.logout-btn {
  background: none; border: none;
  color: var(--text-2); font-size: 16px; cursor: pointer;
  padding: 4px; border-radius: 6px;
  transition: color 0.12s;
}
.logout-btn:hover { color: var(--red); }

/* ── Main Content ────────────────────────────────────────────────────────── */
.main-content {
  flex: 1; overflow-y: auto;
  padding: 32px;
  background: var(--bg-0);
}

.section { display: none; }
.section.active { display: block; }

.section-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 28px;
}
.section-header .btn-primary { width: auto; }
.section-header h2 {
  font-family: var(--font-display);
  font-size: 26px; font-weight: 800;
  margin-bottom: 4px;
}
.section-sub { font-size: 13px; color: var(--text-1); }

/* ── Campaigns Grid ──────────────────────────────────────────────────────── */
.campaigns-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 20px;
}

.campaign-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: default;
}
.campaign-card:hover { border-color: var(--border-light); box-shadow: var(--shadow); }

.card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 16px; }
.card-name {
  font-family: var(--font-display); font-size: 16px; font-weight: 700;
  margin-bottom: 4px;
}
.card-url {
  font-size: 11px; font-family: var(--font-mono);
  color: var(--text-2); max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-badge {
  padding: 3px 8px; border-radius: 20px; font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  font-family: var(--font-mono);
}
.badge-html { background: rgba(61,158,248,0.15); color: var(--blue); }
.badge-image { background: rgba(46,213,115,0.15); color: var(--green); }

.card-meta {
  display: flex; gap: 12px; margin-bottom: 20px;
  font-size: 11px; color: var(--text-2);
}
.card-meta span { display: flex; align-items: center; gap: 4px; }

.card-actions { display: flex; gap: 8px; }
.card-actions .btn-preview {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px;
  background: var(--accent-dim);
  border: 1px solid rgba(245,166,35,0.25);
  border-radius: 8px;
  color: var(--accent);
  font-size: 12px; font-weight: 600; font-family: var(--font-display);
  cursor: pointer; transition: all 0.12s;
}
.card-actions .btn-preview:hover { background: rgba(245,166,35,0.25); }
.card-actions .btn-share {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-1); cursor: pointer;
  font-size: 15px; transition: all 0.12s;
}
.card-actions .btn-share:hover { background: var(--bg-3); color: var(--text-0); }
.card-actions .btn-edit {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-1); cursor: pointer;
  font-size: 14px; transition: all 0.12s;
}
.card-actions .btn-edit:hover { background: var(--bg-3); color: var(--text-0); }
.card-actions .btn-delete {
  display: flex; align-items: center; justify-content: center;
  width: 38px; height: 38px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-2); cursor: pointer;
  font-size: 13px; transition: all 0.12s;
}
.card-actions .btn-delete:hover { background: rgba(255,71,87,0.1); color: var(--red); border-color: rgba(255,71,87,0.3); }

.share-active-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 8px; border-radius: 20px; font-size: 10px;
  background: rgba(46,213,115,0.15); color: var(--green);
  font-family: var(--font-mono); font-weight: 600;
}

.loading-state, .empty-state {
  grid-column: 1/-1;
  text-align: center; padding: 60px 20px;
  color: var(--text-2); font-size: 14px;
}
.empty-state h3 { font-family: var(--font-display); font-size: 20px; color: var(--text-1); margin-bottom: 8px; }

/* ── Campaign Form ───────────────────────────────────────────────────────── */
.campaign-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

.form-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}
.form-card-title {
  font-family: var(--font-display);
  font-size: 14px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--text-2);
  margin-bottom: 24px;
}
.form-actions { display: flex; gap: 12px; margin-top: 8px; }
.form-actions .btn-primary { flex: 1; }
.form-actions .btn-ghost { width: auto; }

.toggle-group { display: flex; gap: 8px; }
.toggle-btn {
  flex: 1; padding: 10px; border-radius: 8px;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text-1); font-size: 13px; cursor: pointer;
  transition: all 0.12s;
}
.toggle-btn.active {
  background: var(--accent-dim);
  border-color: rgba(245,166,35,0.3);
  color: var(--accent);
}

/* ── Ad Mock Preview ─────────────────────────────────────────────────────── */
.preview-card { display: flex; flex-direction: column; }
.ad-mock-container { flex: 1; display: flex; align-items: center; justify-content: center; padding: 16px 0; }

.ad-mock-browser {
  width: 100%;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg-2);
}
.browser-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
}
.browser-dots { display: flex; gap: 5px; }
.browser-dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--border-light); }
.browser-url {
  flex: 1; background: var(--bg-2); border-radius: 4px;
  padding: 3px 8px; font-size: 10px; font-family: var(--font-mono);
  color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.browser-content { position: relative; height: 280px; overflow: hidden; }

.mock-page { padding: 16px; }
.mock-nav { height: 28px; background: var(--bg-3); border-radius: 4px; margin-bottom: 12px; }
.mock-hero { height: 80px; background: var(--bg-3); border-radius: 6px; margin-bottom: 12px; }
.mock-body { display: flex; flex-direction: column; gap: 6px; }
.mock-line { height: 8px; background: var(--border); border-radius: 3px; }
.mock-line.short { width: 60%; }

.ad-overlay {
  position: absolute;
  background: var(--bg-0);
  border: 2px solid var(--accent);
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(245,166,35,0.3);
  z-index: 10;
  min-width: 80px; min-height: 60px;
  max-width: 200px; max-height: 120px;
}
.ad-overlay.top-right { top: 12px; right: 12px; }
.ad-overlay.top-left { top: 12px; left: 12px; }
.ad-overlay.bottom-right { bottom: 12px; right: 12px; }
.ad-overlay.bottom-left { bottom: 12px; left: 12px; }
.ad-overlay.center { top: 50%; left: 50%; transform: translate(-50%,-50%); }
.ad-overlay.top-center { top: 12px; left: 50%; transform: translateX(-50%); }
.ad-overlay.bottom-center { bottom: 12px; left: 50%; transform: translateX(-50%); }
.ad-label {
  position: absolute; top: 0; left: 0;
  background: var(--accent); color: #000;
  font-size: 7px; font-family: var(--font-mono); font-weight: 600;
  padding: 1px 4px;
  z-index: 1; border-bottom-right-radius: 3px;
}
.ad-preview-inner { width: 100%; height: 100%; overflow: hidden; }

.site-picker-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.site-picker-status {
  margin-bottom: 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-2);
  color: var(--text-1);
  font-size: 11px;
  font-family: var(--font-mono);
  line-height: 1.45;
}

#cf-toggle-picker-btn.picker-active {
  background: rgba(46, 213, 115, 0.16);
  border-color: rgba(46, 213, 115, 0.5);
  color: #8bf2b1;
  box-shadow: inset 0 0 0 1px rgba(46, 213, 115, 0.3);
}

#cf-toggle-picker-btn.picker-active:hover {
  background: rgba(46, 213, 115, 0.22);
  border-color: rgba(46, 213, 115, 0.7);
  color: #b6f8cf;
}

.site-picker-stage {
  position: relative;
  flex: 1;
  min-height: 320px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.site-picker-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  cursor: crosshair;
}

.site-picker-marker {
  position: absolute;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.35);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.site-picker-box {
  position: absolute;
  border: 2px solid rgba(245, 166, 35, 0.95);
  background: rgba(245, 166, 35, 0.12);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35);
  pointer-events: none;
}

/* ── Preview Modal ───────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
}
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(4px);
}
.modal-window {
  position: relative; z-index: 1;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90vw; max-width: 1200px;
  max-height: 92vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-window.small { max-width: 480px; }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.modal-title {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display); font-weight: 700; font-size: 15px;
}
.modal-actions { display: flex; gap: 8px; }

.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }

.modal-body { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

.stream-container {
  flex: 1; overflow: hidden; position: relative;
  background: #000;
  display: flex; align-items: center; justify-content: center;
  min-height: 400px;
}
.stream-frame {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  cursor: crosshair;
}
.stream-loading, .stream-error {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  color: var(--text-1); font-size: 14px;
}
.stream-error span { font-size: 28px; }

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.stream-controls {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-2);
}
.stream-info { font-size: 11px; font-family: var(--font-mono); color: var(--text-2); }
.control-group { display: flex; gap: 8px; }
.ctrl-btn {
  padding: 6px 14px; border-radius: 6px;
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-1); font-size: 14px; cursor: pointer;
  transition: all 0.12s;
}
.ctrl-btn:hover { background: var(--bg-1); color: var(--text-0); }

/* ── Share Modal ─────────────────────────────────────────────────────────── */
.share-desc { font-size: 14px; color: var(--text-1); line-height: 1.5; margin-bottom: 20px; }

.share-toggle {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 20px; font-size: 14px;
}
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--bg-3); border: 1px solid var(--border);
  border-radius: 24px; transition: all 0.2s;
}
.slider:before {
  content: ''; position: absolute;
  height: 16px; width: 16px; left: 3px; bottom: 3px;
  background: var(--text-2); border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(20px); background: #000; }

.share-link-container { display: flex; gap: 8px; margin-bottom: 12px; }
.share-link-container input {
  flex: 1; font-family: var(--font-mono); font-size: 11px;
  background: var(--bg-2); color: var(--text-1);
}
.share-link-container .btn-primary { width: auto; flex-shrink: 0; padding: 12px 20px; }
.copy-success { font-size: 13px; color: var(--green); }

/* ── Share View (public) ─────────────────────────────────────────────────── */
#view-share {
  flex-direction: column;
  background: var(--bg-0);
}
.share-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 28px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
}
.share-stream-container {
  flex: 1; background: #000;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.share-stream-frame { width: 100%; height: 100%; object-fit: contain; }
.share-stream-frame { cursor: crosshair; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-0); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
