:root {
  --bg: #f4f8fc;
  --bg-alt: #ffffff;
  --panel: rgba(255, 255, 255, 0.96);
  --ink: #333333;
  --muted: #5f6875;
  --line: rgba(3, 46, 99, 0.12);
  --brand: #032e63;
  --brand-soft: rgba(0, 185, 255, 0.12);
  --accent: #00b9ff;
  --danger: #b9382f;
  --ok: #1f7a53;
  --shadow: 0 14px 36px rgba(3, 46, 99, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Poppins", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(180deg, #ffffff 0, #ffffff 120px, var(--bg) 120px, var(--bg) 100%);
}
a { color: inherit; }

.page-shell {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto 48px;
}

.shell-header,
.hero-strip,
.detail-hero,
.panel,
.campaign-card,
.sync-card,
.login-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.shell-header {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto 18px;
  padding: 28px 12px 18px;
  border-radius: 0;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  background: #fff;
  border: none;
  border-bottom: 1px solid rgba(3, 46, 99, 0.1);
  box-shadow: none;
}

.brand {
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  text-decoration: none;
  color: var(--brand);
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
}

.brand-mark img {
  display: block;
  width: auto;
  height: 56px;
  max-width: 140px;
}

.subtle {
  color: var(--muted);
  margin: 0;
  font-size: 0.98rem;
}

.header-actions,
.campaign-topline,
.card-foot,
.section-head,
.list-row,
.map-legend {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.user-badge,
.status-pill,
.tag-chip,
.ghost-button,
button {
  border-radius: 999px;
}

.ghost-button,
button {
  cursor: pointer;
  border: none;
  padding: 10px 16px;
  font-weight: 700;
}

button {
  background: var(--brand);
  color: white;
}

.ghost-button {
  background: transparent;
  color: var(--brand);
  border: 1px solid rgba(3, 46, 99, 0.14);
  border-radius: 999px;
}

.flash-stack {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto 18px;
}

.data-freshness-bar {
  width: min(1200px, calc(100vw - 32px));
  margin: 0 auto 18px;
  padding: 12px 16px;
  background: rgba(3, 46, 99, 0.05);
  border: 1px solid rgba(3, 46, 99, 0.12);
  color: var(--brand);
  font-size: 0.92rem;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.flash {
  padding: 12px 16px;
  border-radius: 16px;
  margin-bottom: 10px;
}

.flash.error {
  background: rgba(185, 56, 47, 0.12);
  color: var(--danger);
}

.flash.success {
  background: rgba(31, 122, 83, 0.12);
  color: var(--ok);
}

.hero-strip,
.detail-hero {
  border-radius: 0;
  padding: 38px 32px 32px;
  margin-bottom: 24px;
  display: grid;
  gap: 24px;
  grid-template-columns: 1.5fr 1fr;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.98), rgba(255,255,255,0.95)),
    linear-gradient(90deg, rgba(0, 185, 255, 0.08), transparent 40%);
  border: 1px solid rgba(3, 46, 99, 0.12);
  box-shadow: 0 16px 36px rgba(3, 46, 99, 0.06);
}

.hero-strip::before,
.detail-hero::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 6px;
  width: 100%;
  background: linear-gradient(90deg, var(--brand), var(--accent));
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  color: var(--brand);
  margin: 0 0 8px;
  font-weight: 600;
}

h1, h2, h3, p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 3.6vw, 3.25rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
  margin-bottom: 14px;
  max-width: 18ch;
  color: var(--brand);
}

.detail-title {
  font-size: clamp(1.65rem, 2.8vw, 2.5rem);
  max-width: 100%;
}

h2 {
  font-size: clamp(1.45rem, 2.2vw, 2rem);
  line-height: 1.05;
  letter-spacing: -0.03em;
  margin-bottom: 10px;
  color: var(--brand);
}

.lead {
  font-size: 1.08rem;
  color: var(--muted);
  max-width: 60ch;
  line-height: 1.45;
}

.stats-grid,
.portfolio-grid,
.detail-grid,
.sync-grid,
.hero-grid {
  display: grid;
  gap: 16px;
}

.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stats-grid.compact {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.detail-hero .stats-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-self: start;
  gap: 14px;
}

.stat-card,
.mini-stat {
  padding: 18px;
  border-radius: 0;
  background: #fff;
  border: 1px solid rgba(3, 46, 99, 0.12);
  box-shadow: inset 0 4px 0 rgba(0, 185, 255, 0.22);
}

.stat-card span,
.mini-stat span {
  color: var(--muted);
  display: block;
  margin-bottom: 6px;
}

.stat-card strong,
.mini-stat strong {
  font-size: clamp(1.45rem, 2vw, 2rem);
  line-height: 1;
  letter-spacing: -0.03em;
}

