.form-page {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.page-top h1 {
    font-size: 32px;
    color: #0f172a;
}

.page-top p {
    color: #64748b;
}

.form-card,
.table-card {
    background: white;

    padding: 30px;

    border-radius: 20px;

    box-shadow:
        0 4px 15px rgba(0, 0, 0, 0.05);
}

.form-grid {
    display: grid;

    grid-template-columns:
        repeat(auto-fit, minmax(220px, 1fr));

    gap: 20px;

    margin-bottom: 25px;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    margin-bottom: 8px;
    color: #334155;
    font-weight: bold;
}

.form-group input {
    padding: 14px;

    border-radius: 10px;

    border: 1px solid #cbd5e1;

    outline: none;
}

.primary-btn {
    background: #2563eb;
    color: white;

    border: none;

    padding: 14px 25px;

    border-radius: 10px;

    font-weight: bold;

    cursor: pointer;
}

.primary-btn:hover {
    background: #1d4ed8;
}

table {
    width: 100%;
    border-collapse: collapse;
}

table thead {
    background: #f8fafc;
}

table th,
table td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.signature-box {
    margin: 25px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.signature-box label {
    font-weight: bold;
    color: #334155;
}

#signatureCanvas {
    width: 100%;
    max-width: 500px;
    height: 180px;

    background: #ffffff;

    border: 2px dashed #94a3b8;
    border-radius: 12px;

    cursor: crosshair;
}

#clearSignatureBtn {
    width: fit-content;

    padding: 10px 16px;

    border: none;
    border-radius: 8px;

    background: #e2e8f0;
    color: #0f172a;

    font-weight: 600;
    cursor: pointer;
}

.invoice-modal {

    position: fixed;

    inset: 0;

    background:
        rgba(15, 23, 42, 0.75);

    display: none;

    justify-content: center;
    align-items: center;

    z-index: 9999;

    padding: 20px;

}

.invoice-container {

    background: white;

    width: 100%;
    max-width: 850px;

    border-radius: 20px;

    padding: 30px;

    box-shadow:
        0 10px 40px rgba(0, 0, 0, 0.2);

}

.invoice-top {

    display: flex;
    justify-content: space-between;
    align-items: center;

    margin-bottom: 30px;

}

.invoice-top h1 {

    margin: 0;

    color: #0f172a;

}

.invoice-top p {

    margin-top: 8px;

    color: #64748b;

}

.invoice-actions {

    display: flex;
    gap: 12px;

}

.invoice-actions button {

    padding: 10px 16px;

    border: none;

    border-radius: 10px;

    cursor: pointer;

    font-weight: 600;

}

#printInvoiceBtn {

    background: #2563eb;
    color: white;

}

#closeInvoiceBtn {

    background: #e2e8f0;
    color: #0f172a;

}

.invoice-details {

    display: grid;

    grid-template-columns:
        repeat(auto-fit, minmax(220px, 1fr));

    gap: 20px;

    margin-bottom: 30px;

}

.invoice-signature {

    margin-top: 30px;

}

.invoice-signature img {

    width: 250px;

    border-bottom:
        2px solid #0f172a;

    padding-bottom: 10px;

}

/* ===============================
   FLOATING METAL SEARCH
================================ */

.metal-search-overlay {
    position: fixed;
    inset: 0;
    background: rgba(5, 10, 20, 0.65);
    backdrop-filter: blur(6px);
    z-index: 9999;

    display: none;
    justify-content: center;
    align-items: flex-start;

    padding-top: 90px;
}

.metal-search-overlay.show {
    display: flex;
}

.metal-search-box {
    width: min(900px, 92%);
    max-height: 80vh;
    overflow-y: auto;

    background:
        linear-gradient(145deg, #1f2937, #0f172a 45%, #111827);
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow:
        0 25px 70px rgba(0, 0, 0, 0.45),
        inset 0 1px 0 rgba(255, 255, 255, 0.12);

    border-radius: 22px;
    padding: 28px;

    color: white;
    position: relative;
}

.metal-search-close {
    position: absolute;
    top: 18px;
    right: 22px;

    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: white;

    width: 38px;
    height: 38px;
    border-radius: 50%;

    font-size: 24px;
    cursor: pointer;
}

.metal-search-header h2 {
    margin: 0;
    font-size: 34px;
}

.metal-search-header p {
    color: #cbd5e1;
    margin-top: 8px;
}

.metal-search-controls {
    display: grid;
    grid-template-columns: 220px 1fr 120px;
    gap: 14px;
    margin-top: 24px;
}

.metal-search-controls select,
.metal-search-controls input {
    width: 100%;
    padding: 14px 16px;

    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.18);

    background: rgba(255, 255, 255, 0.08);
    color: white;
    font-size: 15px;
}

