/**
 * Share Page — Redesigned
 * Self-contained styles; uses CSS tokens from style.css where available,
 * defines its own fallbacks so it degrades cleanly standalone.
 */

/* ── Design tokens (share-page scoped overrides / supplements) ── */
.share-page {
    --sp-green:       #059669;
    --sp-green-light: #d1fae5;
    --sp-green-dark:  #047857;
    /* Primary accent used by recipe pages' inline styles (was falling back to legacy #2e7d5b) */
    --sp-primary:      var(--sp-green);
    --sp-primary-dark: var(--sp-green-dark);
    --sp-amber:       #f59e0b;
    --sp-red:         #ef4444;
    --sp-blue:        #3b82f6;

    --grade-very_good: #16a34a;
    --grade-good:      #65a30d;
    --grade-moderate:  #ca8a04;
    --grade-weak:      #ea580c;
    --grade-very_weak: #dc2626;

    --sp-bg:       var(--color-bg, #f8fafc);
    --sp-surface:  var(--color-bg-card, #ffffff);
    --sp-border:   var(--color-border, #e2e8f0);
    --sp-text:     var(--color-text, #0f172a);
    --sp-muted:    var(--color-text-light, #64748b);
    --sp-shadow:   var(--shadow-md, 0 4px 6px -1px rgba(15,23,42,.07));
    --sp-radius:   var(--radius-xl, 1rem);
    --sp-card-gap: 1rem;

    font-family: var(--font-family, 'Inter', sans-serif);
    background: var(--sp-bg);
    color: var(--sp-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── Utility ── */
.hidden { display: none !important; }

/* ── Top bar ── */
.sp-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .75rem 1.25rem;
    background: var(--sp-surface);
    border-bottom: 1px solid var(--sp-border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.sp-logo {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-weight: 700;
    font-size: .95rem;
    color: var(--sp-text);
    text-decoration: none;
}
.sp-logo img { border-radius: 4px; }

.sp-lang {
    display: flex;
    align-items: center;
    gap: .375rem;
    font-size: .8rem;
    color: var(--sp-muted);
}
.lang-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: .8rem;
    font-weight: 600;
    color: var(--sp-muted);
    padding: .2rem .3rem;
    border-radius: 4px;
    transition: color .15s;
}
.lang-btn.active, .lang-btn:hover { color: var(--sp-green); }

/* ── Main layout ── */
.sp-main {
    flex: 1;
    max-width: 560px;
    width: 100%;
    margin: 0 auto;
    padding: 1.25rem 1rem 3rem;
    display: flex;
    flex-direction: column;
    gap: var(--sp-card-gap);
}

/* ── States ── */
.sp-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 55vh;
    gap: 1rem;
    text-align: center;
}

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

.sp-error-icon { color: var(--sp-red); opacity: .85; }
#error-state h2 { font-size: 1.25rem; font-weight: 700; margin: 0; }
#error-state p  { color: var(--sp-muted); margin: 0 0 .5rem; }

/* ── Expiry warning ── */
.sp-expiry {
    display: flex; align-items: center; gap: .5rem;
    padding: .5rem .875rem;
    background: rgba(245,158,11,.08);
    border: 1px solid rgba(245,158,11,.25);
    border-radius: var(--radius-full, 999px);
    color: #92400e;
    font-size: .8rem;
    font-weight: 500;
}
.sp-expiry svg { flex-shrink: 0; }

/* ── Card base ── */
.sp-card {
    background: var(--sp-surface);
    border-radius: var(--sp-radius);
    box-shadow: var(--sp-shadow);
    border: 1px solid var(--sp-border);
    padding: 1.25rem 1.125rem;
    animation: sp-fade-up .45s ease both;
}
.sp-card:nth-child(2)  { animation-delay: .05s; }
.sp-card:nth-child(3)  { animation-delay: .10s; }
.sp-card:nth-child(4)  { animation-delay: .15s; }
.sp-card:nth-child(5)  { animation-delay: .20s; }
.sp-card:nth-child(6)  { animation-delay: .25s; }
.sp-card:nth-child(7)  { animation-delay: .30s; }
.sp-card:nth-child(8)  { animation-delay: .35s; }
.sp-card:nth-child(9)  { animation-delay: .40s; }

@keyframes sp-fade-up {
    from { opacity: 0; transform: translateY(14px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sp-card-title {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--sp-muted);
    margin: 0 0 1rem;
}

/* ── Hero ── */
.sp-hero {
    background: var(--sp-surface);
    border-radius: var(--sp-radius);
    box-shadow: var(--sp-shadow);
    border: 1px solid var(--sp-border);
    overflow: hidden;
    animation: sp-fade-up .4s ease both;
}

.sp-hero-img {
    width: 100%;
    max-height: 260px;
    overflow: hidden;
    background: var(--sp-bg);
    display: flex;
    align-items: center;
    justify-content: center;
}
.sp-hero-img img {
    width: 100%;
    height: 260px;
    object-fit: cover;
    object-position: center;
    display: block;
}

.sp-hero-body {
    padding: 1.125rem 1.125rem 1.25rem;
}

.sp-source-badge {
    display: inline-block;
    padding: .2rem .65rem;
    border-radius: var(--radius-full, 999px);
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    background: var(--sp-green-light);
    color: var(--sp-green-dark);
    margin-bottom: .625rem;
}
.sp-source-badge.ai {
    background: linear-gradient(135deg, #ede9fe, #ddd6fe);
    color: #5b21b6;
}

.sp-product-name {
    font-family: var(--font-family-heading, 'Plus Jakarta Sans', 'Inter', sans-serif);
    font-size: 1.45rem;
    font-weight: 800;
    line-height: 1.25;
    color: var(--sp-text);
    margin: 0 0 .375rem;
    letter-spacing: -.02em;
}

.sp-product-meta {
    font-size: .875rem;
    color: var(--sp-muted);
    margin: 0;
}

.sp-barcode {
    display: inline-block;
    font-size: .75rem;
    color: var(--sp-muted);
    background: var(--sp-bg);
    padding: .15rem .45rem;
    border-radius: 4px;
    letter-spacing: .04em;
    margin-top: .375rem;
    font-family: 'Courier New', monospace;
}

/* ── Score rings (AI evaluation) ── */
.sp-rings {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.grade-ring-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .375rem;
}

.ring-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--sp-muted);
}

.ring-wrap {
    position: relative;
    width: 110px;
    height: 110px;
}

.score-ring {
    width: 110px;
    height: 110px;
    transform: rotate(-90deg);
    overflow: visible;
}

.ring-track {
    fill: none;
    stroke: var(--sp-border);
    stroke-width: 8;
}

.ring-progress {
    fill: none;
    stroke-width: 8;
    stroke-linecap: round;
    /* initial state; JS animates to target */
    stroke-dashoffset: 263.9;
    transition: stroke-dashoffset 1.3s cubic-bezier(.4,0,.2,1);
}

.ring-inner {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.ring-score {
    font-size: 1.75rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.04em;
    color: var(--sp-text);
}

.ring-unit {
    font-size: .65rem;
    font-weight: 600;
    color: var(--sp-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-top: .1rem;
}

.ring-grade {
    font-size: .8rem;
    font-weight: 700;
}

.ring-summary {
    font-size: .78rem;
    color: var(--sp-muted);
    text-align: center;
    line-height: 1.45;
    margin: 0;
    max-width: 140px;
}

/* ── NutriScore / NOVA / EcoScore ── */
.scores-grid {
    display: flex;
    gap: .875rem;
    flex-wrap: wrap;
}

.score-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .375rem;
    flex: 1 1 60px;
}

.score-label {
    font-size: .65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--sp-muted);
}

.score-badge {
    width: 52px; height: 52px;
    border-radius: var(--radius-lg, .75rem);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.4rem;
    color: #fff;
    letter-spacing: -.02em;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
    animation: sp-pop .5s var(--ease-out-back, cubic-bezier(.34,1.56,.64,1)) both;
}
@keyframes sp-pop {
    from { transform: scale(.6); opacity: 0; }
    to   { transform: scale(1);  opacity: 1; }
}

.nutriscore-a { background: #038141; }
.nutriscore-b { background: #85bb2f; }
.nutriscore-c { background: #fecb02; color: #1a1a1a; }
.nutriscore-d { background: #ee8100; }
.nutriscore-e { background: #e63e11; }

.ecoscore-a { background: #1e8f4e; }
.ecoscore-b { background: #2ecc71; }
.ecoscore-c { background: #ffc900; color: #1a1a1a; }
.ecoscore-d { background: #ef7e1a; }
.ecoscore-e { background: #e62d19; }

.nova-1 { background: #038141; }
.nova-2 { background: #fecb02; color: #1a1a1a; }
.nova-3 { background: #ee8100; }
.nova-4 { background: #e63e11; }

/* ── AI ingredient chips ── */
.sp-chips-wrap { display: flex; flex-direction: column; gap: .75rem; }
.sp-chip-group { display: flex; flex-direction: column; gap: .375rem; }

.sp-chip-label {
    font-size: .7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
}
.sp-chip-label-good { color: var(--sp-green-dark); }
.sp-chip-label-warn { color: #92400e; }

.sp-chips {
    display: flex;
    flex-wrap: wrap;
    gap: .375rem;
}

/* ai-badge — keep class name as JS uses it */
.ai-badge {
    font-size: .8rem;
    font-weight: 500;
    padding: .3rem .7rem;
    border-radius: var(--radius-full, 999px);
    border: 1px solid transparent;
}
.ai-badge.good {
    background: rgba(5,150,105,.1);
    color: var(--sp-green-dark);
    border-color: rgba(5,150,105,.2);
}
.ai-badge.concern {
    background: rgba(245,158,11,.1);
    color: #92400e;
    border-color: rgba(245,158,11,.2);
}

/* ── Nutrition table ── */
.sp-mode-toggle {
    display: flex;
    gap: .375rem;
    margin-bottom: .875rem;
    background: var(--sp-bg);
    padding: .25rem;
    border-radius: var(--radius-md, .5rem);
    border: 1px solid var(--sp-border);
}

.mode-btn {
    flex: 1;
    padding: .35rem .75rem;
    background: none;
    border: none;
    border-radius: calc(var(--radius-md, .5rem) - 2px);
    color: var(--sp-muted);
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all .15s;
}
.mode-btn.active {
    background: var(--sp-surface);
    color: var(--sp-text);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(15,23,42,.06));
}

.sp-nutrition { display: flex; flex-direction: column; }

.nutrition-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: .5rem;
    padding: .55rem 0;
    border-bottom: 1px solid var(--sp-border);
}
.nutrition-row:last-child { border-bottom: none; }

.nutrition-row-left { display: flex; flex-direction: column; gap: .25rem; }

.nutrition-label {
    font-size: .875rem;
    font-weight: 500;
    color: var(--sp-text);
}

.nutrition-bar-track {
    height: 4px;
    background: var(--sp-border);
    border-radius: 2px;
    overflow: hidden;
    width: 100%;
}

.nutrition-bar {
    height: 100%;
    border-radius: 2px;
    width: 0;
    transition: width 1s cubic-bezier(.4,0,.2,1);
}

.nutrition-value {
    display: flex;
    align-items: baseline;
    gap: .2rem;
    text-align: right;
}

.nutrition-amount {
    font-size: .9rem;
    font-weight: 700;
    color: var(--sp-text);
    font-variant-numeric: tabular-nums;
}

.nutrition-unit {
    font-size: .75rem;
    color: var(--sp-muted);
}

/* ── Nutrient levels ── */
.sp-levels { display: flex; flex-direction: column; gap: .625rem; }

.sp-level-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: .625rem;
}

.sp-level-name {
    font-size: .875rem;
    font-weight: 500;
    color: var(--sp-text);
}

/* Segmented dot indicator — categorical, not proportional */
.sp-level-dots {
    display: flex;
    gap: 5px;
    align-items: center;
}

.sp-level-dot {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--sp-border);
}

.sp-level-dot.low.active      { background: var(--grade-very_good); }
.sp-level-dot.moderate.active { background: var(--sp-amber); }
.sp-level-dot.high.active     { background: var(--sp-red); }

.sp-level-pill {
    font-size: .72rem;
    font-weight: 700;
    padding: .2rem .55rem;
    border-radius: var(--radius-full, 999px);
    text-transform: capitalize;
    white-space: nowrap;
}
.sp-level-pill.low      { background: rgba(5,150,105,.1);  color: var(--sp-green-dark); }
.sp-level-pill.moderate { background: rgba(245,158,11,.1); color: #92400e; }
.sp-level-pill.high     { background: rgba(239,68,68,.1);  color: #991b1b; }

/* ── Oko na skład Rating ── */
.sp-oko-rating { display: flex; align-items: center; gap: 16px; padding: 8px 0; }
.sp-oko-circle {
    width: 72px; height: 72px; border-radius: 50%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sp-oko-score { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.sp-oko-label { font-size: 0.7rem; opacity: 0.8; }
.sp-oko-state-label { font-size: 0.9rem; font-weight: 600; }

/* ── Additive & marker chips ── */
.sp-section-summary { font-size: 0.875rem; color: var(--sp-muted); margin: 0 0 10px; }
.sp-chips-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.sp-chip {
    display: inline-block; padding: 4px 10px; border-radius: 999px;
    font-size: 0.78rem; font-weight: 500;
}
.sp-chip-safe    { background: #dcfce7; color: #166534; }
.sp-chip-caution { background: #fef9c3; color: #713f12; }
.sp-chip-avoid   { background: #ffedd5; color: #7c2d12; }
.sp-chip-banned  { background: #fee2e2; color: #7f1d1d; }
.sp-chip-high    { background: #fee2e2; color: #991b1b; }
.sp-chip-medium  { background: #fef3c7; color: #92400e; }
.sp-chip-low     { background: #dbeafe; color: #1e40af; }

/* ── Ingredients ── */
.sp-ingredients {
    font-size: .85rem;
    line-height: 1.65;
    color: var(--sp-muted);
    margin: 0 0 .75rem;
}

.sp-tag-row {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: .25rem;
    margin-top: .625rem;
    padding-top: .625rem;
    border-top: 1px solid var(--sp-border);
    font-size: .82rem;
}
.sp-tag-label { font-weight: 600; color: var(--sp-muted); }
.sp-tag-value { color: var(--sp-text); }

/* ── User context (AI) ── */
.sp-context-card { background: var(--sp-bg); }

.user-context-item {
    padding-bottom: .875rem;
    margin-bottom: .875rem;
    border-bottom: 1px solid var(--sp-border);
}
.user-context-item:last-child { padding-bottom: 0; margin-bottom: 0; border-bottom: none; }

.context-label {
    display: flex;
    align-items: center;
    gap: .35rem;
    font-size: .72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--sp-muted);
    margin-bottom: .375rem;
}

.context-text {
    font-size: .875rem;
    line-height: 1.55;
    color: var(--sp-text);
    margin: 0;
    white-space: pre-wrap;
}

#context-response .context-text {
    background: var(--sp-surface);
    border-left: 3px solid var(--sp-green);
    padding: .625rem .875rem;
    border-radius: 0 var(--radius-md, .5rem) var(--radius-md, .5rem) 0;
}

/* ── Disclaimer ── */
.sp-disclaimer {
    display: flex;
    align-items: flex-start;
    gap: .625rem;
    padding: .75rem .875rem;
    background: rgba(245,158,11,.06);
    border: 1px solid rgba(245,158,11,.2);
    border-radius: var(--radius-lg, .75rem);
    color: #78350f;
    font-size: .8rem;
    line-height: 1.5;
}
.sp-disclaimer svg { flex-shrink: 0; margin-top: 1px; stroke: #92400e; }
.sp-disclaimer p { margin: 0; }

/* ── CTA ── */
.sp-cta {
    background: linear-gradient(135deg, var(--sp-green-dark) 0%, var(--sp-green) 60%, #10b981 100%);
    border-radius: var(--sp-radius);
    overflow: hidden;
    animation: sp-fade-up .5s .45s ease both;
}

.sp-cta-inner {
    padding: 2rem 1.5rem;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .75rem;
}

.sp-cta-icon {
    font-size: 2.5rem;
    line-height: 1;
    filter: drop-shadow(0 2px 8px rgba(0,0,0,.2));
}

.sp-cta-title {
    font-family: var(--font-family-heading, 'Plus Jakarta Sans', 'Inter', sans-serif);
    font-size: 1.35rem;
    font-weight: 800;
    color: #fff;
    margin: 0;
    line-height: 1.2;
    letter-spacing: -.02em;
}

.sp-cta-sub {
    font-size: .875rem;
    color: rgba(255,255,255,.8);
    margin: 0;
    line-height: 1.5;
    max-width: 320px;
}

.sp-btn {
    display: inline-block;
    padding: .7rem 1.5rem;
    border-radius: var(--radius-full, 999px);
    font-weight: 700;
    font-size: .9rem;
    text-decoration: none;
    transition: all .2s;
    cursor: pointer;
    border: none;
}

.sp-btn-primary {
    background: var(--sp-green);
    color: #fff;
}
.sp-btn-primary:hover { background: var(--sp-green-dark); transform: translateY(-1px); }

.sp-btn-cta {
    background: #fff;
    color: var(--sp-green-dark);
    font-size: 1rem;
    padding: .8rem 2rem;
    box-shadow: 0 4px 14px rgba(0,0,0,.18);
    margin-top: .25rem;
}
.sp-btn-cta:hover {
    background: #f0fdf4;
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0,0,0,.22);
}

/* ── Attribution ── */
.sp-attribution {
    text-align: center;
    padding: .5rem 0 .25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .375rem;
    opacity: .7;
}
.sp-attribution p { font-size: .75rem; color: var(--sp-muted); margin: 0; }
.off-logo-small {
    height: 22px; width: auto;
    filter: grayscale(1); opacity: .7;
    transition: all .2s;
}
.off-logo-small:hover { filter: none; opacity: 1; }

/* ── Dark mode ── */
@media (prefers-color-scheme: dark) {
    .share-page {
        --sp-bg:      #0f172a;
        --sp-surface: #1e293b;
        --sp-border:  #334155;
        --sp-text:    #f1f5f9;
        --sp-muted:   #94a3b8;
        --sp-shadow:  0 4px 6px -1px rgba(0,0,0,.3);
    }

    .sp-context-card { background: #0f172a; }

    .ring-score { color: #f1f5f9; }

    .sp-level-pill.low      { background: rgba(5,150,105,.2);  }
    .sp-level-pill.moderate { background: rgba(245,158,11,.2); }
    .sp-level-pill.high     { background: rgba(239,68,68,.2);  }

    .sp-chip-safe    { background: rgba(5,150,105,.2);  color: #6ee7b7; }
    .sp-chip-caution { background: rgba(245,158,11,.2); color: #fde68a; }
    .sp-chip-avoid   { background: rgba(234,88,12,.2);  color: #fdba74; }
    .sp-chip-banned  { background: rgba(220,38,38,.2);  color: #fca5a5; }
    .sp-chip-high    { background: rgba(220,38,38,.2);  color: #fca5a5; }
    .sp-chip-medium  { background: rgba(245,158,11,.2); color: #fde68a; }
    .sp-chip-low     { background: rgba(37,99,235,.2);  color: #93c5fd; }

    .ai-badge.good    { background: rgba(5,150,105,.15);  }
    .ai-badge.concern { background: rgba(245,158,11,.15); }

    #context-response .context-text { background: #0f172a; }

    .sp-expiry { color: #fcd34d; }

    .sp-disclaimer {
        background: rgba(245,158,11,.08);
        color: #fde68a;
    }
    .sp-disclaimer svg { stroke: #fcd34d; }

    .sp-attribution { opacity: .5; }

    .mode-btn.active { background: #0f172a; }

    .nutriscore-c,
    .ecoscore-c,
    .nova-2 { color: #1a1a1a; } /* keep dark text on yellow even in dark mode */
}

/* ── Mobile fine-tuning ── */
@media (max-width: 420px) {
    .sp-main { padding: 1rem .75rem 2.5rem; }
    .sp-hero-img { max-height: 200px; }
    .sp-hero-img img { height: 200px; }
    .sp-product-name { font-size: 1.2rem; }
    .ring-wrap { width: 92px; height: 92px; }
    .score-ring { width: 92px; height: 92px; }
    .ring-score { font-size: 1.45rem; }
    .sp-cta-title { font-size: 1.15rem; }
    .scores-grid { gap: .5rem; }
    .score-badge { width: 44px; height: 44px; font-size: 1.2rem; }
}