.panel,
.campaign-card,
.sync-card {
  border-radius: 0;
  padding: 26px;
  margin-bottom: 22px;
  border-color: rgba(3, 46, 99, 0.1);
  box-shadow: 0 14px 32px rgba(3, 46, 99, 0.05);
}

.filter-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  align-items: end;
}

label span {
  display: block;
  font-size: 0.9rem;
  margin-bottom: 8px;
  color: var(--muted);
}

input,
select,
textarea {
  width: 100%;
  border-radius: 16px;
  border: 1px solid var(--line);
  padding: 12px 14px;
  font: inherit;
  background: rgba(255, 255, 255, 0.85);
}

textarea { resize: vertical; }

input:disabled,
textarea:disabled {
  background: rgba(3, 46, 99, 0.05);
  color: rgba(51, 51, 51, 0.55);
  cursor: not-allowed;
}

.portfolio-grid {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.target-box,
.note-card,
.ad-preview,
.inset-panel {
  padding: 14px;
  border-radius: 12px;
  background: rgba(0, 185, 255, 0.06);
}

.code-block {
  margin: 0;
  padding: 18px;
  border-radius: 20px;
  overflow-x: auto;
  background: #182322;
  color: #e6f0ee;
  font-family: "SFMono-Regular", "Menlo", monospace;
  font-size: 0.9rem;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 14px 0;
}

.tag-chip {
  display: inline-flex;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border: 1px solid var(--tag-color);
  font-size: 0.85rem;
}

.status-pill {
  padding: 6px 12px;
  font-size: 0.85rem;
  border: 1px solid transparent;
}

.status-enabled,
.status-healthy {
  background: rgba(0, 185, 255, 0.12);
  color: var(--brand);
}

.status-paused,
.status-planned {
  background: rgba(3, 46, 99, 0.08);
  color: var(--brand);
}

.status-error {
  background: rgba(185, 56, 47, 0.12);
  color: var(--danger);
}

.detail-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 28px;
}

.meta-grid > div {
  padding: 12px 0;
  border-bottom: 1px solid rgba(29, 42, 40, 0.08);
}

