/*
 * FILE: miniapp/dist/styles.css
 * WHAT IT DOES: the whole dependency-free dark theme of the mini-app — landing
 *   card, channel list, legal footer, dashboard shell, metric cards, tables,
 *   campaign cards, the per-channel overview table and the two responsive
 *   breakpoints (900px, 560px). No font or image is fetched.
 * INPUT: the class names used by index.html and app.js; nothing else.
 * OUTPUT: the rendered look. Served as /styles.css?v=<token>; that token must
 *   stay identical to the app.js token in index.html.
 */

:root {
  --brand: #a93cff;
  --brand-deep: #6e00f9;
  --text: #f2f2f4;
  --muted: #a6a6ad;
  --bg: #17171b;
  --panel: #202127;
  --line: rgba(255, 255, 255, 0.14);
}

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

html,
body {
  margin: 0;
  padding: 0;
}

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

.card {
  width: 100%;
  max-width: 420px;
  margin: min(15vh, 120px) auto 0;
  text-align: center;
}

h1 {
  margin: 0 0 10px;
  font-size: 23px;
  font-weight: 700;
  line-height: 1.2;
}

.subtitle {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
}

.spinner {
  width: 32px;
  height: 32px;
  margin: 0 auto 17px;
  border: 3px solid rgba(169, 60, 255, 0.22);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.actions {
  display: block;
}

.btn {
  display: block;
  width: 100%;
  margin: 11px 0;
  padding: 16px 20px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
  background: transparent;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
}

.btn--primary {
  border: 0;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-deep) 100%);
  box-shadow: 0 10px 26px rgba(110, 0, 249, 0.4);
  color: #fff;
  font-size: 18px;
}

.btn--secondary {
  padding: 13px 20px;
  color: #cbb2ff;
  font-size: 15px;
  font-weight: 600;
}

.channel-direct {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  margin: 1px 0 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

/* One row per active channel: the title reads left, the button stays compact
   on the right and wraps under the title on a narrow phone. */
.channel-list {
  display: grid;
  gap: 10px;
  margin: 4px 0 0;
  text-align: left;
}

.channel-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1.5px solid var(--line);
  border-radius: 14px;
}

.channel-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

.channel-open {
  width: auto;
  margin: 0;
  padding: 10px 16px;
  white-space: nowrap;
}

.card .control-button {
  margin-top: 10px;
}

/* D20: the legal links sit under both the landing card and the dashboard. */
.legal-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  justify-content: center;
  width: min(1280px, 100%);
  margin: 32px auto 8px;
}

.legal-footer a {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  text-decoration: none;
}

.legal-footer a:hover {
  text-decoration: underline;
}

[hidden] {
  display: none !important;
}

button,
input,
select {
  font: inherit;
}

.dashboard {
  width: 100%;
}

.dashboard-shell {
  width: min(1280px, 100%);
  margin: 0 auto;
}

.dashboard-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 24px;
  margin: 8px 0 26px;
}

.dashboard-header h1 {
  margin: 2px 0 6px;
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: -0.035em;
}

.eyebrow {
  margin: 0;
  color: #c58aff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.dashboard-note,
.section-heading p,
.login-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

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

.control-button {
  min-height: 42px;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: #282932;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
}

.control-button:hover {
  border-color: rgba(197, 138, 255, 0.65);
}

.control-button:disabled {
  opacity: 0.45;
  cursor: default;
}

.control-button--primary {
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--brand-deep));
}

.control-button--quiet {
  background: transparent;
}

.login-panel,
.paid-totals-panel,
.campaigns-panel,
.data-panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.18);
}

.login-panel {
  max-width: 520px;
  margin: 12vh auto 0;
  padding: 26px;
}

.login-panel h2,
.section-heading h2 {
  margin: 0 0 5px;
  font-size: 20px;
}

.login-form {
  display: grid;
  gap: 13px;
  margin-top: 22px;
}

.login-form label,
.filters label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  min-height: 43px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
  background: #17181d;
  color: var(--text);
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(169, 60, 255, 0.15);
}

