/* ==========================================================================
   Case study pages (/officina-case-study, /ilpiaceredileggere-case-study)

   Built on the site tokens from themes.css/style.css. Each page sets its own
   client colours through three variables, for both modes:
     --cs-accent    main ink (headings accents, numbers, links)
     --cs-accent-2  second ink (phase labels, highlights)
     --cs-accent-3  third ink (tags)
   Everything else is shared, so the two pages read as one series.
   ========================================================================== */

:root {
    --cs-radius: 16px;
    --cs-card-bg: color-mix(in srgb, var(--bg-secondary) 92%, var(--cs-accent) 8%);
    --cs-card-border: color-mix(in srgb, var(--border-color) 78%, var(--cs-accent) 22%);
    --cs-code-bg: #0f0e0d;
    --cs-muted-bg: color-mix(in srgb, var(--bg-primary) 90%, var(--cs-accent) 10%);
}

[data-mode="light"] {
    --cs-card-bg: color-mix(in srgb, var(--bg-secondary) 96%, var(--cs-accent) 4%);
    --cs-code-bg: #f4f1ec;
}

/* ---------------- Hero ---------------- */
.cs-hero {
    position: relative;
    padding: clamp(6.5rem, 12vw, 9rem) 1.25rem 3.5rem;
    overflow: hidden;
    border-bottom: 1px solid var(--cs-card-border);
}

.cs-hero-backdrop {
    position: absolute;
    left: -40px;
    bottom: -30px;
    width: clamp(320px, 42vw, 600px);
    height: auto;
    pointer-events: none;
    z-index: 0;
    opacity: 0.1;
}

.cs-hero-container,
.cs-main-body {
    max-width: 1140px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
}

.cs-kicker {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
    margin-bottom: 1.4rem;
    font-family: var(--font-code);
    font-size: 0.78rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.cs-kicker-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    color: var(--cs-accent);
    font-weight: 700;
}

.cs-kicker-brand img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    background: #fff;
}

.cs-motto {
    font-family: var(--font-heading);
    font-style: italic;
    text-transform: none;
    letter-spacing: 0;
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.cs-hero-title {
    font-family: var(--font-heading);
    font-size: clamp(2rem, 5vw, 3.4rem);
    color: var(--text-primary);
    line-height: 1.12;
    letter-spacing: -0.02em;
    margin: 0 0 1.25rem;
    max-width: 22ch;
}

.cs-hero-title em {
    font-style: normal;
    color: var(--cs-accent);
}

.cs-hero-lede {
    font-size: clamp(1.02rem, 2.1vw, 1.22rem);
    color: var(--text-secondary);
    line-height: 1.75;
    max-width: 70ch;
    margin: 0 0 2.5rem;
}

.cs-hero-links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.8rem;
    margin: -1rem 0 2.75rem;
}

/* ---------------- Key facts ---------------- */
.cs-facts {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border-top: 1px solid var(--cs-card-border);
    border-bottom: 1px solid var(--cs-card-border);
}

.cs-fact {
    padding: 1.25rem 1.25rem 1.3rem 0;
    min-width: 0;
}

.cs-fact + .cs-fact {
    padding-left: 1.25rem;
    border-left: 1px solid var(--cs-card-border);
}

.cs-fact-val {
    display: block;
    font-family: var(--font-heading);
    font-size: clamp(1.6rem, 2.8vw, 2.1rem);
    font-weight: 700;
    color: var(--cs-accent);
    line-height: 1.1;
    margin-bottom: 0.35rem;
    font-variant-numeric: tabular-nums;
}

.cs-fact-lbl {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

/* ---------------- Body and sections ---------------- */
.cs-main-body {
    padding: 4rem 1.25rem 5.5rem;
    display: flex;
    flex-direction: column;
    gap: 4.25rem;
}

.cs-section-header {
    margin-bottom: 1.75rem;
    max-width: 75ch;
}

.cs-section-badge {
    display: block;
    font-family: var(--font-code);
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--cs-accent-2);
    margin-bottom: 0.5rem;
}

.cs-section-title {
    font-family: var(--font-heading);
    font-size: clamp(1.5rem, 3.1vw, 2.2rem);
    color: var(--text-primary);
    line-height: 1.22;
    margin: 0;
}

.cs-section-intro {
    margin: 0.85rem 0 0;
    color: var(--text-secondary);
    line-height: 1.7;
    font-size: 1rem;
}

.cs-prose p {
    color: var(--text-secondary);
    line-height: 1.75;
    margin: 0 0 1rem;
    max-width: 75ch;
}

.cs-prose strong {
    color: var(--text-primary);
}

/* ---------------- Card grids ---------------- */
.cs-grid-3,
.cs-grid-2 {
    display: grid;
    gap: 1.25rem;
}

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

.cs-card {
    min-width: 0;
    background: var(--cs-card-bg);
    border: 1px solid var(--cs-card-border);
    border-radius: var(--cs-radius);
    padding: clamp(1.3rem, 2.6vw, 1.75rem);
}