.metal-search-controls input::placeholder {
    color: #94a3b8;
}

.metal-search-controls button {
    border: none;
    border-radius: 12px;

    background: linear-gradient(135deg, #2563eb, #0ea5e9);
    color: white;

    font-weight: bold;
    cursor: pointer;
}

.metal-search-results {
    margin-top: 24px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 16px;
    padding: 18px;
    min-height: 90px;
}

.metal-search-count {
    font-weight: bold;
    margin-bottom: 14px;
    color: #93c5fd;
}

.metal-result-card {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 16px;
    margin-bottom: 12px;
}

.metal-result-card h4 {
    margin: 0 0 10px;
    color: #bfdbfe;
}

.metal-result-card pre {
    white-space: pre-wrap;
    color: #e5e7eb;
    font-size: 13px;
}

/* MOBILE */
@media (max-width: 700px) {
    .metal-search-controls {
        grid-template-columns: 1fr;
    }
}

.invoice-signature img {
    width: 250px;

    border-bottom:
        2px solid #0f172a;

    padding-bottom: 10px;
}

/* =========================================
   ORDER FORM RESPONSIVE WIDTH FIX
========================================= */

.order-form-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: start;
}

.full-row {
    grid-column: 1 / -1;
}

.full-width-btn {
    width: 100%;
}

.table-scroll-box {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

.table-scroll-box .admin-table {
    width: 100%;
    min-width: 720px;
}

.signature-box {
    width: 100%;
    max-width: 700px;
    overflow-x: auto;
}

.signature-box canvas {
    max-width: 100%;
    border: 2px dashed #94a3b8;
    border-radius: 14px;
}

@media (max-width: 1100px) {
    .order-form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 700px) {
    .order-form-grid {
        grid-template-columns: 1fr;
    }

    .table-scroll-box .admin-table {
        min-width: 650px;
    }
}

/* =========================================
   FORCE FIX: ORDER CART TABLE SPILLING
========================================= */

#orderForm {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
}

#orderForm .form-grid,
#orderForm .order-form-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 22px;
    width: 100%;
    max-width: 100%;
}

#orderForm .full-row {
    grid-column: 1 / -1 !important;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

#orderForm .table-scroll-box {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

#orderForm .table-scroll-box table,
#orderForm table.admin-table {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    table-layout: fixed !important;
}

#orderForm table.admin-table th,
#orderForm table.admin-table td {
    white-space: normal !important;
    word-break: break-word;
}

#orderForm table.admin-table th:nth-child(1),
#orderForm table.admin-table td:nth-child(1) {
    width: 35%;
}

#orderForm table.admin-table th:nth-child(2),
#orderForm table.admin-table td:nth-child(2) {
    width: 10%;
}

#orderForm table.admin-table th:nth-child(3),
#orderForm table.admin-table td:nth-child(3),
#orderForm table.admin-table th:nth-child(4),
#orderForm table.admin-table td:nth-child(4) {
    width: 18%;
}

#orderForm table.admin-table th:nth-child(5),
#orderForm table.admin-table td:nth-child(5) {
    width: 19%;
}

@media (max-width: 1100px) {

    #orderForm .form-grid,
    #orderForm .order-form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}

@media (max-width: 700px) {

    #orderForm .form-grid,
    #orderForm .order-form-grid {
        grid-template-columns: 1fr !important;
    }
}

/* =========================================
   PURCHASE ORDER PAGE POLISH
========================================= */

.admin-form-card,
.admin-table-card {
    max-width: 1200px;
    margin: 0 auto 30px;
}

.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 28px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group.full-width,
.form-actions.full-width {
    grid-column: 1 / -1;
}

.admin-form-card input,
.admin-form-card select,
.admin-form-card textarea {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid #dbe4f0;
    background: #ffffff;
    font-size: 15px;
}

.admin-form-card textarea {
    min-height: 120px;
    resize: vertical;
}

