<style>
    .inv_update {
        padding: 20px;
        font-family: 'Segoe UI', Arial, sans-serif;
        background: #f0f4ff;
        min-height: 100%;
    }

    .inv_card {
        background: rgba(255, 255, 255, 0.75);
        backdrop-filter: blur(12px);
        border: 1px solid rgba(255, 255, 255, 0.9);
        border-radius: 14px;
        padding: 20px 24px;
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
        margin-bottom: 16px;
    }

    .inv_section_title {
        font-size: 12px;
        font-weight: 700;
        color: #0f3460;
        text-transform: uppercase;
        letter-spacing: 0.8px;
        margin-bottom: 14px;
        padding-bottom: 8px;
        border-bottom: 2px solid rgba(15, 52, 96, 0.2);
    }

    .inv_info_grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 12px;
    }

    .inv_info_item {
        display: flex;
        flex-direction: column;
        gap: 4px;
    }

    .inv_info_label {
        font-size: 11px;
        font-weight: 700;
        color: #999;
        text-transform: uppercase;
        letter-spacing: 0.4px;
    }

    .inv_info_value {
        font-size: 14px;
        font-weight: 600;
        color: #1a1a2e;
        background: rgba(15, 52, 96, 0.04);
        border: 1px solid rgba(15, 52, 96, 0.1);
        border-radius: 8px;
        padding: 8px 12px;
    }

    .qty_value {
        font-size: 18px;
        font-weight: 700;
        color: #0f3460;
        background: rgba(15, 52, 96, 0.08);
        border: 1px solid rgba(15, 52, 96, 0.2);
    }

    .update_section_title {
        font-size: 12px;
        font-weight: 700;
        color: #f47f20;
        text-transform: uppercase;
        letter-spacing: 0.8px;
        margin-bottom: 14px;
        padding-bottom: 8px;
        border-bottom: 2px solid rgba(244, 127, 32, 0.2);
    }

    .form_group {
        display: flex;
        flex-direction: column;
        gap: 6px;
        margin-bottom: 14px;
    }

    .form_group label {
        font-size: 11px;
        font-weight: 700;
        color: #666;
        text-transform: uppercase;
        letter-spacing: 0.4px;
    }

    .form_group label.required::after {
        content: ' *';
        color: #dc3545;
    }

    .form_group input[type=text],
    .form_group textarea {
        border: 1px solid #e0e0e0;
        border-radius: 8px;
        padding: 10px 12px;
        font-size: 14px;
        color: #333;
        outline: none;
        transition: all 0.2s;
        background: white;
        font-family: 'Segoe UI', Arial, sans-serif;
        width: 100%;
        box-sizing: border-box;
    }

    .form_group input[type=text]:focus,
    .form_group textarea:focus {
        border-color: #f47f20;
        box-shadow: 0 0 0 3px rgba(244, 127, 32, 0.12);
    }

    .form_group textarea {
        resize: vertical;
        min-height: 70px;
    }

    .hint_text {
        font-size: 11px;
        color: #999;
        font-style: italic;
    }

    .submit_btn {
        background: linear-gradient(135deg, #f47f20, #e05f00);
        color: white;
        border: none;
        border-radius: 10px;
        padding: 12px 32px;
        font-size: 14px;
        font-weight: 700;
        cursor: pointer;
        box-shadow: 0 4px 14px rgba(244, 127, 32, 0.4);
        transition: all 0.2s;
        width: 100%;
        font-family: 'Segoe UI', Arial, sans-serif;
    }

    .submit_btn:hover {
        background: linear-gradient(135deg, #ff8f30, #f47f20);
        box-shadow: 0 6px 20px rgba(244, 127, 32, 0.5);
        transform: translateY(-1px);
    }

    #error_message_box {
        background: rgba(220, 53, 69, 0.08);
        border: 1px solid rgba(220, 53, 69, 0.2);
        border-radius: 8px;
        padding: 10px 14px;
        margin-bottom: 14px;
        color: #dc3545;
        font-size: 12px;
        list-style: none;
    }

    #error_message_box li {
        margin-left: 12px;
        list-style: disc;
    }

    /* ── Responsive ── */
    @media (max-width: 768px) {

        .inv_update {
            padding: 12px;
        }

        .inv_card {
            padding: 14px 16px;
            margin-bottom: 12px;
        }

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

        .inv_info_value {
            font-size: 13px;
            padding: 7px 10px;
        }

        .qty_value {
            font-size: 16px;
        }

        .form_group input[type=text],
        .form_group textarea {
            font-size: 14px;
            padding: 10px 12px;
        }

        .submit_btn {
            padding: 12px;
            font-size: 14px;
        }
    }

    @media (max-width: 480px) {

        .inv_update {
            padding: 8px;
        }

        .inv_card {
            padding: 12px;
        }

        .inv_section_title,
        .update_section_title {
            font-size: 11px;
        }

        .inv_info_label {
            font-size: 10px;
        }

        .hint_text {
            font-size: 10px;
        }
    }
