/* Costi del mese — widget della home dev.cgctrl.app, disegnati da costs.js nella sezione #costs.
   Identità della plancia: token della home (--panel, --accent, --font-display…), card con bagliori
   fucsia/verde/arancio, Orbitron per titoli e cifre, Inter per il testo. Nessuna risorsa esterna.
   Colori dei dati: stessa tinta dell'identità, luminosità OKLCH portata nella banda scura 0,48–0,67
   (validata: GitHub e Railway, le due serie che compaiono insieme nel totale, passano tutti i
   controlli CVD e di contrasto su #161618). Il neon resta sul «cromo»: titoli, icone, bordi. */

.cx {
  --cx-text: var(--text, #ededf0);
  --cx-muted: var(--muted, #a1a1aa);
  --cx-label: #8e8e99;                 /* etichette: 5,6:1 sulla card, --faint è troppo tenue per il testo */
  --cx-faint: var(--faint, #5c5c66);
  --cx-line: rgba(255, 255, 255, 0.08);
  --cx-panel: var(--panel, #141416);
  --cx-panel-2: var(--panel-2, #18181b);
  --cx-surface: #161618;               /* superficie media della card: anello dei marker */
  --cx-track: #26262c;
  --cx-time: #8e8e99;                  /* avanzamento del periodo: neutro, non è una spesa */
  --cx-warn: var(--yellow, #ffe70f);
  --cx-danger: var(--red, #ff4d6d);
  --cx-sk1: #1a1a1e;
  --cx-sk2: #27272d;
  --cx-display: var(--font-display, "Orbitron", ui-sans-serif, system-ui, sans-serif);
  --cx-gh: var(--accent, #ff2bd0);     --cx-gh-mark: #f518c7;
  --cx-nf: var(--green, #5cff7a);      --cx-nf-mark: #07b03f;
  --cx-rw: var(--accent-2, #ff8a1f);   --cx-rw-mark: #db7204;
  position: relative;
  margin-top: 34px;
  padding-top: 28px;
  color: var(--cx-text);
}
.cx[hidden], .cx [hidden] { display: none !important; }
.cx::before {
  content: ""; position: absolute; top: 0; left: 8%; right: 8%; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(255, 43, 208, 0.45), rgba(255, 138, 31, 0.35), transparent);
}
.cx-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------- intestazione ---------- */
.cx-head { display: flex; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; gap: 12px 16px; margin-bottom: 16px; }
.cx-heading { flex: 1 1 14rem; min-width: 0; }
.cx-title {
  display: flex; align-items: center; gap: 11px;
  font-family: var(--cx-display); font-weight: 700; font-size: 0.92rem; letter-spacing: 0.22em;
  text-transform: uppercase; color: var(--cx-text);
}
.cx-title::before {
  content: ""; width: 8px; height: 8px; border-radius: 2px; transform: rotate(45deg); flex-shrink: 0;
  background: var(--cx-gh); box-shadow: 0 0 10px var(--cx-gh);
}
.cx-meta { margin-top: 7px; min-height: 1.4em; font-size: 0.8rem; line-height: 1.5; color: var(--cx-muted); }
.cx-month { color: var(--cx-text); font-weight: 600; }
.cx-flag { color: var(--cx-label); }
.cx-flag.is-warn { color: var(--cx-warn); }

/* ---------- pulsanti (stessa famiglia della chip «Account Admin») ---------- */
.cx-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 16px; border-radius: 999px; cursor: pointer; white-space: nowrap;
  font-family: var(--cx-display); font-size: 0.62rem; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--cx-muted); background: var(--cx-panel-2); border: 1px solid var(--cx-line);
  transition: color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.cx-btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.cx-btn:hover { color: var(--cx-gh); border-color: color-mix(in srgb, var(--cx-gh) 40%, transparent); }
.cx-btn:focus-visible { outline: 2px solid var(--cx-gh); outline-offset: 3px; }
.cx-btn.is-busy { cursor: progress; }
.cx-btn.is-busy svg { animation: cx-spin 0.9s linear infinite; }
.cx-btn-primary {
  color: #0b0b0d; font-weight: 700; background: var(--cx-gh); border-color: var(--cx-gh);
  box-shadow: 0 0 18px -4px var(--cx-gh);
}
.cx-btn-primary:hover { color: #0b0b0d; border-color: var(--cx-gh); box-shadow: 0 0 26px -2px var(--cx-gh); }

/* ---------- totale ---------- */
.cx-total {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 30px;
  margin-bottom: 16px; padding: 18px 22px; border-radius: 18px; border: 1px solid var(--cx-line); overflow: hidden;
  background:
    radial-gradient(520px 150px at 0% 0%, color-mix(in srgb, var(--cx-gh) 12%, transparent), transparent 70%),
    radial-gradient(520px 150px at 100% 100%, color-mix(in srgb, var(--cx-rw) 10%, transparent), transparent 70%),
    linear-gradient(160deg, var(--cx-panel) 0%, var(--cx-panel-2) 100%);
}
.cx-total-main { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.cx-total-value {
  font-family: var(--cx-display); font-weight: 700; font-size: clamp(1.9rem, 5.2vw, 2.5rem); line-height: 1;
  color: var(--cx-text); text-shadow: 0 0 22px rgba(255, 43, 208, 0.28); overflow-wrap: anywhere;
}
.cx-parts { list-style: none; display: flex; flex-wrap: wrap; gap: 8px 22px; }
.cx-part { display: inline-flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--cx-muted); }
.cx-part b { color: var(--cx-text); font-weight: 600; }
.cx-key { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.cx-key-github { background: var(--cx-gh-mark); }
.cx-key-railway { background: var(--cx-rw-mark); }
.cx-total-note { margin-left: auto; font-size: 0.74rem; color: var(--cx-label); }

/* ---------- griglia: GitHub a tutta larghezza, Netlify e Railway affiancate ---------- */
.cx-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; }
.cx-grid, .cx-total { transition: opacity 0.2s ease; }
.cx.is-refreshing .cx-grid, .cx.is-refreshing .cx-total { opacity: 0.55; }
@media (min-width: 700px) {
  .cx-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
  .cx-grid > .cx-github { grid-column: 1 / -1; }
  .cx-github[data-status="ok"] .cx-card-body {
    display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 18px 34px; align-items: start;
  }
}

/* ---------- card ---------- */
.cx-card, .cx-compact {
  --c: var(--cx-gh); --m: var(--cx-gh-mark);
  position: relative; min-width: 0; border-radius: 18px; border: 1px solid var(--cx-line); overflow: hidden;
  background:
    radial-gradient(380px 160px at 100% 0%, color-mix(in srgb, var(--c) 11%, transparent), transparent 72%),
    linear-gradient(160deg, var(--cx-panel) 0%, var(--cx-panel-2) 100%);
}
.cx-card::before, .cx-compact::before {
  content: ""; position: absolute; inset: 0; border-radius: 18px; padding: 1px; pointer-events: none;
  background: linear-gradient(160deg, color-mix(in srgb, var(--c) 55%, transparent), transparent 55%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude; opacity: 0.5;
}
.cx-card { display: flex; flex-direction: column; gap: 16px; padding: 20px 20px 18px; }
.cx-card:not(.is-skeleton) { animation: cx-in 0.28s ease-out both; }
.cx-netlify { --c: var(--cx-nf); --m: var(--cx-nf-mark); }
.cx-railway { --c: var(--cx-rw); --m: var(--cx-rw-mark); }
.cx-card[data-status="not_configured"] { --c: var(--cx-faint); --m: var(--cx-faint); }
.cx-card[data-status="not_configured"] .cx-card-title { color: var(--cx-muted); text-shadow: none; }

.cx-card-head { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cx-icon {
  width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; color: var(--c);
  background: color-mix(in srgb, var(--c) 12%, transparent); border: 1px solid color-mix(in srgb, var(--c) 30%, transparent);
}
.cx-icon svg { width: 20px; height: 20px; filter: drop-shadow(0 0 6px color-mix(in srgb, var(--c) 70%, transparent)); }
.cx-card-titles { flex: 1 1 auto; min-width: 0; }
.cx-card-title {
  font-family: var(--cx-display); font-weight: 700; font-size: 1rem; line-height: 1.2; letter-spacing: 0.14em;
  text-transform: uppercase; color: var(--c); text-shadow: 0 0 10px color-mix(in srgb, var(--c) 45%, transparent);
}
.cx-card-sub { margin-top: 3px; font-size: 0.76rem; color: var(--cx-label); overflow-wrap: anywhere; }
.cx-chips { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: 55%; }
.cx-chip {
  padding: 4px 8px; border-radius: 6px; white-space: nowrap;
  font-family: var(--cx-display); font-size: 0.54rem; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--cx-muted); background: rgba(255, 255, 255, 0.03); border: 1px solid var(--cx-line);
}
.cx-chip.is-plan { color: var(--c); background: color-mix(in srgb, var(--c) 10%, transparent); border-color: color-mix(in srgb, var(--c) 30%, transparent); }
.cx-chip.is-alert, .cx-chip.is-error {
  color: #ffd3dc; background: color-mix(in srgb, var(--cx-danger) 16%, transparent);
  border-color: color-mix(in srgb, var(--cx-danger) 55%, transparent);
}
.cx-chip.is-warn {
  color: #fff4a8; background: color-mix(in srgb, var(--cx-warn) 10%, transparent);
  border-color: color-mix(in srgb, var(--cx-warn) 45%, transparent);
}
.cx-card-body { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.cx-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }

/* ---------- cifre, etichette, righe ---------- */
.cx-lead { display: flex; flex-direction: column; gap: 5px; }
.cx-figure { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.cx-figure-value {
  font-family: var(--cx-display); font-weight: 700; font-size: clamp(1.6rem, 4.6vw, 2rem); line-height: 1.05;
  color: var(--cx-text); text-shadow: 0 0 18px color-mix(in srgb, var(--c) 30%, transparent); overflow-wrap: anywhere;
}
.cx-figure-value.is-empty { color: var(--cx-label); text-shadow: none; }
.cx-figure-label, .cx-label { font-size: 0.64rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--cx-label); }
.cx-figure-sub { font-size: 0.8rem; color: var(--cx-muted); }
.cx-note { font-size: 0.78rem; line-height: 1.5; color: var(--cx-muted); }
.cx-block { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cx-row { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; }
.cx-row-label { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; }
.cx-dates, .cx-row-value { font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.cx-dates { color: var(--cx-muted); }
.cx-row-value { color: var(--cx-text); }

/* ---------- barre e misuratori (SVG: larghezze come attributi in %) ---------- */
.cx-meter { display: block; overflow: visible; }
.cx-track { fill: var(--m); fill-opacity: 0.16; }
.cx-fill { fill: var(--m); }
.cx-meter.is-time .cx-track { fill: var(--cx-track); fill-opacity: 1; }
.cx-meter.is-time .cx-fill { fill: var(--cx-time); }
.cx-limit[data-level="warn"] .cx-fill { fill: var(--cx-warn); }
.cx-limit[data-level="over"] .cx-fill { fill: var(--cx-danger); }
.cx-tick { stroke: var(--cx-text); stroke-width: 1.5; stroke-opacity: 0.5; }
.cx-tick-hard { stroke-width: 2; stroke-opacity: 0.9; }
.cx-state { display: inline-flex; align-items: center; gap: 7px; font-size: 0.78rem; color: var(--cx-muted); }
.cx-state-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--m); box-shadow: 0 0 6px var(--m); }
.cx-limit[data-level="warn"] .cx-state, .cx-limit[data-level="over"] .cx-state { color: var(--cx-text); }
.cx-limit[data-level="warn"] .cx-state-dot { background: var(--cx-warn); box-shadow: 0 0 6px var(--cx-warn); }
.cx-limit[data-level="over"] .cx-state-dot { background: var(--cx-danger); box-shadow: 0 0 6px var(--cx-danger); }
.cx-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 0.72rem; color: var(--cx-label); font-variant-numeric: tabular-nums; }
.cx-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.cx-tick-key { width: 2px; height: 12px; border-radius: 1px; background: var(--cx-text); opacity: 0.5; }
.cx-tick-key.is-hard { width: 3px; opacity: 0.9; }

.cx-bars { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.cx-bar-row { display: grid; grid-template-columns: 4.4rem minmax(0, 1fr) auto; align-items: center; gap: 10px; font-size: 0.8rem; }
.cx-bar-name { color: var(--cx-muted); }
.cx-bar-value { min-width: 5.4rem; text-align: right; color: var(--cx-text); font-variant-numeric: tabular-nums; }

/* ---------- sparkline ---------- */
.cx-readout { font-size: 0.8rem; color: var(--cx-label); font-variant-numeric: tabular-nums; }
.cx-readout b { color: var(--cx-text); font-weight: 600; }
.cx-spark-svg { display: block; overflow: visible; cursor: crosshair; touch-action: pan-y; border-radius: 6px; }
.cx-spark-svg:focus { outline: none; }
.cx-spark-svg:focus-visible { outline: 2px solid var(--c); outline-offset: 5px; }
.cx-spark-plot { overflow: visible; filter: drop-shadow(0 0 5px color-mix(in srgb, var(--m) 45%, transparent)); }
.cx-spark-base { stroke: rgba(255, 255, 255, 0.1); stroke-width: 1; }
.cx-spark-area { fill: var(--m); fill-opacity: 0.12; stroke: none; }
.cx-spark-line { fill: none; stroke: var(--m); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.cx-spark-cross { stroke: rgba(255, 255, 255, 0.35); stroke-width: 1; opacity: 0; transition: opacity 0.15s ease; }
.cx-spark.is-active .cx-spark-cross { opacity: 1; }
.cx-spark-dot { fill: var(--m); stroke: var(--cx-surface); stroke-width: 2; }
.cx-spark-axis { display: flex; justify-content: space-between; font-size: 0.68rem; color: var(--cx-label); font-variant-numeric: tabular-nums; }

.cx-more { border-top: 1px solid var(--cx-line); }
.cx-more > summary {
  display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; list-style: none;
  font-size: 0.78rem; color: var(--cx-muted); touch-action: manipulation;
}
.cx-more > summary::-webkit-details-marker { display: none; }
.cx-more > summary::before { content: "▸"; font-size: 0.7rem; color: var(--c); transition: transform 0.15s ease; }
.cx-more[open] > summary::before { transform: rotate(90deg); }
.cx-more > summary:focus-visible { outline: 2px solid var(--c); outline-offset: 2px; border-radius: 6px; }
.cx-table { width: 100%; border-collapse: collapse; margin-bottom: 6px; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.cx-table th {
  padding: 2px 0 6px; text-align: left; font-weight: 500; font-size: 0.62rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--cx-label);
}
.cx-table td { padding: 6px 0; border-top: 1px solid var(--cx-line); color: var(--cx-muted); }
.cx-table th:last-child, .cx-table td:last-child { text-align: right; }
.cx-table td:last-child { color: var(--cx-text); }

/* ---------- elenchi ---------- */
.cx-accounts { list-style: none; display: flex; flex-direction: column; }
.cx-account { display: flex; align-items: baseline; gap: 8px; min-width: 0; padding: 8px 0; border-top: 1px solid var(--cx-line); font-size: 0.8rem; }
.cx-account-name { min-width: 0; font-weight: 600; color: var(--cx-text); overflow-wrap: anywhere; }
.cx-account-kind { font-size: 0.6rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--cx-label); }
.cx-account-value { margin-left: auto; white-space: nowrap; color: var(--cx-text); font-variant-numeric: tabular-nums; }
.cx-account.is-muted .cx-account-value { color: var(--cx-label); }

.cx-facts { display: flex; flex-direction: column; }
.cx-fact { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--cx-line); font-size: 0.8rem; }
.cx-fact dt { color: var(--cx-muted); }
.cx-fact dd { text-align: right; color: var(--cx-text); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

.cx-tags, .cx-codes { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.cx-tag {
  max-width: 100%; padding: 3px 10px; border-radius: 999px; font-size: 0.74rem; overflow-wrap: anywhere;
  color: var(--cx-muted); background: rgba(255, 255, 255, 0.03); border: 1px solid var(--cx-line);
}
.cx-tag.is-more { color: var(--cx-label); }
.cx-code {
  max-width: 100%; padding: 3px 8px; border-radius: 6px; overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.74rem;
  color: var(--cx-text); background: rgba(255, 255, 255, 0.05); border: 1px solid var(--cx-line);
}

.cx-alert {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 12px;
  font-size: 0.78rem; line-height: 1.45; color: var(--cx-text); overflow-wrap: anywhere;
  background: color-mix(in srgb, var(--cx-danger) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--cx-danger) 45%, transparent);
}
.cx-alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; color: var(--cx-danger); }

/* ---------- card compatta: accesso e servizio non disponibile ---------- */
.cx-compact { display: flex; align-items: center; flex-wrap: wrap; gap: 14px 18px; padding: 18px 22px; }
.cx-compact[data-kind="unavailable"] { --c: var(--cx-rw); }
.cx-compact[data-kind="unavailable"] .cx-btn-primary {
  color: var(--cx-text); font-weight: 400; background: var(--cx-panel-2); border-color: color-mix(in srgb, var(--cx-rw) 45%, transparent);
  box-shadow: none;
}
.cx-compact[data-kind="unavailable"] .cx-btn-primary:hover { color: var(--cx-rw); }
.cx-compact-body { flex: 1 1 15rem; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.cx-compact-title {
  font-family: var(--cx-display); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--c); text-shadow: 0 0 10px color-mix(in srgb, var(--c) 45%, transparent);
}
.cx-compact-text { font-size: 0.84rem; line-height: 1.45; color: var(--cx-muted); }

/* ---------- scheletro ---------- */
.cx-sk {
  height: 11px; width: 86%; border-radius: 6px;
  background: linear-gradient(90deg, var(--cx-sk1) 0%, var(--cx-sk2) 45%, var(--cx-sk1) 90%);
  background-size: 250% 100%; animation: cx-shimmer 1.4s ease-in-out infinite;
}
.cx-sk-title { height: 18px; width: 44%; }
.cx-sk-figure { height: 30px; width: 36%; }
.cx-sk-short { width: 60%; }
.cx-sk-label { width: 7rem; }
.cx-sk-meta { display: inline-block; width: 13rem; max-width: 70%; height: 10px; vertical-align: middle; }
.cx-card.is-skeleton { gap: 14px; min-height: 200px; }
.cx-total.is-skeleton { flex-direction: column; align-items: flex-start; gap: 10px; min-height: 96px; }
.cx-total.is-skeleton .cx-sk-figure { width: 9rem; }

@keyframes cx-shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@keyframes cx-spin { to { transform: rotate(360deg); } }
@keyframes cx-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ---------- telefono ---------- */
@media (max-width: 699px) {
  .cx { margin-top: 28px; padding-top: 24px; }
  .cx-card { padding: 18px 16px 16px; }
  .cx-total, .cx-compact { padding: 16px; }
  .cx-total-note { margin-left: 0; }
}
@media (max-width: 480px) {
  .cx-compact .cx-btn { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .cx *, .cx *::before, .cx *::after { animation: none !important; transition: none !important; }
}
@media (forced-colors: active) {
  .cx::before, .cx-card::before, .cx-compact::before { display: none; }
  .cx-fill, .cx-spark-dot { fill: Highlight; }
  .cx-spark-line, .cx-tick { stroke: CanvasText; }
  .cx-track { fill: GrayText; fill-opacity: 0.35; }
}