.cs-card h3 {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    color: var(--text-primary);
    margin: 0 0 0.6rem;
    line-height: 1.3;
}

.cs-card p,
.cs-card li {
    font-size: 0.95rem;
    line-height: 1.65;
    color: var(--text-secondary);
}

.cs-card p { margin: 0; }
.cs-card p + p { margin-top: 0.7rem; }

.cs-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 1rem;
    color: var(--cs-accent);
    border: 1px solid color-mix(in srgb, var(--cs-accent) 45%, transparent);
    background: color-mix(in srgb, var(--cs-accent) 10%, transparent);
}

.cs-list {
    margin: 0;
    padding-left: 1.15rem;
}

.cs-list li + li { margin-top: 0.45rem; }

/* ---------------- Timeline ---------------- */
.cs-timeline {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.cs-phase {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 1.5rem;
    padding: 1.5rem 1.75rem;
    background: var(--cs-card-bg);
    border: 1px solid var(--cs-card-border);
    border-radius: var(--cs-radius);
}

.cs-phase-meta {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding-top: 0.2rem;
}

.cs-phase-badge {
    font-family: var(--font-code);
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--cs-accent-2);
}

.cs-phase-date {
    font-family: var(--font-code);
    font-size: 0.74rem;
    color: var(--text-muted);
}

.cs-phase h3 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    color: var(--text-primary);
    margin: 0 0 0.5rem;
    line-height: 1.3;
}

.cs-phase p {
    font-size: 0.96rem;
    line-height: 1.7;
    color: var(--text-secondary);
    margin: 0 0 0.9rem;
}

.cs-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.cs-tags li {
    font-family: var(--font-code);
    font-size: 0.72rem;
    padding: 0.22rem 0.65rem;
    border-radius: 100px;
    border: 1px solid color-mix(in srgb, var(--cs-accent-3) 40%, transparent);
    background: color-mix(in srgb, var(--cs-accent-3) 10%, transparent);
    color: var(--text-secondary);
}

/* ---------------- Screenshots ---------------- */
.cs-frame {
    margin: 0;
    min-width: 0;
    border: 1px solid var(--cs-card-border);
    border-radius: var(--cs-radius);
    overflow: hidden;
    background: var(--bg-tertiary);
}

.cs-frame-bar {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 0.6rem 1rem;
    background: var(--cs-card-bg);
    border-bottom: 1px solid var(--cs-card-border);
}

.cs-frame-dots {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.cs-frame-dots span {
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--text-muted) 55%, transparent);
}

.cs-frame-url {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-family: var(--font-code);
    font-size: 0.76rem;
    color: var(--text-secondary);
}

.cs-frame img {
    display: block;
    width: 100%;
    height: auto;
}

.cs-frame figcaption,
.cs-phone figcaption {
    padding: 0.75rem 1rem;
    font-size: 0.86rem;
    line-height: 1.5;
    color: var(--text-muted);
    border-top: 1px solid var(--cs-card-border);
    background: var(--cs-card-bg);
}

.cs-shots {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
}

.cs-shots .cs-frame-wide { grid-column: 1 / -1; }

.cs-phones {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 1.5rem;
}

.cs-phone {
    margin: 0;
    width: min(100%, 260px);
    border: 1px solid var(--cs-card-border);
    border-radius: 22px;
    overflow: hidden;
    background: var(--bg-tertiary);
}

.cs-phone img {
    display: block;
    width: 100%;
    height: auto;
}

/* ---------------- Split block (text + visual) ---------------- */
.cs-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 2rem;
    align-items: start;
}

.cs-split > * { min-width: 0; }

/* ---------------- Code / message blocks ---------------- */
.cs-code {
    margin: 0;
    min-width: 0;
    background: var(--cs-code-bg);
    border: 1px solid var(--cs-card-border);
    border-radius: var(--cs-radius);
    overflow: hidden;
}

.cs-code-title {
    display: block;
    padding: 0.6rem 1rem;
    font-family: var(--font-code);
    font-size: 0.74rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--cs-card-border);
}

.cs-code pre {
    margin: 0;
    padding: 1.1rem 1.2rem;
    overflow-x: auto;
    font-family: var(--font-code);
    font-size: 0.82rem;
    line-height: 1.6;
    color: var(--text-primary);
    white-space: pre;
}

.cs-code .c-key { color: var(--cs-accent-3); }
.cs-code .c-val { color: var(--cs-accent); }
.cs-code .c-note { color: var(--text-muted); font-style: italic; }

