/* ============================================================
   inventory.css — หน้าคลังอุปกรณ์ (Item cards)
   ============================================================ */

.item-card {
    background: var(--card-bg);
    border: 1.5px solid var(--border-color);
    border-radius: 14px;
    padding: 16px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    transition: border-color 0.15s, transform 0.15s;
}

.item-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.item-top-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

/* ปรับขนาดรูปในคลังอุปกรณ์ให้ใหญ่ขึ้นตามต้องการ */
.image-picker {
    position: relative;
    width: 72px;  /* ขยายขนาดรูปเป็น 72px */
    height: 72px; /* ขยายขนาดรูปเป็น 72px */
    border-radius: 12px;
    overflow: hidden;
    background-color: #f1f5f9;
    border: 1.5px dashed #cbd5e1;
    cursor: pointer;
    flex-shrink: 0;
}

.image-picker.readonly {
    cursor: pointer;
    border-style: solid;
}

.image-picker img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.image-picker-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    opacity: 0;
    transition: opacity 0.2s;
}

.image-picker:not(.readonly):hover .image-picker-overlay {
    opacity: 1;
}

.item-info {
    flex: 1;
    min-width: 0;
}

.item-name {
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.item-spec {
    font-size: 14px;
    color: #2563eb;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.btn-rename {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    font-size: 12px;
    margin-left: 4px;
}

.btn-rename:hover {
    color: var(--primary-color);
}

.item-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
}

.quantity-control {
    display: flex;
    align-items: center;
    background: #f8fafc;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    padding: 2px;
    gap: 2px;
}

.btn-qty {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    border: none;
    background: white;
    color: var(--text-main);
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-qty:hover {
    background: var(--primary-color);
    color: white;
}

.qty-input {
    width: 56px;
    height: 32px;
    border: none;
    background: transparent;
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    outline: none;
}

.qty-input[readonly] {
    cursor: default;
}

.qty-badge-only {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary-color);
    padding: 2px 8px;
}

/* ============================================================
   [NEW] แจ้งเตือนสต็อกขั้นต่ำ (Low Stock Warning)
   ============================================================ */

.item-card.stock-warning {
    border-color: var(--warning-color);
    border-left: 6px solid var(--warning-color);
    background: #fffcf5;
}

.item-card.stock-danger {
    border-color: var(--danger-color);
    border-left: 6px solid var(--danger-color);
    background: #fef2f2;
}

.stock-warning-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 13px;
    font-weight: 800;
    padding: 4px 11px;
    border-radius: 10px;
    margin-top: 4px;
    margin-left: 4px;
}

.stock-warning-badge i {
    font-size: 13px;
}

.stock-warning-badge.warning {
    background: #f59e0b;
    color: #ffffff;
    border: 1px solid #d97706;
}

.stock-warning-badge.danger {
    background: #ef4444;
    color: #ffffff;
    border: 1px solid #dc2626;
}

/* ============================================================
   [NEW] โหมด "ตาราง" (Table View)
   ============================================================ */

.items-table-wrap {
    width: 100%;
    min-width: 0;
}

.items-table {
    width: 100%;
    min-width: 640px;
    border-collapse: collapse;
    background: var(--card-bg);
    border-radius: 12px;
    overflow: hidden;
    font-size: 14px;
}

.items-table thead th:nth-child(5) {
    text-align: center;
}

.items-table thead th:nth-child(3),
.items-table thead th:nth-child(4),
.items-table tbody td:nth-child(3),
.items-table tbody td:nth-child(4) {
    text-align: center;
}

.items-table thead th {
    background: #f1f5f9;
    color: var(--text-muted);
    font-size: 12.5px;
    font-weight: 700;
    text-align: left;
    padding: 10px 12px;
    white-space: nowrap;
    border-bottom: 1.5px solid var(--border-color);
}

