* { box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: #eef2f5; margin: 0; padding: 12px; color: #1c1e21; }
a { text-decoration: none; }
.hidden { display: none !important; }

.catalog-container { max-width: 1400px; margin: 0 auto; padding: 10px; }
header { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; background: #fff; padding: 16px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
h2 { margin: 0; font-size: 20px; color: #2c3e50; }
.header-actions { display: flex; gap: 10px; }
.btn-sm { background: #475f77; color: #fff; border: none; border-radius: 6px; padding: 8px 14px; cursor: pointer; font-weight: 600; font-size: 14px; display: flex; align-items: center; }
.btn-nav { background: #0288d1; }

.toolbar { display: flex; gap: 12px; margin-bottom: 20px; flex-direction: column; background: #fff; padding: 16px; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.05); }
.toolbar input, .toolbar select { padding: 12px; border: 2px solid #cbd5e1; border-radius: 6px; font-size: 15px; outline: none; min-width: 0; }
.toolbar input:focus, .toolbar select:focus { border-color: #3b82f6; }

#itemList { display: grid; grid-template-columns: 1fr; gap: 16px; }
.item-card { background: #fff; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,0.04); padding: 16px; display: flex; gap: 16px; cursor: pointer; border: 1px solid #e2e8f0; transition: transform 0.2s, border-color 0.2s; position: relative; }
.item-card:hover, .item-card:focus { transform: translateY(-3px); border-color: #94a3b8; outline: none; }
.item-card.is-historic { opacity: 0.7; filter: grayscale(45%); background: #f8fafc; }
.item-thumb { width: 100px; height: 100px; object-fit: cover; border-radius: 8px; border: 1px solid #e2e8f0; background: #f1f5f9; flex-shrink: 0; }
.item-info { flex: 1; overflow: hidden; display: flex; flex-direction: column; justify-content: center; }
.item-info h3 { margin: 0 0 6px; font-size: 16px; color: #1d4ed8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-info div { font-size: 13px; margin-bottom: 4px; color: #475569; }
.item-info strong { color: #0f172a; font-weight: 700; }
.badge-hist { margin-left: 8px; background: #fef08a; color: #854d0e; padding: 3px 7px; border-radius: 6px; font-size: 11px; font-weight: bold; border: 1px solid #fde047; }
.empty-state { grid-column: 1 / -1; background: #fff; border: 1px dashed #cbd5e1; color: #64748b; border-radius: 10px; padding: 28px; text-align: center; }
.error-state { color: #991b1b; background: #fef2f2; border-color: #fecaca; }

.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.85); display: none; align-items: center; justify-content: center; z-index: 200; padding: 16px; backdrop-filter: blur(4px); }
.modal { background: #fff; border-radius: 16px; width: 100%; max-height: 92vh; overflow-y: auto; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5); display: flex; flex-direction: column; }
.modal-content-wrapper { padding: 20px; }
.modal-content-wrapper h3 { margin-top: 0; color: #37474f; }
.modal-left-col { padding: 20px; background: #f8fafc; }
#modalImage { width: 100%; height: 250px; object-fit: contain; border-radius: 8px; background: #f1f5f9; margin-bottom: 16px; border: 1px solid #e2e8f0; }
.modal-nav { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 18px; }
.modal-nav button { flex: 1; padding: 10px 20px; font-size: 15px; background: #3b82f6; color: #fff; border: none; border-radius: 8px; cursor: pointer; }
.modal-nav button:disabled { background: #cbd5e1; cursor: not-allowed; }

.qr-panel { border-top: 1px solid #e2e8f0; padding-top: 16px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.qr-panel img { width: 180px; height: 180px; background: #fff; border: 1px solid #cbd5e1; border-radius: 8px; padding: 6px; }
.qr-panel strong { font-size: 17px; color: #0f172a; word-break: break-all; }
.qr-panel small { color: #64748b; max-width: 300px; line-height: 1.35; }
.btn-print { background: #475f77; color: #fff; border: none; border-radius: 7px; padding: 10px 14px; font-weight: 700; cursor: pointer; }

.modal-fields { display: flex; flex-direction: column; gap: 12px; }
.field-group { display: flex; flex-direction: column; gap: 4px; }
.field-group label { font-size: 12px; font-weight: 700; color: #64748b; text-transform: uppercase; }
.field-group .val-readonly { font-size: 16px; font-weight: 600; color: #0f172a; padding: 10px; background: #f8fafc; border-radius: 8px; border: 1px dashed #cbd5e1; min-height: 44px; }
.field-group input, .field-group select { padding: 12px; border: 2px solid #cbd5e1; border-radius: 8px; font-size: 16px; color: #1e293b; background: #fff; outline: none; }
.field-group input:focus, .field-group select:focus { border-color: #3b82f6; }

.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 24px; border-top: 1px solid #e2e8f0; padding-top: 20px; }
.btn-save { background: #16a34a; color: #fff; padding: 14px; border: none; border-radius: 8px; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn-save:disabled { opacity: 0.6; cursor: wait; }
.close-btn { background: #64748b; color: #fff; padding: 14px; border: none; border-radius: 8px; cursor: pointer; font-size: 16px; font-weight: 600; }
.history-banner { background: #ffedd5; color: #9a3412; padding: 10px; border-radius: 6px; margin-bottom: 15px; font-weight: bold; text-align: center; }

.overlay { position: fixed; inset: 0; background: rgba(15,23,42,0.9); display: flex; align-items: center; justify-content: center; z-index: 1000; padding: 16px; }
.login-card { background: #fff; padding: 32px; border-radius: 16px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 16px; }
.login-card h3 { margin: 0; color: #0f172a; text-align: center; font-size: 22px; }
.login-card input { padding: 12px; border: 2px solid #cbd5e1; border-radius: 8px; font-size: 16px; }

@media (min-width: 640px) {
    #itemList { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .modal-actions { flex-direction: row; justify-content: flex-end; }
    .modal-actions button { width: auto; min-width: 160px; }
}

@media (min-width: 900px) {
    header h2 { font-size: 26px; }
    .toolbar { flex-direction: row; }
    .toolbar input { flex: 2; }
    .toolbar select { flex: 1; }
    #itemList { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }

    .modal { max-width: 1050px; flex-direction: row; align-items: stretch; overflow: hidden; }
    .modal-content-wrapper { flex: 1; padding: 32px; overflow-y: auto; }
    .modal-left-col { width: 400px; padding: 24px; border-right: 1px solid #e2e8f0; overflow-y: auto; }
    #modalImage { height: 330px; }
    .modal-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
    .field-group.full-width { grid-column: 1 / -1; }
}

@media (min-width: 1280px) {
    #itemList { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 24px; }
    .item-card { padding: 20px; }
    .item-thumb { width: 120px; height: 120px; }
    .modal { max-width: 1180px; }
    .modal-left-col { width: 460px; padding: 32px; }
}
