/* Base layout */
body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
}

.app-container {
    max-width: 900px;
    width: 100%;
    margin: 2rem auto;
    padding: 0 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* Typography styles consistent with main site */
.app-title {
    font-size: 2.25rem;
    font-weight: 800;
    color: var(--ink-deep);
    text-align: center;
    margin-bottom: 0.5rem;
}

.app-subtitle {
    font-size: 1.1rem;
    color: var(--ink-2);
    text-align: center;
    margin-bottom: 2rem;
}

.results-title {
    font-size: 1.75rem;
    font-weight: 800;
    color: var(--ink-deep);
    margin-bottom: 1.5rem;
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 1rem;
}

/* Cards */
.calculator-card {
    background: #ffffff;
    border-radius: 20px;
    padding: 2.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

/* Buttons */
.mode-toggle {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-bottom: 2rem;
    flex-wrap: wrap;
}

.mode-btn {
    padding: 0.75rem 1.5rem;
    border-radius: 99px;
    border: 1px solid #e2e8f0;
    background: white;
    font-weight: 600;
    cursor: pointer;
    font-size: 1rem;
    color: var(--ink-2);
    transition: all 0.2s ease;
}

.mode-btn:hover {
    background: #f8fafc;
    color: var(--brand);
    border-color: #cbd5e1;
}

.mode-btn.active {
    background: var(--brand);
    color: white;
    border-color: var(--brand);
    box-shadow: 0 4px 12px rgba(10, 91, 99, 0.2);
}

.calculate-btn {
    width: 100%;
    padding: 1rem;
    border-radius: 12px;
    border: none;
    background: var(--brand);
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(10, 91, 99, 0.2);
}

.calculate-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(10, 91, 99, 0.3);
}

.calculate-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: white;
    color: var(--brand);
    border: 2px solid var(--brand);
    box-shadow: none;
}

.btn-secondary:hover {
    background: #f0fdfa;
    box-shadow: 0 4px 12px rgba(10, 91, 99, 0.1);
}

/* Forms */
.input-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.controls-row {
    display: flex;
    gap: 1rem;
    margin-top: 1rem;
}

/* MathLive Editor Styling */
.editor-wrapper {
    position: relative;
    width: 100%;
}

.math-editor {
    width: 100%;
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    padding: 0.75rem;
    font-size: 1.5rem;
    font-family: 'Fira Code', monospace;
    background: #f8fafc;
    transition: border-color 0.2s;
    min-height: 50px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
}

/* Custom MathLive Placeholder Overlay */
.placeholder-overlay {
    position: absolute;
    top: 50%;
    left: 1rem;
    transform: translateY(-50%);
    color: #94a3b8;
    pointer-events: none;
    font-size: 1.25rem;
    font-family: inherit;
    transition: opacity 0.2s;
}

/* Error Message */
.error-msg {
    margin-top: 1rem;
    padding: 1rem;
    background: #fef2f2;
    border-left: 4px solid #ef4444;
    color: #991b1b;
    border-radius: 8px;
    font-weight: 500;
}

.hidden {
    display: none !important;
}

/* Detailed Results Steps Styling */
.final-result-box {
    background: #eff6ff;
    border: 2px solid #bfdbfe;
    border-radius: 16px;
    padding: 1.5rem;
    text-align: center;
    margin-bottom: 2rem;
}

.final-result-box h3 {
    color: #1e40af;
    margin-top: 0;
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

.final-latex-text {
    font-size: 1.4rem;
    color: #1e3a8a;
    overflow-x: auto;
    padding: 0.5rem 0;
}

.steps-section {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.step-card {
    background: white;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
    position: relative;
}

.step-card::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: var(--brand);
    border-radius: 12px 0 0 12px;
}

.step-header {
    font-weight: 700;
    color: var(--ink-deep);
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.step-formula {
    background: #f8fafc;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 1.2rem;
    text-align: center;
    border: 1px solid #f1f5f9;
}

.step-explanation {
    margin-top: 1rem;
    color: var(--ink-2);
    line-height: 1.6;
}

/* Function Plot specifics */
#function-plot svg {
    border-radius: 8px;
}

@media (max-width: 600px) {
    .calculator-card {
        padding: 1.5rem;
    }

    .controls-row {
        flex-direction: column;
    }

    .mode-btn {
        width: 100%;
        text-align: center;
    }

    .math-editor {
        font-size: 1.2rem;
    }

    .final-latex-text {
        font-size: 1.15rem;
    }
}

/* Markdown Table Styles */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    margin: 1.5rem 0;
}

.math-table {
    width: 100%;
    border-collapse: collapse;
    background-color: #ffffff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid #e2e8f0;
}

