﻿/* ==========================================================================
   WAMUGUNDA FARM - THERMAL RECEIPT PRINTER (Enhanced & Responsive)
   ========================================================================== */

.farm-printer-card {
    background: #fdfbf7;
    border: 1px solid #e7e2d7;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
    border-radius: 20px;
    padding: 35px 20px 40px;
    text-align: center;
    position: relative;
}

.farm-printer-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 25px 10px 30px;
    position: relative;
    min-height: 700px;
    width: 100%;
}

.printer-wrapper {
    --printer-color: #1b5e20;
    --printer-color-2: #144617;
    --printer-accent: #facc15;
    --receipt-color: #fffefb;

    font-size: 14px;
    position: relative;
    user-select: none;
    width: 340px;
    margin: 0 auto;
}

.printer {
    width: 340px;
    height: 90px;
    border-radius: 0 0 14px 14px;
    background-color: var(--printer-color);
    background-image: linear-gradient(135deg, #1e6b24 0%, #134617 100%);
    border: 2px solid var(--printer-color-2);
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.28), 0 -25px 20px rgba(0, 0, 0, 0.08);
    position: relative;
    z-index: 10;
}

.printer::before {
    content: "";
    position: absolute;
    top: -32px;
    left: 0;
    width: 100%;
    height: 72px;
    border-radius: 14px 14px 0 0;
    border-bottom: 2px solid rgba(0, 0, 0, 0.25);
    box-shadow: inset 0 12px 16px -10px rgba(255, 255, 255, 0.35), inset 0 -6px 16px -6px rgba(0, 0, 0, 0.35);
    box-sizing: border-box;
    background-color: inherit;
    background-image: inherit;
    filter: brightness(1.15);
    z-index: 11;
}

.printer::after {
    content: "";
    position: absolute;
    top: 24px;
    left: 25px;
    width: 290px;
    height: 40px;
    border-radius: 0 0 6px 6px;
    border-bottom: 1.5px solid rgba(0, 0, 0, 0.4);
    background-color: #071e09;
    box-shadow: inset 0 6px 8px -2px rgba(0, 0, 0, 0.6);
    z-index: 9;
}

.printer-display {
    z-index: 12;
    display: flex;
    align-items: center;
    padding: 6px 12px;
    position: absolute;
    top: -12px;
    left: 25px;
    width: 185px;
    height: 36px;
    background-color: #051407;
    border: 2.5px solid #22c55e;
    border-radius: 7px;
    box-sizing: border-box;
    box-shadow: inset 0 0 10px rgba(34, 197, 94, 0.45), 0 0 8px rgba(34, 197, 94, 0.3);
    font-family: "Courier New", Courier, monospace;
    font-size: 0.82em;
    font-weight: bold;
    color: #4ade80;
    overflow: hidden;
    letter-spacing: 0.5px;
}

.printer-message {
    transition: opacity 0.3s ease;
    white-space: nowrap;
}

.print-button {
    z-index: 12;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15em;
    position: absolute;
    top: -32px;
    right: 5px;
    margin: 16px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 8px;
    width: 56px;
    height: 40px;
    background-color: #facc15;
    color: #144617;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    transition: all 0.2s ease-in-out;
}

.print-button:hover {
    transform: scale(1.06);
    background-color: #fde047;
    box-shadow: 0 0 14px rgba(250, 204, 21, 0.7);
}

.print-button:active {
    transform: scale(0.95);
}

/* ==================== THERMAL PAPER RECEIPT ==================== */
.receipt-wrapper {
    position: absolute;
    top: 10px;
    left: 28px;
    z-index: 8;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.14));
    transform: translateY(-90%);
    clip-path: inset(100% -20px -20px -20px);
    transition: transform 1s cubic-bezier(0.16, 1, 0.3, 1), clip-path 1s ease;
    width: 284px;
}

.receipt {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.75em;
    padding: 22px 18px 24px;
    width: 284px;
    font-size: 0.76em;
    font-family: "Courier New", Courier, "Space Mono", monospace;
    font-weight: 500;
    color: #1a1a1a;
    background-color: var(--receipt-color);
    background-image: radial-gradient(#eceae4 0.75px, transparent 0.75px);
    background-size: 6px 6px;
    border-left: 1px dashed #d6d3cb;
    border-right: 1px dashed #d6d3cb;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.08);
    box-sizing: border-box;
}

/* Diagonal Watermark Across Receipt */
.receipt-watermark {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-32deg);
    font-size: 22px;
    font-weight: 900;
    color: rgba(27, 94, 32, 0.07);
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 3px;
    z-index: 1;
    text-transform: uppercase;
    font-family: Arial, Helvetica, sans-serif;
}

/* Jagged Paper Top & Bottom Edges */
.receipt-jagged-top,
.receipt-jagged-bottom {
    position: absolute;
    left: 0;
    width: 100%;
    height: 10px;
    background-size: 10px 10px;
    background-repeat: repeat-x;
    z-index: 5;
}

.receipt-jagged-top {
    top: -10px;
    background-image: linear-gradient(-45deg, var(--receipt-color) 5px, transparent 0),
                      linear-gradient(45deg, var(--receipt-color) 5px, transparent 0);
    background-position: 5px 0;
}

.receipt-jagged-bottom {
    bottom: -10px;
    background-image: linear-gradient(135deg, var(--receipt-color) 5px, transparent 0),
                      linear-gradient(-135deg, var(--receipt-color) 5px, transparent 0);
    background-position: 0 100%;
}

