/* 
   Rustic Paper Theme - Design System 
   Inspired by high-quality stationery and executive briefs
*/

:root {
    /* Colors */
    --paper-bg: #F5F2E8;
    --paper-card: #FBF9F5;
    --paper-shadow: #EBE7DA;
    --paper-texture-color: rgba(0, 0, 0, 0.04);

    --ink-black: #1C1917;
    --ink-light: #44403C;
    --ink-faded: #57534E;

    --accent-blue: #1C1917;
    /* Use ink for primary emphasis */
    --accent-copper: #EA580C;
    /* Dunesurf rust accent */
    --accent-copper-dark: #C2410C;

    --line-color: #D7D3C8;
    --line-strong: rgba(28, 25, 23, 0.45);
    --paper-pattern: url("https://www.transparenttextures.com/patterns/cream-paper.png");
    --paper-noise: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.12'/%3E%3C/svg%3E");

    /* Typography */
    --font-heading: 'Cormorant Garamond', serif;
    --font-body: 'Inter', sans-serif;
    --font-hand: 'Caveat', cursive;

    /* Effects */
    --shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.06);
    --shadow-deep: 0 10px 40px rgba(0, 0, 0, 0.12);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--paper-bg);
    /* Slightly darker than paper for contrast */
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 400 400' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)' opacity='0.15'/%3E%3C/svg%3E");
    font-family: var(--font-body);
    color: var(--ink-black);
    font-size: 15.2px;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

/* --- Paper Container --- */
.paper-container {
    background-color: var(--paper-card);
    width: 100%;
    max-width: 800px;
    min-height: 900px;
    box-shadow: 2px 4px 12px rgba(28, 25, 23, 0.05);
    border: 1px solid rgba(28, 25, 23, 0.1);
    position: relative;
    padding: 60px;

    /* Paper Grain Texture */
    background-image: var(--paper-noise);
    background-color: var(--paper-bg);
    background-blend-mode: multiply;
}

/* --- Header --- */
.brief-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 20px;
}


.ink-logo {
    height: 40px;
    opacity: 0.9;
    /* Blend mode to look like printed on paper */
    mix-blend-mode: multiply;
}

.document-meta {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.meta-label {
    font-family: var(--font-heading);
    font-size: 0.7rem;
    letter-spacing: 0.18em;
    color: var(--ink-faded);
    text-transform: uppercase;
}

.meta-value {
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--accent-blue);
    letter-spacing: 0.08em;
}

.logout-link {
    margin-top: 10px;
    background: transparent;
    border: none;
    color: rgba(68, 64, 60, 0.75);
    font-family: var(--font-body);
    font-size: 0.85rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    cursor: pointer;
    transition: color 0.2s ease;
}

.logout-link:hover {
    color: var(--accent-copper-dark);
}

.logout-link:focus-visible {
    outline: 2px solid rgba(194, 65, 12, 0.45);
    outline-offset: 2px;
}

.divider-line {
    height: 1px;
    background-color: var(--line-strong);
    width: 100%;
    margin-bottom: 32px;
    opacity: 0.6;
}

/* --- Typography & Intro --- */
.rustic-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 400;
    line-height: 1.1;
    margin-bottom: 4px;
    color: var(--ink-black);
    letter-spacing: 0.01em;
}

.rustic-subtitle {
    font-family: var(--font-heading);
    font-size: 1.15rem;
    font-style: normal;
    color: var(--ink-light);
    margin-bottom: 32px;
    line-height: 1.35;
    /* Tighter line height for single unit feel */
    margin-top: 6px;
    /* Visual grouping with title */
}

/* --- Inputs --- */
.input-section {
    position: relative;
    margin-bottom: 32px;
    margin-top: 40px;
    padding: 28px 32px 32px;
    border: 1px solid rgba(28, 25, 23, 0.1);
    box-shadow: 2px 4px 12px rgba(28, 25, 23, 0.05);
    background-color: var(--paper-card);
    background-image: var(--paper-pattern);
    background-blend-mode: multiply;
    /* Added spacing to separate from header */
    transition: all 0.5s ease;
    text-align: center;
    font-size: 1.06rem;
    border-radius: 6px;
}

.handwritten-note {
    font-family: var(--font-heading);
    color: var(--accent-blue);
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 20px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.input-group {
    margin-bottom: 30px;
    text-align: left;
    max-width: 520px;
    margin-left: auto;
    margin-right: auto;
}

label {
    display: block;
    font-family: var(--font-heading);
    font-size: 1.15rem;
    margin-bottom: 6px;
    color: var(--ink-light);
}

.unit {
    font-size: 0.95rem;
    font-family: var(--font-body);
    font-style: normal;
    opacity: 0.6;
}

.input-wrapper {
    position: relative;
    width: 100%;
    max-width: 520px;
}

input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 1px solid rgba(109, 106, 99, 0.35);
    font-family: var(--font-hand);
    font-size: 2.05rem;
    color: var(--accent-blue);
    padding: 8px 0 10px;
    outline: none;
    transition: border-color 0.3s;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.02em;
}