</style>

<ul id="error_message_box" style="display:none;"></ul>

<?php
echo form_open('items/find_item_info/' . $item_info->item_id, array('id' => 'item_number_form'));
echo form_close();
echo form_open('items/save_inventory/' . $item_info->item_id, array('id' => 'item_form'));
?>

<div class="inv_update">

    <!-- Item Info -->
    <div class="inv_card">
        <div class="inv_section_title">📦 <?php echo $this->lang->line('items_basic_information'); ?></div>
        <div class="inv_info_grid">
            <div class="inv_info_item">
                <span class="inv_info_label"><?php echo $this->lang->line('items_item_number'); ?></span>
                <span class="inv_info_value"><?php echo $item_info->item_number ? $item_info->item_number : '—'; ?></span>
            </div>
            <div class="inv_info_item">
                <span class="inv_info_label"><?php echo $this->lang->line('items_name'); ?></span>
                <span class="inv_info_value"><?php echo $item_info->name; ?></span>
            </div>
            <div class="inv_info_item">
                <span class="inv_info_label"><?php echo $this->lang->line('items_category'); ?></span>
                <span class="inv_info_value"><?php echo $item_info->category; ?></span>
            </div>
            <div class="inv_info_item">
                <span class="inv_info_label"><?php echo $this->lang->line('items_current_quantity'); ?></span>
                <span class="inv_info_value qty_value"><?php echo number_format($item_info->quantity, 2); ?></span>
            </div>
        </div>
    </div>

    <!-- Update Inventory -->
    <div class="inv_card">
        <div class="update_section_title">✏️ Update Inventory</div>

        <div class="form_group">
            <label class="required"><?php echo $this->lang->line('items_add_minus'); ?></label>
            <?php echo form_input(array('name' => 'newquantity', 'id' => 'newquantity', 'placeholder' => 'e.g. 50 to add, -10 to subtract')); ?>
            <span class="hint_text">Use positive numbers to add stock, negative to subtract</span>
        </div>

        <div class="form_group">
            <label><?php echo $this->lang->line('items_inventory_comments'); ?></label>
            <?php echo form_textarea(array('name' => 'trans_comment', 'id' => 'trans_comment', 'rows' => 3, 'cols' => 17, 'placeholder' => 'Add a note about this inventory change...')); ?>
        </div>

        <button type="submit" class="submit_btn">
            💾 <?php echo $this->lang->line('common_submit'); ?>
        </button>
    </div>

</div>

<?php echo form_close(); ?>

<script type='text/javascript'>
    $(document).ready(function() {
        $('#item_form').validate({
            submitHandler: function(form) {
                $(form).ajaxSubmit({
                    success: function(response) {
                        tb_remove();
                        post_item_form_submit(response);
                    },
                    dataType: 'json'
                });
            },
            errorLabelContainer: "#error_message_box",
            wrapper: "li",
            rules: {
                newquantity: {
                    required: true,
                    number: true
                }
            },
            messages: {
                newquantity: {
                    required: "<?php echo $this->lang->line('items_quantity_required'); ?>",
                    number: "<?php echo $this->lang->line('items_quantity_number'); ?>"
                }
            },
            showErrors: function(errorMap, errorList) {
                $('#error_message_box').show();
                this.defaultShowErrors();
            }
        });
    });
</script>