/* ═══════════════════════════════════════════════════════════════
   Tract Generator — Styles
   ═══════════════════════════════════════════════════════════════ */

:root {
    --tg-primary: #4338ca;
    --tg-primary-light: #5b4ec4;
    --tg-accent: #6366f1;
    --tg-accent-light: #a5b4fc;
    --tg-bg: #f8f7fc;
    --tg-card: #ffffff;
    --tg-text: #1e1b4b;
    --tg-text-muted: #6b7280;
    --tg-border: #e5e7eb;
    --tg-shadow: 0 1px 3px rgba(67, 56, 202, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --tg-shadow-lg: 0 10px 25px rgba(67, 56, 202, 0.1);
    --tg-radius: 12px;
    --tg-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --tg-serif: 'Georgia', 'Times New Roman', serif;
}

/* ── App container ─────────────────────────────────────────── */
.tg-app {
    min-height: 100vh;
    background: var(--tg-bg);
    font-family: var(--tg-font);
    color: var(--tg-text);
}

/* ── Hero / Landing ────────────────────────────────────────── */
.tg-landing {
    padding: 2rem 1rem;
}

.tg-hero {
    max-width: 720px;
    margin: 0 auto;
    padding: 3rem 0 2rem;
    text-align: center;
}

.tg-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 0.75rem;
}

.tg-logo img {
    height: 64px;
    width: auto;
}

.tg-title {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--tg-primary);
    margin: 0 0 0.5rem;
}

.tg-subtitle {
    font-size: 1.1rem;
    color: var(--tg-text-muted);
    margin: 0 0 2rem;
}

/* ── Form ──────────────────────────────────────────────────── */
.tg-form {
    max-width: 640px;
    margin: 0 auto;
}

.tg-input-group {
    position: relative;
    margin-bottom: 1.25rem;
}

.tg-input {
    width: 100%;
    padding: 1rem 1.25rem;
    font-size: 1.05rem;
    font-family: var(--tg-font);
    border: 2px solid var(--tg-border);
    border-radius: var(--tg-radius);
    background: var(--tg-card);
    color: var(--tg-text);
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}

.tg-input:focus {
    outline: none;
    border-color: var(--tg-accent);
    box-shadow: 0 0 0 3px rgba(197, 148, 58, 0.15);
}

.tg-input::placeholder {
    color: var(--tg-text-muted);
}

/* ── Options row ───────────────────────────────────────────── */
.tg-options {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    justify-content: center;
    margin-bottom: 1.5rem;
}

.tg-option-group {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.tg-option-group label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--tg-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.tg-select {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    font-family: var(--tg-font);
    border: 1.5px solid var(--tg-border);
    border-radius: 8px;
    background: var(--tg-card);
    color: var(--tg-text);
    cursor: pointer;
}

.tg-select:focus {
    outline: none;
    border-color: var(--tg-accent);
}

.tg-option-toggle {
    justify-content: flex-end;
}

.tg-option-toggle label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--tg-text);
    text-transform: none;
    letter-spacing: 0;
}

.tg-option-toggle input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--tg-accent);
}

/* ── Custom message textarea ───────────────────────────────── */
.tg-custom-message-group {
    max-width: 480px;
    margin: 0 auto 1.5rem;
    text-align: left;
}

.tg-custom-message-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--tg-text);
    margin-bottom: 0.35rem;
}

.tg-optional {
    font-weight: 400;
    color: var(--tg-text-muted);
    font-size: 0.8rem;
}

.tg-custom-message {
    width: 100%;
    padding: 0.7rem 0.9rem;
    font-size: 0.9rem;
    font-family: var(--tg-font);
    border: 1.5px solid var(--tg-border);
    border-radius: 8px;
    background: var(--tg-card);
    color: var(--tg-text);
    resize: vertical;
    min-height: 60px;
    max-height: 120px;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.tg-custom-message:focus {
    outline: none;
    border-color: var(--tg-accent);
    box-shadow: 0 0 0 3px rgba(197, 148, 58, 0.12);
}

.tg-custom-message::placeholder {
    color: var(--tg-text-muted);
    font-size: 0.85rem;
}

.tg-char-count {
    display: block;
    text-align: right;
    font-size: 0.75rem;
    color: var(--tg-text-muted);
    margin-top: 0.2rem;
}

/* ── Tract contact footer (in generated output) ──────────── */
.tract-contact {
    padding: 1.25rem 2.5rem;
    background: #f0ebe2;
    border-top: 1.5px solid var(--tg-border);
    text-align: center;
}

.tract-contact p {
    font-size: 0.92rem;
    line-height: 1.55;
    color: var(--tg-primary);
    margin: 0;
    white-space: pre-line;
}

/* ── Generate button ───────────────────────────────────────── */
.tg-generate-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.9rem 2.5rem;
    font-size: 1.05rem;
    font-weight: 600;
    font-family: var(--tg-font);
    color: #fff;
    background: linear-gradient(135deg, #4338ca, #6366f1);
    border: none;
    border-radius: var(--tg-radius);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.2s;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.tg-generate-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--tg-shadow-lg);
}

