/* StockCard Styles - ตามแบบฟอร์ม Big Foods Group */
:root {
    --primary-green: #4a7c59;
    --light-green: #e8f5e9;
    --form-bg: #f0f7f0;
    --border-color: #2d5a3d;
    --text-dark: #1a3d25;
    --white: #ffffff;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Sarabun', 'Segoe UI', Tahoma, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

/* Container */
.stock-card-container {
    max-width: 1100px;
    margin: 0 auto;
    background: var(--form-bg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* Header */
.header {
    background: linear-gradient(90deg, var(--primary-green), #3d6b4a);
    color: var(--white);
    padding: 20px 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
}

.header-left {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 15px;
}

.logo-img {
    width: 80px;
    height: 80px;
    object-fit: contain;
}

.logo {
    width: 60px;
    height: 60px;
    background: var(--white);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: var(--primary-green);
    font-size: 20px;
}

.company-name {
    font-size: 1.5rem;
    font-weight: 600;
}

.header-right {
    position: absolute;
    top: 15px;
    right: 20px;
    text-align: right;
    font-size: 0.85rem;
}

.doc-number {
    font-weight: 600;
    margin-bottom: 5px;
}

/* Title */
.title-section {
    text-align: center;
    padding: 25px;
    background: var(--light-green);
    border-bottom: 2px solid var(--border-color);
}

.title-section h1 {
    font-size: 1.8rem;
    color: var(--text-dark);
    font-weight: 700;
}

/* Search Section */
.search-section {
    padding: 25px 30px;
    background: var(--white);
    border-bottom: 1px solid #ddd;
}

.search-form {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.form-group {
    flex: 1;
    min-width: 200px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-dark);
}

.form-group input {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary-green);
    box-shadow: 0 0 0 3px rgba(74, 124, 89, 0.2);
}

.btn-search {
    padding: 12px 30px;
    background: var(--primary-green);
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-search:hover {
    background: #3d6b4a;
    transform: translateY(-2px);
}

.btn-print {
    padding: 12px 30px;
    background: #1976d2;
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-print:hover {
    background: #1565c0;
    transform: translateY(-2px);
}

/* Product Info */
.product-info {
    padding: 20px 30px;
    background: var(--light-green);
    border-bottom: 2px solid var(--border-color);
}

.product-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 15px;
}

.info-item {
    display: flex;
    gap: 10px;
}

.info-label {
    font-weight: 600;
    color: var(--text-dark);
    min-width: 100px;
}

.info-value {
    color: #333;
    border-bottom: 1px dotted #999;
    flex: 1;
    padding-bottom: 3px;
}

/* Table Section */
.table-section {
    padding: 20px;
    background: var(--white);
    overflow-x: auto;
}

.stock-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.stock-table thead {
    background: var(--primary-green);
    color: var(--white);
}

.stock-table th {
    padding: 12px 10px;
    text-align: center;
    font-weight: 600;
    border: 1px solid var(--border-color);
}

.stock-table td {
    padding: 10px;
    text-align: center;
    border: 1px solid #ddd;
}

.stock-table tbody tr:nth-child(even) {
    background: #f8fdf8;
}

.stock-table tbody tr:hover {
    background: var(--light-green);
}

/* Number columns */
.stock-table .qty-in {
    color: #2e7d32;
    font-weight: 600;
}

.stock-table .qty-out {
    color: #c62828;
    font-weight: 600;
}

.stock-table .qty-balance {
    color: #1565c0;
    font-weight: 700;
    background: #e3f2fd;
}

/* Editable input in table */
.editable-input {
    width: 90px;
    padding: 4px 2px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.8rem;
    text-align: center;
    background: #fff;
}

.editable-input:focus {
    outline: none;
    border-color: var(--primary-green);
    background: #f0fff0;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 20px;
    color: #ddd;
}

.empty-state p {
    font-size: 1.2rem;
}

/* Empty rows for print */
.empty-row {
    display: none;
    /* ซ่อนบนหน้าจอ */
}

/* Summary visible only on screen */
.screen-only {
    display: block;
}

/* Footer */
.footer {
    padding: 15px 30px;
    background: var(--light-green);
    border-top: 2px solid var(--border-color);
    text-align: center;
    font-size: 0.85rem;
    color: #666;
}

/* Loading */
.loading {
    display: none;
    text-align: center;
    padding: 40px;
}

.loading.active {
    display: block;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #ddd;
    border-top-color: var(--primary-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Print Styles - พื้นหลังขาว */
@media print {
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    body {
        background: #fff !important;
        padding: 0;
        margin: 0;
        font-size: 11pt;
    }

    .stock-card-container {
        box-shadow: none;
        border-radius: 0;
        max-width: 100%;
        background: #fff !important;
        border: none;
    }

    /* Hide search section in print */
    .search-section {
        display: none !important;
    }

    /* Print Header - แบบฟอร์มกระดาษ (ซ้ำทุกหน้า) */
    .header {
        background: #fff !important;
        color: #000 !important;
        padding: 15px 20px;
        border-bottom: none;
        display: flex;
        justify-content: center;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
    }

    .header-left {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        gap: 10px;
    }

    .logo-img {
        width: 60px;
        height: 60px;
    }

    .company-name {
        font-size: 14pt;
        color: #000 !important;
    }

    .header-right {
        position: absolute;
        top: 10px;
        right: 15px;
        color: #000 !important;
        font-size: 9pt;
        border: none;
        padding: 0;
        text-align: right;
    }

    /* Print Title (ซ้ำทุกหน้า) */
    .title-section {
        background: #fff !important;
        padding: 10px;
        border-bottom: none;
        position: fixed;
        top: 80px;
        left: 0;
        right: 0;
        z-index: 99;
    }

    .title-section h1 {
        font-size: 14pt;
        color: #000 !important;
    }

    /* Print Product Info (ซ้ำทุกหน้า) */
    .product-info {
        background: #fff !important;
        padding: 10px 20px;
        border-bottom: none;
        position: fixed;
        top: 120px;
        left: 0;
        right: 0;
        z-index: 98;
    }

    /* Table section ต้องมี margin-top เพื่อไม่ให้ซ้อนกับ header */
    .table-section {
        background: #fff !important;
        padding: 10px;
        margin-top: 200px;
    }

    /* Print Title */
    .title-section {
        background: #fff !important;
        padding: 10px;
        border-bottom: none;
    }

    .title-section h1 {
        font-size: 14pt;
        color: #000 !important;
    }

    /* Print Product Info */
    .product-info {
        background: #fff !important;
        padding: 10px 20px;
        border-bottom: 1px solid #333;
    }

    .product-info-grid {
        grid-template-columns: 1fr;
        gap: 5px;
    }

    .info-label {
        color: #000 !important;
        font-size: 10pt;
        min-width: 100px;
        width: 100px;
    }

    .info-value {
        color: #000 !important;
        border-bottom: 1px dotted #999;
        font-size: 10pt;
        flex: 1;
        padding-left: 10px;
    }

    /* Print Table - เส้นขอบชัดเจน */
    .table-section {
        background: #fff !important;
        padding: 10px;
    }

    .stock-table {
        border: none;
        font-size: 9pt;
    }

    .stock-table thead {
        display: table-header-group;
        background: #f0f0f0 !important;
    }

    .stock-table th {
        color: #000 !important;
        background: #f0f0f0 !important;
        padding: 8px 4px;
        border: 1px solid #333 !important;
        font-size: 9pt;
        font-weight: 600;
    }

    .stock-table td {
        padding: 6px 4px;
        border: 1px solid #333 !important;
        font-size: 9pt;
        background: #fff !important;
    }

    .stock-table tbody tr:nth-child(even) td {
        background: #fff !important;
    }

    .stock-table .qty-in {
        color: #000 !important;
    }

    .stock-table .qty-out {
        color: #000 !important;
    }

    .stock-table .qty-balance {
        color: #000 !important;
        background: #fff !important;
        font-weight: bold;
    }

    /* Hide summary in print */
    .table-section>div:last-child {
        display: none !important;
    }

    /* Show empty rows in print */
    .empty-row {
        display: table-row !important;
    }

    .empty-row td {
        height: 20px;
        background: #fff !important;
    }

    /* Hide screen-only elements */
    .screen-only {
        display: none !important;
    }

    /* Print Footer - ซ่อน */
    .footer {
        display: none !important;
    }

    /* Hide input borders in print */
    .editable-input {
        border: none !important;
        background: transparent !important;
        padding: 0 !important;
    }

    /* Hide placeholder in print */
    .editable-input::placeholder {
        color: transparent !important;
    }

    /* Page setup */
    @page {
        size: A4 portrait;
        margin: 10mm;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .header {
        flex-direction: column;
        text-align: center;
        gap: 15px;
    }

    .header-right {
        text-align: center;
    }

    .search-form {
        flex-direction: column;
    }

    .form-group {
        width: 100%;
    }
}