.items-table tbody td {
    padding: 8px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

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

.items-table tbody tr:hover {
    background: #f8fafc;
}

/* คอลัมน์ "จำนวน": ตัวควบคุมจำนวนอยู่ซ้าย ส่วนป้ายแจ้งเตือนสต็อก (ใกล้หมด/ของหมด) + กระดิ่งตั้งค่า
   ให้ชิดขวาในแถวเดียวกัน แทนที่จะตกลงมาอยู่บรรทัดใหม่ด้านล่าง */
.qty-cell {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.qty-cell-right {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}

/* มือถือ (จอแคบ): กันป้าย "ใกล้หมด/ของหมด" ตกลงบรรทัดใหม่ ให้อยู่ชิดขวาในแถวเดียวกับ
   ข้อความจำนวนเสมอ — ไม่กระทบเลย์เอาต์บน PC ซึ่งพื้นที่กว้างพออยู่แล้ว */
@media (max-width: 900px) {
    .qty-cell {
        flex-wrap: nowrap;
    }

    .qty-cell .qty-badge-only {
        white-space: nowrap;
    }

    .qty-cell-right {
        flex-shrink: 0;
    }
}

.items-table tbody tr.stock-warning {
    background: #fffbeb;
    box-shadow: inset 4px 0 0 0 var(--warning-color);
}

.items-table tbody tr.stock-danger {
    background: #fef2f2;
    box-shadow: inset 4px 0 0 0 var(--danger-color);
}

.item-table-thumb {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
    cursor: pointer;
    background: #f8fafc;
    flex-shrink: 0;
}

.item-table-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ============================================================
   ขยาย "พื้นที่กด" ให้ใหญ่ขึ้นโดยหน้าตาเท่าเดิม (ส่วนที่ขยายมองไม่เห็น)
   ช่วยให้กดถูกแม้มือเปื้อน/ใส่ถุงมือ โดยไม่ทำให้การ์ดอ้วนขึ้น
   ============================================================ */
.btn-qty,
.btn-rename,
.btn-delete {
    position: relative;
}

.btn-qty::after {
    content: '';
    position: absolute;
    inset: -6px;
}

.btn-rename::after {
    content: '';
    position: absolute;
    top: -3px;
    bottom: -3px;
    left: -10px;
    right: -10px;
}

.btn-delete::after {
    content: '';
    position: absolute;
    inset: -6px -4px;
}

/* ============================================================
   ปุ่มกรอง "ใกล้หมด/หมด" (เห็นจำนวนรายการที่ต้องสั่งของทันที)
   ============================================================ */
.btn-lowstock {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 8px 14px;
    background: #ffffff;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    color: #334155;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.btn-lowstock .lowstock-count {
    min-width: 26px;
    padding: 1px 8px;
    border-radius: 12px;
    background: #e2e8f0;
    color: #334155;
    font-size: 14px;
    text-align: center;
}

.btn-lowstock.has-alert {
    border-color: var(--danger-strong);
    color: var(--danger-strong);
    background: #fef2f2;
}

.btn-lowstock.has-alert .lowstock-count {
    background: var(--danger-strong);
    color: #ffffff;
}

.btn-lowstock.active {
    background: var(--danger-strong);
    border-color: var(--danger-strong);
    color: #ffffff;
}

.btn-lowstock.active .lowstock-count {
    background: #ffffff;
    color: var(--danger-strong);
}

/* ============================================================
   [NEW] บรรทัด "ถูกยืมอยู่ X ชิ้น (ชื่อผู้ยืม)" บนการ์ด/ตาราง
   ============================================================ */
.borrowed-out {
    display: block;
    margin-top: 8px;
    padding: 6px 10px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 10px;
    color: #92400e;
    font-size: 13.5px;
    line-height: 1.45;
    white-space: normal;      /* ชื่อผู้ยืมยาว ให้ขึ้นบรรทัดใหม่ ไม่ถูกตัดด้วย ellipsis */
    overflow-wrap: anywhere;
}

.borrowed-out i {
    margin-right: 2px;
}

.borrowed-out-who {
    color: #475569;
    font-weight: 500;
}