.save-btn {
    background: linear-gradient(135deg,
            #0f766e,
            #0f172a);

    color: white;
    border: none;
    padding: 14px 24px;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
}

.save-btn:hover {
    opacity: 0.92;
    transform: translateY(-1px);
}

.admin-table-card table {
    width: 100%;
    border-collapse: collapse;
}

.admin-table-card th,
.admin-table-card td {
    padding: 14px;
    border-bottom: 1px solid #edf2f7;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: #dcfce7;
    color: #166534;
    font-size: 13px;
    font-weight: 700;
}

/* MOBILE */

@media (max-width: 768px) {

    .admin-form-grid {
        grid-template-columns: 1fr;
    }

}

/* =========================================
   FINAL PURCHASE ORDER UI OVERRIDE
========================================= */

.admin-content {
    padding: 30px;
}

.admin-form-card,
.admin-table-card {

    background: #ffffff !important;

    border-radius: 24px !important;

    padding: 30px !important;

    margin-bottom: 30px !important;

    box-shadow:
        0 10px 30px rgba(15, 23, 42, 0.08) !important;
}

.admin-form-grid {

    display: grid !important;

    grid-template-columns:
        repeat(2, minmax(320px, 1fr)) !important;

    column-gap: 40px !important;

    row-gap: 28px !important;

    align-items: start !important;
}

.form-group {

    display: flex !important;

    flex-direction: column !important;

    margin-bottom: 8px;
}

.form-group label {

    margin-bottom: 10px !important;

    font-weight: 700 !important;

    color: #0f172a !important;

    font-size: 14px !important;
}

.form-group input,
.form-group textarea,
.form-group select {

    width: 100% !important;

    background: #f8fafc !important;

    border:
        1px solid #dbe2ea !important;

    border-radius: 14px !important;

    padding: 14px 16px !important;

    font-size: 14px !important;

    color: #0f172a !important;

    transition: 0.2s ease;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {

    outline: none !important;

    border-color: #0f766e !important;

    background: #ffffff !important;
}

.form-group textarea {

    resize: vertical !important;

    min-height: 120px !important;
}

.full-width {

    grid-column: 1 / -1 !important;
}

.table-wrapper {

    width: 100% !important;

    overflow-x: auto !important;

    margin-top: 14px !important;
}

.admin-table {

    width: 100% !important;

    border-collapse: collapse !important;
}

.admin-table thead {

    background: #f1f5f9 !important;
}

.admin-table th {

    padding: 16px !important;

    font-size: 14px !important;

    text-align: left !important;

    color: #0f172a !important;
}

.admin-table td {

    padding: 16px !important;

    border-bottom:
        1px solid #e2e8f0 !important;
}

.admin-table input {

    width: 100% !important;

    padding: 12px !important;

    border-radius: 10px !important;

    border:
        1px solid #cbd5e1 !important;
}

.save-btn {

    border: none !important;

    background:
        linear-gradient(135deg,
            #14532d,
            #0f172a) !important;

    color: #ffffff !important;

    padding: 14px 22px !important;

    border-radius: 14px !important;

    font-weight: 700 !important;

    cursor: pointer !important;

    transition: 0.2s ease !important;
}

.save-btn:hover {

    transform: translateY(-2px);
}

.danger-btn {

    border: none !important;

    background: #dc2626 !important;

    color: white !important;

    padding: 12px 16px !important;

    border-radius: 10px !important;

    cursor: pointer !important;
}

.status-pill {

    display: inline-flex !important;

    align-items: center !important;

    justify-content: center !important;

    padding: 7px 14px !important;

    border-radius: 999px !important;

    background: #dcfce7 !important;

    color: #166534 !important;

    font-size: 12px !important;

    font-weight: 800 !important;
}

/* =========================================
   MOBILE
========================================= */

@media (max-width: 768px) {

    .admin-form-grid {

        grid-template-columns: 1fr !important;
    }

    .admin-content {

        padding: 18px !important;
    }

}

/* =========================================
   FINAL PRINT FIX - PURCHASE ORDER ONLY
========================================= */

@media print {

    html,
    body {
        width: 210mm !important;
        height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible !important;
        background: white !important;
    }

    body>*:not(#poModal) {
        display: none !important;
    }

    #poModal {
        display: block !important;
        position: static !important;
        width: 100% !important;
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    #poModal .invoice-box {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: none !important;
        height: auto !important;
        min-height: 0 !important;
        max-height: none !important;
        overflow: visible !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        padding: 10mm !important;
        margin: 0 !important;
    }

    .invoice-close-btn,
    .invoice-actions {
        display: none !important;
    }

    #poModal * {
        page-break-before: auto !important;
        page-break-after: auto !important;
        page-break-inside: avoid !important;
    }

    @page {
        size: A4 portrait;
        margin: 10mm;
    }
}