.tg-generate-btn:active {
    transform: translateY(0);
}

.tg-generate-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ── Suggestions ───────────────────────────────────────────── */
.tg-suggestions {
    max-width: 720px;
    margin: 1.5rem auto 0;
    text-align: center;
}

.tg-suggestions-label {
    font-size: 0.85rem;
    color: var(--tg-text-muted);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.tg-suggestion-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
}

.tg-suggestion-card {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1rem;
    background: var(--tg-card);
    border: 1.5px solid var(--tg-border);
    border-radius: 10px;
    cursor: pointer;
    font-family: var(--tg-font);
    font-size: 0.9rem;
    color: var(--tg-text);
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.15s;
}

.tg-suggestion-card:hover {
    border-color: var(--tg-accent);
    box-shadow: var(--tg-shadow);
    transform: translateY(-1px);
}

.tg-suggestion-card i {
    color: #6366f1;
    font-size: 1.1rem;
    flex-shrink: 0;
}

/* ── Progress indicator ────────────────────────────────────── */
.tg-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    padding: 2rem;
}

.tg-progress-card {
    background: var(--tg-card);
    border-radius: var(--tg-radius);
    box-shadow: var(--tg-shadow-lg);
    padding: 3rem;
    text-align: center;
    max-width: 420px;
    width: 100%;
}

.tg-progress-spinner {
    width: 56px;
    height: 56px;
    border: 4px solid var(--tg-border);
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: tg-spin 0.9s linear infinite;
    margin: 0 auto 1.5rem;
}

@keyframes tg-spin {
    to { transform: rotate(360deg); }
}

.tg-progress-title {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--tg-primary);
    margin: 0 0 1.5rem;
}

.tg-progress-steps {
    text-align: left;
}

.tg-step {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0;
    font-size: 0.9rem;
    color: var(--tg-text-muted);
    transition: color 0.3s;
}

.tg-step i {
    width: 20px;
    text-align: center;
    font-size: 0.85rem;
}

.tg-step.active {
    color: var(--tg-primary);
    font-weight: 600;
}

.tg-step.active i {
    color: #6366f1;
    animation: tg-pulse 1.2s ease-in-out infinite;
}

.tg-step.done {
    color: #4a9e6e;
}

.tg-step.done i::before {
    content: "\f00c";
    font-family: "Font Awesome 6 Free";
    font-weight: 900;
}

@keyframes tg-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ── Result area ───────────────────────────────────────────── */
.tg-result {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem;
}

.tg-result-standalone {
    padding-top: 2rem;
}

.tg-result-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.tg-toolbar-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    font-family: var(--tg-font);
    color: var(--tg-primary);
    background: var(--tg-card);
    border: 1.5px solid var(--tg-border);
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.2s, background 0.2s;
}

.tg-toolbar-btn:hover {
    border-color: var(--tg-accent);
    background: #fdfbf7;
}

.tg-verification-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-left: auto;
    padding: 0.45rem 0.9rem;
    font-size: 0.8rem;
    font-weight: 600;
    color: #3730a3;
    background: #eef2ff;
    border-radius: 20px;
}

.tg-verification-badge i {
    color: #6366f1;
}

/* ── Tract content styles ──────────────────────────────────── */
.tg-result-content {
    background: var(--tg-card);
    border-radius: var(--tg-radius);
    box-shadow: var(--tg-shadow-lg);
    overflow: hidden;
}

.tract-content {
    padding: 0;
}

.tract-cover {
    width: 100%;
    max-height: 500px;
    overflow: hidden;
}

.tract-cover img {
    width: 100%;
    height: auto;
    display: block;
    object-fit: cover;
}

.tract-header {
    padding: 2.5rem 2.5rem 1.5rem;
    text-align: center;
    border-bottom: 2px solid var(--tg-border);
}

.tract-title {
    font-family: var(--tg-serif);
    font-size: 2rem;
    font-weight: 700;
    color: var(--tg-primary);
    margin: 0 0 0.5rem;
    line-height: 1.2;
}

.tract-subtitle {
    font-size: 1.1rem;
    color: var(--tg-text-muted);
    font-style: italic;
    margin: 0;
}

.tract-section {
    padding: 2rem 2.5rem;
    border-bottom: 1px solid var(--tg-border);
}