.form-error,
.dashboard-status {
  min-height: 20px;
  margin: 14px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.form-error,
.dashboard-status--error {
  color: #ff9a9f;
}

.filters {
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}

.metric-card {
  min-height: 112px;
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: linear-gradient(145deg, #23242b, #1d1e24);
}

.metric-card span {
  display: block;
  min-height: 34px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.25;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
  line-height: 1;
}

.metric-card--accent strong { color: #c58aff; }
.metric-card--positive strong { color: #66d69d; }
.metric-card--negative strong { color: #ff8d94; }
.metric-card--return strong { color: #70b7ff; }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 0 20px 20px;
}

.panel-warning {
  min-height: 18px;
  margin: -7px 20px 17px;
  color: #ffc27a;
  font-size: 12px;
  font-weight: 700;
}

.data-panel {
  margin-top: 12px;
  overflow: hidden;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 19px 20px 15px;
}

.ad-spend-status {
  max-width: 520px;
  align-self: center;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.4;
  text-align: right;
}

.ad-spend-status--fresh { color: #79e3aa; }

.ad-spend-status--stale,
.ad-spend-status--unavailable { color: #ffc27a; }

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.sources-table {
  min-width: 1640px;
}

.paid-metric {
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 13px 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.035em;
  text-transform: uppercase;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

.table-action {
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid rgba(197, 138, 255, 0.45);
  border-radius: 9px;
  background: rgba(169, 60, 255, 0.1);
  color: #d6a7ff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.table-action:hover {
  border-color: #c58aff;
  background: rgba(169, 60, 255, 0.18);
}

.table-action:disabled {
  opacity: 0.55;
  cursor: default;
}

.source-name {
  display: block;
  max-width: 240px;
  overflow: hidden;
  font-weight: 700;
  text-overflow: ellipsis;
}

.source-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
}

.empty-state {
  margin: 0;
  padding: 24px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--muted);
  text-align: center;
}

.dashboard-status {
  display: block;
  min-height: 20px;
  margin-top: 14px;
  text-align: right;
}

@media (max-width: 900px) {
  body { padding: 16px; }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 560px) {
  .dashboard-header { display: block; }
  .header-actions { margin-top: 16px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .metric-card { min-height: 100px; }
  .filters { grid-template-columns: 1fr; }
  .login-panel { margin-top: 6vh; padding: 20px; }
  .data-panel .section-heading { display: block; }
  .data-panel .ad-spend-status { margin-top: 9px; text-align: left; }
}

/* --- Campaign clarity (campaign-dashboard-clarity.md) -------------------- */

.filters--top {
  /* Channel, period and source; the two blocks at the end of this file fold
     them back to two columns and then one. */
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  max-width: 740px;
  margin-bottom: 10px;
}

.basis-note {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.paid-totals-panel,
.campaigns-panel {
  margin-bottom: 18px;
  overflow: hidden;
}

.paid-totals-panel .ad-spend-status {
  margin: 0 18px 14px;
}

.filter-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  font-size: 13px;
}

.section-details {
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  padding: 0 18px 6px;
}

.section-details > summary {
  cursor: pointer;
  padding: 14px 0;
  font-weight: 700;
  font-size: 15px;
  list-style-position: inside;
}

.section-details .data-panel {
  border: 0;
  box-shadow: none;
  background: transparent;
}

.details-caption,
.legend p {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.legend-boundary,
.legend-footnote {
  border-left: 3px solid var(--line);
  padding-left: 10px;
}

.campaign-cards {
  display: grid;
  gap: 12px;
  padding: 0 18px 14px;
}

.campaign-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px 16px;
  display: grid;
  gap: 8px;
}

.campaign-card h3 {
  margin: 0;
  font-size: 16px;
}

.campaign-card .money-line {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
}

.chain {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chain-step {
  display: grid;
  gap: 2px;
  min-width: 84px;
}

.chain-step span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.chain-step strong { font-size: 15px; }

.chain-arrow {
  align-self: center;
  color: var(--muted);
}

.card-status {
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.card-status--alert { color: #ff9da4; }
.campaign-card .table-action { justify-self: start; }

.campaigns-panel .panel-warning,
.paid-totals-panel .panel-warning { min-height: 0; }

.metric-card small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

@media (max-width: 560px) {
  .chain { gap: 4px 8px; }
  .chain-step { min-width: 40%; }
  .chain-arrow { display: none; }
  .channel-open { width: 100%; }
}

/* --- Channels: selector, overview table and unbound campaigns (Part 4/5) - */

.overview-panel {
  margin-bottom: 18px;
}

.overview-table {
  min-width: 1180px;
}

.cell-meta {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.campaign-card h3 .campaign-channel {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

@media (max-width: 900px) {
  .filters--top { grid-template-columns: repeat(2, 1fr); max-width: 500px; }
}

@media (max-width: 560px) {
  .filters--top { grid-template-columns: 1fr; }
}

/* The two static legal pages (privacy.html, legal.html). They reuse .card, so
   they only need readable running text: the app itself never renders long
   paragraphs or lists outside a table. */
.legal-page {
  text-align: left;
  max-width: 44rem;
}

.legal-page h2 {
  margin: 1.6em 0 0.4em;
  font-size: 1.05rem;
}

.legal-page p,
.legal-page li {
  line-height: 1.55;
  color: var(--text);
}

.legal-page ul {
  padding-left: 1.1rem;
  margin: 0.4em 0;
}

.legal-page li {
  margin-bottom: 0.3em;
}

.legal-back {
  margin-top: 2em;
}