.math-table th,
.math-table td {
    padding: 0.75rem 1rem;
    text-align: center;
    border-bottom: 1px solid #e2e8f0;
    border-right: 1px solid #e2e8f0;
}

.math-table th:last-child,
.math-table td:last-child {
    border-right: none;
}

.math-table th {
    background-color: var(--brand);
    color: #ffffff;
    font-weight: 600;
    white-space: nowrap;
}

.math-table tr:last-child td {
    border-bottom: none;
}

.math-table tr:nth-child(even) {
    background-color: #f8fafc;
}

.math-table tr:hover td {
    background-color: #f1f5f9;
}

/* ---------------------------------------------------
   Sign Chart Custom UI (Grafico dei Segni)
   --------------------------------------------------- */
.sign-chart-wrapper {
    margin-top: 1.5rem;
    padding: 1rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
}

.sc-title {
    font-weight: 700;
    color: var(--brand);
    text-align: center;
    margin-bottom: 1rem;
    font-size: 1.1rem;
}

.sign-chart-container {
    overflow-x: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-bottom: 1rem;
}

.sc-row {
    display: flex;
    align-items: center;
    position: relative;
    min-width: max-content;
}

.sc-label {
    width: 60px;
    font-weight: 600;
    text-align: right;
    padding-right: 1.5rem;
    flex-shrink: 0;
    color: var(--ink-deep);
}

.sc-intervals {
    display: flex;
    flex-grow: 1;
    align-items: center;
}

.sc-segment {
    width: 80px;
    /* Base width for an interval */
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.sc-axis {
    margin-bottom: 0.5rem;
}

.sc-axis .sc-segment {
    border-bottom: 1px solid #94a3b8;
    height: 20px;
}

.sc-point-val {
    position: absolute;
    right: -10px;
    top: -15px;
    font-weight: 700;
    color: var(--brand);
    background: #f8fafc;
    padding: 0 4px;
    z-index: 2;
}

.sc-line-plus {
    border-bottom: 2px solid #10b981;
    /* Green solid line for + */
}

.sc-line-minus {
    border-bottom: 2px dashed #ef4444;
    /* Red dashed line for - */
}

.sc-line-zero {
    border-bottom: 2px dotted #94a3b8;
    /* Neutral for 0 or non-existent */
}

.sc-vert-bar {
    position: absolute;
    right: 0;
    width: 1px;
    height: 40px;
    background: #cbd5e1;
    z-index: 1;
}

.sc-final {
    margin-top: 1rem;
    border-top: 1px solid #e2e8f0;
    padding-top: 0.5rem;
}

.sc-final-sign {
    font-size: 1.25rem;
    color: var(--ink-deep);
}

/* ============================================================
   Avviso «strumento in ricostruzione»
   ------------------------------------------------------------
   Sta sopra i comandi. Oro del tema come filo verticale e velo di
   fondo — l'oro qui e' fondo e bordo, mai la scritta: --accent su
   bianco fa 1,94:1 e non si legge. Il testo e' --ink sul velo
   --accent-soft, che misura molto sopra la soglia AA.

   Non e' un messaggio d'errore e non usa il rosso: lo strumento non
   e' rotto, e dirlo col colore sbagliato sarebbe la prima cosa che
   il visitatore capisce male.
   ============================================================ */
.avviso-ricostruzione {
    background: var(--accent-soft);
    /* NON `var(--accent)`: l'app di ruffini lo riscrive su :root (blu #3b82f6,
       vedi l'inizio di questo foglio), e il filo uscirebbe blu. `--accent-rgb`
       non e' scavalcato da nessuna delle tre app e vale l'oro vero del tema,
       254 168 0. Misurato in pagina, non dedotto. */
    border-left: 4px solid rgb(var(--accent-rgb));
    border-radius: var(--radius-sm);
    padding: 0.9rem 1.1rem;
    margin-bottom: 1.2rem;
    color: var(--ink);
    font-size: 0.95rem;
    line-height: 1.55;
    text-align: left;
}

.avviso-ricostruzione p {
    margin: 0 0 0.5rem;
}

.avviso-ricostruzione p:last-child {
    margin-bottom: 0;
}

.avviso-ricostruzione .avviso-titolo {
    font-weight: 800;
}

.avviso-ricostruzione .avviso-coda {
    color: var(--ink-2);
    font-size: 0.9rem;
}

/* Il campo e il pulsante spenti si devono VEDERE spenti: se restassero
   identici, il visitatore proverebbe a scriverci e penserebbe che il
   sito e' rotto — cioe' l'opposto di quello che dice l'avviso. */
math-field[read-only],
.calculate-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}