input:focus {
    border-bottom-color: var(--accent-blue);
    box-shadow: 0 6px 0 -5px rgba(28, 25, 23, 0.4);
}

input::placeholder {
    color: rgba(87, 83, 78, 0.35);
    font-family: var(--font-heading);
    font-style: italic;
}

/* --- Stamp Button --- */
.action-area {
    margin-top: 36px;
    display: flex;
    justify-content: center;
    /* Centered as requested */
}

.stamp-button {
    background: transparent;
    border: 2px solid var(--accent-copper);
    color: var(--accent-copper);
    padding: 14px 42px;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 1.1rem;
    letter-spacing: 0.1em;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    transition: all 0.2s;
    text-transform: uppercase;
    /* Rough edges effect */
    border-radius: 2px;
}

.stamp-button:hover {
    background: rgba(234, 88, 12, 0.08);
    transform: scale(1.02);
}

.stamp-button:active {
    transform: scale(0.98);
    background: rgba(234, 88, 12, 0.12);
}

/* --- Results Section --- */
.results-section {
    margin-top: 32px;
    padding: 32px;
    border: 1px solid rgba(28, 25, 23, 0.1);
    box-shadow: 2px 4px 12px rgba(28, 25, 23, 0.05);
    background-color: var(--paper-card);
    background-image: var(--paper-pattern);
    background-blend-mode: multiply;
    border-radius: 6px;
    position: relative;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.results-section.show {
    opacity: 1;
    transform: translateY(0);
}

.hidden {
    display: none;
}

/* --- Auth Page --- */
.auth-section {
    margin-top: 30px;
    padding: 28px 32px 32px;
    border: 1px solid rgba(28, 25, 23, 0.1);
    box-shadow: 2px 4px 12px rgba(28, 25, 23, 0.05);
    background-color: var(--paper-card);
    background-image: var(--paper-pattern);
    background-blend-mode: multiply;
    border-radius: 6px;
}

.auth-section .input-group {
    margin-bottom: 18px;
}

.auth-section input {
    font-size: 1.7rem;
    letter-spacing: 0.03em;
}

.auth-hint {
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--ink-faded);
    text-align: center;
}

.auth-error {
    margin-top: 12px;
    font-size: 0.95rem;
    font-family: var(--font-body);
    color: var(--accent-copper-dark);
    text-align: center;
}

.auth-actions {
    margin-top: 26px;
    display: flex;
    justify-content: center;
}

.stamp-button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

/* --- Confetti Effect (Delightful) --- */
.confetti-particle {
    position: fixed;
    width: 10px;
    height: 10px;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
}

@keyframes puff {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
    }

    100% {
        transform: translateY(100vh) rotate(720deg);
        opacity: 0;
    }
}

/* --- Summary Band (Result Highlight) --- */
.summary-band {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    margin: 10px auto 28px auto;
    padding: 12px 28px 14px;
    border: 1px solid rgba(28, 25, 23, 0.18);
    box-shadow: 4px 10px 20px rgba(28, 25, 23, 0.08);
    background: transparent;
    color: var(--accent-blue);
    border-radius: 999px;
    font-family: var(--font-heading);
    min-height: 52px;
}

.summary-label {
    font-size: 0.95rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: var(--ink-faded);
    line-height: 1.1;
}

.summary-value {
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--accent-blue);
    line-height: 1;
}

/* --- Impact Card (Key Figure) --- */
.impact-card {
    background-color: #fff;
    border: 1px solid var(--accent-copper);
    border-left: 6px solid var(--accent-copper);
    padding: 20px 30px;
    margin-bottom: 40px;
    box-shadow: var(--shadow-soft);
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
    animation: slideUp 0.6s ease-out forwards;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.impact-header {
    font-size: 0.8rem;
    letter-spacing: 0.2em;
    color: var(--ink-faded);
    text-transform: uppercase;
    margin-bottom: 10px;
    font-weight: 600;
}

.impact-value {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.impact-label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--accent-blue);
    margin-top: 5px;
    letter-spacing: 0.05em;
}

/* Texture overlay for impact card */
.impact-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='20' height='20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1h2v2H1z' fill='%23EA580C' fill-opacity='0.05'/%3E%3C/svg%3E");
    opacity: 0.4;
    pointer-events: none;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-top: 24px;
    padding: 18px 0;
    border-top: 1px solid rgba(28, 25, 23, 0.12);
    border-bottom: 1px solid rgba(28, 25, 23, 0.12);
}

.result-card {
    padding: 18px 16px;
    background-color: transparent;
    border: 1px solid transparent;
    box-shadow: none;
    text-align: center;
    transition: all 0.3s ease;
}

.result-card.highlight {
    background-color: var(--paper-card);
    border: 1px solid rgba(28, 25, 23, 0.18);
    box-shadow: 4px 10px 20px rgba(28, 25, 23, 0.08);
    transform: rotate(-0.5deg);
    background-image: var(--paper-pattern);
    background-blend-mode: multiply;
}