/* WhatsApp-style message bubble */
.cs-bubble {
    margin: 0;
    min-width: 0;
    max-width: 420px;
    padding: 0.95rem 1.1rem 0.75rem;
    border-radius: 14px 14px 14px 4px;
    background: #dcf8c6;
    color: #1f2a2c;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

[data-mode="dark"] .cs-bubble {
    background: #005c4b;
    color: #e9edef;
}

.cs-bubble b { font-weight: 700; }

.cs-bubble-meta {
    display: block;
    margin-top: 0.4rem;
    text-align: right;
    font-size: 0.72rem;
    opacity: 0.7;
}

/* ---------------- Steps ---------------- */
.cs-steps {
    counter-reset: cs-step;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 1rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.cs-steps li {
    counter-increment: cs-step;
    min-width: 0;
    padding-top: 0.9rem;
    border-top: 2px solid var(--cs-accent);
    font-size: 0.93rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.cs-steps li::before {
    content: counter(cs-step, decimal-leading-zero);
    display: block;
    font-family: var(--font-code);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--cs-accent);
    margin-bottom: 0.35rem;
}

.cs-steps strong {
    display: block;
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 0.2rem;
}

/* ---------------- Tables ---------------- */
.cs-table-wrap {
    min-width: 0;
    overflow-x: auto;
    border: 1px solid var(--cs-card-border);
    border-radius: var(--cs-radius);
}

.cs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.cs-table th,
.cs-table td {
    padding: 0.8rem 1rem;
    text-align: left;
    vertical-align: top;
    border-bottom: 1px solid var(--cs-card-border);
    color: var(--text-secondary);
}

.cs-table tr:last-child td { border-bottom: 0; }

.cs-table th {
    font-family: var(--font-code);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    background: var(--cs-card-bg);
}

.cs-table td:first-child {
    color: var(--text-primary);
    font-weight: 600;
    white-space: nowrap;
}

.cs-table code {
    font-family: var(--font-code);
    font-size: 0.85em;
}

/* ---------------- Closing blocks ---------------- */
.cs-note {
    border-left: 3px solid var(--cs-accent);
    padding: 0.2rem 0 0.2rem 1.1rem;
    color: var(--text-secondary);
    line-height: 1.7;
    max-width: 75ch;
}

.cs-cta {
    text-align: center;
    background: var(--cs-card-bg);
    border: 1px solid var(--cs-card-border);
    border-radius: 20px;
    padding: clamp(2.2rem, 5vw, 3.5rem) 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
}

.cs-cta h2 {
    font-family: var(--font-heading);
    font-size: clamp(1.6rem, 3.4vw, 2.3rem);
    color: var(--text-primary);
    margin: 0;
}

.cs-cta p {
    color: var(--text-secondary);
    max-width: 60ch;
    line-height: 1.7;
    margin: 0;
}

.cs-cta-actions {
    display: flex;
    gap: 0.9rem;
    flex-wrap: wrap;
    justify-content: center;
}

.cs-more {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--cs-card-border);
    font-size: 0.95rem;
    color: var(--text-secondary);
}

.cs-more a {
    color: var(--cs-accent);
    font-weight: 600;
    text-decoration: none;
}

.cs-more a:hover { text-decoration: underline; }

/* ---------------- Responsive ---------------- */
@media (max-width: 960px) {
    .cs-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .cs-fact:nth-child(3) { padding-left: 0; border-left: 0; }
    .cs-fact:nth-child(n + 3) { border-top: 1px solid var(--cs-card-border); }
    .cs-grid-3 { grid-template-columns: minmax(0, 1fr); }
    .cs-split { grid-template-columns: minmax(0, 1fr); }
    .cs-steps { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 1.5rem; }
    .cs-phase { grid-template-columns: minmax(0, 1fr); gap: 0.6rem; }
}

@media (max-width: 640px) {
    .cs-grid-2,
    .cs-shots { grid-template-columns: minmax(0, 1fr); }

    /* Tables become one small block per row: name, text, then the tech in small print */
    .cs-table thead { display: none; }
    .cs-table,
    .cs-table tbody,
    .cs-table tr,
    .cs-table td { display: block; width: 100%; }
    .cs-table tr { padding: 0.85rem 1rem; border-bottom: 1px solid var(--cs-card-border); }
    .cs-table tr:last-child { border-bottom: 0; }
    .cs-table td { padding: 0.1rem 0; border: 0; }
    .cs-table td:first-child { white-space: normal; margin-bottom: 0.2rem; }
    .cs-table td.cs-td-tech { font-family: var(--font-code); font-size: 0.78rem; color: var(--text-muted); margin-top: 0.25rem; }
    .cs-steps { grid-template-columns: minmax(0, 1fr); }
    .cs-phase { padding: 1.25rem; }
    .cs-hero-title { max-width: none; }
}

@media (max-width: 420px) {
    .cs-facts { grid-template-columns: minmax(0, 1fr); }
    .cs-fact,
    .cs-fact + .cs-fact { padding-left: 0; border-left: 0; }
    .cs-fact + .cs-fact { border-top: 1px solid var(--cs-card-border); }
}

@media (prefers-reduced-motion: reduce) {
    .cs-card,
    .cs-phase { transition: none; }
}