/* Receipt Header */
.receipt-header {
    text-align: center;
    border-bottom: 1px dashed #888888;
    padding-bottom: 10px;
    position: relative;
    z-index: 2;
}

.receipt-logo {
    max-height: 44px;
    margin-bottom: 4px;
    filter: contrast(1.2);
}

.receipt-farm-name {
    font-size: 1.25em;
    font-weight: 800;
    color: #1b5e20;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-top: 2px;
    display: block;
}

.receipt-contacts {
    font-size: 0.88em;
    color: #4b5563;
    line-height: 1.35em;
    margin-top: 2px;
}

.receipt-subheader {
    display: flex;
    justify-content: space-between;
    font-size: 0.92em;
    border-bottom: 1px dashed #888888;
    padding: 6px 0;
    position: relative;
    z-index: 2;
    font-weight: 600;
}

.receipt-customer-meta {
    font-size: 0.88em;
    color: #2b2b2b;
    line-height: 1.4em;
    padding: 4px 0;
    border-bottom: 1px dashed #888888;
    position: relative;
    z-index: 2;
}

/* Table */
.receipt-table {
    width: 100%;
    font: inherit;
    color: inherit;
    line-height: 1.4em;
    border-collapse: collapse;
    position: relative;
    z-index: 2;
    margin: 4px 0;
}

.receipt-table th {
    border-bottom: 1px solid #444444;
    padding: 4px 0;
    text-align: left;
    font-size: 0.92em;
    font-weight: 700;
}

.receipt-table th:last-child,
.receipt-table td:last-child {
    text-align: right;
}

.receipt-table td {
    padding: 3.5px 0;
}

.receipt-subtotal td {
    border-top: 1px dashed #888888;
    padding-top: 6px;
}

.receipt-total td {
    border-top: 1.5px solid #111827;
    border-bottom: 1.5px solid #111827;
    font-size: 1.15em;
    font-weight: 800;
    padding: 6px 0;
    color: #1b5e20;
}

.receipt-mpesa-badge {
    font-size: 0.85em;
    text-align: center;
    color: #166534;
    background: #f0fdf4;
    padding: 6px;
    border: 1px dashed #22c55e;
    border-radius: 4px;
    position: relative;
    z-index: 2;
    line-height: 1.4em;
}

.receipt-message {
    text-align: center;
    font-size: 0.88em;
    padding-top: 6px;
    color: #4b5563;
    border-top: 1px dashed #888888;
    position: relative;
    z-index: 2;
    font-style: italic;
}

.receipt-barcode {
    text-align: center;
    letter-spacing: 4px;
    font-size: 1.2em;
    font-family: "Courier New", monospace;
    margin-top: 4px;
    font-weight: bold;
    color: #111827;
    position: relative;
    z-index: 2;
}

/* ==================== ANIMATION TRIGGERS ==================== */
.letter-wrapper {
    position: inherit;
    display: flex;
}

.letter {
    display: inline-block;
    opacity: 0;
}

.printer-wrapper.printed .receipt-wrapper {
    animation: printReceipt 1.4s 1 forwards cubic-bezier(0.16, 1, 0.3, 1);
}

.printer-wrapper.printed .printer-message {
    opacity: 0;
}

.printer-wrapper.printed .letter {
    animation: showLetter 0.6s 1 forwards linear;
}

.printer-wrapper.printed .letter:nth-child(1) { animation-delay: 0.05s; }
.printer-wrapper.printed .letter:nth-child(2) { animation-delay: 0.1s; }
.printer-wrapper.printed .letter:nth-child(3) { animation-delay: 0.15s; }
.printer-wrapper.printed .letter:nth-child(4) { animation-delay: 0.2s; }
.printer-wrapper.printed .letter:nth-child(5) { animation-delay: 0.25s; }
.printer-wrapper.printed .letter:nth-child(6) { animation-delay: 0.3s; }
.printer-wrapper.printed .letter:nth-child(7) { animation-delay: 0.35s; }
.printer-wrapper.printed .letter:nth-child(8) { animation-delay: 0.4s; }
.printer-wrapper.printed .letter:nth-child(9) { animation-delay: 0.45s; }
.printer-wrapper.printed .letter:nth-child(10) { animation-delay: 0.5s; }
.printer-wrapper.printed .letter:nth-child(11) { animation-delay: 0.55s; }

@keyframes printReceipt {
    0% {
        transform: translateY(-90%);
        clip-path: inset(100% -20px -20px -20px);
    }
    60% {
        transform: translateY(35px);
        clip-path: inset(-10px -20px -20px -20px);
    }
    100% {
        transform: translateY(40px);
        clip-path: inset(-10px -20px -20px -20px);
        z-index: 15;
    }
}

@keyframes showLetter {
    10%, 100% { opacity: 1; }
}

/* Action buttons below printer */
.receipt-action-buttons {
    margin-top: 45px;
    position: relative;
    z-index: 25;
}

/* Print Styling for Mobile / Desktop window.print() */
@media print {
    body * {
        visibility: hidden !important;
    }
    .receipt, .receipt * {
        visibility: visible !important;
    }
    .receipt {
        position: absolute !important;
        left: 0 !important;
        top: 0 !important;
        width: 100% !important;
        max-width: 320px !important;
        box-shadow: none !important;
        border: none !important;
    }
}