.tract-section:last-of-type {
    border-bottom: none;
}

.tract-section h2 {
    font-family: var(--tg-serif);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--tg-primary);
    margin: 0 0 1rem;
}

.tract-section p {
    font-size: 1.02rem;
    line-height: 1.75;
    margin: 0 0 1rem;
    color: var(--tg-text);
}

.tract-section p:last-child {
    margin-bottom: 0;
}

.bible-ref {
    color: #4338ca;
    font-weight: 600;
    font-size: 0.92em;
}

.tract-appeal {
    padding: 2rem 2.5rem;
    background: linear-gradient(135deg, #f0edff, #eef2ff);
    border-top: 2px solid var(--tg-accent-light);
}

.tract-appeal h2 {
    font-family: var(--tg-serif);
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--tg-primary);
    margin: 0 0 1rem;
}

.tract-appeal p {
    font-size: 1.02rem;
    line-height: 1.75;
    margin: 0 0 1rem;
    color: var(--tg-text);
}

.tract-further-reading {
    padding: 1.5rem 2.5rem 2rem;
    background: #f8f6f2;
}

.tract-further-reading h2 {
    font-family: var(--tg-serif);
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--tg-primary);
    margin: 0 0 0.75rem;
}

.tract-further-reading ul {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tract-further-reading li {
    padding: 0.4rem 0.9rem;
    background: var(--tg-card);
    border: 1px solid var(--tg-border);
    border-radius: 6px;
    font-size: 0.9rem;
    color: var(--tg-primary);
    font-weight: 500;
}

/* ── Recent tracts ─────────────────────────────────────────── */
.tg-recent {
    max-width: 800px;
    margin: 3rem auto;
    padding: 0 1rem;
}

.tg-recent-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--tg-primary);
    margin: 0 0 1rem;
}

.tg-recent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.tg-recent-card {
    background: var(--tg-card);
    border: 1.5px solid var(--tg-border);
    border-radius: var(--tg-radius);
    overflow: hidden;
    text-decoration: none;
    color: var(--tg-text);
    transition: box-shadow 0.2s, transform 0.15s;
}

.tg-recent-card:hover {
    box-shadow: var(--tg-shadow-lg);
    transform: translateY(-2px);
}

.tg-recent-thumb {
    height: 120px;
    background-size: cover;
    background-position: center;
}

