/* ============================================================================
   Chrysalis project page styles — sourced from the Chrysalis extension popup.

   PARTITIONED: every rule is nested under [data-project-page="chrysalis"], and
   this file is loaded ONLY on /projects/chrysalis (via the project's
   `pageStylesheet` frontmatter). It cannot affect the site nav, footer, or any
   other page. The popup's fixed-window sizing (480px width, overflow:hidden)
   is adapted into a page panel.
   ============================================================================ */

/* Chrysalis brand fonts — fetched here so they load ONLY on this page. */
@import url("https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,600&family=Hanken+Grotesk:wght@400;500;600;700&family=Spline+Sans+Mono:wght@400&display=swap");

[data-project-page="chrysalis"] {
  /* canvas + surfaces */
  --canvas: #f8f5ed;
  --canvas-2: #f0ece2;
  --card: #ffffff;
  --line: #e6e2d8;
  --line-strong: #d8d3c6;

  /* ink / text */
  --ink: #16150f;
  --ink-2: #56524a;
  --ink-3: #8a857a;

  /* primary action = ink, NOT a gradient */
  --primary: #2d2b25;
  --primary-hover: #3a382f;

  /* semantic state */
  --good: #0f8f63;
  --good-bg: #e7f4ee;
  --good-line: #bfe3d3;

  /* data-source identity colors */
  --monarch: #ef6c2b;
  --monarch-bg: #fdeee4;
  --monarch-ink: #c1521b;
  --projlab: #2f6bff;
  --projlab-bg: #e8efff;
  --projlab-ink: #1f4fcc;

  /* shadows */
  --shadow-sm: 0 1px 2px rgba(28, 25, 15, 0.05), 0 1px 1px rgba(28, 25, 15, 0.04);
  --shadow-md: 0 6px 16px -6px rgba(28, 25, 15, 0.12), 0 2px 6px -2px rgba(28, 25, 15, 0.08);

  /* radii */
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;

  /* warning state (distinct ochre — not the Monarch amber) */
  --yellow: #b45309;
  --yellow-bg: #fdf3e7;
  --yellow-line: #f0d9b5;

  /* legacy aliases mapped onto the new palette */
  --bg: var(--card);
  --surface: var(--card);
  --border: var(--line);
  --text: var(--ink);
  --muted: var(--ink-2);
  --accent: var(--projlab);
  --monarch-blue: var(--projlab);
  --green: var(--good);
  --red: #dc2626;
  --gradient: var(--primary);
  --gradient-subtle: var(--canvas-2);

  /* --- body styles adapted onto the page panel (window sizing dropped) --- */
  font-family: "Hanken Grotesk", -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  padding: clamp(1.25rem, 4vw, 2rem);
  margin-block: 1rem;

  & * {
    box-sizing: border-box;
  }

  .header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    background: transparent;
  }
  .logo {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    flex-shrink: 0;
    object-fit: cover;
    background: #fff;
    display: block;
    box-shadow: var(--shadow-sm);
  }
  .title-wrap {
    flex: 1;
    min-width: 0;
  }
  .title {
    font-family: "Fraunces", Georgia, serif;
    font-weight: 600;
    font-size: 18px;
    letter-spacing: -0.01em;
    color: var(--ink);
  }
  .subtitle {
    font-size: 12px;
    color: var(--ink-2);
  }
  .setup-btn {
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-2);
    background: none;
    border: none;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 8px;
    text-decoration: none;
  }
  .setup-btn:hover {
    background: var(--canvas-2);
    color: var(--ink);
  }
  .main {
    padding: 16px;
    min-height: 120px;
  }
  .status-bar {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 999px;
    margin-bottom: 14px;
    font-size: 13px;
    font-weight: 500;
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    color: var(--ink-2);
  }
  .status-bar.yellow {
    background: var(--yellow-bg);
    border-color: var(--yellow-line);
    color: var(--yellow);
  }
  .status-bar.gray {
    color: var(--ink-2);
  }
  .status-bar.green {
    background: var(--good-bg);
    border-color: var(--good-line);
    color: var(--good);
  }
  .status-bar-hidden {
    display: none !important;
  }
  .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .dot.gray {
    background: var(--ink-3);
  }
  .dot.green {
    background: var(--good);
  }
  .dot.yellow {
    background: var(--yellow);
  }
  .cta-card {
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    border-radius: var(--r-md);
    padding: 16px;
    margin-bottom: 14px;
  }
  .cta-card p {
    margin: 0 0 12px;
    color: var(--ink-2);
    font-size: 13px;
    line-height: 1.5;
  }
  .btn {
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 11px 18px;
    border-radius: var(--r-sm);
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background 0.15s, box-shadow 0.15s, transform 0.05s;
  }
  .btn:active:not(:disabled) {
    transform: translateY(1px);
  }
  .btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
    box-shadow: var(--shadow-md);
  }
  .btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    box-shadow: var(--shadow-lg);
    transform: translateY(-1px);
  }
  .btn-primary:disabled {
    background: var(--line-strong);
    color: var(--ink-3);
    cursor: not-allowed;
    box-shadow: none;
  }
  .btn-secondary {
    background: transparent;
    color: var(--ink-2);
    border: 1px solid var(--line-strong);
  }
  .btn-secondary:hover {
    background: var(--canvas-2);
    border-color: var(--line-strong);
    color: var(--ink);
  }
  .sync-wrap {
    position: relative;
  }
  .sync-wrap-top {
    margin-bottom: 14px;
  }
  .btn-sync-now {
    font-size: 14px;
    font-weight: 600;
    padding: 12px 20px;
  }
  .sync-history-block {
    margin-top: 16px;
  }
  .sync-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
  }
  .sync-history-title {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
  }
  .sync-history-open-link {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-2);
    text-decoration: none;
  }
  .sync-history-open-link:hover {
    color: var(--ink);
    text-decoration: underline;
  }
  .sync-history-rows {
    display: flex;
    flex-direction: column;
    gap: 0;
  }
  .sync-history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
  }
  .sync-history-row:first-child {
    border-top: 1px solid var(--border);
  }
  .sync-history-row:hover {
    background: var(--canvas-2);
  }
  .sync-history-time {
    color: var(--ink-2);
    flex-shrink: 0;
  }
  .sync-history-summary {
    color: var(--ink);
    word-break: break-word;
  }
  .sync-wrap .tooltip {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    margin-bottom: 6px;
    padding: 8px 12px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 12px;
    color: var(--ink-2);
    box-shadow: var(--shadow-md);
    display: none;
    z-index: 2;
  }
  .sync-wrap.has-tooltip .tooltip {
    display: block;
  }
  .spinner {
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    opacity: 0.8;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
  }
  .summary {
    font-size: 13px;
    margin-bottom: 10px;
    font-weight: 500;
  }
  .summary.ok {
    color: var(--green);
  }
  .summary.warn {
    color: var(--yellow);
  }
  .summary.fail {
    color: var(--red);
  }
  .result-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .result-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px;
    border-radius: 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    background: var(--bg);
  }
  .result-row.success {
    background: var(--good-bg);
    border-color: var(--good-line);
  }
  .result-row.fail {
    background: #fef2f2;
    border-color: #fecaca;
  }
  .result-icon {
    flex-shrink: 0;
    font-size: 14px;
  }
  .result-row.success .result-icon {
    color: var(--green);
  }
  .result-row.fail .result-icon {
    color: var(--red);
  }
  .result-body {
    flex: 1;
    min-width: 0;
  }
  .result-pl-name {
    font-weight: 600;
    color: var(--text);
  }
  .result-detail {
    font-size: 11px;
    color: var(--muted);
    margin-top: 2px;
  }
  .result-warning {
    font-size: 11px;
    color: var(--yellow);
    margin-top: 4px;
  }
  .result-error {
    font-size: 11px;
    color: var(--red);
    margin-top: 4px;
  }
  .result-error-banner {
    font-size: 12px;
    color: var(--red);
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 12px;
  }
  .result-balance {
    font-weight: 600;
    flex-shrink: 0;
  }
  .result-balance.positive {
    color: var(--green);
  }
  .result-balance.negative {
    color: var(--red);
  }
  .sync-details-section {
    margin-top: 14px;
    padding: 14px;
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    border-radius: var(--r-md);
    font-size: 12px;
  }
  .sync-details-title {
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text);
  }
  .sync-details-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
  }
  .sync-details-table tbody tr.success .sync-detail-result {
    color: var(--green);
  }
  .sync-details-table tbody tr.fail .sync-detail-result {
    color: var(--red);
  }
  .sync-details-table tbody tr {
    border-bottom: 1px solid var(--border);
  }
  .sync-details-table .sync-detail-name {
    padding: 6px 8px 6px 0;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
  }
  .sync-details-table .sync-detail-payload {
    padding: 6px 8px;
    font-size: 10px;
    word-break: break-all;
    color: var(--muted);
  }
  .sync-details-table .sync-detail-result {
    padding: 6px 0;
    font-weight: 500;
  }
  .debug-section {
    margin-top: 12px;
    padding: 12px;
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    border-radius: var(--r-md);
    font-size: 12px;
  }
  .debug-toggle {
    background: none;
    border: none;
    color: var(--ink-2);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    padding: 0;
    text-align: left;
    font-family: inherit;
  }
  .debug-toggle:hover {
    color: var(--ink);
    text-decoration: underline;
  }
  .debug-content pre {
    margin: 0;
    padding: 10px;
    background: var(--canvas-2);
    border-radius: 8px;
    font-size: 10px;
    overflow: auto;
    max-height: 120px;
    border: 1px solid var(--line);
    font-family: "Spline Sans Mono", ui-monospace, monospace;
  }
  .last-sync-card {
    margin-top: 10px;
    border-radius: var(--r-md);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-sm);
    background: var(--card);
    padding: 10px 12px;
  }
  .last-sync-head {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
  }
  .last-sync-title {
    font-weight: 600;
    font-size: 13px;
    color: var(--text);
  }
  .last-sync-summary {
    margin-left: auto;
    font-size: 12px;
    color: var(--muted);
  }
  .last-sync-chevron {
    margin-left: 6px;
    width: 16px;
    height: 16px;
    color: var(--muted);
    flex-shrink: 0;
    transition: transform 0.2s ease;
  }
  .last-sync-chevron svg {
    width: 100%;
    height: 100%;
    display: block;
  }
  .last-sync-card.collapsed .last-sync-chevron {
    transform: rotate(-90deg);
  }
  .last-sync-body {
    margin-top: 8px;
  }
  .last-sync-card.collapsed .last-sync-body {
    display: none;
  }
  .popup-footer {
    display: flex;
    align-items: center;
    margin-top: 12px;
    border-top: 1px solid var(--line);
    padding: 8px 12px 10px;
    gap: 8px;
  }
  .popup-footer-spacer {
    flex: 1;
    min-width: 0;
  }
  .coffee-footer {
    flex: 0 0 auto;
    text-align: center;
    padding: 0;
    margin: 0;
    border: none;
  }
  .popup-footer-actions {
    flex: 1;
    min-width: 0;
    display: flex;
    justify-content: flex-end;
    align-items: center;
  }
  .coffee-footer a {
    font-size: 11px;
    color: var(--ink-3);
    text-decoration: none;
    transition: color 0.15s;
  }
  .coffee-footer a:hover {
    color: var(--ink);
  }
  .help-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 1px solid var(--line-strong);
    background: var(--card);
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
    transition: border-color 0.15s, color 0.15s, background 0.15s, box-shadow 0.15s;
    flex-shrink: 0;
  }
  .help-icon-link:hover {
    border-color: var(--line-strong);
    color: var(--ink);
    background: var(--canvas-2);
    box-shadow: var(--shadow-sm);
  }
  /* Rating prompt — the loudest callout: dark card, gold stars, glowing CTA */
  .rating-prompt {
    margin-top: 16px;
    padding: 16px 16px 14px;
    background: var(--primary);
    border: 1px solid #2c2a20;
    border-radius: var(--r-md);
    font-size: 13.5px;
    font-weight: 600;
    color: #ffffff;
    line-height: 1.5;
    box-shadow: var(--shadow-lg);
    animation: rating-glow 2.8s ease-in-out infinite;
  }
  .rating-prompt::before {
    content: "★★★★★";
    display: block;
    color: #ffc02e;
    font-size: 16px;
    letter-spacing: 3px;
    margin-bottom: 7px;
  }
  .rating-prompt-actions {
    margin-top: 13px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
  }
  .rating-prompt-store-link {
    font-weight: 700;
    font-size: 12.5px;
    color: var(--ink);
    background: #ffc02e;
    text-decoration: none;
    padding: 8px 15px;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(255, 192, 46, 0.35);
    transition: background 0.15s, transform 0.05s;
  }
  .rating-prompt-store-link:hover {
    background: #ffce52;
    text-decoration: none;
  }
  .rating-prompt-store-link:active {
    transform: translateY(1px);
  }
  .rating-prompt-dismiss {
    background: none;
    border: none;
    padding: 0;
    font-size: 12px;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.6);
    cursor: pointer;
    font-family: inherit;
    text-decoration: underline;
  }
  .rating-prompt-dismiss:hover {
    color: #ffffff;
  }

  @media (prefers-reduced-motion: reduce) {
    .rating-prompt {
      animation: none;
    }
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@keyframes rating-glow {
  0%,
  100% {
    box-shadow: 0 10px 26px -10px rgba(28, 25, 15, 0.4), 0 0 0 0 rgba(255, 192, 46, 0);
  }
  50% {
    box-shadow: 0 12px 30px -10px rgba(28, 25, 15, 0.5), 0 0 0 3px rgba(255, 192, 46, 0.3);
  }
}