.card-label {
    display: block;
    font-family: var(--font-heading);
    color: var(--ink-faded);
    margin-bottom: 10px;
    font-size: 0.95rem;
}

.card-value {
    display: block;
    font-family: var(--font-hand);
    font-size: 2rem;
    font-weight: 700;
    color: var(--ink-black);
    line-height: 1.2;
}

.highlight .card-value {
    color: var(--accent-blue);
    font-size: 2.15rem;
}

.card-sub {
    display: block;
    font-size: 0.8rem;
    color: var(--ink-faded);
    font-style: italic;
}

.actions-secondary {
    margin-top: 28px;
    text-align: center;
    display: flex;
    justify-content: center;
    gap: 30px;
}

.link-button {
    background: none;
    border: none;
    font-family: var(--font-body);
    font-size: 0.9rem;
    color: var(--accent-blue);
    cursor: pointer;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s;
    letter-spacing: 0.02em;
}

.link-button:hover {
    border-bottom-color: var(--accent-blue);
}

.link-button.muted {
    color: var(--ink-faded);
}

/* --- Footer --- */
.brief-footer {
    margin-top: 44px;
    padding: 24px 20px;
    text-align: center;
    border-top: 1px dotted var(--line-color);
}

.brief-footer p {
    font-size: 0.75rem;
    color: var(--ink-faded);
    letter-spacing: 0.12em;
    text-transform: uppercase;
    line-height: 1.6;
}

/* --- Modal --- */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.4);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
}

.modal-backdrop.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-paper {
    background-color: var(--paper-card);
    width: 95%;
    max-width: 900px;
    /* Increased from 700px */
    padding: 50px;
    position: relative;
    box-shadow: var(--shadow-deep);
    /* Folded letter effect */
    transform-origin: top center;
    animation: unfold 0.5s ease-out forwards;
    background-image: var(--paper-pattern);
}

@keyframes unfold {
    0% {
        transform: scaleY(0.2) translateY(-100px);
        opacity: 0;
    }

    100% {
        transform: scaleY(1) translateY(0);
        opacity: 1;
    }
}

.close-modal {
    position: absolute;
    top: 20px;
    right: 20px;
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--ink-faded);
    cursor: pointer;
}

.modal-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    margin-bottom: 20px;
    color: var(--ink-black);
    text-align: center;
}

.modal-intro {
    text-align: center;
    font-family: var(--font-body);
    color: var(--ink-light);
    margin-bottom: 30px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.ledger-container {
    border: 1px solid rgba(29, 27, 22, 0.15);
    padding: 5px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ledger-table {
    width: 100%;
    min-width: 550px;
    /* Force horizontal scroll on mobile */
    border-collapse: collapse;
    font-family: var(--font-body);
    font-size: 0.9rem;
}

.ledger-table th {
    text-align: left;
    padding: 12px 10px;
    border-bottom: 1px solid rgba(29, 27, 22, 0.45);
    font-weight: 600;
    color: var(--ink-black);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.75rem;
}

.ledger-table td {
    padding: 12px 10px;
    border-bottom: 1px solid rgba(29, 27, 22, 0.08);
    color: var(--ink-light);
}

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

.num-col {
    text-align: right;
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
}

.modal-footer {
    margin-top: 20px;
    text-align: center;
    font-size: 0.7rem;
    color: var(--ink-faded);
    font-style: italic;
}

/* Animations */
@keyframes writeIn {
    from {
        clip-path: inset(0 100% 0 0);
    }

    to {
        clip-path: inset(0 0 0 0);
    }
}

/* Responsive */
@media (max-width: 600px) {
    .paper-container {
        padding: 30px 20px;
    }

    .rustic-title {
        font-size: 1.64rem;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .input-wrapper {
        width: 100%;
    }

    /* Modal adjustments for mobile */
    .modal-paper {
        padding: 30px 15px;
        margin: 20px;
        max-width: 95vw;
    }

    /* Enable horizontal scroll for table */
    .ledger-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* Smooth scrolling on iOS */
        margin: 0 -15px;
        /* Compensate for modal padding */
        padding: 0 15px;
    }

    .ledger-table {
        min-width: 600px;
        /* Force table to maintain width */
    }

    /* Footer spacing fix */
    .brief-footer {
        padding: 20px 15px;
        font-size: 0.75rem;
        line-height: 1.5;
    }

    .brief-footer p {
        word-spacing: 0.1em;
    }

    .summary-band {
        width: 100%;
        justify-content: center;
        text-align: center;
        flex-wrap: wrap;
        min-height: 0;
    }

    /* Result cards spacing */
    .result-card {
        margin-bottom: 20px;
    }

    /* Actions spacing */
    .actions-secondary {
        flex-direction: column;
        gap: 15px;
    }

    .actions-secondary button {
        width: 100%;
    }
}