.tg-recent-thumb-placeholder {
    background: linear-gradient(135deg, #1e1b4b, #4a4ab0);
    display: flex;
    align-items: center;
    justify-content: center;
}

.tg-recent-thumb-placeholder i {
    font-size: 2rem;
    color: rgba(255, 255, 255, 0.5);
}

.tg-recent-info {
    padding: 0.75rem 1rem;
}

.tg-recent-info h3 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0 0 0.25rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.tg-recent-date {
    font-size: 0.75rem;
    color: var(--tg-text-muted);
}

/* ═══════════════════════════════════════════════════════════════
   PRINT STYLES — Publication-ready tract output
   ═══════════════════════════════════════════════════════════════ */
@media print {

    /* Zero margin eliminates Chrome/Edge header/footer (URL, date, page#) */
    @page {
        size: letter;
        margin: 0;
    }

    /* Hide everything except the tract content */
    .tg-result-toolbar,
    .tg-landing,
    .tg-recent,
    .tg-progress,
    .tg-verification-badge,
    .tg-app > *:not(.tg-result) {
        display: none !important;
    }

    /* Reset all web styles — use padding instead of @page margin */
    body {
        background: white !important;
        margin: 0 !important;
        padding: 0.6in 0.75in !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    .tg-app {
        background: white !important;
        min-height: auto !important;
    }

    .tg-result {
        max-width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .tg-result-content {
        box-shadow: none !important;
        border-radius: 0 !important;
        border: none !important;
        overflow: visible !important;
    }

    .tract-content {
        padding: 0 !important;
    }

    /* ── Cover image — bleeds to page edges ─────────────────── */
    .tract-cover {
        max-height: 4in;
        overflow: hidden;
        margin: -0.6in -0.75in 0 -0.75in;
        width: calc(100% + 1.5in);
        page-break-after: avoid;
    }

    .tract-cover img {
        width: 100%;
        height: 4in;
        object-fit: cover;
        display: block;
    }

    /* ── Title block ─────────────────────────────────────────── */
    .tract-header {
        padding: 0.4in 0 0.3in 0;
        text-align: center;
        border-bottom: 2pt solid #5b4a3f;
        margin-bottom: 0;
        page-break-after: avoid;
    }

    .tract-title {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 22pt;
        font-weight: 700;
        color: #3d2b1f !important;
        margin: 0 0 4pt 0;
        line-height: 1.15;
    }

    .tract-subtitle {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 11pt;
        color: #6b5d4f !important;
        font-style: italic;
        margin: 0;
    }

    /* ── Content sections ────────────────────────────────────── */
    .tract-section {
        padding: 0.2in 0;
        border-bottom: 0.5pt solid #d5cdc2;
        page-break-inside: avoid;
    }

    .tract-section:last-of-type {
        border-bottom: none;
    }

    .tract-section h2 {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 14pt;
        font-weight: 700;
        color: #3d2b1f !important;
        margin: 0 0 6pt 0;
        page-break-after: avoid;
    }

    .tract-section p {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 10.5pt;
        line-height: 1.6;
        margin: 0 0 8pt 0;
        color: #1a1a1a !important;
        text-align: justify;
        hyphens: auto;
        orphans: 3;
        widows: 3;
    }

    .tract-section p:last-child {
        margin-bottom: 0;
    }

    /* ── Bible references — bold and dark for print ──────────── */
    .bible-ref {
        color: #3d2b1f !important;
        font-weight: 700;
        font-size: 0.9em;
    }

    /* ── Appeal section ──────────────────────────────────────── */
    .tract-appeal {
        padding: 0.2in 0.25in;
        background: #f5f0e8 !important;
        border-top: 2pt solid #c5943a;
        border-left: none;
        border-right: none;
        border-bottom: none;
        margin-top: 0.1in;
        page-break-inside: avoid;
    }

    .tract-appeal h2 {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 14pt;
        font-weight: 700;
        color: #3d2b1f !important;
        margin: 0 0 6pt 0;
        page-break-after: avoid;
    }

    .tract-appeal p {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 10.5pt;
        line-height: 1.6;
        margin: 0 0 8pt 0;
        color: #1a1a1a !important;
        text-align: justify;
        orphans: 3;
        widows: 3;
    }

    /* ── Further reading ─────────────────────────────────────── */
    .tract-further-reading {
        padding: 0.15in 0;
        background: transparent !important;
        border-top: 0.5pt solid #d5cdc2;
        margin-top: 0.1in;
        page-break-inside: avoid;
    }

    .tract-further-reading h2 {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 11pt;
        font-weight: 700;
        color: #3d2b1f !important;
        margin: 0 0 4pt 0;
    }

    .tract-further-reading ul {
        list-style: none;
        padding: 0;
        margin: 0;
        display: flex;
        flex-wrap: wrap;
        gap: 4pt;
    }

    .tract-further-reading li {
        font-family: Georgia, 'Times New Roman', serif;
        padding: 2pt 8pt;
        background: transparent !important;
        border: 0.75pt solid #8b7d6f;
        border-radius: 3pt;
        font-size: 9.5pt;
        color: #3d2b1f !important;
        font-weight: 600;
    }

    /* ── Contact footer ───────────────────────────────────────── */
    .tract-contact {
        padding: 0.12in 0;
        background: transparent !important;
        border-top: 1pt solid #5b4a3f;
        margin-top: 0.1in;
        text-align: center;
        page-break-inside: avoid;
    }

    .tract-contact p {
        font-family: Georgia, 'Times New Roman', serif;
        font-size: 9.5pt;
        line-height: 1.45;
        color: #3d2b1f !important;
        white-space: pre-line;
    }

    /* ── Page break control ──────────────────────────────────── */
    h2 {
        page-break-after: avoid !important;
    }

    p {
        orphans: 3 !important;
        widows: 3 !important;
    }

    img {
        page-break-inside: avoid !important;
    }

    .tract-section,
    .tract-appeal,
    .tract-further-reading {
        page-break-inside: avoid;
    }
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 640px) {
    .tg-title {
        font-size: 1.75rem;
    }

    .tg-hero {
        padding: 2rem 0 1.5rem;
    }

    .tg-options {
        flex-direction: column;
        align-items: stretch;
    }

    .tg-option-group {
        width: 100%;
    }

    .tg-select {
        width: 100%;
    }

    .tg-suggestion-grid {
        grid-template-columns: 1fr 1fr;
    }

    .tg-custom-message-group {
        max-width: 100%;
    }

    .tract-header {
        padding: 1.5rem 1.25rem 1rem;
    }

    .tract-title {
        font-size: 1.5rem;
    }

    .tract-section,
    .tract-appeal,
    .tract-further-reading {
        padding: 1.25rem;
    }

    .tg-result {
        padding: 0.75rem;
    }

    .tg-result-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .tg-verification-badge {
        margin-left: 0;
        justify-content: center;
    }
}