.meta-grid dt {
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.meta-grid dd {
  margin: 0;
  font-size: 1.08rem;
  line-height: 1.4;
}

.wrap-anywhere {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.empty-state {
  padding: 18px;
  border-radius: 0;
  background: linear-gradient(90deg, rgba(3, 46, 99, 0.04), rgba(0, 185, 255, 0.04));
  border: 1px dashed rgba(3, 46, 99, 0.18);
}

.empty-state h3 {
  margin-bottom: 8px;
}

.empty-state p {
  margin-bottom: 0;
  color: var(--muted);
}

.ad-group-table {
  min-width: 980px;
}

.simple-list,
.note-stack {
  display: grid;
  gap: 12px;
}

.list-row {
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.list-row:last-child {
  border-bottom: none;
}

.ad-preview-grid {
  display: grid;
  gap: 12px;
}

.ad-url {
  color: var(--ok);
  font-size: 0.85rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
  min-width: 1120px;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 14px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}

.data-table th {
  white-space: nowrap;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--brand);
  font-weight: 700;
  border-bottom: 2px solid rgba(3, 46, 99, 0.18);
}

.data-table tbody tr:hover {
  background: linear-gradient(90deg, rgba(0, 185, 255, 0.05), transparent 75%);
}

.data-table td a {
  text-underline-offset: 0.16em;
  color: var(--brand);
}

.numeric {
  text-align: right !important;
  font-variant-numeric: tabular-nums;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 0;
}

.context-form .meta-grid label {
  display: block;
}

.context-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.full-width {
  grid-column: 1 / -1;
}

.chip-fieldset {
  border: 1px solid var(--line);
  padding: 14px;
  margin: 0;
}

.chip-fieldset legend {
  padding: 0 8px;
  color: var(--brand);
  font-weight: 600;
}

.chip-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.checkbox-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  background: #fff;
  flex-wrap: wrap;
}

.checkbox-chip input {
  width: auto;
}

.panel-actions {
  margin-top: 16px;
  display: flex;
  justify-content: flex-end;
}

.analysis-form {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.analysis-form label {
  min-width: 120px;
}

.analysis-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.job-status-panel {
  margin-top: 14px;
  padding: 12px 14px;
  border: 1px solid rgba(3, 46, 99, 0.12);
  background: rgba(3, 46, 99, 0.05);
  color: var(--brand);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.job-status-error {
  border-color: rgba(185, 56, 47, 0.18);
  background: rgba(185, 56, 47, 0.08);
  color: var(--danger);
}

.custom-rule-builder {
  margin-top: 14px;
  display: grid;
  gap: 12px;
}

.custom-rule-input-row {
  display: flex;
  gap: 10px;
  align-items: center;
}

.custom-rule-input-row input {
  flex: 1 1 auto;
}

.custom-chip-grid {
  min-height: 20px;
}

.checkbox-chip-custom {
  padding-right: 10px;
}

.chip-remove-button {
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid rgba(3, 46, 99, 0.16);
  background: transparent;
  color: var(--brand);
  font-size: 0.8rem;
  font-weight: 600;
}

.inline-form {
  display: inline-flex;
}

.context-status {
  margin-top: 14px;
  color: var(--brand);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.context-warning {
  color: var(--danger);
}

.ai-pill {
  min-width: 72px;
  display: inline-flex;
  justify-content: center;
  font-size: 0.76rem;
}

.ai-green {
  background: rgba(31, 122, 83, 0.12);
  color: #1f7a53;
}

.ai-yellow {
  background: rgba(191, 124, 18, 0.14);
  color: #8a5a00;
}

.ai-red {
  background: rgba(185, 56, 47, 0.12);
  color: #b9382f;
}

.ai-row-green {
  background: rgba(31, 122, 83, 0.03);
}

.ai-row-yellow {
  background: rgba(191, 124, 18, 0.04);
}

.ai-row-red {
  background: rgba(185, 56, 47, 0.05);
}

.ai-details summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
}

.ai-details summary::-webkit-details-marker {
  display: none;
}

.ai-detail-card {
  margin-top: 10px;
  padding: 12px;
  background: rgba(3, 46, 99, 0.04);
  border: 1px solid rgba(3, 46, 99, 0.12);
  min-width: 320px;
  max-width: 520px;
}

.ai-detail-card p {
  margin-bottom: 8px;
}

.recommendation-cell {
  min-width: 300px;
}

.recommendation-note {
  margin: 6px 0 0;
  color: var(--muted);
}

.manual-feedback-card {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(3, 46, 99, 0.12);
  background: rgba(0, 185, 255, 0.06);
}

.ai-details-inline {
  margin-top: 10px;
}

.ai-detail-card-inline {
  min-width: 0;
  max-width: 100%;
}

.feedback-form {
  display: grid;
  gap: 12px;
}

.feedback-form hr {
  border: 0;
  border-top: 1px solid var(--line);
  margin: 10px 0;
}

.recommendation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.recommendation-card {
  padding: 18px;
  border: 1px solid var(--line);
  background: #fff;
}

.card-actions {
  margin-top: 12px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.details-trigger {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

@media (max-width: 900px) {
  .context-grid {
    grid-template-columns: 1fr;
  }

  .custom-rule-input-row {
    flex-direction: column;
    align-items: stretch;
  }
}

.subsection {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.map-shell {
  margin-bottom: 16px;
}

.map-canvas {
  position: relative;
  height: 260px;
  border-radius: 24px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(215, 233, 250, 0.95), rgba(195, 221, 236, 0.75)),
    linear-gradient(45deg, rgba(255,255,255,0.1), rgba(15,92,77,0.1));
  border: 1px solid rgba(15, 92, 77, 0.15);
}

.map-overlay {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 35% 55%, rgba(230, 221, 196, 0.8), transparent 22%),
    radial-gradient(circle at 54% 42%, rgba(217, 206, 173, 0.8), transparent 20%),
    radial-gradient(circle at 62% 55%, rgba(197, 221, 187, 0.7), transparent 18%);
}

.map-point {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  transform: translate(-50%, -50%);
  border: 2px solid white;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.18);
}

.map-point.target { background: var(--accent); }
.map-point.company { background: var(--brand); }

.dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 50%;
}

.dot.target { background: var(--accent); }
.dot.company { background: var(--brand); }

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-layout {
  width: min(1100px, calc(100vw - 32px));
  display: grid;
  gap: 20px;
  grid-template-columns: 1.2fr 0.8fr;
}

.login-panel {
  border-radius: 30px;
  padding: 28px;
}

.hero-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 24px;
}

.hero-grid article {
  padding: 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.54);
}

.login-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

@media (max-width: 900px) {
  .hero-strip,
  .detail-hero,
  .detail-grid,
  .login-layout,
  .filter-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid.compact,
  .stats-grid,
  .hero-grid,
  .meta-grid {
    grid-template-columns: 1fr 1fr;
  }

  .detail-hero .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  h1 {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .shell-header,
  .campaign-topline,
  .card-foot,
  .section-head,
  .header-actions {
    flex-direction: column;
    align-items: flex-start;
  }

  .brand-lockup {
    align-items: flex-start;
  }

  .brand-mark img {
    height: 44px;
    max-width: 110px;
  }

  .stats-grid.compact,
  .stats-grid,
  .hero-grid,
  .meta-grid {
    grid-template-columns: 1fr;
  }

  .page-shell,
  .shell-header,
  .flash-stack,
  .login-layout {
    width: min(100vw - 20px, 100%);
  }
}
